Skip to content

Commit

Permalink
Merge pull request #1051 from DLR-SC/coverage-html-optional
Browse files Browse the repository at this point in the history
Fix CI: Linux Test job capturing code coverage is broken
  • Loading branch information
joergbrech authored Jan 22, 2025
2 parents d1753b4 + 2c33f71 commit 4b34202
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
# only enable coverage for Debug build on latest ubuntu
include:
- config: "Debug"
os: "ubuntu-latest"
os: "ubuntu-22.04"
coverage: "ON"
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -98,10 +98,10 @@ jobs:
# generate coverage reports on latest ubuntu debug builds
exclude:
- config: "Debug"
os: "ubuntu-latest"
os: "ubuntu-22.04"
include:
- config: "Debug"
os: "ubuntu-latest"
os: "ubuntu-22.04"
coverage: "ON"
unit-tests: false
runs-on: ${{ matrix.os }}
Expand Down
22 changes: 15 additions & 7 deletions cmake/CodeCoverage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@
# which runs your test executable and produces a lcov code coverage report.
#

OPTION(TIGL_COVERAGE_GENHTML "Use Genhtml to generate htmls from gcov output" OFF)

# Check prereqs
FIND_PROGRAM( GCOV_PATH gcov )
FIND_PROGRAM( LCOV_PATH lcov )
FIND_PROGRAM( GENHTML_PATH genhtml )

IF(TIGL_COVERAGE_GENHTML)
FIND_PROGRAM( GENHTML_PATH genhtml )
ENDIF()
FIND_PROGRAM( GCOVR_PATH gcovr PATHS ${PROJECT_SOURCE_DIR}/tests)

IF(NOT GCOV_PATH)
Expand Down Expand Up @@ -55,9 +60,11 @@ FUNCTION(SETUP_TARGET_FOR_COVERAGE _targetname _testrunner _testdir _outputname)
MESSAGE(FATAL_ERROR "lcov not found! Aborting...")
ENDIF() # NOT LCOV_PATH

IF(TIGL_COVERAGE_GENHTML)
IF(NOT GENHTML_PATH)
MESSAGE(FATAL_ERROR "genhtml not found! Aborting...")
ENDIF() # NOT GENHTML_PATH
ENDIF() # TIGL_COVERAGE_GENHTML

# copy testdata
file(COPY ${PROJECT_SOURCE_DIR}/${_testdir}/TestData DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
Expand All @@ -77,19 +84,20 @@ FUNCTION(SETUP_TARGET_FOR_COVERAGE _targetname _testrunner _testdir _outputname)
# Capturing lcov counters and generating report
COMMAND ${LCOV_PATH} --directory ../.. --capture --output-file ${_outputname}_all.info
COMMAND ${LCOV_PATH} --remove ${_outputname}_all.info '${PROJECT_SOURCE_DIR}/${_testdir}/*' '${PROJECT_SOURCE_DIR}/tests/common/*' '${PROJECT_SOURCE_DIR}/thirdparty/**' '/usr/*' '*oce*' '*build*' '*tixi3*' '${PROJECT_SOURCE_DIR}/src/generated/*' --output-file ${_outputname}.info
COMMAND ${GENHTML_PATH} -o ../../${_outputname} ${_outputname}.info

COMMAND ${CMAKE_COMMAND} -E remove ${_outputname}_all.info

USES_TERMINAL
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${_testdir}
COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report."
)

# Show info where to find the report
ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD
COMMAND ;
COMMENT "Open ./${_outputname}/index.html in your browser to view the coverage report."
)
IF(TIGL_COVERAGE_GENHTML)
ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD
COMMAND ${GENHTML_PATH} -o ../../${_outputname} ${_outputname}.info
COMMENT "Generating HTML report. Open ./${_outputname}/index.html in your browser to view the coverage report."
)
ENDIF()

ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE

Expand Down

0 comments on commit 4b34202

Please sign in to comment.