Skip to content

Commit b25d92c

Browse files
committed
Compute code coverage
Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
1 parent 9a79644 commit b25d92c

File tree

5 files changed

+134
-1
lines changed

5 files changed

+134
-1
lines changed

.github/workflows/coverage.yml

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

cmake/helpers.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,13 @@ function(add_umf_target_compile_options name)
255255
)
256256
endif()
257257
target_compile_options(${name} PRIVATE --coverage)
258+
if(${CMAKE_C_COMPILER} MATCHES "gcc")
259+
# Fix for the following error: geninfo: ERROR: Unexpected
260+
# negative count '-1' for provider_os_memory.c:1037. Perhaps you
261+
# need to compile with '-fprofile-update=atomic
262+
target_compile_options(${name} PRIVATE -fprofile-update=atomic
263+
-g -O0)
264+
endif()
258265
endif()
259266
elseif(MSVC)
260267
target_compile_options(

scripts/coverage/coverage_capture.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
# This script calculates coverage for a single build
7+
8+
set -e
9+
10+
[ "$1" != "" ] && OUTPUT_NAME="$1" || OUTPUT_NAME="output_coverage"
11+
12+
set -x
13+
14+
lcov --capture --directory . \
15+
--exclude "/usr/*" \
16+
--exclude "*/build/*" \
17+
--exclude "*/benchmark/*" \
18+
--exclude "*/examples/*" \
19+
--exclude "*/test/*" \
20+
--exclude "*/src/critnib/*" \
21+
--exclude "*/src/ravl/*" \
22+
--exclude "*proxy_lib_new_delete.h" \
23+
--output-file $OUTPUT_NAME || \
24+
( echo "RETRY after ERROR !!!:" && \
25+
lcov --capture --directory . \
26+
--exclude "/usr/*" \
27+
--exclude "*/build/*" \
28+
--exclude "*/benchmark/*" \
29+
--exclude "*/examples/*" \
30+
--exclude "*/test/*" \
31+
--exclude "*/src/critnib/*" \
32+
--exclude "*/src/ravl/*" \
33+
--exclude "*proxy_lib_new_delete.h" \
34+
--ignore-errors mismatch,unused,negative,corrupt \
35+
--output-file $OUTPUT_NAME )
36+
37+
# Most common UMF source code directory on most GH CI runners
38+
COMMON_UMF_DIR=/home/runner/work/unified-memory-framework/unified-memory-framework
39+
40+
# Get the current UMF source code directory
41+
# This is ${CURRENT_UMF_DIR}/scripts/coverage/coverage_capture.sh file, so
42+
CURRENT_UMF_DIR=$(realpath $(dirname $0)/../..)
43+
44+
# Coverage (lcov) has to be run in the same directory on all runners:
45+
# /home/runner/work/unified-memory-framework/unified-memory-framework/build
46+
# to be able to merge all results, so we have to replace the paths if they are different:
47+
if [ "$CURRENT_UMF_DIR" != "$COMMON_UMF_DIR" ]; then
48+
sed -i "s|$CURRENT_UMF_DIR|$COMMON_UMF_DIR|g" $OUTPUT_NAME
49+
fi
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
#
7+
# Arguments: <PREFIX> <OUTPUT_NAME>
8+
#
9+
# This script looks for "${PREFIX}-*" lcov output files in the current directory,
10+
# merges them and saves the merged output in the $OUTPUT_NAME file.
11+
#
12+
13+
[ "$1" != "" ] && PREFIX="$1" || PREFIX="exports-coverage"
14+
[ "$2" != "" ] && OUTPUT_NAME="$2" || OUTPUT_NAME="total_coverage"
15+
16+
OPTS=""
17+
for file in $(ls -1 ${PREFIX}-*); do
18+
OPTS="$OPTS -a $file"
19+
done
20+
21+
set -x
22+
23+
lcov $OPTS -o $OUTPUT_NAME || \
24+
( echo "RETRY after ERROR !!!:" && \
25+
lcov $OPTS \
26+
--ignore-errors mismatch,unused,negative,corrupt \
27+
--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)