From 3fef60b2dfa25e703b65c90c2f359d1006e52b6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Fri, 16 Oct 2020 11:21:51 +0200 Subject: [PATCH 1/3] test, cmake: Add option to disable evm-test tool --- test/CMakeLists.txt | 7 +++++-- test/unittests/CMakeLists.txt | 11 +++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 27cf18ffc5..229582a9b2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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) @@ -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 $) 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 $) + endif() endif() diff --git a/test/unittests/CMakeLists.txt b/test/unittests/CMakeLists.txt index a989e6f830..29bd84fd2c 100644 --- a/test/unittests/CMakeLists.txt +++ b/test/unittests/CMakeLists.txt @@ -1,5 +1,5 @@ # 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) @@ -30,9 +30,12 @@ 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( From 0596f06474c06b62f6f8824e0240b491d3ff7e43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Fri, 16 Oct 2020 11:25:36 +0200 Subject: [PATCH 2/3] test, cmake: Drop evm-unittests OBJECT library --- test/unittests/CMakeLists.txt | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/test/unittests/CMakeLists.txt b/test/unittests/CMakeLists.txt index 29bd84fd2c..09c59bd6dc 100644 --- a/test/unittests/CMakeLists.txt +++ b/test/unittests/CMakeLists.txt @@ -5,27 +5,21 @@ 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.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/) From c292236d829bad4cc4a9627b3499a97344ead8ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Fri, 16 Oct 2020 11:36:05 +0200 Subject: [PATCH 3/3] test: Drop vm_loader.hpp --- test/unittests/CMakeLists.txt | 2 +- test/unittests/evm_calls_test.cpp | 4 ++-- .../{vm_loader_evmone.cpp => evm_fixture.cpp} | 7 +++++-- test/unittests/evm_fixture.hpp | 10 +++++++--- test/unittests/evm_other_test.cpp | 5 ++--- test/unittests/evm_state_test.cpp | 4 ++-- test/unittests/evm_test.cpp | 3 ++- test/unittests/vm_loader.hpp | 8 -------- 8 files changed, 21 insertions(+), 22 deletions(-) rename test/unittests/{vm_loader_evmone.cpp => evm_fixture.cpp} (64%) delete mode 100644 test/unittests/vm_loader.hpp diff --git a/test/unittests/CMakeLists.txt b/test/unittests/CMakeLists.txt index 09c59bd6dc..59b26b4e4f 100644 --- a/test/unittests/CMakeLists.txt +++ b/test/unittests/CMakeLists.txt @@ -9,6 +9,7 @@ find_package(GTest CONFIG REQUIRED) add_executable(evmone-unittests analysis_test.cpp bytecode_test.cpp + evm_fixture.cpp evm_fixture.hpp evm_test.cpp evm_calls_test.cpp @@ -17,7 +18,6 @@ add_executable(evmone-unittests evmone_test.cpp op_table_test.cpp utils_test.cpp - vm_loader_evmone.cpp ) 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}) diff --git a/test/unittests/evm_calls_test.cpp b/test/unittests/evm_calls_test.cpp index 548a015f00..caf82d2152 100644 --- a/test/unittests/evm_calls_test.cpp +++ b/test/unittests/evm_calls_test.cpp @@ -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 perform any kind of calls. @@ -7,7 +7,7 @@ #include "evm_fixture.hpp" using namespace evmc::literals; -using evm_calls = evm; +using evm_calls = evmone::test::evm; TEST_F(evm_calls, delegatecall) { diff --git a/test/unittests/vm_loader_evmone.cpp b/test/unittests/evm_fixture.cpp similarity index 64% rename from test/unittests/vm_loader_evmone.cpp rename to test/unittests/evm_fixture.cpp index 1a7581f97d..089b5197e5 100644 --- a/test/unittests/vm_loader_evmone.cpp +++ b/test/unittests/evm_fixture.cpp @@ -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 +namespace evmone::test +{ evmc::VM& get_vm() noexcept { static auto vm = evmc::VM{evmc_create_evmone()}; return vm; } +} // namespace evmone::test diff --git a/test/unittests/evm_fixture.hpp b/test/unittests/evm_fixture.hpp index df54e56c0a..1b97c095d9 100644 --- a/test/unittests/evm_fixture.hpp +++ b/test/unittests/evm_fixture.hpp @@ -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 #include #include @@ -27,6 +25,11 @@ EXPECT_EQ(hex({result.output_data, result.output_size}), \ hex({intx::be::store(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 { @@ -97,3 +100,4 @@ class evm : public testing::Test execute({code.data(), code.size()}, input_hex); } }; +} // namespace evmone::test diff --git a/test/unittests/evm_other_test.cpp b/test/unittests/evm_other_test.cpp index c99ed1096c..3fd8b293a7 100644 --- a/test/unittests/evm_other_test.cpp +++ b/test/unittests/evm_other_test.cpp @@ -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: @@ -8,10 +8,9 @@ /// - evmone's internal tests. #include "evm_fixture.hpp" - #include -using evm_other = evm; +using evm_other = evmone::test::evm; TEST_F(evm_other, evmone_loaded_program_relocation) { diff --git a/test/unittests/evm_state_test.cpp b/test/unittests/evm_state_test.cpp index 4b9b00e51f..4dd6efd8d4 100644 --- a/test/unittests/evm_state_test.cpp +++ b/test/unittests/evm_state_test.cpp @@ -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 @@ -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) { diff --git a/test/unittests/evm_test.cpp b/test/unittests/evm_test.cpp index bee800a65b..c914f11752 100644 --- a/test/unittests/evm_test.cpp +++ b/test/unittests/evm_test.cpp @@ -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" @@ -11,6 +11,7 @@ using namespace evmc::literals; using namespace intx; +using evmone::test::evm; TEST_F(evm, empty) { diff --git a/test/unittests/vm_loader.hpp b/test/unittests/vm_loader.hpp deleted file mode 100644 index a5523725eb..0000000000 --- a/test/unittests/vm_loader.hpp +++ /dev/null @@ -1,8 +0,0 @@ -// evmone: Fast Ethereum Virtual Machine implementation -// Copyright 2019 The evmone Authors. -// SPDX-License-Identifier: Apache-2.0 -#pragma once - -#include - -evmc::VM& get_vm() noexcept;