Skip to content

Commit

Permalink
Coverage changes
Browse files Browse the repository at this point in the history
Rename target name to coverage
Add support for jacoco, clover, lcov
Upgrade gcovr in the workflow
Switch codecov to lcov
Add .codecov.yml
  • Loading branch information
Bronek committed Apr 3, 2024
1 parent e4b5109 commit f66b32a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 26 deletions.
15 changes: 15 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
coverage:
status:
project:
default:
target: 95%
threshold: 3%

patch:
default:
target: auto
threshold: 6%

ignore:
- "tests/"
- "third_party/"
22 changes: 11 additions & 11 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
submodules: true
- name: install gcovr
shell: bash
run: pip install gcovr==6
run: pip install "gcovr>=7,<8"
- name: configure
shell: bash
run: |
Expand All @@ -100,31 +100,31 @@ jobs:
-DCMAKE_C_COMPILER=gcc \
-DCMAKE_CXX_COMPILER=g++ \
-DCODE_COVERAGE=True \
-DCODE_COVERAGE_REPORT_FORMAT=xml \
-DCODE_COVERAGE_REPORT_FORMAT=lcov \
..
- name: build all targets
shell: bash
run: |
cd ${build_dir}
cmake --build . --target all
- name: prepare coverage_report
- name: prepare coverage report
shell: bash
run: |
pushd ${build_dir}
cmake --build . --target coverage_report
cmake --build . --target coverage
popd
mv ${build_dir}/coverage_report.xml coverage_report.xml
cat coverage_report.xml
mv ${build_dir}/coverage.lcov coverage.lcov
cat coverage.lcov
- name: archive coverage report
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: coverage_report.xml
path: coverage_report.xml
name: coverage.lcov
path: coverage.lcov
if-no-files-found: error
- name: upload coverage report
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
files: coverage_report.xml
files: coverage.lcov
fail_ci_if_error: true
verbose: true
token: ${{ secrets.CODECOV_TOKEN }}
35 changes: 24 additions & 11 deletions cmake/CodeCoverage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,17 @@
# - fix append_coverage_compiler_flags_to_target to correctly add flags
# - replace "-fprofile-arcs -ftest-coverage" with "--coverage" (equivalent)
#
# 2023-12-15, Bronek Kozicki
# 2024-01-04, Bronek Kozicki
# - remove setup_target_for_coverage_lcov (slow) and setup_target_for_coverage_fastcov (no support for Clang)
# - fix Clang support by adding find_program( ... llvm-cov )
# - add Apple Clang support by adding execute_process( COMMAND xcrun -f llvm-cov ... )
# - add CODE_COVERAGE_GCOV_TOOL to explicitly select gcov tool and disable find_program
# - replace both functions setup_target_for_coverage_gcovr_* with single setup_target_for_coverage_gcovr
# - replace both functions setup_target_for_coverage_gcovr_* with a single setup_target_for_coverage_gcovr
# - add support for all gcovr output formats
#
# 2024-04-03, Bronek Kozicki
# - add support for output formats: jacoco, clover, lcov
#
# USAGE:
#
# 1. Copy this file into your cmake modules path.
Expand Down Expand Up @@ -159,12 +162,12 @@ option(CODE_COVERAGE_VERBOSE "Verbose information" FALSE)
# Check prereqs
find_program( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/scripts/test)

if (DEFINED CODE_COVERAGE_GCOV_TOOL)
if(DEFINED CODE_COVERAGE_GCOV_TOOL)
set(GCOV_TOOL "${CODE_COVERAGE_GCOV_TOOL}")
elseif (DEFINED ENV{CODE_COVERAGE_GCOV_TOOL})
elseif(DEFINED ENV{CODE_COVERAGE_GCOV_TOOL})
set(GCOV_TOOL "$ENV{CODE_COVERAGE_GCOV_TOOL}")
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang")
if (APPLE)
if(APPLE)
execute_process( COMMAND xcrun -f llvm-cov
OUTPUT_VARIABLE LLVMCOV_PATH
OUTPUT_STRIP_TRAILING_WHITESPACE
Expand All @@ -175,7 +178,7 @@ elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang")
if(LLVMCOV_PATH)
set(GCOV_TOOL "${LLVMCOV_PATH} gcov")
endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
find_program( GCOV_PATH gcov )
set(GCOV_TOOL "${GCOV_PATH}")
endif()
Expand Down Expand Up @@ -256,10 +259,10 @@ endif()
# BASE_DIRECTORY "../" # Base directory for report
# # (defaults to PROJECT_SOURCE_DIR)
# FORMAT "cobertura" # Output format, one of:
# # xml cobertura sonarqube json-summary
# # json-details coveralls csv txt
# # html-single html-nested html-details
# # (xml is an alias to cobertura;
# # xml cobertura sonarqube jacoco clover
# # json-summary json-details coveralls csv
# # txt html-single html-nested html-details
# # lcov (xml is an alias to cobertura;
# # if no format is set, defaults to xml)
# EXCLUDE "src/dir1/*" "src/dir2/*" # Patterns to exclude (can be relative
# # to BASE_DIRECTORY, with CMake 3.4+)
Expand Down Expand Up @@ -308,18 +311,28 @@ function(setup_target_for_coverage_gcovr)
set(GCOVR_OUTPUT_FILE ${Coverage_NAME}.txt)
elseif(Coverage_FORMAT STREQUAL "csv")
set(GCOVR_OUTPUT_FILE ${Coverage_NAME}.csv)
elseif(Coverage_FORMAT STREQUAL "lcov")
set(GCOVR_OUTPUT_FILE ${Coverage_NAME}.lcov)
else()
set(GCOVR_OUTPUT_FILE ${Coverage_NAME}.xml)
endif()
endif()

if ((Coverage_FORMAT STREQUAL "cobertura")
if((Coverage_FORMAT STREQUAL "cobertura")
OR (Coverage_FORMAT STREQUAL "xml"))
list(APPEND GCOVR_ADDITIONAL_ARGS --cobertura "${GCOVR_OUTPUT_FILE}" )
list(APPEND GCOVR_ADDITIONAL_ARGS --cobertura-pretty )
set(Coverage_FORMAT cobertura) # overwrite xml
elseif(Coverage_FORMAT STREQUAL "sonarqube")
list(APPEND GCOVR_ADDITIONAL_ARGS --sonarqube "${GCOVR_OUTPUT_FILE}" )
elseif(Coverage_FORMAT STREQUAL "jacoco")
list(APPEND GCOVR_ADDITIONAL_ARGS --jacoco "${GCOVR_OUTPUT_FILE}" )
list(APPEND GCOVR_ADDITIONAL_ARGS --jacoco-pretty )
elseif(Coverage_FORMAT STREQUAL "clover")
list(APPEND GCOVR_ADDITIONAL_ARGS --clover "${GCOVR_OUTPUT_FILE}" )
list(APPEND GCOVR_ADDITIONAL_ARGS --clover-pretty )
elseif(Coverage_FORMAT STREQUAL "lcov")
list(APPEND GCOVR_ADDITIONAL_ARGS --lcov "${GCOVR_OUTPUT_FILE}" )
elseif(Coverage_FORMAT STREQUAL "json-summary")
list(APPEND GCOVR_ADDITIONAL_ARGS --json-summary "${GCOVR_OUTPUT_FILE}" )
list(APPEND GCOVR_ADDITIONAL_ARGS --json-summary-pretty)
Expand Down
8 changes: 4 additions & 4 deletions cmake/MarketCov.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Enable coverage_report using two options CMAKE_BUILD_TYPE=Debug CODE_COVERAGE=True e.g.
# cmake -DCMAKE_BUILD_TYPE=Debug -DCODE_COVERAGE=True (followed by usual options)
# Enable coverage using two options CMAKE_BUILD_TYPE=Debug CODE_COVERAGE=True e.g.
# cmake -DCMAKE_BUILD_TYPE=Debug -DCODE_COVERAGE=ON (followed by usual options)

if (CODE_COVERAGE)
if (NOT GCOVR_PATH)
Expand All @@ -9,13 +9,13 @@ if (CODE_COVERAGE)
if (DEFINED CODE_COVERAGE_REPORT_FORMAT)
set(CODE_COVERAGE_FORMAT ${CODE_COVERAGE_REPORT_FORMAT})
else()
set(CODE_COVERAGE_FORMAT html-details)
set(CODE_COVERAGE_FORMAT xml)
endif()

set (GCOVR_ADDITIONAL_ARGS --exclude-throw-branches -s)

setup_target_for_coverage_gcovr(
NAME coverage_report
NAME coverage
FORMAT ${CODE_COVERAGE_FORMAT}
EXECUTABLE tests
EXECUTABLE_ARGS -r console
Expand Down

0 comments on commit f66b32a

Please sign in to comment.