5 #include "../src/commandlineflags.h"
6 #include "../src/string_util.h"
7 #include "benchmark/benchmark.h"
8 #include "gmock/gmock.h"
9 #include "gtest/gtest.h"
20 class EventQueue :
public std::queue<std::string> {
37 EventQueue*
queue =
new EventQueue();
39 class NullReporter :
public BenchmarkReporter {
41 bool ReportContext(
const Context& )
override {
return true; }
42 void ReportRuns(
const std::vector<Run>& )
override {}
47 static void SetupHook(
int ) {
queue->push(
"Setup"); }
49 static void TeardownHook(
int ) {
queue->push(
"Teardown"); }
54 BenchmarkReporter* reporter =
new NullReporter;
55 FLAGS_benchmark_filter =
pattern;
79 TEST_F(BenchmarkTest, Match1) {
92 TEST_F(BenchmarkTest, Match1WithRepetition) {
93 FLAGS_benchmark_repetitions = 2;
95 Execute(
"BM_Match1/(64|80)");
103 TEST_F(BenchmarkTest, Match1WithRandomInterleaving) {
104 FLAGS_benchmark_enable_random_interleaving =
true;
105 FLAGS_benchmark_repetitions = 100;
107 std::map<std::string, int> element_count;
108 std::map<std::string, int> interleaving_count;
109 Execute(
"BM_Match1/(64|80)");
110 for (
int i = 0;
i < 100; ++
i) {
111 std::vector<std::string> interleaving;
112 interleaving.push_back(
queue->Get());
113 interleaving.push_back(
queue->Get());
114 element_count[interleaving[0].c_str()]++;
115 element_count[interleaving[1].c_str()]++;
117 interleaving[1].
c_str())]++;
119 EXPECT_EQ(element_count[
"BM_Match1/64"], 100) <<
"Unexpected repetitions.";
120 EXPECT_EQ(element_count[
"BM_Match1/80"], 100) <<
"Unexpected repetitions.";
121 EXPECT_GE(interleaving_count.size(), 2) <<
"Interleaving was not randomized.";