diff --git a/test/bench/CMakeLists.txt b/test/bench/CMakeLists.txt index 23f37cb121..875c7eb45e 100644 --- a/test/bench/CMakeLists.txt +++ b/test/bench/CMakeLists.txt @@ -38,3 +38,19 @@ if(NOT HAVE_STD_FILESYSTEM) elseif(UNIX AND NOT APPLE) target_link_libraries(evmone-bench PRIVATE stdc++fs) endif() + + +# Tests + +set(PREFIX evmone/bench) + +# Check if DIR argument works. +add_test(NAME ${PREFIX}/dir COMMAND evmone-bench ${CMAKE_CURRENT_SOURCE_DIR}/../benchmarks --benchmark_list_tests) + +# Empty DIR name should run no benchmarks. +add_test(NAME ${PREFIX}/dirname_empty COMMAND evmone-bench "" --benchmark_list_tests) +set_tests_properties(${PREFIX}/dirname_empty PROPERTIES PASS_REGULAR_EXPRESSION "Failed to match any benchmarks") + +# Missing DIR argument is an error. +add_test(NAME ${PREFIX}/no_dir COMMAND evmone-bench) +set_tests_properties(${PREFIX}/no_dir PROPERTIES PASS_REGULAR_EXPRESSION "DIR argument .* missing") diff --git a/test/bench/bench.cpp b/test/bench/bench.cpp index d5307ab9f6..ea72861e7f 100644 --- a/test/bench/bench.cpp +++ b/test/bench/bench.cpp @@ -201,11 +201,11 @@ constexpr auto cli_parsing_error = -3; std::tuple> parseargs(int argc, char** argv) { // Arguments' placeholders: - const char* evmc_config{}; - const char* benchmarks_dir{}; - const char* code_hex_file{}; - const char* input_hex{}; - const char* expected_output_hex{}; + std::string evmc_config; + std::string benchmarks_dir; + std::string code_hex_file; + std::string input_hex; + std::string expected_output_hex; switch (argc) { @@ -229,10 +229,10 @@ std::tuple> parseargs(int argc, char** argv) return {cli_parsing_error, {}}; } - if (evmc_config) + if (!evmc_config.empty()) { auto ec = evmc_loader_error_code{}; - registered_vms["external"] = evmc::VM{evmc_load_and_configure(evmc_config, &ec)}; + registered_vms["external"] = evmc::VM{evmc_load_and_configure(evmc_config.c_str(), &ec)}; if (ec != EVMC_LOADER_SUCCESS) { @@ -246,11 +246,12 @@ std::tuple> parseargs(int argc, char** argv) std::cout << "External VM: " << evmc_config << "\n"; } - if (benchmarks_dir) + if (!benchmarks_dir.empty()) { return {0, load_benchmarks_from_dir(benchmarks_dir)}; } - else + + if (!code_hex_file.empty()) { std::ifstream file{code_hex_file}; std::string code_hex{ @@ -264,6 +265,8 @@ std::tuple> parseargs(int argc, char** argv) return {0, {std::move(b)}}; } + + return {0, {}}; } } // namespace } // namespace evmone::test