mirror of https://github.com/status-im/evmc.git
Merge pull request #463 from ethereum/vmtester
Refactoring and CMake changes around vmtester
This commit is contained in:
commit
36d9f14307
|
@ -9,23 +9,27 @@ if(TARGET evmc)
|
|||
return()
|
||||
endif()
|
||||
|
||||
option(EVMC_INSTALL "Enable EVMC installation (e.g. make install)" ON)
|
||||
option(EVMC_TESTING "Build EVMC examples, tests and test tools (i.e. everything)" OFF)
|
||||
option(EVMC_TEST_TOOLS "Build EVMC test tools" ${EVMC_TESTING})
|
||||
if(EVMC_TESTING OR EVMC_TEST_TOOLS)
|
||||
set(hunter_and_examples_required TRUE)
|
||||
endif()
|
||||
option(EVMC_EXAMPLES "Build EVMC examples" ${hunter_and_examples_required})
|
||||
option(HUNTER_ENABLED "Enable Hunter package manager support" ${hunter_and_examples_required})
|
||||
|
||||
include(cmake/cable/bootstrap.cmake)
|
||||
include(CableBuildType)
|
||||
include(CableCompilerSettings)
|
||||
include(CMakeDependentOption)
|
||||
include(CablePackage)
|
||||
include(CableToolchains)
|
||||
include(CMakePackageConfigHelpers)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
option(EVMC_INSTALL "Enable EVMC installation (e.g. make install)" ON)
|
||||
|
||||
option(EVMC_TESTING "Build everything (libraries, tools, examples, internal tests)" OFF)
|
||||
|
||||
cmake_dependent_option(EVMC_TOOLS "Build EVMC tools" OFF
|
||||
"NOT EVMC_TESTING" ON)
|
||||
|
||||
cmake_dependent_option(EVMC_EXAMPLES "Build EVMC examples" OFF
|
||||
"NOT EVMC_TESTING" ON)
|
||||
|
||||
option(HUNTER_ENABLED "Enable Hunter package manager support" ${EVMC_TOOLS})
|
||||
|
||||
if(HUNTER_ENABLED)
|
||||
set(HUNTER_CONFIGURATION_TYPES Release CACHE STRING "Build type of Hunter packages")
|
||||
include(HunterGate)
|
||||
|
@ -53,7 +57,7 @@ if(EVMC_TESTING)
|
|||
enable_testing()
|
||||
endif()
|
||||
|
||||
if(EVMC_TESTING OR EVMC_TEST_TOOLS)
|
||||
if(EVMC_TESTING OR EVMC_TOOLS)
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ include(GNUInstallDirs)
|
|||
|
||||
add_executable(evmc-vmtester vmtester.hpp vmtester.cpp tests.cpp)
|
||||
set_target_properties(evmc-vmtester PROPERTIES RUNTIME_OUTPUT_DIRECTORY ..)
|
||||
target_link_libraries(evmc-vmtester PRIVATE evmc loader evmc-example-host GTest::gtest)
|
||||
target_link_libraries(evmc-vmtester PRIVATE evmc::loader evmc::mocked_host GTest::gtest)
|
||||
set_source_files_properties(vmtester.cpp PROPERTIES COMPILE_DEFINITIONS PROJECT_VERSION="${PROJECT_VERSION}")
|
||||
add_executable(evmc::evmc-vmtester ALIAS evmc-vmtester)
|
||||
|
||||
|
|
|
@ -2,30 +2,25 @@
|
|||
// Copyright 2018-2019 The EVMC Authors.
|
||||
// Licensed under the Apache License, Version 2.0.
|
||||
|
||||
#include "../../examples/example_host.h"
|
||||
#include "vmtester.hpp"
|
||||
|
||||
#include <evmc/evmc.hpp>
|
||||
|
||||
#include <evmc/mocked_host.hpp>
|
||||
#include <array>
|
||||
#include <cstring>
|
||||
|
||||
namespace
|
||||
{
|
||||
// NOTE: this is to avoid compiler optimisations when reading the buffer
|
||||
uint8_t read_uint8(const volatile uint8_t* p)
|
||||
uint8_t read_uint8(const volatile uint8_t* p) noexcept
|
||||
{
|
||||
return *p;
|
||||
}
|
||||
|
||||
void read_buffer(const uint8_t* ptr, size_t size)
|
||||
void read_buffer(const uint8_t* ptr, size_t size) noexcept
|
||||
{
|
||||
for (size_t i = 0; i < size; i++)
|
||||
{
|
||||
read_uint8(&ptr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_F(evmc_vm_test, abi_version_match)
|
||||
|
@ -59,13 +54,13 @@ TEST_F(evmc_vm_test, capabilities)
|
|||
|
||||
TEST_F(evmc_vm_test, execute_call)
|
||||
{
|
||||
const evmc_host_interface* host = example_host_get_interface();
|
||||
evmc_host_context* context = example_host_create_context(evmc_tx_context{});
|
||||
evmc::MockedHost mockedHost;
|
||||
evmc_message msg{};
|
||||
std::array<uint8_t, 2> code = {{0xfe, 0x00}};
|
||||
|
||||
evmc_result result =
|
||||
vm->execute(vm, host, context, EVMC_MAX_REVISION, &msg, code.data(), code.size());
|
||||
vm->execute(vm, &evmc::MockedHost::get_interface(), mockedHost.to_context(),
|
||||
EVMC_MAX_REVISION, &msg, code.data(), code.size());
|
||||
|
||||
// Validate some constraints
|
||||
if (result.status_code != EVMC_SUCCESS && result.status_code != EVMC_REVERT)
|
||||
|
@ -87,21 +82,19 @@ TEST_F(evmc_vm_test, execute_call)
|
|||
|
||||
if (result.release != nullptr)
|
||||
result.release(&result);
|
||||
|
||||
example_host_destroy_context(context);
|
||||
}
|
||||
|
||||
TEST_F(evmc_vm_test, execute_create)
|
||||
{
|
||||
const evmc_host_interface* host = example_host_get_interface();
|
||||
evmc_host_context* context = example_host_create_context(evmc_tx_context{});
|
||||
evmc::MockedHost mockedHost;
|
||||
evmc_message msg{
|
||||
EVMC_CREATE, 0, 0, 65536, evmc_address{}, evmc_address{}, nullptr, 0, evmc_uint256be{},
|
||||
evmc_bytes32{}};
|
||||
std::array<uint8_t, 2> code = {{0xfe, 0x00}};
|
||||
|
||||
evmc_result result =
|
||||
vm->execute(vm, host, context, EVMC_MAX_REVISION, &msg, code.data(), code.size());
|
||||
vm->execute(vm, &evmc::MockedHost::get_interface(), mockedHost.to_context(),
|
||||
EVMC_MAX_REVISION, &msg, code.data(), code.size());
|
||||
|
||||
// Validate some constraints
|
||||
if (result.status_code != EVMC_SUCCESS && result.status_code != EVMC_REVERT)
|
||||
|
@ -124,8 +117,6 @@ TEST_F(evmc_vm_test, execute_create)
|
|||
|
||||
if (result.release != nullptr)
|
||||
result.release(&result);
|
||||
|
||||
example_host_destroy_context(context);
|
||||
}
|
||||
|
||||
TEST_F(evmc_vm_test, set_option_unknown_name)
|
||||
|
|
Loading…
Reference in New Issue