summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/benchmark/test/reporter_output_test.cc
blob: 00f02f264023e8dc5e64a1d6f65967fe854376d7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#undef NDEBUG
#include "benchmark/benchmark.h"
#include "output_test.h"
#include <utility>


// ========================================================================= //
// ---------------------- Testing Prologue Output -------------------------- //
// ========================================================================= //

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"}
});

// ========================================================================= //
// ------------------------ Testing Basic Output --------------------------- //
// ========================================================================= //

void BM_basic(benchmark::State& state) {
  while (state.KeepRunning()) {}
}
BENCHMARK(BM_basic);

ADD_CASES(TC_ConsoleOut, {
    {"^BM_basic %console_report$"}
});
ADD_CASES(TC_JSONOut, {
    {"\"name\": \"BM_basic\",$"},
    {"\"iterations\": %int,$", MR_Next},
    {"\"real_time\": %int,$", MR_Next},
    {"\"cpu_time\": %int,$", MR_Next},
    {"\"time_unit\": \"ns\"$", MR_Next},
    {"}", MR_Next}
});
ADD_CASES(TC_CSVOut, {
    {"^\"BM_basic\",%csv_report$"}
});

// ========================================================================= //
// ------------------------ Testing Error Output --------------------------- //
// ========================================================================= //

void BM_error(benchmark::State& state) {
    state.SkipWithError("message");
    while(state.KeepRunning()) {}
}
BENCHMARK(BM_error);
ADD_CASES(TC_ConsoleOut, {
    {"^BM_error[ ]+ERROR OCCURRED: 'message'$"}
});
ADD_CASES(TC_JSONOut, {
    {"\"name\": \"BM_error\",$"},
    {"\"error_occurred\": true,$", MR_Next},
    {"\"error_message\": \"message\",$", MR_Next}
});

ADD_CASES(TC_CSVOut, {
    {"^\"BM_error\",,,,,,,,true,\"message\"$"}
});


// ========================================================================= //
// ----------------------- Testing Complexity Output ----------------------- //
// ========================================================================= //

void BM_Complexity_O1(benchmark::State& state) {
  while (state.KeepRunning()) {
  }
  state.SetComplexityN(state.range(0));
}
BENCHMARK(BM_Complexity_O1)->Range(1, 1<<18)->Complexity(benchmark::o1);
SET_SUBSTITUTIONS({
  {"%bigOStr", "[ ]*[0-9]+\\.[0-9]+ \\([0-9]+\\)"},
  {"%RMS", "[ ]*[0-9]+ %"}
});
ADD_CASES(TC_ConsoleOut, {
   {"^BM_Complexity_O1_BigO %bigOStr %bigOStr[ ]*$"},
   {"^BM_Complexity_O1_RMS %RMS %RMS[ ]*$"}
});


// ========================================================================= //
// ----------------------- Testing Aggregate Output ------------------------ //
// ========================================================================= //

// Test that non-aggregate data is printed by default
void BM_Repeat(benchmark::State& state) { while (state.KeepRunning()) {} }
BENCHMARK(BM_Repeat)->Repetitions(3);
ADD_CASES(TC_ConsoleOut, {
    {"^BM_Repeat/repeats:3 %console_report$"},
    {"^BM_Repeat/repeats:3 %console_report$"},
    {"^BM_Repeat/repeats:3 %console_report$"},
    {"^BM_Repeat/repeats:3_mean %console_report$"},
    {"^BM_Repeat/repeats:3_stddev %console_report$"}
});
ADD_CASES(TC_JSONOut, {
    {"\"name\": \"BM_Repeat/repeats:3\",$"},
    {"\"name\": \"BM_Repeat/repeats:3\",$"},
    {"\"name\": \"BM_Repeat/repeats:3\",$"},
    {"\"name\": \"BM_Repeat/repeats:3_mean\",$"},
    {"\"name\": \"BM_Repeat/repeats:3_stddev\",$"}
});
ADD_CASES(TC_CSVOut, {
    {"^\"BM_Repeat/repeats:3\",%csv_report$"},
    {"^\"BM_Repeat/repeats:3\",%csv_report$"},
    {"^\"BM_Repeat/repeats:3\",%csv_report$"},
    {"^\"BM_Repeat/repeats:3_mean\",%csv_report$"},
    {"^\"BM_Repeat/repeats:3_stddev\",%csv_report$"}
});

// Test that a non-repeated test still prints non-aggregate results even when
// only-aggregate reports have been requested
void BM_RepeatOnce(benchmark::State& state) { while (state.KeepRunning()) {} }
BENCHMARK(BM_RepeatOnce)->Repetitions(1)->ReportAggregatesOnly();
ADD_CASES(TC_ConsoleOut, {
    {"^BM_RepeatOnce/repeats:1 %console_report$"}
});
ADD_CASES(TC_JSONOut, {
    {"\"name\": \"BM_RepeatOnce/repeats:1\",$"}
});
ADD_CASES(TC_CSVOut, {
    {"^\"BM_RepeatOnce/repeats:1\",%csv_report$"}
});


// Test that non-aggregate data is not reported
void BM_SummaryRepeat(benchmark::State& state) { while (state.KeepRunning()) {} }
BENCHMARK(BM_SummaryRepeat)->Repetitions(3)->ReportAggregatesOnly();
ADD_CASES(TC_ConsoleOut, {
    {".*BM_SummaryRepeat/repeats:3 ", MR_Not},
    {"^BM_SummaryRepeat/repeats:3_mean %console_report$"},
    {"^BM_SummaryRepeat/repeats:3_stddev %console_report$"}
});
ADD_CASES(TC_JSONOut, {
    {".*BM_SummaryRepeat/repeats:3 ", MR_Not},
    {"\"name\": \"BM_SummaryRepeat/repeats:3_mean\",$"},
    {"\"name\": \"BM_SummaryRepeat/repeats:3_stddev\",$"}
});
ADD_CASES(TC_CSVOut, {
    {".*BM_SummaryRepeat/repeats:3 ", MR_Not},
    {"^\"BM_SummaryRepeat/repeats:3_mean\",%csv_report$"},
    {"^\"BM_SummaryRepeat/repeats:3_stddev\",%csv_report$"}
});

// ========================================================================= //
// --------------------------- TEST CASES END ------------------------------ //
// ========================================================================= //


int main(int argc, char* argv[]) {
  RunOutputTests(argc, argv);
}