From d99becfa9ab254c7fe8bde1ea7d13c6949706054 Mon Sep 17 00:00:00 2001 From: Eggbertx Date: Sun, 3 Mar 2024 23:06:59 -0800 Subject: [PATCH] Add lcov test coverage report --- CMakeLists.txt | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0de15f7..d36516e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,9 @@ project(oc8-test VERSION 0.1.0 LANGUAGES C CXX) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) +add_definitions(-fprofile-arcs -ftest-coverage) +set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE ON) +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lgcov") include(CTest) include(CTestCoverageCollectGCOV) @@ -15,7 +18,8 @@ FetchContent_Declare( set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCMAKE_TEST") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCMAKE_TEST -fprofile-arcs -ftest-coverage") +set(OBJECT_DIR ${CMAKE_BINARY_DIR}/CMakeFiles/oc8-test.dir/src) FetchContent_MakeAvailable(googletest) enable_testing() @@ -28,7 +32,22 @@ add_executable(oc8-test src/tests/chip8_test.cc ) -target_link_libraries(oc8-test GTest::gtest_main) +add_custom_target(lcov + COMMAND rm -rf lcov + COMMAND mkdir lcov + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} +) + +add_custom_command(TARGET lcov + COMMAND lcov -d ${OBJECT_DIR} -c -o ${CMAKE_BINARY_DIR}/lcov/coverage.info -rc lcov_branch_coverage=1 --ignore-errors mismatch + COMMAND lcov -r ${CMAKE_BINARY_DIR}/lcov/coverage.info "/usr/include/*" "${CMAKE_BINARY_DIR}/_deps/*" -o ${CMAKE_BINARY_DIR}/lcov/coverage.info --ignore-errors unused + COMMAND genhtml ${CMAKE_BINARY_DIR}/lcov/coverage.info --branch-coverage --output-directory ${CMAKE_BINARY_DIR}/lcov/html +) + +add_test(oc8-test ${CMAKE_CURRENT_BINARY_DIR}/oc8-test) + +target_link_libraries(oc8-test GTest::gtest_main -fprofile-arcs) include(GoogleTest) gtest_discover_tests(oc8-test) +