diff options
-rw-r--r-- | src/common/util.cpp | 19 | ||||
-rw-r--r-- | src/common/util.h | 2 | ||||
-rw-r--r-- | tests/core_tests/chaingen.h | 1 | ||||
-rw-r--r-- | tests/core_tests/chaingen_main.cpp | 6 | ||||
-rw-r--r-- | tests/performance_tests/main.cpp | 21 |
5 files changed, 29 insertions, 20 deletions
diff --git a/src/common/util.cpp b/src/common/util.cpp index 7d9d7b408..f644c573c 100644 --- a/src/common/util.cpp +++ b/src/common/util.cpp @@ -919,4 +919,23 @@ std::string get_nix_version_display_string() return {}; } } + + std::string glob_to_regex(const std::string &val) + { + std::string newval; + + bool escape = false; + for (char c: val) + { + if (c == '*') + newval += escape ? "*" : ".*"; + else if (c == '?') + newval += escape ? "?" : "."; + else if (c == '\\') + newval += '\\', escape = !escape; + else + newval += c; + } + return newval; + } } diff --git a/src/common/util.h b/src/common/util.h index a57a85fee..6ec901e7f 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -231,4 +231,6 @@ namespace tools bool is_hdd(const char *path); boost::optional<std::pair<uint32_t, uint32_t>> parse_subaddress_lookahead(const std::string& str); + + std::string glob_to_regex(const std::string &val); } diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h index 201da4fa0..bbc9edd19 100644 --- a/tests/core_tests/chaingen.h +++ b/tests/core_tests/chaingen.h @@ -664,6 +664,7 @@ inline bool do_replay_file(const std::string& filename) } #define GENERATE_AND_PLAY(genclass) \ + if (filter.empty() || boost::regex_match(std::string(#genclass), match, boost::regex(filter))) \ { \ std::vector<test_event_entry> events; \ ++tests_count; \ diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp index 6a1992cd1..c31655070 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -30,6 +30,7 @@ #include "chaingen.h" #include "chaingen_tests_list.h" +#include "common/util.h" #include "common/command_line.h" #include "transaction_tests.h" @@ -42,6 +43,7 @@ namespace const command_line::arg_descriptor<bool> arg_play_test_data = {"play_test_data", ""}; const command_line::arg_descriptor<bool> arg_generate_and_play_test_data = {"generate_and_play_test_data", ""}; const command_line::arg_descriptor<bool> arg_test_transactions = {"test_transactions", ""}; + const command_line::arg_descriptor<std::string> arg_filter = { "filter", "Regular expression filter for which tests to run" }; } int main(int argc, char* argv[]) @@ -61,6 +63,7 @@ int main(int argc, char* argv[]) command_line::add_arg(desc_options, arg_play_test_data); command_line::add_arg(desc_options, arg_generate_and_play_test_data); command_line::add_arg(desc_options, arg_test_transactions); + command_line::add_arg(desc_options, arg_filter); po::variables_map vm; bool r = command_line::handle_error_helper(desc_options, [&]() @@ -78,6 +81,9 @@ int main(int argc, char* argv[]) return 0; } + const std::string filter = tools::glob_to_regex(command_line::get_arg(vm, arg_filter)); + boost::smatch match; + size_t tests_count = 0; std::vector<std::string> failed_tests; std::string tests_folder = command_line::get_arg(vm, arg_test_data_path); diff --git a/tests/performance_tests/main.cpp b/tests/performance_tests/main.cpp index 902bd89c0..bc3622ea8 100644 --- a/tests/performance_tests/main.cpp +++ b/tests/performance_tests/main.cpp @@ -54,25 +54,6 @@ namespace po = boost::program_options; -std::string glob_to_regex(const std::string &val) -{ - std::string newval; - - bool escape = false; - for (char c: val) - { - if (c == '*') - newval += escape ? "*" : ".*"; - else if (c == '?') - newval += escape ? "?" : "."; - else if (c == '\\') - newval += '\\', escape = !escape; - else - newval += c; - } - return newval; -} - int main(int argc, char** argv) { TRY_ENTRY(); @@ -97,7 +78,7 @@ int main(int argc, char** argv) if (!r) return 1; - const std::string filter = glob_to_regex(command_line::get_arg(vm, arg_filter)); + const std::string filter = tools::glob_to_regex(command_line::get_arg(vm, arg_filter)); performance_timer timer; timer.start(); |