Skip to content

Commit c07f438

Browse files
committed
cmake: add test coverage generation
This commit also adds the sample `script/coverage` script to help developer in generating the coverage reports, and requires the updated build container with `gcovr`
1 parent 890963d commit c07f438

5 files changed

Lines changed: 23 additions & 3 deletions

File tree

.github/workflows/actions.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
build:
77
runs-on: ubuntu-24.04
88
container:
9-
image: giomba/ceda-cemu-builder:3
9+
image: giomba/ceda-cemu-builder:4
1010
options: --user root
1111
steps:
1212
- name: Checkout repository
@@ -23,4 +23,7 @@ jobs:
2323
- name: Test
2424
run: |
2525
script/test
26+
- name: Coverage
27+
run: |
28+
script/coverage
2629

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ set_source_files_properties(src/3rd/disassembler.c PROPERTIES COMPILE_FLAGS -Wno
7272
# Automatically add targets, with same properties
7373
function(add_ceda_target target)
7474

75-
target_compile_options(${target} PRIVATE -W -Wformat -Wall -Wundef -Wpointer-arith -Wcast-qual -Wwrite-strings -Wsign-compare -Wmissing-noreturn -Wextra -Wconversion)
75+
target_compile_options(${target} PRIVATE -W -Wformat -Wall -Wundef -Wpointer-arith -Wcast-qual -Wwrite-strings -Wsign-compare -Wmissing-noreturn -Wextra -Wconversion -coverage)
7676

7777
if(CMAKE_BUILD_TYPE MATCHES "Release")
7878
target_compile_options(${target} PRIVATE -Werror)
@@ -86,6 +86,7 @@ function(add_ceda_target target)
8686
SDL3_mixer
8787
inih
8888
)
89+
target_link_options(${target} PRIVATE -coverage)
8990

9091
set_target_properties(${target} PROPERTIES C_CLANG_TIDY "${CLANG_TIDY_COMMAND}")
9192

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ RUN cd /build && \
3737
meson install -C build && \
3838
ldconfig
3939

40+
RUN apt install -y gcovr
41+
4042
RUN useradd -s /bin/bash --create-home builder
4143
USER builder
4244
RUN mkdir -p /home/builder/workspace

script/coverage

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
pushd build.release
6+
ctest -T coverage
7+
8+
pushd Testing/CoverageInfo
9+
gcovr --root ../../.. --html-details coverage.html
10+
11+
popd
12+
popd
13+
14+

script/docker

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ docker run --rm -ti -u ubuntu \
1212
-v "$(pwd)":/home/ubuntu/workspace \
1313
-v /tmp:/tmp \
1414
-w /home/ubuntu/workspace \
15-
giomba/ceda-cemu-builder:3 \
15+
giomba/ceda-cemu-builder:4 \
1616
"$@"

0 commit comments

Comments
 (0)