Skip to content

Commit 8df5265

Browse files
committed
Compute code coverage
Signed-off-by: Lukasz Dorau <[email protected]>
1 parent 166e1a0 commit 8df5265

File tree

5 files changed

+120
-1
lines changed

5 files changed

+120
-1
lines changed

.github/workflows/coverage.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Coverage build
2+
name: Coverage
3+
4+
on: workflow_call
5+
6+
permissions:
7+
contents: read
8+
9+
env:
10+
BUILD_DIR : "${{github.workspace}}/build"
11+
INSTL_DIR : "${{github.workspace}}/../install-dir"
12+
COVERAGE_DIR : "${{github.workspace}}/coverage"
13+
14+
jobs:
15+
Coverage:
16+
name: Coverage build
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Install dependencies (ubuntu-latest)
26+
run: |
27+
sudo apt-get update
28+
sudo apt-get install -y lcov
29+
30+
- name: Compute coverage
31+
working-directory: ${{env.COVERAGE_DIR}}
32+
run: |
33+
echo "DIR: $(pwd)" && ls -al
34+
../scripts/coverage/merge_coverage_files.sh exports-coverage total_coverage
35+
genhtml --ignore-errors source -o html_report total_coverage 2>&1 | tee output.txt
36+
mkdir coverage_report
37+
mv html_report ./coverage_report/
38+
tail -n3 output.txt >> $GITHUB_STEP_SUMMARY
39+
40+
- name: Upload coverage report
41+
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
42+
with:
43+
name: coverage_html_report
44+
path: coverage/coverage_report

cmake/helpers.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,13 @@ function(add_umf_target_compile_options name)
252252
message(FATAL_ERROR "To use gcov, the build type must be Debug")
253253
endif()
254254
target_compile_options(${name} PRIVATE --coverage)
255+
if(${CMAKE_C_COMPILER} MATCHES "gcc")
256+
# Fix for the following error: geninfo: ERROR: Unexpected
257+
# negative count '-1' for provider_os_memory.c:1037. Perhaps you
258+
# need to compile with '-fprofile-update=atomic
259+
target_compile_options(${name} PRIVATE -fprofile-update=atomic
260+
-g -O0)
261+
endif()
255262
endif()
256263
elseif(MSVC)
257264
target_compile_options(

scripts/coverage/coverage_capture.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
# Copyright (C) 2024 Intel Corporation
3+
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
set -e
7+
8+
[ "$1" != "" ] && OUTPUT_NAME="$1" || OUTPUT_NAME="total_coverage"
9+
10+
set -x
11+
12+
lcov --capture --directory . \
13+
--exclude "/usr/*" \
14+
--exclude "*/build/*" \
15+
--exclude "*/benchmark/*" \
16+
--exclude "*/examples/*" \
17+
--exclude "*/test/*" \
18+
--exclude "*/src/critnib/*" \
19+
--exclude "*/src/ravl/*" \
20+
--exclude "*proxy_lib_new_delete.h" \
21+
--output-file $OUTPUT_NAME || \
22+
( echo "RETRY after ERROR !!!:" && \
23+
lcov --capture --directory . \
24+
--exclude "/usr/*" \
25+
--exclude "*/build/*" \
26+
--exclude "*/benchmark/*" \
27+
--exclude "*/examples/*" \
28+
--exclude "*/test/*" \
29+
--exclude "*/src/critnib/*" \
30+
--exclude "*/src/ravl/*" \
31+
--exclude "*proxy_lib_new_delete.h" \
32+
--ignore-errors mismatch,unused,negative,corrupt \
33+
--output-file $OUTPUT_NAME )
34+
35+
# Most common UMF source code directory on most GH CI runners
36+
COMMON_UMF_DIR=/home/runner/work/unified-memory-framework/unified-memory-framework
37+
38+
# Get the current UMF source code directory
39+
# This is ${CURRENT_UMF_DIR}/scripts/coverage/coverage_capture.sh file, so
40+
CURRENT_UMF_DIR=$(realpath $(dirname $0)/../..)
41+
42+
# Coverage (lcov) has to be run in the same directory on all runners:
43+
# /home/runner/work/unified-memory-framework/unified-memory-framework/build
44+
# to be able to merge all results, so we have to replace the paths if they are different:
45+
if [ "$CURRENT_UMF_DIR" != "$COMMON_UMF_DIR" ]; then
46+
sed -i "s|$CURRENT_UMF_DIR|$COMMON_UMF_DIR|g" $OUTPUT_NAME
47+
fi
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
# Copyright (C) 2024 Intel Corporation
3+
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
[ "$1" != "" ] && PREFIX="$1" || PREFIX="exports-coverage"
7+
[ "$2" != "" ] && OUTPUT_NAME="$2" || OUTPUT_NAME="total_coverage"
8+
9+
OPTS=""
10+
for file in $(ls -1 ${PREFIX}-*); do
11+
OPTS="$OPTS -a $file"
12+
done
13+
14+
set -x
15+
16+
lcov $OPTS -o $OUTPUT_NAME || \
17+
( echo "RETRY after ERROR !!!:" && \
18+
lcov $OPTS \
19+
--ignore-errors mismatch,unused,negative,corrupt \
20+
--output-file $OUTPUT_NAME )

test/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,8 @@ if(LINUX
498498
(UMF_USE_ASAN
499499
OR UMF_USE_UBSAN
500500
OR UMF_USE_TSAN
501-
OR UMF_USE_MSAN))
501+
OR UMF_USE_MSAN
502+
OR UMF_USE_COVERAGE))
502503

503504
set(EXAMPLES "")
504505

0 commit comments

Comments
 (0)