Skip to content
Snippets Groups Projects
Commit e77cf093 authored by Tom Fischer's avatar Tom Fischer
Browse files

Merge branch 'ctest-coverage-vis' into 'master'

Code coverage visualization

See merge request ogs/ogs!3664
parents 216c26d2 ffe91906
No related branches found
No related tags found
No related merge requests found
Subproject commit f854e10b2ae9e69b46464476bd84131de6aa4fd6 Subproject commit 20cc58ea0f939c6b2f5dbea8981c91b49d4ed4f9
...@@ -21,13 +21,14 @@ code coverage: ...@@ -21,13 +21,14 @@ code coverage:
- genhtml --demangle-cpp -o coverage_report coverage.info - genhtml --demangle-cpp -o coverage_report coverage.info
- wget https://raw.github.com/eriwen/lcov-to-cobertura-xml/master/lcov_cobertura/lcov_cobertura.py - wget https://raw.github.com/eriwen/lcov-to-cobertura-xml/master/lcov_cobertura/lcov_cobertura.py
- poetry run python lcov_cobertura.py coverage.info --base-dir $CI_PROJECT_DIR - poetry run python lcov_cobertura.py coverage.info --base-dir $CI_PROJECT_DIR
- poetry run ./generate_coverage_vis_data.py
artifacts: artifacts:
expose_as: 'Coverage'
paths: paths:
- Coverage.html - Coverage.html
- build/coverage/coverage_report - build/coverage/coverage_report
- build/coverage/coverage.json - build/coverage/coverage.json
- build/coverage/coverage.xml - build/coverage/coverage.xml
- build/coverage/coverage_reports/*.json
expire_in: 1 week expire_in: 1 week
reports: reports:
cobertura: build/coverage/coverage.xml cobertura: build/coverage/coverage.xml
...@@ -13,7 +13,7 @@ endif() ...@@ -13,7 +13,7 @@ endif()
CPMAddPackage( CPMAddPackage(
NAME cmake-modules NAME cmake-modules
GITHUB_REPOSITORY bilke/cmake-modules GITHUB_REPOSITORY bilke/cmake-modules
GIT_TAG d6d1a778e41cb114e5cdf279b8a659fa0ce9a0d4 GIT_TAG d98828f54f6974717798e63195cfbf08fe2daad0
DOWNLOAD_ONLY YES DOWNLOAD_ONLY YES
) )
set(CMAKE_MODULE_PATH set(CMAKE_MODULE_PATH
......
...@@ -3,6 +3,16 @@ if(NOT FASTCOV_PATH AND NOT POETRY) ...@@ -3,6 +3,16 @@ if(NOT FASTCOV_PATH AND NOT POETRY)
message(FATAL_ERROR "Code coverage requires either fastcov or poetry.") message(FATAL_ERROR "Code coverage requires either fastcov or poetry.")
endif() endif()
# https://github.com/linux-test-project/lcov/pull/125
if(APPLE)
file(
DOWNLOAD
https://raw.githubusercontent.com/linux-test-project/lcov/41d8655951d6898511f98be2a2dbcfbe662f0b17/bin/genhtml
${PROJECT_BINARY_DIR}/bin/genhtml
)
set(GENHTML_PATH ${PROJECT_BINARY_DIR}/bin/genhtml)
endif()
include(CodeCoverage) include(CodeCoverage)
append_coverage_compiler_flags() append_coverage_compiler_flags()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Og") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Og")
...@@ -28,6 +38,8 @@ endif() ...@@ -28,6 +38,8 @@ endif()
setup_target_for_coverage_fastcov( setup_target_for_coverage_fastcov(
NAME NAME
testrunner_coverage testrunner_coverage
BASE_DIRECTORY
${PROJECT_BINARY_DIR}
EXECUTABLE EXECUTABLE
$<TARGET_FILE:testrunner> $<TARGET_FILE:testrunner>
-l -l
...@@ -36,6 +48,7 @@ setup_target_for_coverage_fastcov( ...@@ -36,6 +48,7 @@ setup_target_for_coverage_fastcov(
DEPENDENCIES DEPENDENCIES
testrunner testrunner
FASTCOV_ARGS FASTCOV_ARGS
--branch-coverage
--include --include
${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}
${COVERAGE_ADDITIONAL_ARGS} ${COVERAGE_ADDITIONAL_ARGS}
...@@ -49,6 +62,8 @@ setup_target_for_coverage_fastcov( ...@@ -49,6 +62,8 @@ setup_target_for_coverage_fastcov(
setup_target_for_coverage_fastcov( setup_target_for_coverage_fastcov(
NAME NAME
ctest_coverage ctest_coverage
BASE_DIRECTORY
${PROJECT_BINARY_DIR}
EXECUTABLE EXECUTABLE
ctest ctest
-E -E
...@@ -56,14 +71,27 @@ setup_target_for_coverage_fastcov( ...@@ -56,14 +71,27 @@ setup_target_for_coverage_fastcov(
DEPENDENCIES DEPENDENCIES
all all
FASTCOV_ARGS FASTCOV_ARGS
--branch-coverage
--include --include
${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}
${COVERAGE_ADDITIONAL_ARGS} ${COVERAGE_ADDITIONAL_ARGS}
EXCLUDE EXCLUDE
Applications/CLI/ Applications/CLI/
Tests/ Tests/
POST_CMD
perl
-i
-pe
s!${PROJECT_SOURCE_DIR}/!!g
ctest_coverage.json
NO_DEMANGLE
) )
if(UNIX) if(UNIX)
add_custom_target(clean_coverage find . -name '*.gcda' -delete) add_custom_target(clean_coverage find . -name '*.gcda' -delete)
endif() endif()
configure_file(
${PROJECT_SOURCE_DIR}/scripts/test/generate_coverage_vis_data.in.py
${PROJECT_BINARY_DIR}/generate_coverage_vis_data.py @ONLY
)
#!/usr/bin/env python
import os
# need to increase OGS_CTEST_MAX_RUNTIME to enable these:
# ctests = ["SurfaceComplexation", "EquilibriumPhase", "KineticReactant"]
ctests = ["SteadyState", "ComponentTransport", "ThermoHydroMechanics"]
report_path = "./coverage_reports"
os.makedirs(report_path, exist_ok=True)
for t in ctests:
os.system("cmake --build . -t clean_coverage")
os.system(f"ctest -R {t}")
report = f"{report_path}/{t}_coverage.json"
os.system(
f"@FASTCOV_PATH@ --branch-coverage --include @PROJECT_SOURCE_DIR@ --gcov @GCOV_PATH@ --search-directory @PROJECT_BINARY_DIR@ --process-gcno --output {report} --exclude Applications/CLI/ ProcessLib/ Tests/ --exclude Applications/CLI/ ProcessLib/ Tests/"
)
os.system(f"perl -i -pe s!@PROJECT_SOURCE_DIR@/!!g {report}")
if "CI" in os.environ:
print(
f"Coverage visualization: https://ogs.ogs.xyz/code-coverage-vis/?report={os.environ.get('CI_JOB_URL')}/artifacts/raw/build/coverage/{report}"
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment