Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unittest tools #262

Merged
merged 3 commits into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ add_subdirectory(bench)
add_subdirectory(internal_benchmarks)
add_subdirectory(unittests)

set(targets evm-test evmone-bench evmone-bench-internal evmone-unittests testutils)
set(targets evmone-bench evmone-bench-internal evmone-unittests testutils)

if(EVMONE_FUZZING)
add_subdirectory(fuzzer)
Expand All @@ -31,6 +31,9 @@ set_target_properties(

get_target_property(type evmone TYPE)
if(type STREQUAL SHARED_LIBRARY)
add_test(NAME ${PROJECT_NAME}/evm-test COMMAND evm-test $<TARGET_FILE:evmone>)
evmc_add_vm_test(NAME ${PROJECT_NAME}/evmc-vmtester TARGET evmone)

if(TARGET evm-test)
add_test(NAME ${PROJECT_NAME}/evm-test COMMAND evm-test $<TARGET_FILE:evmone>)
endif()
endif()
29 changes: 13 additions & 16 deletions test/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,38 +1,35 @@
# evmone: Fast Ethereum Virtual Machine implementation
# Copyright 2018-2019 The evmone Authors.
# Copyright 2018-2020 The evmone Authors.
# SPDX-License-Identifier: Apache-2.0

hunter_add_package(GTest)
find_package(GTest CONFIG REQUIRED)

# The evm-unittests library contains generic EVM unit tests for EVMC-compatible VMs.
add_library(evm-unittests OBJECT
# The internal evmone unit tests. The generic EVM ones are also built in.
add_executable(evmone-unittests
analysis_test.cpp
bytecode_test.cpp
evm_fixture.cpp
evm_fixture.hpp
evm_test.cpp
evm_calls_test.cpp
evm_state_test.cpp
evm_other_test.cpp
)
target_link_libraries(evm-unittests PRIVATE testutils evmc::mocked_host GTest::gtest)
target_include_directories(evm-unittests PRIVATE ${evmone_private_include_dir})

# The internal evmone unit tests. The generic EVM ones are also built in.
add_executable(evmone-unittests
analysis_test.cpp
bytecode_test.cpp
evmone_test.cpp
op_table_test.cpp
utils_test.cpp
vm_loader_evmone.cpp
)
target_link_libraries(evmone-unittests PRIVATE evm-unittests evmone testutils evmc::instructions GTest::gtest GTest::gtest_main)
target_link_libraries(evmone-unittests PRIVATE evmone testutils evmc::instructions GTest::gtest GTest::gtest_main)
target_include_directories(evmone-unittests PRIVATE ${evmone_private_include_dir})

gtest_discover_tests(evmone-unittests TEST_PREFIX ${PROJECT_NAME}/unittests/)

# The evm-test tool that contains the all evm-unittests and loads VMs as EVMC modules.
add_executable(evm-test main.cpp)
target_link_libraries(evm-test PRIVATE evm-unittests testutils evmc::evmc evmc::loader GTest::gtest)
option(EVMONE_EVM_TEST_TOOL "Enable EVM unit testing tool for EVMC implementations (not maintained)" OFF)
if(EVMONE_EVM_TEST_TOOL)
# The evm-test tool that contains the all evm-unittests and loads VMs as EVMC modules.
add_executable(evm-test main.cpp)
target_link_libraries(evm-test PRIVATE evm-unittests testutils evmc::evmc evmc::loader GTest::gtest)
endif()

# Provide the project version to selected source files.
set_source_files_properties(
Expand Down
4 changes: 2 additions & 2 deletions test/unittests/evm_calls_test.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// evmone: Fast Ethereum Virtual Machine implementation
// Copyright 2019 The evmone Authors.
// Copyright 2019-2020 The evmone Authors.
// SPDX-License-Identifier: Apache-2.0

/// This file contains EVM unit tests that perform any kind of calls.

#include "evm_fixture.hpp"

using namespace evmc::literals;
using evm_calls = evm;
using evm_calls = evmone::test::evm;

TEST_F(evm_calls, delegatecall)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// evmone: Fast Ethereum Virtual Machine implementation
// Copyright 2019 The evmone Authors.
// Copyright 2019-2020 The evmone Authors.
// SPDX-License-Identifier: Apache-2.0

#include "vm_loader.hpp"
#include "evm_fixture.hpp"
#include <evmone/evmone.h>

namespace evmone::test
{
evmc::VM& get_vm() noexcept
{
static auto vm = evmc::VM{evmc_create_evmone()};
return vm;
}
} // namespace evmone::test
10 changes: 7 additions & 3 deletions test/unittests/evm_fixture.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// evmone: Fast Ethereum Virtual Machine implementation
// Copyright 2019 The evmone Authors.
// Copyright 2019-2020 The evmone Authors.
// SPDX-License-Identifier: Apache-2.0
#pragma once

#include "vm_loader.hpp"

#include <evmc/mocked_host.hpp>
#include <gtest/gtest.h>
#include <intx/intx.hpp>
Expand All @@ -27,6 +25,11 @@
EXPECT_EQ(hex({result.output_data, result.output_size}), \
hex({intx::be::store<evmc_bytes32>(intx::uint256{X}).bytes, sizeof(evmc_bytes32)}))


namespace evmone::test
{
evmc::VM& get_vm() noexcept;

/// The "evm" test fixture with generic unit tests for EVMC-compatible VM implementations.
class evm : public testing::Test
{
Expand Down Expand Up @@ -97,3 +100,4 @@ class evm : public testing::Test
execute({code.data(), code.size()}, input_hex);
}
};
} // namespace evmone::test
5 changes: 2 additions & 3 deletions test/unittests/evm_other_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// evmone: Fast Ethereum Virtual Machine implementation
// Copyright 2019 The evmone Authors.
// Copyright 2019-2020 The evmone Authors.
// SPDX-License-Identifier: Apache-2.0

/// This file contains non-mainstream EVM unit tests not matching any concrete category:
Expand All @@ -8,10 +8,9 @@
/// - evmone's internal tests.

#include "evm_fixture.hpp"

#include <evmone/limits.hpp>

using evm_other = evm;
using evm_other = evmone::test::evm;

TEST_F(evm_other, evmone_loaded_program_relocation)
{
Expand Down
4 changes: 2 additions & 2 deletions test/unittests/evm_state_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// evmone: Fast Ethereum Virtual Machine implementation
// Copyright 2019 The evmone Authors.
// Copyright 2019-2020 The evmone Authors.
// SPDX-License-Identifier: Apache-2.0

/// This file contains EVM unit tests that access or modify Ethereum state
Expand All @@ -8,7 +8,7 @@
#include "evm_fixture.hpp"

using namespace evmc::literals;
using evm_state = evm;
using evm_state = evmone::test::evm;

TEST_F(evm_state, code)
{
Expand Down
3 changes: 2 additions & 1 deletion test/unittests/evm_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// evmone: Fast Ethereum Virtual Machine implementation
// Copyright 2019 The evmone Authors.
// Copyright 2019-2020 The evmone Authors.
// SPDX-License-Identifier: Apache-2.0

#include "evm_fixture.hpp"
Expand All @@ -11,6 +11,7 @@

using namespace evmc::literals;
using namespace intx;
using evmone::test::evm;

TEST_F(evm, empty)
{
Expand Down
8 changes: 0 additions & 8 deletions test/unittests/vm_loader.hpp

This file was deleted.