1a8c51b3fSopenharmony_ci# Enable the tests 2a8c51b3fSopenharmony_ci 3a8c51b3fSopenharmony_ciset(THREADS_PREFER_PTHREAD_FLAG ON) 4a8c51b3fSopenharmony_ci 5a8c51b3fSopenharmony_cifind_package(Threads REQUIRED) 6a8c51b3fSopenharmony_ciinclude(CheckCXXCompilerFlag) 7a8c51b3fSopenharmony_ci 8a8c51b3fSopenharmony_ci# NOTE: Some tests use `<cassert>` to perform the test. Therefore we must 9a8c51b3fSopenharmony_ci# strip -DNDEBUG from the default CMake flags in DEBUG mode. 10a8c51b3fSopenharmony_cistring(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) 11a8c51b3fSopenharmony_ciif( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" ) 12a8c51b3fSopenharmony_ci add_definitions( -UNDEBUG ) 13a8c51b3fSopenharmony_ci add_definitions(-DTEST_BENCHMARK_LIBRARY_HAS_NO_ASSERTIONS) 14a8c51b3fSopenharmony_ci # Also remove /D NDEBUG to avoid MSVC warnings about conflicting defines. 15a8c51b3fSopenharmony_ci foreach (flags_var_to_scrub 16a8c51b3fSopenharmony_ci CMAKE_CXX_FLAGS_RELEASE 17a8c51b3fSopenharmony_ci CMAKE_CXX_FLAGS_RELWITHDEBINFO 18a8c51b3fSopenharmony_ci CMAKE_CXX_FLAGS_MINSIZEREL 19a8c51b3fSopenharmony_ci CMAKE_C_FLAGS_RELEASE 20a8c51b3fSopenharmony_ci CMAKE_C_FLAGS_RELWITHDEBINFO 21a8c51b3fSopenharmony_ci CMAKE_C_FLAGS_MINSIZEREL) 22a8c51b3fSopenharmony_ci string (REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" " " 23a8c51b3fSopenharmony_ci "${flags_var_to_scrub}" "${${flags_var_to_scrub}}") 24a8c51b3fSopenharmony_ci endforeach() 25a8c51b3fSopenharmony_ciendif() 26a8c51b3fSopenharmony_ci 27a8c51b3fSopenharmony_ciif (NOT BUILD_SHARED_LIBS) 28a8c51b3fSopenharmony_ci add_definitions(-DBENCHMARK_STATIC_DEFINE) 29a8c51b3fSopenharmony_ciendif() 30a8c51b3fSopenharmony_ci 31a8c51b3fSopenharmony_cicheck_cxx_compiler_flag(-O3 BENCHMARK_HAS_O3_FLAG) 32a8c51b3fSopenharmony_ciset(BENCHMARK_O3_FLAG "") 33a8c51b3fSopenharmony_ciif (BENCHMARK_HAS_O3_FLAG) 34a8c51b3fSopenharmony_ci set(BENCHMARK_O3_FLAG "-O3") 35a8c51b3fSopenharmony_ciendif() 36a8c51b3fSopenharmony_ci 37a8c51b3fSopenharmony_ci# NOTE: These flags must be added after find_package(Threads REQUIRED) otherwise 38a8c51b3fSopenharmony_ci# they will break the configuration check. 39a8c51b3fSopenharmony_ciif (DEFINED BENCHMARK_CXX_LINKER_FLAGS) 40a8c51b3fSopenharmony_ci list(APPEND CMAKE_EXE_LINKER_FLAGS ${BENCHMARK_CXX_LINKER_FLAGS}) 41a8c51b3fSopenharmony_ciendif() 42a8c51b3fSopenharmony_ci 43a8c51b3fSopenharmony_ciadd_library(output_test_helper STATIC output_test_helper.cc output_test.h) 44a8c51b3fSopenharmony_citarget_link_libraries(output_test_helper PRIVATE benchmark::benchmark) 45a8c51b3fSopenharmony_ci 46a8c51b3fSopenharmony_cimacro(compile_benchmark_test name) 47a8c51b3fSopenharmony_ci add_executable(${name} "${name}.cc") 48a8c51b3fSopenharmony_ci target_link_libraries(${name} benchmark::benchmark ${CMAKE_THREAD_LIBS_INIT}) 49a8c51b3fSopenharmony_ci if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "NVHPC") 50a8c51b3fSopenharmony_ci target_compile_options( ${name} PRIVATE --diag_suppress partial_override ) 51a8c51b3fSopenharmony_ci endif() 52a8c51b3fSopenharmony_ciendmacro(compile_benchmark_test) 53a8c51b3fSopenharmony_ci 54a8c51b3fSopenharmony_cimacro(compile_benchmark_test_with_main name) 55a8c51b3fSopenharmony_ci add_executable(${name} "${name}.cc") 56a8c51b3fSopenharmony_ci target_link_libraries(${name} benchmark::benchmark_main) 57a8c51b3fSopenharmony_ciendmacro(compile_benchmark_test_with_main) 58a8c51b3fSopenharmony_ci 59a8c51b3fSopenharmony_cimacro(compile_output_test name) 60a8c51b3fSopenharmony_ci add_executable(${name} "${name}.cc" output_test.h) 61a8c51b3fSopenharmony_ci target_link_libraries(${name} output_test_helper benchmark::benchmark_main 62a8c51b3fSopenharmony_ci ${BENCHMARK_CXX_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) 63a8c51b3fSopenharmony_ciendmacro(compile_output_test) 64a8c51b3fSopenharmony_ci 65a8c51b3fSopenharmony_ci# Demonstration executable 66a8c51b3fSopenharmony_cicompile_benchmark_test(benchmark_test) 67a8c51b3fSopenharmony_ciadd_test(NAME benchmark COMMAND benchmark_test --benchmark_min_time=0.01s) 68a8c51b3fSopenharmony_ci 69a8c51b3fSopenharmony_cicompile_benchmark_test(spec_arg_test) 70a8c51b3fSopenharmony_ciadd_test(NAME spec_arg COMMAND spec_arg_test --benchmark_filter=BM_NotChosen) 71a8c51b3fSopenharmony_ci 72a8c51b3fSopenharmony_cicompile_benchmark_test(spec_arg_verbosity_test) 73a8c51b3fSopenharmony_ciadd_test(NAME spec_arg_verbosity COMMAND spec_arg_verbosity_test --v=42) 74a8c51b3fSopenharmony_ci 75a8c51b3fSopenharmony_cicompile_benchmark_test(benchmark_setup_teardown_test) 76a8c51b3fSopenharmony_ciadd_test(NAME benchmark_setup_teardown COMMAND benchmark_setup_teardown_test) 77a8c51b3fSopenharmony_ci 78a8c51b3fSopenharmony_cicompile_benchmark_test(filter_test) 79a8c51b3fSopenharmony_cimacro(add_filter_test name filter expect) 80a8c51b3fSopenharmony_ci add_test(NAME ${name} COMMAND filter_test --benchmark_min_time=0.01s --benchmark_filter=${filter} ${expect}) 81a8c51b3fSopenharmony_ci add_test(NAME ${name}_list_only COMMAND filter_test --benchmark_list_tests --benchmark_filter=${filter} ${expect}) 82a8c51b3fSopenharmony_ciendmacro(add_filter_test) 83a8c51b3fSopenharmony_ci 84a8c51b3fSopenharmony_cicompile_benchmark_test(benchmark_min_time_flag_time_test) 85a8c51b3fSopenharmony_ciadd_test(NAME min_time_flag_time COMMAND benchmark_min_time_flag_time_test) 86a8c51b3fSopenharmony_ci 87a8c51b3fSopenharmony_cicompile_benchmark_test(benchmark_min_time_flag_iters_test) 88a8c51b3fSopenharmony_ciadd_test(NAME min_time_flag_iters COMMAND benchmark_min_time_flag_iters_test) 89a8c51b3fSopenharmony_ci 90a8c51b3fSopenharmony_ciadd_filter_test(filter_simple "Foo" 3) 91a8c51b3fSopenharmony_ciadd_filter_test(filter_simple_negative "-Foo" 2) 92a8c51b3fSopenharmony_ciadd_filter_test(filter_suffix "BM_.*" 4) 93a8c51b3fSopenharmony_ciadd_filter_test(filter_suffix_negative "-BM_.*" 1) 94a8c51b3fSopenharmony_ciadd_filter_test(filter_regex_all ".*" 5) 95a8c51b3fSopenharmony_ciadd_filter_test(filter_regex_all_negative "-.*" 0) 96a8c51b3fSopenharmony_ciadd_filter_test(filter_regex_blank "" 5) 97a8c51b3fSopenharmony_ciadd_filter_test(filter_regex_blank_negative "-" 0) 98a8c51b3fSopenharmony_ciadd_filter_test(filter_regex_none "monkey" 0) 99a8c51b3fSopenharmony_ciadd_filter_test(filter_regex_none_negative "-monkey" 5) 100a8c51b3fSopenharmony_ciadd_filter_test(filter_regex_wildcard ".*Foo.*" 3) 101a8c51b3fSopenharmony_ciadd_filter_test(filter_regex_wildcard_negative "-.*Foo.*" 2) 102a8c51b3fSopenharmony_ciadd_filter_test(filter_regex_begin "^BM_.*" 4) 103a8c51b3fSopenharmony_ciadd_filter_test(filter_regex_begin_negative "-^BM_.*" 1) 104a8c51b3fSopenharmony_ciadd_filter_test(filter_regex_begin2 "^N" 1) 105a8c51b3fSopenharmony_ciadd_filter_test(filter_regex_begin2_negative "-^N" 4) 106a8c51b3fSopenharmony_ciadd_filter_test(filter_regex_end ".*Ba$" 1) 107a8c51b3fSopenharmony_ciadd_filter_test(filter_regex_end_negative "-.*Ba$" 4) 108a8c51b3fSopenharmony_ci 109a8c51b3fSopenharmony_cicompile_benchmark_test(options_test) 110a8c51b3fSopenharmony_ciadd_test(NAME options_benchmarks COMMAND options_test --benchmark_min_time=0.01s) 111a8c51b3fSopenharmony_ci 112a8c51b3fSopenharmony_cicompile_benchmark_test(basic_test) 113a8c51b3fSopenharmony_ciadd_test(NAME basic_benchmark COMMAND basic_test --benchmark_min_time=0.01s) 114a8c51b3fSopenharmony_ci 115a8c51b3fSopenharmony_cicompile_output_test(repetitions_test) 116a8c51b3fSopenharmony_ciadd_test(NAME repetitions_benchmark COMMAND repetitions_test --benchmark_min_time=0.01s --benchmark_repetitions=3) 117a8c51b3fSopenharmony_ci 118a8c51b3fSopenharmony_cicompile_benchmark_test(diagnostics_test) 119a8c51b3fSopenharmony_ciadd_test(NAME diagnostics_test COMMAND diagnostics_test --benchmark_min_time=0.01s) 120a8c51b3fSopenharmony_ci 121a8c51b3fSopenharmony_cicompile_benchmark_test(skip_with_error_test) 122a8c51b3fSopenharmony_ciadd_test(NAME skip_with_error_test COMMAND skip_with_error_test --benchmark_min_time=0.01s) 123a8c51b3fSopenharmony_ci 124a8c51b3fSopenharmony_cicompile_benchmark_test(donotoptimize_test) 125a8c51b3fSopenharmony_ci# Enable errors for deprecated deprecations (DoNotOptimize(Tp const& value)). 126a8c51b3fSopenharmony_cicheck_cxx_compiler_flag(-Werror=deprecated-declarations BENCHMARK_HAS_DEPRECATED_DECLARATIONS_FLAG) 127a8c51b3fSopenharmony_ciif (BENCHMARK_HAS_DEPRECATED_DECLARATIONS_FLAG) 128a8c51b3fSopenharmony_ci target_compile_options (donotoptimize_test PRIVATE "-Werror=deprecated-declarations") 129a8c51b3fSopenharmony_ciendif() 130a8c51b3fSopenharmony_ci# Some of the issues with DoNotOptimize only occur when optimization is enabled 131a8c51b3fSopenharmony_cicheck_cxx_compiler_flag(-O3 BENCHMARK_HAS_O3_FLAG) 132a8c51b3fSopenharmony_ciif (BENCHMARK_HAS_O3_FLAG) 133a8c51b3fSopenharmony_ci set_target_properties(donotoptimize_test PROPERTIES COMPILE_FLAGS "-O3") 134a8c51b3fSopenharmony_ciendif() 135a8c51b3fSopenharmony_ciadd_test(NAME donotoptimize_test COMMAND donotoptimize_test --benchmark_min_time=0.01s) 136a8c51b3fSopenharmony_ci 137a8c51b3fSopenharmony_cicompile_benchmark_test(fixture_test) 138a8c51b3fSopenharmony_ciadd_test(NAME fixture_test COMMAND fixture_test --benchmark_min_time=0.01s) 139a8c51b3fSopenharmony_ci 140a8c51b3fSopenharmony_cicompile_benchmark_test(register_benchmark_test) 141a8c51b3fSopenharmony_ciadd_test(NAME register_benchmark_test COMMAND register_benchmark_test --benchmark_min_time=0.01s) 142a8c51b3fSopenharmony_ci 143a8c51b3fSopenharmony_cicompile_benchmark_test(map_test) 144a8c51b3fSopenharmony_ciadd_test(NAME map_test COMMAND map_test --benchmark_min_time=0.01s) 145a8c51b3fSopenharmony_ci 146a8c51b3fSopenharmony_cicompile_benchmark_test(multiple_ranges_test) 147a8c51b3fSopenharmony_ciadd_test(NAME multiple_ranges_test COMMAND multiple_ranges_test --benchmark_min_time=0.01s) 148a8c51b3fSopenharmony_ci 149a8c51b3fSopenharmony_cicompile_benchmark_test(args_product_test) 150a8c51b3fSopenharmony_ciadd_test(NAME args_product_test COMMAND args_product_test --benchmark_min_time=0.01s) 151a8c51b3fSopenharmony_ci 152a8c51b3fSopenharmony_cicompile_benchmark_test_with_main(link_main_test) 153a8c51b3fSopenharmony_ciadd_test(NAME link_main_test COMMAND link_main_test --benchmark_min_time=0.01s) 154a8c51b3fSopenharmony_ci 155a8c51b3fSopenharmony_cicompile_output_test(reporter_output_test) 156a8c51b3fSopenharmony_ciadd_test(NAME reporter_output_test COMMAND reporter_output_test --benchmark_min_time=0.01s) 157a8c51b3fSopenharmony_ci 158a8c51b3fSopenharmony_cicompile_output_test(templated_fixture_test) 159a8c51b3fSopenharmony_ciadd_test(NAME templated_fixture_test COMMAND templated_fixture_test --benchmark_min_time=0.01s) 160a8c51b3fSopenharmony_ci 161a8c51b3fSopenharmony_cicompile_output_test(user_counters_test) 162a8c51b3fSopenharmony_ciadd_test(NAME user_counters_test COMMAND user_counters_test --benchmark_min_time=0.01s) 163a8c51b3fSopenharmony_ci 164a8c51b3fSopenharmony_cicompile_output_test(perf_counters_test) 165a8c51b3fSopenharmony_ciadd_test(NAME perf_counters_test COMMAND perf_counters_test --benchmark_min_time=0.01s --benchmark_perf_counters=CYCLES,BRANCHES) 166a8c51b3fSopenharmony_ci 167a8c51b3fSopenharmony_cicompile_output_test(internal_threading_test) 168a8c51b3fSopenharmony_ciadd_test(NAME internal_threading_test COMMAND internal_threading_test --benchmark_min_time=0.01s) 169a8c51b3fSopenharmony_ci 170a8c51b3fSopenharmony_cicompile_output_test(report_aggregates_only_test) 171a8c51b3fSopenharmony_ciadd_test(NAME report_aggregates_only_test COMMAND report_aggregates_only_test --benchmark_min_time=0.01s) 172a8c51b3fSopenharmony_ci 173a8c51b3fSopenharmony_cicompile_output_test(display_aggregates_only_test) 174a8c51b3fSopenharmony_ciadd_test(NAME display_aggregates_only_test COMMAND display_aggregates_only_test --benchmark_min_time=0.01s) 175a8c51b3fSopenharmony_ci 176a8c51b3fSopenharmony_cicompile_output_test(user_counters_tabular_test) 177a8c51b3fSopenharmony_ciadd_test(NAME user_counters_tabular_test COMMAND user_counters_tabular_test --benchmark_counters_tabular=true --benchmark_min_time=0.01s) 178a8c51b3fSopenharmony_ci 179a8c51b3fSopenharmony_cicompile_output_test(user_counters_thousands_test) 180a8c51b3fSopenharmony_ciadd_test(NAME user_counters_thousands_test COMMAND user_counters_thousands_test --benchmark_min_time=0.01s) 181a8c51b3fSopenharmony_ci 182a8c51b3fSopenharmony_cicompile_output_test(memory_manager_test) 183a8c51b3fSopenharmony_ciadd_test(NAME memory_manager_test COMMAND memory_manager_test --benchmark_min_time=0.01s) 184a8c51b3fSopenharmony_ci 185a8c51b3fSopenharmony_ci# MSVC does not allow to set the language standard to C++98/03. 186a8c51b3fSopenharmony_ciif(NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") 187a8c51b3fSopenharmony_ci compile_benchmark_test(cxx03_test) 188a8c51b3fSopenharmony_ci set_target_properties(cxx03_test 189a8c51b3fSopenharmony_ci PROPERTIES 190a8c51b3fSopenharmony_ci CXX_STANDARD 98 191a8c51b3fSopenharmony_ci CXX_STANDARD_REQUIRED YES) 192a8c51b3fSopenharmony_ci # libstdc++ provides different definitions within <map> between dialects. When 193a8c51b3fSopenharmony_ci # LTO is enabled and -Werror is specified GCC diagnoses this ODR violation 194a8c51b3fSopenharmony_ci # causing the test to fail to compile. To prevent this we explicitly disable 195a8c51b3fSopenharmony_ci # the warning. 196a8c51b3fSopenharmony_ci check_cxx_compiler_flag(-Wno-odr BENCHMARK_HAS_WNO_ODR) 197a8c51b3fSopenharmony_ci check_cxx_compiler_flag(-Wno-lto-type-mismatch BENCHMARK_HAS_WNO_LTO_TYPE_MISMATCH) 198a8c51b3fSopenharmony_ci # Cannot set_target_properties multiple times here because the warnings will 199a8c51b3fSopenharmony_ci # be overwritten on each call 200a8c51b3fSopenharmony_ci set (DISABLE_LTO_WARNINGS "") 201a8c51b3fSopenharmony_ci if (BENCHMARK_HAS_WNO_ODR) 202a8c51b3fSopenharmony_ci set(DISABLE_LTO_WARNINGS "${DISABLE_LTO_WARNINGS} -Wno-odr") 203a8c51b3fSopenharmony_ci endif() 204a8c51b3fSopenharmony_ci if (BENCHMARK_HAS_WNO_LTO_TYPE_MISMATCH) 205a8c51b3fSopenharmony_ci set(DISABLE_LTO_WARNINGS "${DISABLE_LTO_WARNINGS} -Wno-lto-type-mismatch") 206a8c51b3fSopenharmony_ci endif() 207a8c51b3fSopenharmony_ci set_target_properties(cxx03_test PROPERTIES LINK_FLAGS "${DISABLE_LTO_WARNINGS}") 208a8c51b3fSopenharmony_ci add_test(NAME cxx03 COMMAND cxx03_test --benchmark_min_time=0.01s) 209a8c51b3fSopenharmony_ciendif() 210a8c51b3fSopenharmony_ci 211a8c51b3fSopenharmony_ci# Attempt to work around flaky test failures when running on Appveyor servers. 212a8c51b3fSopenharmony_ciif (DEFINED ENV{APPVEYOR}) 213a8c51b3fSopenharmony_ci set(COMPLEXITY_MIN_TIME "0.5s") 214a8c51b3fSopenharmony_cielse() 215a8c51b3fSopenharmony_ci set(COMPLEXITY_MIN_TIME "0.01s") 216a8c51b3fSopenharmony_ciendif() 217a8c51b3fSopenharmony_cicompile_output_test(complexity_test) 218a8c51b3fSopenharmony_ciadd_test(NAME complexity_benchmark COMMAND complexity_test --benchmark_min_time=${COMPLEXITY_MIN_TIME}) 219a8c51b3fSopenharmony_ci 220a8c51b3fSopenharmony_ci############################################################################### 221a8c51b3fSopenharmony_ci# GoogleTest Unit Tests 222a8c51b3fSopenharmony_ci############################################################################### 223a8c51b3fSopenharmony_ci 224a8c51b3fSopenharmony_ciif (BENCHMARK_ENABLE_GTEST_TESTS) 225a8c51b3fSopenharmony_ci macro(compile_gtest name) 226a8c51b3fSopenharmony_ci add_executable(${name} "${name}.cc") 227a8c51b3fSopenharmony_ci target_link_libraries(${name} benchmark::benchmark 228a8c51b3fSopenharmony_ci gmock_main ${CMAKE_THREAD_LIBS_INIT}) 229a8c51b3fSopenharmony_ci endmacro(compile_gtest) 230a8c51b3fSopenharmony_ci 231a8c51b3fSopenharmony_ci macro(add_gtest name) 232a8c51b3fSopenharmony_ci compile_gtest(${name}) 233a8c51b3fSopenharmony_ci add_test(NAME ${name} COMMAND ${name}) 234a8c51b3fSopenharmony_ci endmacro() 235a8c51b3fSopenharmony_ci 236a8c51b3fSopenharmony_ci add_gtest(benchmark_gtest) 237a8c51b3fSopenharmony_ci add_gtest(benchmark_name_gtest) 238a8c51b3fSopenharmony_ci add_gtest(benchmark_random_interleaving_gtest) 239a8c51b3fSopenharmony_ci add_gtest(commandlineflags_gtest) 240a8c51b3fSopenharmony_ci add_gtest(statistics_gtest) 241a8c51b3fSopenharmony_ci add_gtest(string_util_gtest) 242a8c51b3fSopenharmony_ci add_gtest(perf_counters_gtest) 243a8c51b3fSopenharmony_ci add_gtest(time_unit_gtest) 244a8c51b3fSopenharmony_ci add_gtest(min_time_parse_gtest) 245a8c51b3fSopenharmony_ciendif(BENCHMARK_ENABLE_GTEST_TESTS) 246a8c51b3fSopenharmony_ci 247a8c51b3fSopenharmony_ci############################################################################### 248a8c51b3fSopenharmony_ci# Assembly Unit Tests 249a8c51b3fSopenharmony_ci############################################################################### 250a8c51b3fSopenharmony_ci 251a8c51b3fSopenharmony_ciif (BENCHMARK_ENABLE_ASSEMBLY_TESTS) 252a8c51b3fSopenharmony_ci if (NOT LLVM_FILECHECK_EXE) 253a8c51b3fSopenharmony_ci message(FATAL_ERROR "LLVM FileCheck is required when including this file") 254a8c51b3fSopenharmony_ci endif() 255a8c51b3fSopenharmony_ci include(AssemblyTests.cmake) 256a8c51b3fSopenharmony_ci add_filecheck_test(donotoptimize_assembly_test) 257a8c51b3fSopenharmony_ci add_filecheck_test(state_assembly_test) 258a8c51b3fSopenharmony_ci add_filecheck_test(clobber_memory_assembly_test) 259a8c51b3fSopenharmony_ciendif() 260a8c51b3fSopenharmony_ci 261a8c51b3fSopenharmony_ci 262a8c51b3fSopenharmony_ci 263a8c51b3fSopenharmony_ci############################################################################### 264a8c51b3fSopenharmony_ci# Code Coverage Configuration 265a8c51b3fSopenharmony_ci############################################################################### 266a8c51b3fSopenharmony_ci 267a8c51b3fSopenharmony_ci# Add the coverage command(s) 268a8c51b3fSopenharmony_ciif(CMAKE_BUILD_TYPE) 269a8c51b3fSopenharmony_ci string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_LOWER) 270a8c51b3fSopenharmony_ciendif() 271a8c51b3fSopenharmony_ciif (${CMAKE_BUILD_TYPE_LOWER} MATCHES "coverage") 272a8c51b3fSopenharmony_ci find_program(GCOV gcov) 273a8c51b3fSopenharmony_ci find_program(LCOV lcov) 274a8c51b3fSopenharmony_ci find_program(GENHTML genhtml) 275a8c51b3fSopenharmony_ci find_program(CTEST ctest) 276a8c51b3fSopenharmony_ci if (GCOV AND LCOV AND GENHTML AND CTEST AND HAVE_CXX_FLAG_COVERAGE) 277a8c51b3fSopenharmony_ci add_custom_command( 278a8c51b3fSopenharmony_ci OUTPUT ${CMAKE_BINARY_DIR}/lcov/index.html 279a8c51b3fSopenharmony_ci COMMAND ${LCOV} -q -z -d . 280a8c51b3fSopenharmony_ci COMMAND ${LCOV} -q --no-external -c -b "${CMAKE_SOURCE_DIR}" -d . -o before.lcov -i 281a8c51b3fSopenharmony_ci COMMAND ${CTEST} --force-new-ctest-process 282a8c51b3fSopenharmony_ci COMMAND ${LCOV} -q --no-external -c -b "${CMAKE_SOURCE_DIR}" -d . -o after.lcov 283a8c51b3fSopenharmony_ci COMMAND ${LCOV} -q -a before.lcov -a after.lcov --output-file final.lcov 284a8c51b3fSopenharmony_ci COMMAND ${LCOV} -q -r final.lcov "'${CMAKE_SOURCE_DIR}/test/*'" -o final.lcov 285a8c51b3fSopenharmony_ci COMMAND ${GENHTML} final.lcov -o lcov --demangle-cpp --sort -p "${CMAKE_BINARY_DIR}" -t benchmark 286a8c51b3fSopenharmony_ci DEPENDS filter_test benchmark_test options_test basic_test fixture_test cxx03_test complexity_test 287a8c51b3fSopenharmony_ci WORKING_DIRECTORY ${CMAKE_BINARY_DIR} 288a8c51b3fSopenharmony_ci COMMENT "Running LCOV" 289a8c51b3fSopenharmony_ci ) 290a8c51b3fSopenharmony_ci add_custom_target(coverage 291a8c51b3fSopenharmony_ci DEPENDS ${CMAKE_BINARY_DIR}/lcov/index.html 292a8c51b3fSopenharmony_ci COMMENT "LCOV report at lcov/index.html" 293a8c51b3fSopenharmony_ci ) 294a8c51b3fSopenharmony_ci message(STATUS "Coverage command added") 295a8c51b3fSopenharmony_ci else() 296a8c51b3fSopenharmony_ci if (HAVE_CXX_FLAG_COVERAGE) 297a8c51b3fSopenharmony_ci set(CXX_FLAG_COVERAGE_MESSAGE supported) 298a8c51b3fSopenharmony_ci else() 299a8c51b3fSopenharmony_ci set(CXX_FLAG_COVERAGE_MESSAGE unavailable) 300a8c51b3fSopenharmony_ci endif() 301a8c51b3fSopenharmony_ci message(WARNING 302a8c51b3fSopenharmony_ci "Coverage not available:\n" 303a8c51b3fSopenharmony_ci " gcov: ${GCOV}\n" 304a8c51b3fSopenharmony_ci " lcov: ${LCOV}\n" 305a8c51b3fSopenharmony_ci " genhtml: ${GENHTML}\n" 306a8c51b3fSopenharmony_ci " ctest: ${CTEST}\n" 307a8c51b3fSopenharmony_ci " --coverage flag: ${CXX_FLAG_COVERAGE_MESSAGE}") 308a8c51b3fSopenharmony_ci endif() 309a8c51b3fSopenharmony_ciendif() 310