• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Enable the tests
2
3find_package(Threads REQUIRED)
4
5set(CXX03_FLAGS "${CMAKE_CXX_FLAGS}")
6string(REPLACE "-std=c++11" "-std=c++03" CXX03_FLAGS "${CXX03_FLAGS}")
7string(REPLACE "-std=c++0x" "-std=c++03" CXX03_FLAGS "${CXX03_FLAGS}")
8
9macro(compile_benchmark_test name)
10  add_executable(${name} "${name}.cc")
11  target_link_libraries(${name} benchmark ${CMAKE_THREAD_LIBS_INIT})
12endmacro(compile_benchmark_test)
13
14# Demonstration executable
15compile_benchmark_test(benchmark_test)
16add_test(benchmark benchmark_test --benchmark_min_time=0.01)
17
18compile_benchmark_test(filter_test)
19macro(add_filter_test name filter expect)
20  add_test(${name} filter_test --benchmark_min_time=0.01 --benchmark_filter=${filter} ${expect})
21endmacro(add_filter_test)
22
23add_filter_test(filter_simple "Foo" 3)
24add_filter_test(filter_suffix "BM_.*" 4)
25add_filter_test(filter_regex_all ".*" 5)
26add_filter_test(filter_regex_blank "" 5)
27add_filter_test(filter_regex_none "monkey" 0)
28add_filter_test(filter_regex_wildcard ".*Foo.*" 3)
29add_filter_test(filter_regex_begin "^BM_.*" 4)
30add_filter_test(filter_regex_begin2 "^N" 1)
31add_filter_test(filter_regex_end ".*Ba$" 1)
32
33compile_benchmark_test(options_test)
34add_test(options_benchmarks options_test --benchmark_min_time=0.01)
35
36compile_benchmark_test(basic_test)
37add_test(basic_benchmark basic_test --benchmark_min_time=0.01)
38
39compile_benchmark_test(fixture_test)
40add_test(fixture_test fixture_test --benchmark_min_time=0.01)
41
42compile_benchmark_test(map_test)
43add_test(map_test map_test --benchmark_min_time=0.01)
44
45compile_benchmark_test(cxx03_test)
46set_target_properties(cxx03_test
47    PROPERTIES COMPILE_FLAGS "${CXX03_FLAGS}")
48add_test(cxx03 cxx03_test --benchmark_min_time=0.01)
49
50# Add the coverage command(s)
51if(CMAKE_BUILD_TYPE)
52  string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_LOWER)
53endif()
54if (${CMAKE_BUILD_TYPE_LOWER} MATCHES "coverage")
55  find_program(GCOV gcov)
56  find_program(LCOV lcov)
57  find_program(GENHTML genhtml)
58  find_program(CTEST ctest)
59  if (GCOV AND LCOV AND GENHTML AND CTEST AND HAVE_CXX_FLAG_COVERAGE)
60    add_custom_command(
61      OUTPUT ${CMAKE_BINARY_DIR}/lcov/index.html
62      COMMAND ${LCOV} -q -z -d .
63      COMMAND ${LCOV} -q --no-external -c -b "${CMAKE_SOURCE_DIR}" -d . -o before.lcov -i
64      COMMAND ${CTEST} --force-new-ctest-process
65      COMMAND ${LCOV} -q --no-external -c -b "${CMAKE_SOURCE_DIR}" -d . -o after.lcov
66      COMMAND ${LCOV} -q -a before.lcov -a after.lcov --output-file final.lcov
67      COMMAND ${LCOV} -q -r final.lcov "'${CMAKE_SOURCE_DIR}/test/*'" -o final.lcov
68      COMMAND ${GENHTML} final.lcov -o lcov --demangle-cpp --sort -p "${CMAKE_BINARY_DIR}" -t benchmark
69      DEPENDS filter_test benchmark_test options_test basic_test fixture_test cxx03_test
70      WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
71      COMMENT "Running LCOV"
72    )
73    add_custom_target(coverage
74      DEPENDS ${CMAKE_BINARY_DIR}/lcov/index.html
75      COMMENT "LCOV report at lcov/index.html"
76    )
77    message(STATUS "Coverage command added")
78  else()
79    if (HAVE_CXX_FLAG_COVERAGE)
80      set(CXX_FLAG_COVERAGE_MESSAGE supported)
81    else()
82      set(CXX_FLAG_COVERAGE_MESSAGE unavailable)
83    endif()
84    message(WARNING
85      "Coverage not available:\n"
86      "  gcov: ${GCOV}\n"
87      "  lcov: ${LCOV}\n"
88      "  genhtml: ${GENHTML}\n"
89      "  ctest: ${CTEST}\n"
90      "  --coverage flag: ${CXX_FLAG_COVERAGE_MESSAGE}")
91  endif()
92endif()
93