From 40c52edf260f60f782ab8cc84ffa3045c9608dea Mon Sep 17 00:00:00 2001 From: sowle Date: Mon, 15 Feb 2021 15:48:50 +0300 Subject: [PATCH] functional_tests: crypto_tests: tests wildcard filtering added --- tests/functional_tests/crypto_tests.cpp | 43 ++++++++++++++++++++++--- tests/functional_tests/crypto_tests.h | 2 +- tests/functional_tests/main.cpp | 6 ++-- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/tests/functional_tests/crypto_tests.cpp b/tests/functional_tests/crypto_tests.cpp index 565b1522..7539a74b 100644 --- a/tests/functional_tests/crypto_tests.cpp +++ b/tests/functional_tests/crypto_tests.cpp @@ -1394,10 +1394,38 @@ TEST(ml2s, hs) // test's runner // -int crypto_tests() +bool wildcard_match(const std::string& needle, const std::string& haystack) { - epee::log_space::get_set_log_detalisation_level(true, LOG_LEVEL_1); - epee::log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, LOG_LEVEL_2); + size_t h = 0; + for (size_t n = 0; n < needle.size(); ++n) + { + switch (needle[n]) + { + case '?': + if (h == haystack.size()) + return false; + ++h; + break; + case '*': + if (n + 1 == needle.size()) + return true; + for (size_t i = 0; i + h < haystack.size(); i++) + if (wildcard_match(needle.substr(n + 1), haystack.substr(h + i))) + return true; + return false; + default: + if (haystack[h] != needle[n]) + return false; + ++h; + } + } + return h == haystack.size(); +} + +int crypto_tests(const std::string& cmd_line_param) +{ + epee::log_space::get_set_log_detalisation_level(true, LOG_LEVEL_3); + epee::log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, LOG_LEVEL_3); epee::log_space::log_singletone::add_logger(LOGGER_FILE, epee::log_space::log_singletone::get_default_log_file().c_str(), epee::log_space::log_singletone::get_default_log_folder().c_str()); @@ -1408,6 +1436,11 @@ int crypto_tests() for (size_t i = 0; i < g_tests.size(); ++i) { auto& test = g_tests[i]; + + if (!wildcard_match(cmd_line_param.c_str(), test.first.c_str())) + continue; + + LOG_PRINT(" " << std::setw(40) << std::left << test.first << " >", LOG_LEVEL_0); TIME_MEASURE_START(runtime); bool r = false; try @@ -1427,11 +1460,11 @@ int crypto_tests() uint64_t runtime_mcs = runtime % 1000; if (r) { - LOG_PRINT_GREEN(" " << std::setw(40) << std::left << test.first << "OK [" << runtime_ms << "." << std::setw(3) << std::setfill('0') << runtime_mcs << " ms]", LOG_LEVEL_0); + LOG_PRINT_GREEN(" " << std::setw(40) << std::left << test.first << "OK [" << runtime_ms << "." << std::setw(3) << std::setfill('0') << runtime_mcs << " ms]", LOG_LEVEL_0); } else { - LOG_PRINT_RED(ENDL << " " << std::setw(40) << std::left << test.first << "FAILED" << ENDL, LOG_LEVEL_0); + LOG_PRINT_RED(ENDL << " " << std::setw(40) << std::left << test.first << "FAILED" << ENDL, LOG_LEVEL_0); failed_tests.push_back(i); } } diff --git a/tests/functional_tests/crypto_tests.h b/tests/functional_tests/crypto_tests.h index 492b27e0..16290dd4 100644 --- a/tests/functional_tests/crypto_tests.h +++ b/tests/functional_tests/crypto_tests.h @@ -3,4 +3,4 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #pragma once -int crypto_tests(); +int crypto_tests(const std::string& cmd_line_param); diff --git a/tests/functional_tests/main.cpp b/tests/functional_tests/main.cpp index 65acf07d..ed53cbe3 100644 --- a/tests/functional_tests/main.cpp +++ b/tests/functional_tests/main.cpp @@ -56,7 +56,7 @@ namespace const command_line::arg_descriptor arg_deadlock_guard = { "test-deadlock-guard", "Do deadlock guard test", false, true }; const command_line::arg_descriptor arg_difficulty_analysis = { "difficulty-analysis", "Do difficulty analysis", "", true }; const command_line::arg_descriptor arg_test_plain_wallet = { "test-plainwallet", "Do testing of plain wallet interface", false, true }; - const command_line::arg_descriptor arg_crypto_tests = { "crypto-tests", "Run experimental crypto tests", false, true }; + const command_line::arg_descriptor arg_crypto_tests = { "crypto-tests", "Run experimental crypto tests", "", true }; } @@ -212,9 +212,9 @@ int main(int argc, char* argv[]) } return 0; } - else if (command_line::get_arg(vm, arg_crypto_tests)) + else if (command_line::has_arg(vm, arg_crypto_tests)) { - return crypto_tests(); + return crypto_tests(command_line::get_arg(vm, arg_crypto_tests)); } else {