Skip to content

Commit 063944b

Browse files
authored
Adding gcovr code coverage generation and use reusable workflow from everest-ci (#36)
Signed-off-by: Sebastian Lukas <sebastian.lukas@pionix.de> Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
1 parent a00f639 commit 063944b

File tree

8 files changed

+111
-59
lines changed

8 files changed

+111
-59
lines changed

.ci/build-kit/build_and_test.sh

-16
This file was deleted.

.ci/build-kit/docker/Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# syntax=docker/dockerfile:1
2+
ARG BASE_IMAGE_TAG=latest
3+
FROM ghcr.io/everest/everest-ci/build-kit-base:${BASE_IMAGE_TAG}

.ci/build-kit/scripts/compile.sh

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/sh
2+
3+
cmake \
4+
-B "$EXT_MOUNT/build" \
5+
-S "$EXT_MOUNT/source" \
6+
-G Ninja \
7+
-DBUILD_TESTING=ON \
8+
-DCMAKE_BUILD_TYPE=Debug \
9+
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
10+
11+
retVal=$?
12+
if [ $retVal -ne 0 ]; then
13+
echo "Configuring failed with return code $retVal"
14+
exit $retVal
15+
fi
16+
17+
ninja -C "$EXT_MOUNT/build"
18+
retVal=$?
19+
if [ $retVal -ne 0 ]; then
20+
echo "Compiling failed with return code $retVal"
21+
exit $retVal
22+
fi

.ci/build-kit/scripts/run_coverage.sh

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
3+
ninja \
4+
-C "$EXT_MOUNT/build" \
5+
iso15118_gcovr_coverage
6+
retValHTML=$?
7+
8+
ninja \
9+
-C "$EXT_MOUNT/build" \
10+
iso15118_gcovr_coverage_xml
11+
retValXML=$?
12+
13+
# Copy the generated coverage report and xml to the mounted directory in any case
14+
cp -R "$EXT_MOUNT/build/iso15118_gcovr_coverage" "$EXT_MOUNT/gcovr-coverage"
15+
cp "$EXT_MOUNT/build/iso15118_gcovr_coverage_xml.xml" "$EXT_MOUNT/gcovr-coverage-xml.xml"
16+
17+
if [ $retValHTML -ne 0 ]; then
18+
echo "Coverage HTML report failed with return code $retValHTML"
19+
exit $retValHTML
20+
fi
21+
22+
if [ $retValXML -ne 0 ]; then
23+
echo "Coverage XML report failed with return code $retValXML"
24+
exit $retValXML
25+
fi
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
3+
CTEST_OUTPUT_ON_FAILURE=1 ninja -C "$EXT_MOUNT/build" test
4+
retVal=$?
5+
6+
# Copy the LastTest.log file to the mounted directory in any case
7+
cp "$EXT_MOUNT/build/Testing/Temporary/LastTest.log" "$EXT_MOUNT/ctest-report"
8+
9+
if [ $retVal -ne 0 ]; then
10+
echo "Unit tests failed with return code $retVal"
11+
exit $retVal
12+
fi

.github/workflows/build_and_test.yaml

+21-43
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build and test libiso15118
1+
name: Build, lint and test libiso15118
22
on:
33
pull_request: {}
44
workflow_dispatch:
@@ -11,46 +11,24 @@ on:
1111
options:
1212
- 'ubuntu-22.04'
1313
- 'large-ubuntu-22.04-xxl'
14+
schedule:
15+
- cron: '37 13,1 * * *'
1416
jobs:
15-
lint:
16-
name: Lint
17-
runs-on: ${{ inputs.runner || 'ubuntu-22.04' }}
18-
steps:
19-
- name: Checkout libiso15118
20-
uses: actions/checkout@v3
21-
with:
22-
path: source
23-
- name: Run clang-format
24-
uses: everest/everest-ci/github-actions/run-clang-format@v1.1.0
25-
with:
26-
source-dir: source
27-
extensions: hpp,cpp
28-
exclude: cache
29-
build_and_test:
30-
name: Build and test
31-
runs-on: ${{ inputs.runner || 'ubuntu-22.04' }}
32-
steps:
33-
- name: Checkout libiso15118
34-
uses: actions/checkout@v3
35-
with:
36-
path: source
37-
- name: Setup run scripts
38-
run: |
39-
mkdir scripts
40-
rsync -a source/.ci/build-kit/ scripts
41-
- name: Pull docker container
42-
run: |
43-
docker pull --platform=linux/x86_64 --quiet ghcr.io/everest/build-kit-alpine:latest
44-
docker image tag ghcr.io/everest/build-kit-alpine:latest build-kit
45-
- name: Build and test
46-
run: |
47-
docker run \
48-
--volume "$(pwd):/ext" \
49-
--name test-container \
50-
build-kit run-script build_and_test
51-
- name: Archive test results
52-
if: always()
53-
uses: actions/upload-artifact@v3
54-
with:
55-
name: ctest-report
56-
path: ${{ github.workspace }}/ctest-report
17+
ci:
18+
name: Build, Lint and Test
19+
uses: everest/everest-ci/.github/workflows/continuous_integration.yml@v1.4.3
20+
permissions:
21+
contents: read
22+
secrets:
23+
coverage_deploy_token: ${{ secrets.SA_GITHUB_PAT }}
24+
with:
25+
runner: ${{ inputs.runner || 'ubuntu-22.04' }}
26+
artifact_deploy_target_repo: EVerest/everest.github.io
27+
run_coverage: true
28+
do_not_run_coverage_badge_creation: false
29+
run_install: false
30+
run_install_wheels: false
31+
run_integration_tests: false
32+
ctest_report_path: ctest-report
33+
coverage_report_path: gcovr-coverage
34+
coverage_xml_path: gcovr-coverage-xml.xml

CMakeLists.txt

+18
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ message(STATUS "Building libiso15118 with the following compile options: ${ISO15
3737

3838
if((${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME} OR ${PROJECT_NAME}_BUILD_TESTING) AND BUILD_TESTING)
3939
set(ISO15118_BUILD_TESTING ON)
40+
evc_include(CodeCoverage)
41+
append_coverage_compiler_flags()
4042
endif()
4143

4244
# dependencies
@@ -54,9 +56,25 @@ add_subdirectory(input)
5456
add_subdirectory(src)
5557

5658
if (ISO15118_BUILD_TESTING)
59+
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type" FORCE) # TODO(sl): Check if necessary
60+
5761
include(CTest)
5862
list(APPEND CMAKE_MODULE_PATH ${CPM_PACKAGE_catch2_SOURCE_DIR}/extras)
5963
add_subdirectory(test)
64+
65+
# FIXME(sl): Set gcovr correctly so that it finds the catch2 files.
66+
set(GCOVR_ADDITIONAL_ARGS "--gcov-ignore-errors=no_working_dir_found")
67+
setup_target_for_coverage_gcovr_html(
68+
NAME ${PROJECT_NAME}_gcovr_coverage
69+
EXECUTABLE ctest
70+
EXCLUDE "test/*" "build/*"
71+
)
72+
73+
setup_target_for_coverage_gcovr_xml(
74+
NAME ${PROJECT_NAME}_gcovr_coverage_xml
75+
EXECUTABLE ctest
76+
EXCLUDE "test/*" "build/*"
77+
)
6078
endif()
6179

6280
if (ISO15118_INSTALL)

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,14 @@ ninja -C build
4343
4444
# Running tests
4545
ninja -C build test
46+
47+
# Generating a code coverage (BUILD_TESTING should be enabled)
48+
ninja -C build iso15118_gcovr_coverage
49+
```
50+
51+
The coverage report will be available in the index.html file in the `build/iso15118_gcovr_coverage` directory.
52+
53+
Version 8.2 or higher of gcovr is required for the coverage report. Install gcovr release from PyPI:
54+
```
55+
pip install gcovr
4656
```

0 commit comments

Comments
 (0)