6 #include "../src/check.h"
7 #include "benchmark/benchmark.h"
18 all_runs_.insert(all_runs_.end(),
begin(report),
end(report));
23 virtual ~TestReporter() {}
25 mutable std::vector<Run> all_runs_;
35 void CheckRun(
Run const&
run)
const {
37 <<
"expected " <<
name <<
" got " <<
run.benchmark_name();
48 std::vector<TestCase> ExpectedResults;
50 int AddCases(
const char* base_name, std::initializer_list<TestCase>
const&
v) {
52 TC.name = base_name + TC.name;
58 #define CONCAT(x, y) CONCAT2(x, y)
59 #define CONCAT2(x, y) x##y
60 #define ADD_CASES(...) int CONCAT(dummy, __LINE__) = AddCases(__VA_ARGS__)
65 state.SkipWithError(
"error message");
68 ADD_CASES(
"BM_error_no_running", {{
"",
true,
"error message"}});
71 state.SkipWithError(
"error message");
72 while (
state.KeepRunning()) {
77 ADD_CASES(
"BM_error_before_running", {{
"",
true,
"error message"}});
80 state.SkipWithError(
"error message");
81 while (
state.KeepRunningBatch(17)) {
86 ADD_CASES(
"BM_error_before_running_batch", {{
"",
true,
"error message"}});
89 state.SkipWithError(
"error message");
95 ADD_CASES(
"BM_error_before_running_range_for", {{
"",
true,
"error message"}});
98 int first_iter =
true;
99 while (
state.KeepRunning()) {
100 if (
state.range(0) == 1 &&
state.thread_index() <= (
state.threads() / 2)) {
103 state.SkipWithError(
"error message");
106 state.ResumeTiming();
111 ADD_CASES(
"BM_error_during_running", {{
"/1/threads:1",
true,
"error message"},
112 {
"/1/threads:2",
true,
"error message"},
113 {
"/1/threads:4",
true,
"error message"},
114 {
"/1/threads:8",
true,
"error message"},
115 {
"/2/threads:1",
false,
""},
116 {
"/2/threads:2",
false,
""},
117 {
"/2/threads:4",
false,
""},
118 {
"/2/threads:8",
false,
""}});
121 assert(
state.max_iterations > 3 &&
"test requires at least a few iterations");
122 int first_iter =
true;
124 for (
auto It =
state.begin(), End =
state.end(); It != End; ++It) {
125 if (
state.range(0) == 1) {
128 state.SkipWithError(
"error message");
137 ADD_CASES(
"BM_error_during_running_ranged_for",
138 {{
"/1/iterations:5",
true,
"error message"},
139 {
"/2/iterations:5",
false,
""}});
145 if (
state.thread_index() <= (
state.threads() / 2))
146 state.SkipWithError(
"error message");
149 ADD_CASES(
"BM_error_after_running", {{
"/threads:1",
true,
"error message"},
150 {
"/threads:2",
true,
"error message"},
151 {
"/threads:4",
true,
"error message"},
152 {
"/threads:8",
true,
"error message"}});
155 bool first_iter =
true;
156 while (
state.KeepRunning()) {
157 if (
state.range(0) == 1 &&
state.thread_index() <= (
state.threads() / 2)) {
161 state.SkipWithError(
"error message");
164 state.ResumeTiming();
169 ADD_CASES(
"BM_error_while_paused", {{
"/1/threads:1",
true,
"error message"},
170 {
"/1/threads:2",
true,
"error message"},
171 {
"/1/threads:4",
true,
"error message"},
172 {
"/1/threads:8",
true,
"error message"},
173 {
"/2/threads:1",
false,
""},
174 {
"/2/threads:2",
false,
""},
175 {
"/2/threads:4",
false,
""},
176 {
"/2/threads:8",
false,
""}});
178 int main(
int argc,
char* argv[]) {
181 TestReporter test_reporter;
185 auto EB = ExpectedResults.begin();
187 for (
Run const&
run : test_reporter.all_runs_) {
188 assert(EB != ExpectedResults.end());
192 assert(EB == ExpectedResults.end());