Skip to content

Commit

Permalink
Merge pull request #303 from ethereum/cmake_vmtester_helper
Browse files Browse the repository at this point in the history
cmake: Add helper for adding vmtester based VM test
  • Loading branch information
chfast authored Jul 23, 2019
2 parents 22ed657 + 2a2a732 commit 1a45ce6
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [6.3.0] - unreleased

- Added: [[#303](https://github.com/ethereum/evmc/pull/303)]
A CMake helper for running evmc-vmtester.
- Added: [[#313](https://github.com/ethereum/evmc/pull/313)]
The loader module introduces standardized EVMC module configuration string
which contains path to the module and additional options.
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/evmcConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/evmcConfigVersion.cmake
cmake/EVMC.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/evmc
)

Expand Down
4 changes: 3 additions & 1 deletion cmake/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/evmcTargets.cmake")
include(${CMAKE_CURRENT_LIST_DIR}/evmcTargets.cmake)
check_required_components(evmc)

include(${CMAKE_CURRENT_LIST_DIR}/EVMC.cmake)
18 changes: 18 additions & 0 deletions cmake/EVMC.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# EVMC: Ethereum Client-VM Connector API.
# Copyright 2019 The EVMC Authors.
# Licensed under the Apache License, Version 2.0.


# Adds a CMake test to check the given EVMC VM implementation with the evmc-vmtester tool.
#
# evmc_add_vm_test(NAME <test_name> TARGET <vm>)
# - NAME argument specifies the name of the added test,
# - TARGET argument specifies the CMake target being a shared library with EVMC VM implementation.
function(evmc_add_vm_test)
if(NOT TARGET evmc::evmc-vmtester)
message(FATAL_ERROR "The evmc-vmtester has not been installed with this EVMC package")
endif()

cmake_parse_arguments("" "" NAME;TARGET "" ${ARGN})
add_test(NAME ${_NAME} COMMAND $<TARGET_FILE:evmc::evmc-vmtester> $<TARGET_FILE:${_TARGET}>)
endfunction()
7 changes: 7 additions & 0 deletions examples/use_evmc_in_cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ find_package(evmc CONFIG REQUIRED)

add_executable(use_evmc_in_cmake use_evmc_in_cmake.c)
target_link_libraries(use_evmc_in_cmake PRIVATE evmc::evmc)



# Only for integration tests.
if(NOT COMMAND evmc_add_vm_test)
message(FATAL_ERROR "Function evmc_add_vm_test() not in EVMC.cmake module")
endif()
8 changes: 5 additions & 3 deletions test/vmtester/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@
# Copyright 2018-2019 The EVMC Authors.
# Licensed under the Apache License, Version 2.0.

include(EVMC)
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)
set_source_files_properties(vmtester.cpp PROPERTIES COMPILE_DEFINITIONS PROJECT_VERSION="${PROJECT_VERSION}")
add_executable(evmc::evmc-vmtester ALIAS evmc-vmtester)


install(TARGETS evmc-vmtester RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(TARGETS evmc-vmtester EXPORT evmcTargets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

set(prefix ${PROJECT_NAME}/vmtester)

add_test(NAME ${prefix}/examplevm COMMAND evmc-vmtester $<TARGET_FILE:evmc-example-vm>)
add_test(NAME ${prefix}/example_precompiles_vm COMMAND evmc-vmtester $<TARGET_FILE:evmc-example-precompiles-vm>)
evmc_add_vm_test(NAME ${prefix}/examplevm TARGET evmc-example-vm)
evmc_add_vm_test(NAME ${prefix}/example_precompiles_vm TARGET evmc-example-precompiles-vm)

add_test(NAME ${prefix}/help COMMAND evmc-vmtester --version --help)
set_tests_properties(${prefix}/help PROPERTIES PASS_REGULAR_EXPRESSION "Usage:")
Expand Down

0 comments on commit 1a45ce6

Please sign in to comment.