Skip to content

Commit 49e0596

Browse files
authored
Add coverage and use reusable workflow from everest-ci (#858)
* Enable coverage generation * Use reusable workflow * Remove old install_and_test script * Set specific paths for ctest and coverage results * Exclude tests directory from code coverage --------- Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
1 parent af3d08e commit 49e0596

File tree

9 files changed

+112
-66
lines changed

9 files changed

+112
-66
lines changed

.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/install_and_test.sh

-21
This file was deleted.

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

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

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

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
3+
ninja -C "$EXT_MOUNT/build" install
4+
retVal=$?
5+
6+
if [ $retVal -ne 0 ]; then
7+
echo "Installation failed with return code $retVal"
8+
exit $retVal
9+
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+
ocpp_gcovr_coverage
6+
retValHTML=$?
7+
8+
ninja \
9+
-C "$EXT_MOUNT/build" \
10+
ocpp_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/ocpp_gcovr_coverage" "$EXT_MOUNT/gcovr-coverage"
15+
cp "$EXT_MOUNT/build/ocpp_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+
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

+22-45
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
name: Build and test libocpp
2-
on:
1+
name: Build, Lint and Test
2+
on:
33
pull_request: {}
44
workflow_dispatch:
55
inputs:
@@ -11,47 +11,24 @@ on:
1111
options:
1212
- 'ubuntu-22.04'
1313
- 'large-ubuntu-22.04-xxl'
14-
jobs:
15-
lint:
16-
name: Lint
17-
runs-on: ${{ inputs.runner || 'ubuntu-22.04' }}
18-
steps:
19-
- name: Checkout libocpp
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-
install_and_test:
30-
name: Install and test
31-
runs-on: ${{ inputs.runner || 'ubuntu-22.04' }}
32-
steps:
33-
- name: Checkout libocpp
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/everest-ci/build-kit-base:latest
44-
docker image tag ghcr.io/everest/everest-ci/build-kit-base:latest build-kit
45-
- name: Run install with tests
46-
run: |
47-
docker run \
48-
--volume "$(pwd):/ext" \
49-
--name test-container \
50-
build-kit run-script install_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
14+
schedule:
15+
- cron: '37 13,1 * * *'
5716

17+
jobs:
18+
ci:
19+
name: Build, Lint and Test
20+
uses: everest/everest-ci/.github/workflows/continuous_integration.yml@v1.4.2
21+
permissions:
22+
contents: read
23+
secrets:
24+
coverage_deploy_token: ${{ secrets.SA_GITHUB_PAT }}
25+
with:
26+
runner: ${{ inputs.runner || 'ubuntu-22.04' }}
27+
artifact_deploy_target_repo: EVerest/everest.github.io
28+
run_coverage: true
29+
do_not_run_coverage_badge_creation: 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

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ endif()
3131

3232
if((${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME} OR ${PROJECT_NAME}_BUILD_TESTING) AND BUILD_TESTING)
3333
set(LIBOCPP_BUILD_TESTING ON)
34+
evc_include(CodeCoverage)
35+
36+
append_coverage_compiler_flags()
3437
endif()
3538

3639
# dependencies

tests/CMakeLists.txt

+14
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,17 @@ endif()
8888
if(LIBOCPP_ENABLE_V201)
8989
add_subdirectory(lib/ocpp/v201)
9090
endif()
91+
92+
setup_target_for_coverage_gcovr_html(
93+
NAME ${PROJECT_NAME}_gcovr_coverage
94+
EXECUTABLE ctest
95+
DEPENDENCIES libocpp_unit_tests
96+
EXCLUDE "src/*" "tests/*"
97+
)
98+
99+
setup_target_for_coverage_gcovr_xml(
100+
NAME ${PROJECT_NAME}_gcovr_coverage_xml
101+
EXECUTABLE ctest
102+
DEPENDENCIES libocpp_unit_tests
103+
EXCLUDE "src/*" "tests/*"
104+
)

0 commit comments

Comments
 (0)