diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 95b4f37b..195d6797 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,7 +1,12 @@ # Demonstration executable add_executable(benchmark_test benchmark_test.cc) target_link_libraries(benchmark_test benchmark ${CMAKE_THREAD_LIBS_INIT}) -add_test(benchmark benchmark_test) +add_test(benchmark benchmark_test 50) +add_test(benchmark_filter_simple benchmark_test --benchmark_filter=Calculate 16) +add_test(benchmark_filter_prefix benchmark_test --benchmark_filter=*Calculate 0) +add_test(benchmark_filter_suffix benchmark_test --benchmark_filter=Calculate* 16) +add_test(benchmark_filter_both benchmark_test --benchmark_filter=*Calculate* 0) +add_test(benchmark_filter_regex_wildcard benchmark_test --benchmark_filter=.*Calculate.* 16) # Test harness for regex wrapper add_executable(re_test ${RE_FILES} "re_test.cc") diff --git a/test/benchmark_test.cc b/test/benchmark_test.cc index 5474000c..07016b77 100644 --- a/test/benchmark_test.cc +++ b/test/benchmark_test.cc @@ -10,6 +10,7 @@ #include #include #include +#include #include namespace { @@ -141,12 +142,45 @@ static void BM_LongTest(benchmark::State& state) { } BENCHMARK(BM_LongTest)->Range(1<<16,1<<28); +class TestReporter : public benchmark::internal::ConsoleReporter { + public: + virtual bool ReportContext(const Context& context) const { + return ConsoleReporter::ReportContext(context); + }; + + virtual void ReportRuns(const std::vector& report) const { + ++count_; + ConsoleReporter::ReportRuns(report); + }; + + TestReporter() : count_(0) {} + + virtual ~TestReporter() {} + + int GetCount() const { + return count_; + } + + private: + mutable size_t count_; +}; + int main(int argc, const char* argv[]) { benchmark::Initialize(&argc, argv); CHECK(Factorial(8) == 40320); CHECK(CalculatePi(1) == 0.0); - benchmark::RunSpecifiedBenchmarks(); + TestReporter test_reporter; + benchmark::RunSpecifiedBenchmarks(&test_reporter); + + // Make sure we ran all of the tests + const size_t count = test_reporter.GetCount(); + const size_t expected = (argc == 2) ? std::stoul(argv[1]) : count; + if (count != expected) { + std::cerr << "ERROR: Expected " << expected << " tests to be ran but only " + << count << " completed" << std::endl; + return -1; + } }