• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Enable the tests
2
3find_package(Threads REQUIRED)
4
5# NOTE: These flags must be added after find_package(Threads REQUIRED) otherwise
6# they will break the configuration check.
7if (DEFINED BENCHMARK_CXX_LINKER_FLAGS)
8  list(APPEND CMAKE_EXE_LINKER_FLAGS ${BENCHMARK_CXX_LINKER_FLAGS})
9endif()
10
11add_library(output_test_helper STATIC output_test_helper.cc)
12
13macro(compile_benchmark_test name)
14  add_executable(${name} "${name}.cc")
15  target_link_libraries(${name} benchmark ${CMAKE_THREAD_LIBS_INIT})
16endmacro(compile_benchmark_test)
17
18
19macro(compile_output_test name)
20  add_executable(${name} "${name}.cc" output_test.h)
21  target_link_libraries(${name} output_test_helper benchmark
22          ${BENCHMARK_CXX_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
23endmacro(compile_output_test)
24
25
26# Demonstration executable
27compile_benchmark_test(benchmark_test)
28add_test(benchmark benchmark_test --benchmark_min_time=0.01)
29
30compile_benchmark_test(filter_test)
31macro(add_filter_test name filter expect)
32  add_test(${name} filter_test --benchmark_min_time=0.01 --benchmark_filter=${filter} ${expect})
33  add_test(${name}_list_only filter_test --benchmark_list_tests --benchmark_filter=${filter} ${expect})
34endmacro(add_filter_test)
35
36add_filter_test(filter_simple "Foo" 3)
37add_filter_test(filter_suffix "BM_.*" 4)
38add_filter_test(filter_regex_all ".*" 5)
39add_filter_test(filter_regex_blank "" 5)
40add_filter_test(filter_regex_none "monkey" 0)
41add_filter_test(filter_regex_wildcard ".*Foo.*" 3)
42add_filter_test(filter_regex_begin "^BM_.*" 4)
43add_filter_test(filter_regex_begin2 "^N" 1)
44add_filter_test(filter_regex_end ".*Ba$" 1)
45
46compile_benchmark_test(options_test)
47add_test(options_benchmarks options_test --benchmark_min_time=0.01)
48
49compile_benchmark_test(basic_test)
50add_test(basic_benchmark basic_test --benchmark_min_time=0.01)
51
52compile_benchmark_test(diagnostics_test)
53add_test(diagnostics_test diagnostics_test --benchmark_min_time=0.01)
54
55compile_benchmark_test(skip_with_error_test)
56add_test(skip_with_error_test skip_with_error_test --benchmark_min_time=0.01)
57
58compile_benchmark_test(donotoptimize_test)
59add_test(donotoptimize_test donotoptimize_test --benchmark_min_time=0.01)
60
61compile_benchmark_test(fixture_test)
62add_test(fixture_test fixture_test --benchmark_min_time=0.01)
63
64compile_benchmark_test(register_benchmark_test)
65add_test(register_benchmark_test register_benchmark_test --benchmark_min_time=0.01)
66
67compile_benchmark_test(map_test)
68add_test(map_test map_test --benchmark_min_time=0.01)
69
70compile_benchmark_test(multiple_ranges_test)
71add_test(multiple_ranges_test multiple_ranges_test --benchmark_min_time=0.01)
72
73compile_output_test(reporter_output_test)
74add_test(reporter_output_test reporter_output_test --benchmark_min_time=0.01)
75
76check_cxx_compiler_flag(-std=c++03 BENCHMARK_HAS_CXX03_FLAG)
77if (BENCHMARK_HAS_CXX03_FLAG)
78  set(CXX03_FLAGS "${CMAKE_CXX_FLAGS}")
79  string(REPLACE "-std=c++11" "-std=c++03" CXX03_FLAGS "${CXX03_FLAGS}")
80  string(REPLACE "-std=c++0x" "-std=c++03" CXX03_FLAGS "${CXX03_FLAGS}")
81
82  compile_benchmark_test(cxx03_test)
83  set_target_properties(cxx03_test
84      PROPERTIES COMPILE_FLAGS "${CXX03_FLAGS}")
85  add_test(cxx03 cxx03_test --benchmark_min_time=0.01)
86endif()
87
88# Attempt to work around flaky test failures when running on Appveyor servers.
89if (DEFINED ENV{APPVEYOR})
90  set(COMPLEXITY_MIN_TIME "0.5")
91else()
92  set(COMPLEXITY_MIN_TIME "0.01")
93endif()
94compile_output_test(complexity_test)
95add_test(complexity_benchmark complexity_test --benchmark_min_time=${COMPLEXITY_MIN_TIME})
96
97# Add the coverage command(s)
98if(CMAKE_BUILD_TYPE)
99  string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_LOWER)
100endif()
101if (${CMAKE_BUILD_TYPE_LOWER} MATCHES "coverage")
102  find_program(GCOV gcov)
103  find_program(LCOV lcov)
104  find_program(GENHTML genhtml)
105  find_program(CTEST ctest)
106  if (GCOV AND LCOV AND GENHTML AND CTEST AND HAVE_CXX_FLAG_COVERAGE)
107    add_custom_command(
108      OUTPUT ${CMAKE_BINARY_DIR}/lcov/index.html
109      COMMAND ${LCOV} -q -z -d .
110      COMMAND ${LCOV} -q --no-external -c -b "${CMAKE_SOURCE_DIR}" -d . -o before.lcov -i
111      COMMAND ${CTEST} --force-new-ctest-process
112      COMMAND ${LCOV} -q --no-external -c -b "${CMAKE_SOURCE_DIR}" -d . -o after.lcov
113      COMMAND ${LCOV} -q -a before.lcov -a after.lcov --output-file final.lcov
114      COMMAND ${LCOV} -q -r final.lcov "'${CMAKE_SOURCE_DIR}/test/*'" -o final.lcov
115      COMMAND ${GENHTML} final.lcov -o lcov --demangle-cpp --sort -p "${CMAKE_BINARY_DIR}" -t benchmark
116      DEPENDS filter_test benchmark_test options_test basic_test fixture_test cxx03_test complexity_test
117      WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
118      COMMENT "Running LCOV"
119    )
120    add_custom_target(coverage
121      DEPENDS ${CMAKE_BINARY_DIR}/lcov/index.html
122      COMMENT "LCOV report at lcov/index.html"
123    )
124    message(STATUS "Coverage command added")
125  else()
126    if (HAVE_CXX_FLAG_COVERAGE)
127      set(CXX_FLAG_COVERAGE_MESSAGE supported)
128    else()
129      set(CXX_FLAG_COVERAGE_MESSAGE unavailable)
130    endif()
131    message(WARNING
132      "Coverage not available:\n"
133      "  gcov: ${GCOV}\n"
134      "  lcov: ${LCOV}\n"
135      "  genhtml: ${GENHTML}\n"
136      "  ctest: ${CTEST}\n"
137      "  --coverage flag: ${CXX_FLAG_COVERAGE_MESSAGE}")
138  endif()
139endif()
140