Skip to content

Commit

Permalink
Merge pull request #4110
Browse files Browse the repository at this point in the history
639ca3b core_tests: add --filter to select which tests to run (moneromooo-monero)
  • Loading branch information
luigi1111 committed Jul 27, 2018
2 parents f739a3c + 639ca3b commit ff01c3a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 20 deletions.
19 changes: 19 additions & 0 deletions src/common/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 2 additions & 0 deletions src/common/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions tests/core_tests/chaingen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
Expand Down
6 changes: 6 additions & 0 deletions tests/core_tests/chaingen_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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[])
Expand All @@ -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, [&]()
Expand All @@ -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);
Expand Down
21 changes: 1 addition & 20 deletions tests/performance_tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit ff01c3a

Please sign in to comment.