mirror of
https://github.com/google/benchmark.git
synced 2024-12-27 04:50:19 +08:00
Add tests for reporters (#307)
* Test bytes_per_second and items_per_second. * Test SetLabel. * Reformat. * Make State::error_occurred_ private. * Fix tests with floats. * Merge private blocks
This commit is contained in:
parent
8e08aa75d9
commit
0064c56abd
@ -431,8 +431,6 @@ class State {
|
||||
|
||||
int complexity_n_;
|
||||
|
||||
public:
|
||||
// FIXME: Make this private somehow.
|
||||
bool error_occurred_;
|
||||
|
||||
public:
|
||||
|
@ -40,7 +40,13 @@ SubMap& GetSubstitutions() {
|
||||
{"%console_report", "[ ]*[0-9]{1,5} ns [ ]*[0-9]{1,5} ns [ ]*[0-9]+"},
|
||||
{"%console_us_report", "[ ]*[0-9] us [ ]*[0-9] us [ ]*[0-9]+"},
|
||||
{"%csv_report", "[0-9]+," + dec_re + "," + dec_re + ",ns,,,,,"},
|
||||
{"%csv_us_report", "[0-9]+," + dec_re + "," + dec_re + ",us,,,,,"}};
|
||||
{"%csv_us_report", "[0-9]+," + dec_re + "," + dec_re + ",us,,,,,"},
|
||||
{"%csv_bytes_report",
|
||||
"[0-9]+," + dec_re + "," + dec_re + ",ns," + dec_re + ",,,,"},
|
||||
{"%csv_items_report",
|
||||
"[0-9]+," + dec_re + "," + dec_re + ",ns,," + dec_re + ",,,"},
|
||||
{"%csv_label_report_begin", "[0-9]+," + dec_re + "," + dec_re + ",ns,,,"},
|
||||
{"%csv_label_report_end", ",,"}};
|
||||
return map;
|
||||
}
|
||||
|
||||
|
@ -11,9 +11,9 @@
|
||||
|
||||
ADD_CASES(TC_ConsoleOut, {{"^Benchmark %s Time %s CPU %s Iterations$", MR_Next},
|
||||
{"^[-]+$", MR_Next}});
|
||||
ADD_CASES(TC_CSVOut, {{"name,iterations,real_time,cpu_time,time_unit,bytes_per_"
|
||||
"second,items_per_second,"
|
||||
"label,error_occurred,error_message"}});
|
||||
ADD_CASES(TC_CSVOut,
|
||||
{{"name,iterations,real_time,cpu_time,time_unit,bytes_per_second,"
|
||||
"items_per_second,label,error_occurred,error_message"}});
|
||||
|
||||
// ========================================================================= //
|
||||
// ------------------------ Testing Basic Output --------------------------- //
|
||||
@ -34,6 +34,72 @@ ADD_CASES(TC_JSONOut, {{"\"name\": \"BM_basic\",$"},
|
||||
{"}", MR_Next}});
|
||||
ADD_CASES(TC_CSVOut, {{"^\"BM_basic\",%csv_report$"}});
|
||||
|
||||
// ========================================================================= //
|
||||
// ------------------------ Testing Bytes per Second Output ---------------- //
|
||||
// ========================================================================= //
|
||||
|
||||
void BM_bytes_per_second(benchmark::State& state) {
|
||||
while (state.KeepRunning()) {
|
||||
}
|
||||
state.SetBytesProcessed(1);
|
||||
}
|
||||
BENCHMARK(BM_bytes_per_second);
|
||||
|
||||
ADD_CASES(TC_ConsoleOut,
|
||||
{{"^BM_bytes_per_second %console_report +%floatB/s$"}});
|
||||
ADD_CASES(TC_JSONOut, {{"\"name\": \"BM_bytes_per_second\",$"},
|
||||
{"\"iterations\": %int,$", MR_Next},
|
||||
{"\"real_time\": %int,$", MR_Next},
|
||||
{"\"cpu_time\": %int,$", MR_Next},
|
||||
{"\"time_unit\": \"ns\",$", MR_Next},
|
||||
{"\"bytes_per_second\": %int$", MR_Next},
|
||||
{"}", MR_Next}});
|
||||
ADD_CASES(TC_CSVOut, {{"^\"BM_bytes_per_second\",%csv_bytes_report$"}});
|
||||
|
||||
// ========================================================================= //
|
||||
// ------------------------ Testing Items per Second Output ---------------- //
|
||||
// ========================================================================= //
|
||||
|
||||
void BM_items_per_second(benchmark::State& state) {
|
||||
while (state.KeepRunning()) {
|
||||
}
|
||||
state.SetItemsProcessed(1);
|
||||
}
|
||||
BENCHMARK(BM_items_per_second);
|
||||
|
||||
ADD_CASES(TC_ConsoleOut,
|
||||
{{"^BM_items_per_second %console_report +%float items/s$"}});
|
||||
ADD_CASES(TC_JSONOut, {{"\"name\": \"BM_items_per_second\",$"},
|
||||
{"\"iterations\": %int,$", MR_Next},
|
||||
{"\"real_time\": %int,$", MR_Next},
|
||||
{"\"cpu_time\": %int,$", MR_Next},
|
||||
{"\"time_unit\": \"ns\",$", MR_Next},
|
||||
{"\"items_per_second\": %int$", MR_Next},
|
||||
{"}", MR_Next}});
|
||||
ADD_CASES(TC_CSVOut, {{"^\"BM_items_per_second\",%csv_items_report$"}});
|
||||
|
||||
// ========================================================================= //
|
||||
// ------------------------ Testing Label Output --------------------------- //
|
||||
// ========================================================================= //
|
||||
|
||||
void BM_label(benchmark::State& state) {
|
||||
while (state.KeepRunning()) {
|
||||
}
|
||||
state.SetLabel("some label");
|
||||
}
|
||||
BENCHMARK(BM_label);
|
||||
|
||||
ADD_CASES(TC_ConsoleOut, {{"^BM_label %console_report some label$"}});
|
||||
ADD_CASES(TC_JSONOut, {{"\"name\": \"BM_label\",$"},
|
||||
{"\"iterations\": %int,$", MR_Next},
|
||||
{"\"real_time\": %int,$", MR_Next},
|
||||
{"\"cpu_time\": %int,$", MR_Next},
|
||||
{"\"time_unit\": \"ns\",$", MR_Next},
|
||||
{"\"label\": \"some label\"$", MR_Next},
|
||||
{"}", MR_Next}});
|
||||
ADD_CASES(TC_CSVOut, {{"^\"BM_label\",%csv_label_report_begin\"some "
|
||||
"label\"%csv_label_report_end$"}});
|
||||
|
||||
// ========================================================================= //
|
||||
// ------------------------ Testing Error Output --------------------------- //
|
||||
// ========================================================================= //
|
||||
|
Loading…
Reference in New Issue
Block a user