[Tarantool-patches] [PATCH] cmake: add code coverage support
Sergey Bronnikov
sergeyb at tarantool.org
Tue Aug 8 11:16:49 MSK 2023
Hello,
Unfortunately we cannot control order of running dependencies for target.
On practice we can get a situation when target LuaJIT-coverage, that
generates a code coverage report,
runs before finishing target LuaJIT-test, that generates code coverage data.
Therefore target "coverage" that combined LuaJIT-test and
LuaJIT-coverage, has been removed
by patch below. Updated patches force-pushed.
diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml
index 78abf2e1..13ea6c5b 100644
--- a/.github/workflows/coverage.yml
+++ b/.github/workflows/coverage.yml
@@ -50,8 +50,10 @@ jobs:
- name: build
run: cmake --build . --parallel
working-directory: ${{ env.BUILDDIR }}
- - name: test and generate code coverage report
- run: cmake --build ${{ env.BUILDDIR }} --parallel --target coverage
+ - name: run regression tests
+ run: cmake --build ${{ env.BUILDDIR }} --parallel --target test
+ - name: generate code coverage report
+ run: cmake --build ${{ env.BUILDDIR }} --parallel --target
LuaJIT-coverage
- name: send code coverage to coveralls.io
run: |
curl -LO https://coveralls.io/coveralls-linux.tar.gz
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index e23d6d45..47296a22 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -76,11 +76,4 @@ if(LUAJIT_USE_TEST)
${PROJECT_NAME}-test
${PROJECT_NAME}-luacheck
)
-
- if (LUAJIT_ENABLE_COVERAGE)
- add_custom_target(coverage DEPENDS
- ${PROJECT_NAME}-test
- ${PROJECT_NAME}-coverage
- )
- endif (LUAJIT_ENABLE_COVERAGE)
endif()
Sergey
On 7/25/23 16:52, Sergey Bronnikov wrote:
> From: Sergey Bronnikov <sergeyb at tarantool.org>
>
> The patch adds building code coverage report using gcovr [1] and gcov.
> gcovr is a better version of lcov, see [2]. CMake target LuaJIT-coverage
> executes regression tests, proccess *.gcno and *.gcda files with gcov,
> builds detailed HTML report and prints summary about code coverage.
>
> ```
> $ cmake -S . -B build -DENABLE_COVERAGE=ON
> $ cmake --build build --parallel
> $ cmake --build build --target LuaJIT-coverage
>
> <snipped>
>
> lines: 84.1% (26056 out of 30997)
> functions: 88.8% (2055 out of 2314)
> branches: 71.5% (14801 out of 20703)
> ```
>
> 1. https://gcovr.com/
> 2. https://gcovr.com/en/stable/faq.html#what-is-the-difference-between-lcov-and-gcovr
> ---
> CMakeLists.txt | 9 ++++++
> test/CMakeLists.txt | 40 +++++++++++++++++++++++++++
> test/tarantool-c-tests/CMakeLists.txt | 2 +-
> 3 files changed, 50 insertions(+), 1 deletion(-)
>
> diff --git a/CMakeLists.txt b/CMakeLists.txt
> index 6ef24bba..8bc63b90 100644
> --- a/CMakeLists.txt
> +++ b/CMakeLists.txt
> @@ -116,6 +116,15 @@ if(LUAJIT_ENABLE_WARNINGS)
> )
> endif()
>
> +set(ENABLE_COVERAGE_DEFAULT OFF)
> +option(ENABLE_COVERAGE "Enable integration with gcovr, a code coverage program" ${ENABLE_COVERAGE_DEFAULT})
> +if (ENABLE_COVERAGE)
> + AppendFlags(CMAKE_C_FLAGS
> + -fprofile-arcs
> + -ftest-coverage
> + )
> +endif()
> +
> # Auxiliary flags for main targets (libraries, binaries).
> AppendFlags(TARGET_C_FLAGS
> -D_FILE_OFFSET_BITS=64
> diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
> index 47296a22..9b0f11d8 100644
> --- a/test/CMakeLists.txt
> +++ b/test/CMakeLists.txt
> @@ -59,6 +59,44 @@ add_custom_target(${PROJECT_NAME}-test DEPENDS
> tarantool-tests
> )
>
> +find_program(GCOVR gcovr)
> +find_program(GCOV gcov)
> +set(COVERAGE_HTML_REPORT "luajit-coverage.html")
> +set(COVERAGE_JSON_REPORT "luajit-coverage.json")
> +if(ENABLE_COVERAGE)
> + if(NOT GCOVR OR NOT GCOV)
> + add_custom_target(${PROJECT_NAME}-coverage)
> + add_custom_command(TARGET ${PROJECT_NAME}-coverage
> + COMMENT "Either `gcovr' or `gcov` not found, so ${PROJECT_NAME}-coverage target is dummy"
> + )
> + return()
> + endif()
> +
> + add_custom_target(${PROJECT_NAME}-coverage)
> + add_custom_command(TARGET ${PROJECT_NAME}-coverage
> + COMMENT "Building coverage report"
> + COMMAND
> + ${GCOVR}
> + # See https://gcovr.com/en/stable/guide/configuration.html
> + --root ${PROJECT_SOURCE_DIR}
> + --filter ${PROJECT_SOURCE_DIR}/src
> + --print-summary
> + --output ${COVERAGE_HTML_REPORT}
> + --coveralls ${COVERAGE_JSON_REPORT}
> + --html
> + --html-title "LuaJIT Code Coverage Report"
> + --html-details
> + --sort-percentage
> + --branches
> + --decisions
> + --verbose
> + -j ${CMAKE_BUILD_PARALLEL_LEVEL}
> + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
> + )
> + message(STATUS "Code coverage HTML report: ${COVERAGE_HTML_REPORT}")
> + message(STATUS "Code coverage JSON report: ${COVERAGE_JSON_REPORT}")
> +endif(ENABLE_COVERAGE)
> +
> if(LUAJIT_USE_TEST)
> if(POLICY CMP0037)
> if(CMAKE_VERSION VERSION_LESS 3.11)
> @@ -76,4 +114,6 @@ if(LUAJIT_USE_TEST)
> ${PROJECT_NAME}-test
> ${PROJECT_NAME}-luacheck
> )
> +
> + add_dependencies(${PROJECT_NAME}-coverage ${PROJECT_NAME}-test)
> endif()
> diff --git a/test/tarantool-c-tests/CMakeLists.txt b/test/tarantool-c-tests/CMakeLists.txt
> index 17255345..8cd76b44 100644
> --- a/test/tarantool-c-tests/CMakeLists.txt
> +++ b/test/tarantool-c-tests/CMakeLists.txt
> @@ -45,7 +45,7 @@ foreach(test_source ${tests})
> OUTPUT_NAME "${exe}${C_TEST_SUFFIX}"
> RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
> )
> - target_link_libraries(${exe} libtest ${LUAJIT_LIBRARY})
> + target_link_libraries(${exe} libtest ${LUAJIT_LIBRARY} --coverage)
> LIST(APPEND TESTS_COMPILED ${exe})
> endforeach()
>
More information about the Tarantool-patches
mailing list