forked from ethereum/evmone
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ethereum#204 from ethereum/loader-tests
Loader unit tests
- Loading branch information
Showing
8 changed files
with
152 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,19 @@ | ||
# EVMC: Ethereum Client-VM Connector API. | ||
# Copyright 2018 The EVMC Authors. | ||
# Licensed under the Apache License, Version 2.0. See the LICENSE file. | ||
# Copyright 2019 The EVMC Authors. | ||
# Licensed under the Apache License, Version 2.0. | ||
|
||
add_library(vm-mock SHARED vm_mock.c) | ||
target_link_libraries(vm-mock PRIVATE evmc) | ||
|
||
add_library(vm-mock-default SHARED vm_mock_default.c) | ||
target_link_libraries(vm-mock-default PRIVATE evmc) | ||
|
||
|
||
if(UNIX) | ||
set(cmd create_symlink) | ||
else() | ||
set(cmd copy) | ||
endif() | ||
|
||
add_custom_command( | ||
TARGET vm-mock POST_BUILD | ||
|
||
COMMAND ${CMAKE_COMMAND} -E ${cmd} $<TARGET_FILE:vm-mock> libaaa.so | ||
COMMAND ${CMAKE_COMMAND} -E ${cmd} $<TARGET_FILE:vm-mock> double_prefix_aaa.evm | ||
COMMAND ${CMAKE_COMMAND} -E ${cmd} $<TARGET_FILE:vm-mock> double-prefix-aaa.evm | ||
COMMAND ${CMAKE_COMMAND} -E ${cmd} $<TARGET_FILE:vm-mock> eee-bbb.dll | ||
COMMAND ${CMAKE_COMMAND} -E ${cmd} $<TARGET_FILE:vm-mock> libeee1.so | ||
COMMAND ${CMAKE_COMMAND} -E ${cmd} $<TARGET_FILE:vm-mock> eee2.so | ||
COMMAND ${CMAKE_COMMAND} -E ${cmd} $<TARGET_FILE:vm-mock> libeee3.x | ||
COMMAND ${CMAKE_COMMAND} -E ${cmd} $<TARGET_FILE:vm-mock> eee4 | ||
COMMAND ${CMAKE_COMMAND} -E ${cmd} $<TARGET_FILE:vm-mock> _ | ||
COMMAND ${CMAKE_COMMAND} -E ${cmd} $<TARGET_FILE:vm-mock> lib_.so | ||
COMMAND ${CMAKE_COMMAND} -E ${cmd} $<TARGET_FILE:vm-mock> ../aaa.evm | ||
COMMAND ${CMAKE_COMMAND} -E ${cmd} $<TARGET_FILE:vm-mock> failure.vm | ||
COMMAND ${CMAKE_COMMAND} -E ${cmd} $<TARGET_FILE:vm-mock> abi42.vm | ||
|
||
COMMAND ${CMAKE_COMMAND} -E ${cmd} $<TARGET_FILE:vm-mock-default> default.evmc | ||
|
||
COMMAND ${CMAKE_COMMAND} -E touch empty.file | ||
) | ||
add_library(loader-mocked STATIC ${PROJECT_SOURCE_DIR}/lib/loader/loader.c) | ||
target_link_libraries(loader-mocked PRIVATE evmc) | ||
target_compile_definitions(loader-mocked PRIVATE EVMC_LOADER_MOCK=1) | ||
|
||
add_executable( | ||
evmc-test | ||
loader_mock.h | ||
test_cpp.cpp | ||
test_helpers.cpp | ||
test_instructions.cpp | ||
test_loader.cpp | ||
) | ||
|
||
target_link_libraries(evmc-test PRIVATE evmc-example-vm instructions loader GTest::gtest GTest::main) | ||
target_link_libraries(evmc-test PRIVATE loader-mocked evmc-example-vm instructions GTest::gtest GTest::main) | ||
set_target_properties(evmc-test PROPERTIES RUNTIME_OUTPUT_DIRECTORY ..) | ||
add_dependencies(evmc-test vm-mock) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* EVMC: Ethereum Client-VM Connector API. | ||
* Copyright 2019 The EVMC Authors. | ||
* Licensed under the Apache License, Version 2.0. | ||
*/ | ||
|
||
/** | ||
* @file | ||
* The loader OS mock for opening DLLs. To be inserted in loader.c for unit tests. | ||
*/ | ||
|
||
static const int magic_handle = 0xE7AC; | ||
|
||
const char* evmc_test_library_path = NULL; | ||
const char* evmc_test_library_symbol = NULL; | ||
evmc_create_fn evmc_test_create_fn = NULL; | ||
|
||
static int evmc_test_load_library(const char* filename) | ||
{ | ||
if (filename && evmc_test_library_path && strcmp(filename, evmc_test_library_path) == 0) | ||
return magic_handle; | ||
return 0; | ||
} | ||
|
||
static void evmc_test_free_library(int handle) | ||
{ | ||
(void)handle; | ||
} | ||
|
||
static evmc_create_fn evmc_test_get_symbol_address(int handle, const char* symbol) | ||
{ | ||
if (handle != magic_handle) | ||
return NULL; | ||
|
||
if (evmc_test_library_symbol && strcmp(symbol, evmc_test_library_symbol) == 0) | ||
return evmc_test_create_fn; | ||
return NULL; | ||
} | ||
|
||
#define DLL_HANDLE int | ||
#define DLL_OPEN(filename) evmc_test_load_library(filename) | ||
#define DLL_CLOSE(handle) evmc_test_free_library(handle) | ||
#define DLL_GET_CREATE_FN(handle, name) evmc_test_get_symbol_address(handle, name) |
Oops, something went wrong.