Home | History | Annotate | Download | only in test
      1 # Enable the tests
      2 
      3 find_package(Threads REQUIRED)
      4 
      5 set(CXX03_FLAGS "${CMAKE_CXX_FLAGS}")
      6 string(REPLACE "-std=c++11" "-std=c++03" CXX03_FLAGS "${CXX03_FLAGS}")
      7 string(REPLACE "-std=c++0x" "-std=c++03" CXX03_FLAGS "${CXX03_FLAGS}")
      8 
      9 macro(compile_benchmark_test name)
     10   add_executable(${name} "${name}.cc")
     11   target_link_libraries(${name} benchmark ${CMAKE_THREAD_LIBS_INIT})
     12 endmacro(compile_benchmark_test)
     13 
     14 # Demonstration executable
     15 compile_benchmark_test(benchmark_test)
     16 add_test(benchmark benchmark_test --benchmark_min_time=0.01)
     17 
     18 compile_benchmark_test(filter_test)
     19 macro(add_filter_test name filter expect)
     20   add_test(${name} filter_test --benchmark_min_time=0.01 --benchmark_filter=${filter} ${expect})
     21 endmacro(add_filter_test)
     22 
     23 add_filter_test(filter_simple "Foo" 3)
     24 add_filter_test(filter_suffix "BM_.*" 4)
     25 add_filter_test(filter_regex_all ".*" 5)
     26 add_filter_test(filter_regex_blank "" 5)
     27 add_filter_test(filter_regex_none "monkey" 0)
     28 add_filter_test(filter_regex_wildcard ".*Foo.*" 3)
     29 add_filter_test(filter_regex_begin "^BM_.*" 4)
     30 add_filter_test(filter_regex_begin2 "^N" 1)
     31 add_filter_test(filter_regex_end ".*Ba$" 1)
     32 
     33 compile_benchmark_test(options_test)
     34 add_test(options_benchmarks options_test --benchmark_min_time=0.01)
     35 
     36 compile_benchmark_test(basic_test)
     37 add_test(basic_benchmark basic_test --benchmark_min_time=0.01)
     38 
     39 compile_benchmark_test(fixture_test)
     40 add_test(fixture_test fixture_test --benchmark_min_time=0.01)
     41 
     42 compile_benchmark_test(map_test)
     43 add_test(map_test map_test --benchmark_min_time=0.01)
     44 
     45 compile_benchmark_test(cxx03_test)
     46 set_target_properties(cxx03_test
     47     PROPERTIES COMPILE_FLAGS "${CXX03_FLAGS}")
     48 add_test(cxx03 cxx03_test --benchmark_min_time=0.01)
     49 
     50 # Add the coverage command(s)
     51 if(CMAKE_BUILD_TYPE)
     52   string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_LOWER)
     53 endif()
     54 if (${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()
     92 endif()
     93