Commit f987667f authored by Lukas Riedel's avatar Lukas Riedel 📝

Add CMake option for enabling coverage flags

Coverage compiler and linker flags are now appended to *all* targets
when the option is turned on. Use the option to enable coverage
reports in the CI pipeline. Adjust build job "needs" to make pipeline
run as fast as possible.
parent a1bfe8b5
variables: variables:
DUNE_CONTROL_PATH: /opt/dune:$CI_PROJECT_DIR DUNE_DIR: /opt/dune
DUNE_CONTROL_PATH: $DUNE_DIR:$CI_PROJECT_DIR
DUNECONTROL: ./dune-common/bin/dunecontrol DUNECONTROL: ./dune-common/bin/dunecontrol
CPUS_MULTICORE: 4 CPUS_MULTICORE: 4
CPUS_DIND: 2 CPUS_DIND: 2
...@@ -30,8 +31,9 @@ variables: ...@@ -30,8 +31,9 @@ variables:
image: $DUNE_ENV_IMAGE image: $DUNE_ENV_IMAGE
# Move into top-level DUNE directory
before_script: before_script:
- cd /opt/dune - cd $DUNE_DIR
# Provide SSH access via the SSH_PRIVATE_KEY and SSH_KNOWN_HOSTS variables # Provide SSH access via the SSH_PRIVATE_KEY and SSH_KNOWN_HOSTS variables
.ssh-access: &ssh_access .ssh-access: &ssh_access
...@@ -123,7 +125,7 @@ prep:update-dune-clang: ...@@ -123,7 +125,7 @@ prep:update-dune-clang:
build:system-tests: &build-tests build:system-tests: &build-tests
stage: build stage: build
script: script:
- CMAKE_FLAGS="$CMAKE_FLAGS" - CMAKE_FLAGS="$CMAKE_FLAGS -DCOVERAGE_REPORT=On"
$DUNECONTROL --only=dorie configure $DUNECONTROL --only=dorie configure
- $DUNECONTROL --only=dorie make $MAKE_FLAGS dorie-rfg - $DUNECONTROL --only=dorie make $MAKE_FLAGS dorie-rfg
- $DUNECONTROL --only=dorie make $MAKE_FLAGS build_system_tests - $DUNECONTROL --only=dorie make $MAKE_FLAGS build_system_tests
...@@ -136,20 +138,22 @@ build:system-tests: &build-tests ...@@ -136,20 +138,22 @@ build:system-tests: &build-tests
build:unit-tests: build:unit-tests:
<<: *build-tests <<: *build-tests
script: script:
- CMAKE_FLAGS="$CMAKE_FLAGS - CMAKE_FLAGS="$CMAKE_FLAGS -DCOVERAGE_REPORT=On
-DCMAKE_BUILD_TYPE=Debug" -DCMAKE_BUILD_TYPE=None"
$DUNECONTROL --only=dorie configure $DUNECONTROL --only=dorie configure
- $DUNECONTROL --only=dorie make $MAKE_FLAGS build_unit_tests - $DUNECONTROL --only=dorie make $MAKE_FLAGS build_unit_tests
build:debug: &debug build:debug: &debug
stage: build stage: build
allow_failure: true allow_failure: true
script: before_script:
- cd $DUNE_DIR
- CMAKE_FLAGS=" - CMAKE_FLAGS="
$CMAKE_FLAGS $CMAKE_FLAGS
-DCMAKE_BUILD_TYPE=Debug -DCMAKE_BUILD_TYPE=Debug
-DCMAKE_CXX_FLAGS_DEBUG='-Werror'" -DCMAKE_CXX_FLAGS_DEBUG='-Werror'"
$DUNECONTROL --only=dorie configure $DUNECONTROL --only=dorie configure
script:
- $DUNECONTROL --only=dorie make $MAKE_FLAGS dorie-rfg - $DUNECONTROL --only=dorie make $MAKE_FLAGS dorie-rfg
- $DUNECONTROL --only=dorie make $MAKE_FLAGS build_unit_tests - $DUNECONTROL --only=dorie make $MAKE_FLAGS build_unit_tests
- $DUNECONTROL --only=dorie make $MAKE_FLAGS richards_d2_r1 transport_d2_r0_t0 - $DUNECONTROL --only=dorie make $MAKE_FLAGS richards_d2_r1 transport_d2_r0_t0
...@@ -157,7 +161,9 @@ build:debug: &debug ...@@ -157,7 +161,9 @@ build:debug: &debug
build:debug-clang: build:debug-clang:
<<: *debug <<: *debug
image: ${DUNE_ENV_IMAGE}-clang image: ${DUNE_ENV_IMAGE}-clang
script: before_script:
- cd $DUNE_DIR
# Choose Clang compiler explicitly
- CMAKE_FLAGS=" - CMAKE_FLAGS="
$CMAKE_FLAGS $CMAKE_FLAGS
-DCMAKE_BUILD_TYPE=Debug -DCMAKE_BUILD_TYPE=Debug
...@@ -165,9 +171,6 @@ build:debug-clang: ...@@ -165,9 +171,6 @@ build:debug-clang:
-DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_COMPILER=clang++
-DCMAKE_CXX_FLAGS_DEBUG='-Werror'" -DCMAKE_CXX_FLAGS_DEBUG='-Werror'"
$DUNECONTROL --only=dorie configure $DUNECONTROL --only=dorie configure
- $DUNECONTROL --only=dorie make $MAKE_FLAGS dorie-rfg
- $DUNECONTROL --only=dorie make $MAKE_FLAGS build_unit_tests
- $DUNECONTROL --only=dorie make $MAKE_FLAGS transport_d2_r0_t0 transport_d2_r1_t0
build:docs: build:docs:
stage: build stage: build
...@@ -186,50 +189,53 @@ test:system-tests: &test ...@@ -186,50 +189,53 @@ test:system-tests: &test
stage: test stage: test
dependencies: dependencies:
- build:system-tests - build:system-tests
needs: ["build:system-tests"]
variables:
GCOVR_PATHS:
--root $CI_PROJECT_DIR
--exclude $CI_PROJECT_DIR/dune/dorie/test
--exclude $CI_PROJECT_DIR/plugins
script: script:
- $DUNECONTROL --only=dorie configure - $DUNECONTROL --only=dorie configure
- $DUNECONTROL --only=dorie make system_tests - $DUNECONTROL --only=dorie make system_tests
# Run coverage utility (will also run after failed job)
after_script:
- source $CI_PROJECT_DIR/build-cmake/activate
- pip3 install gcovr
- cd $CI_PROJECT_DIR/build-cmake
- mkdir coverage
- gcovr $GCOVR_PATHS --html --html-details -o coverage/report.html
# run again for coverage report in GitLab
- gcovr $GCOVR_PATHS
coverage: '/^TOTAL.*\s+(\d+\%)$/'
artifacts: artifacts:
name: "$CI_JOB_NAME" name: "$CI_JOB_NAME"
paths: paths:
- $CI_PROJECT_DIR/build-cmake/test - $CI_PROJECT_DIR/build-cmake/test
- $CI_PROJECT_DIR/build-cmake/coverage
expire_in: 1 day expire_in: 1 day
test:unit-tests: test:unit-tests:
<<: *test <<: *test
dependencies: dependencies:
- build:unit-tests - build:unit-tests
needs: ["build:unit-tests"]
script: script:
# install coverage reporter
- $DUNECONTROL --only=dorie bexec
"./run-in-dune-env python3 -m pip install gcovr"
# perform the tests
- $DUNECONTROL --only=dorie configure - $DUNECONTROL --only=dorie configure
- $DUNECONTROL --only=dorie make unit_tests - $DUNECONTROL --only=dorie make unit_tests
# report coverage
- cd $CI_PROJECT_DIR/build-cmake
- mkdir -p dune/dorie/test/coverage
- ./run-in-dune-env gcovr
--root ../
--exclude ../dune/dorie/test
--exclude ../plugins
--html --html-details
-o dune/dorie/test/coverage/coverage.html
# run again for coverage report in GitLab
- ./run-in-dune-env gcovr
--root ../
--exclude ../dune/dorie/test
--exclude ../plugins
coverage: '/^TOTAL.*\s+(\d+\%)$/'
artifacts: artifacts:
name: "$CI_JOB_NAME" name: "$CI_JOB_NAME"
paths: paths:
- $CI_PROJECT_DIR/build-cmake/dune/dorie/test - $CI_PROJECT_DIR/build-cmake/dune/dorie/test
- $CI_PROJECT_DIR/build-cmake/coverage
expire_in: 1 day expire_in: 1 day
test:python-tests: test:python-tests:
<<: *test <<: *test
dependencies: [] dependencies: []
# TODO: Make empty once https://gitlab.com/gitlab-org/gitlab/issues/30631
# is resolved
needs: ["build:docs"] # Any quick job from previous stage
script: script:
- $DUNECONTROL --only=dorie configure - $DUNECONTROL --only=dorie configure
- $DUNECONTROL --only=dorie make test_python - $DUNECONTROL --only=dorie make test_python
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
* ParaView tutorial for analyzing DORiE output files !173 * ParaView tutorial for analyzing DORiE output files !173
* Parameter XML files support tags for version changes !171 * Parameter XML files support tags for version changes !171
* Unit test for Parameter XML file parser !171 * Unit test for Parameter XML file parser !171
* CMake option to enable code coverage flags on all targets !172
### Changed ### Changed
* Data structures for storing and accessing parameter information !55 * Data structures for storing and accessing parameter information !55
...@@ -57,6 +58,7 @@ ...@@ -57,6 +58,7 @@
* `SimulationBase` unit test now uses Google Test !159 * `SimulationBase` unit test now uses Google Test !159
* Deploy online documentation for each branch to private server !163 * Deploy online documentation for each branch to private server !163
* Use YAML (instead of muPhi `.bcdat`) files for specifying BCs !121 * Use YAML (instead of muPhi `.bcdat`) files for specifying BCs !121
* Unit and system tests report code coverage separately !172
### Fixed ### Fixed
* Allow meta-ini files for unit tests !101 * Allow meta-ini files for unit tests !101
......
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.10)
project(dorie C CXX) project(dorie C CXX)
# Configuration options
option(COVERAGE_REPORT "Enable coverage compiler flags")
# set build type # set build type
if(NOT CMAKE_BUILD_TYPE) if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release") set(CMAKE_BUILD_TYPE "Release")
endif() endif()
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPER) string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPER)
if(CMAKE_BUILD_TYPE_UPPER MATCHES DEBUG) if(CMAKE_BUILD_TYPE_UPPER MATCHES DEBUG)
set(CMAKE_VERBOSE_MAKEFILE ON) set(CMAKE_VERBOSE_MAKEFILE ON)
endif() endif()
# add extra flags to debug compiler flags # add extra flags to debug compiler flags
......
...@@ -432,9 +432,15 @@ Additionaly, there is a set of tests for the Python module. ...@@ -432,9 +432,15 @@ Additionaly, there is a set of tests for the Python module.
The `make` commands are to be executed from within the `build-cmake` directory. The `make` commands are to be executed from within the `build-cmake` directory.
The unit tests automatically include compiler flags for code coverage reports. #### Code Coverage Report
After building them with `Debug` flags and executing them, you can To enable code coverage reports, configure DORiE with the CMake option
retrieve code coverage information using the `COVERAGE_REPORT` enabled, like so (from the `build-cmake` directory):
cmake -DCOVERAGE_REPORT=On ..
This will add the appropriate compiler flags to _all_ targets. You then have to
re-build all binaries. After running tests or executing the application, you
can retrieve code coverage information using the
[`gcovr`](https://gcovr.com/index.html) utility. [`gcovr`](https://gcovr.com/index.html) utility.
### Further Help ### Further Help
......
...@@ -100,6 +100,12 @@ function(dorie_compile_instance) ...@@ -100,6 +100,12 @@ function(dorie_compile_instance)
add_executable(${exe_name} EXCLUDE_FROM_ALL ${src_file}) add_executable(${exe_name} EXCLUDE_FROM_ALL ${src_file})
target_link_libraries(${exe_name} PUBLIC ${lib_name}) target_link_libraries(${exe_name} PUBLIC ${lib_name})
# Coverage links if enabled
if(COVERAGE_REPORT)
target_compile_options(${exe_name} PUBLIC --coverage)
target_link_libraries(${exe_name} PUBLIC --coverage)
endif()
# Add the executable to the default targets # Add the executable to the default targets
if ((ARGS_RORDER LESS_EQUAL DORIE_MAX_DEFAULT_RORDER_${ARGS_DIMENSION}) if ((ARGS_RORDER LESS_EQUAL DORIE_MAX_DEFAULT_RORDER_${ARGS_DIMENSION})
AND ((NOT ARGS_TORDER) AND ((NOT ARGS_TORDER)
......
...@@ -100,6 +100,10 @@ function(dorie_add_unit_test) ...@@ -100,6 +100,10 @@ function(dorie_add_unit_test)
GTEST GTEST
) )
if(COVERAGE_REPORT)
add_coverage_links(${UNIT_TEST_TARGET})
endif()
if (UNIT_TEST_CUSTOM_MAIN) if (UNIT_TEST_CUSTOM_MAIN)
target_link_libraries(${UNIT_TEST_TARGET} gtest) target_link_libraries(${UNIT_TEST_TARGET} gtest)
else () else ()
...@@ -226,15 +230,20 @@ function(dorie_add_metaini_test) ...@@ -226,15 +230,20 @@ function(dorie_add_metaini_test)
# report created targets to parent scope # report created targets to parent scope
set(${SYSTEM_TEST_CREATED_TARGETS} ${created_targets} PARENT_SCOPE) set(${SYSTEM_TEST_CREATED_TARGETS} ${created_targets} PARENT_SCOPE)
# Link to dependencies # Set properties for new target
if(NOT SYSTEM_TEST_TARGET) if(NOT SYSTEM_TEST_TARGET)
# Link to dependencies
target_link_libraries(${created_targets} target_link_libraries(${created_targets}
muparser::muparser hdf5 yaml-cpp spdlog) muparser::muparser hdf5 yaml-cpp spdlog)
# Add coverage flags if enabled
if(COVERAGE_REPORT)
add_coverage_links(${created_targets})
endif()
endif() endif()
# add dependencies and flags # add dependencies and flags
if(SYSTEM_TEST_UNIT_TEST) if(SYSTEM_TEST_UNIT_TEST)
# add_coverage_links(${created_targets})
add_dependencies(build_unit_tests ${created_targets}) add_dependencies(build_unit_tests ${created_targets})
target_compile_definitions(${created_targets} target_compile_definitions(${created_targets}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment