Skip to content

Commit

Permalink
bench: Modernize CLI parsing, ignore empty args
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Jan 19, 2021
1 parent bbd118f commit 9d10117
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
16 changes: 16 additions & 0 deletions test/bench/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
21 changes: 12 additions & 9 deletions test/bench/bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,11 @@ constexpr auto cli_parsing_error = -3;
std::tuple<int, std::vector<BenchmarkCase>> 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)
{
Expand All @@ -229,10 +229,10 @@ std::tuple<int, std::vector<BenchmarkCase>> 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)
{
Expand All @@ -246,11 +246,12 @@ std::tuple<int, std::vector<BenchmarkCase>> 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{
Expand All @@ -264,6 +265,8 @@ std::tuple<int, std::vector<BenchmarkCase>> parseargs(int argc, char** argv)

return {0, {std::move(b)}};
}

return {0, {}};
}
} // namespace
} // namespace evmone::test
Expand Down

0 comments on commit 9d10117

Please sign in to comment.