Merge pull request #47 from mattyclarkson/benchmark_test

Make sure all benchmark tests run
This commit is contained in:
Dominic Hamon 2014-08-19 21:17:20 -07:00
commit d32c5c6442
4 changed files with 43 additions and 3 deletions

1
.gitignore vendored
View File

@ -7,6 +7,7 @@
*~
/test/benchmark_test
/test/re_test
/Testing
CMakeCache.txt
CMakeFiles/
Makefile

View File

@ -38,7 +38,7 @@ function(get_git_version var)
ERROR_QUIET)
string(COMPARE NOTEQUAL "${GIT_DIFF_INDEX}" "" GIT_DIRTY)
if (${GIT_DIRTY})
string(CONCAT GIT_VERSION ${GIT_VERSION} "-dirty")
set(GIT_VERSION "${GIT_VERSION}-dirty")
endif()
message("-- git Version: ${GIT_VERSION}")
set(${var} ${GIT_VERSION} PARENT_SCOPE)

View File

@ -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")

View File

@ -10,6 +10,7 @@
#include <mutex>
#include <set>
#include <sstream>
#include <string>
#include <vector>
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<Run>& 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;
}
}