JayBeams  0.1
Another project to have fun coding.
microbenchmark_group_main.cpp
Go to the documentation of this file.
2 
3 namespace jb {
4 namespace testing {
5 
7  int argc, char* argv[],
8  microbenchmark_group<microbenchmark_config> const& testcases) try {
9  // Create a default instance of the configuration ...
11  // ... parse the command-line arguments ...
12  cfg.process_cmdline(argc, argv);
13  // ... print out the test parameters ...
14  if (cfg.verbose()) {
15  JB_LOG(info) << "Configuration for test\n" << cfg << "\n";
16  }
17  // ... find out if the requested test case is in the list of known
18  // test cases ...
19  auto testcase = testcases.find(cfg.test_case());
20  // ... if not, print a usage message and terminate the test ...
21  if (testcase == testcases.end()) {
22  std::ostringstream os;
23  os << "Unknown test case (" << cfg.test_case() << ")\n";
24  os << " --test-case must be one of:";
25  for (auto const& i : testcases) {
26  os << " " << i.first << "\n";
27  }
28  throw jb::usage(os.str(), 1);
29  }
30  // ... run the test that was configured ...
31  testcase->second(cfg);
32  // ... exit with a success status ...
33  return 0;
34 } catch (...) {
36 }
37 
38 namespace detail {
40  // rethrow the current exception so we can obtain its type in the
41  // catch() blocks ...
42  throw;
43 } catch (jb::usage const& ex) {
44  std::cerr << "usage: " << ex.what() << std::endl;
45  return ex.exit_status();
46 } catch (std::exception const& ex) {
47  std::cerr << "standard exception raised: " << ex.what() << std::endl;
48  return 1;
49 } catch (...) {
50  std::cerr << "unknown exception raised" << std::endl;
51  return 1;
52 }
53 
54 } // namespace detail
55 
56 } // namespace testing
57 } // namespace jb
jb::config_attribute< microbenchmark_config, std::string > test_case
jb::config_attribute< microbenchmark_config, bool > verbose
int exit_status() const
Definition: usage.hpp:21
int microbenchmark_group_main(int argc, char *argv[], microbenchmark_group< microbenchmark_config > const &testcases)
Overload microbenchmark_group_main for jb::testing::microbenchmark_config.
std::map< std::string, std::function< void(config const &cfg)> > microbenchmark_group
Define a representation for a group of microbenchmarks.
A simple class to communicate the result of parsing the options.
Definition: usage.hpp:11
void process_cmdline(int &argc, char *argv[])
Process the command line.
#define JB_LOG(lvl)
Definition: log.hpp:70
The top-level namespace for the JayBeams library.
Definition: as_hhmmss.hpp:7