Skip to content

Commit d62f122

Browse files
committed
TEST COVERAGE - LCOV
Signed-off-by: Lukasz Dorau <[email protected]>
1 parent d948fe0 commit d62f122

File tree

7 files changed

+129
-4
lines changed

7 files changed

+129
-4
lines changed

.github/workflows/basic.yml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ env:
1111
UMF_VERSION: 0.10.0
1212
BUILD_DIR : "${{github.workspace}}/build"
1313
INSTL_DIR : "${{github.workspace}}/../install-dir"
14+
COVERAGE_DIR : "${{github.workspace}}/coverage"
15+
COVERAGE_NAME : "exports-coverage-basic"
1416

1517
jobs:
1618
ubuntu-build:
@@ -122,8 +124,8 @@ jobs:
122124
- name: Install apt packages
123125
run: |
124126
sudo apt-get update
125-
sudo apt-get install -y clang cmake libnuma-dev libjemalloc-dev
126-
127+
sudo apt-get install -y clang cmake libnuma-dev libjemalloc-dev lcov
128+
127129
- name: Install TBB apt package
128130
if: matrix.install_tbb == 'ON'
129131
run: |
@@ -167,6 +169,7 @@ jobs:
167169
-DUMF_TESTS_FAIL_ON_SKIP=ON
168170
-DUMF_DISABLE_HWLOC=${{matrix.disable_hwloc}}
169171
-DUMF_LINK_HWLOC_STATICALLY=${{matrix.link_hwloc_statically}}
172+
${{ matrix.build_type == 'Debug' && matrix.compiler.c == 'gcc' && '-DUMF_USE_COVERAGE=ON' || '' }}
170173
171174
- name: Build UMF
172175
run: |
@@ -177,7 +180,23 @@ jobs:
177180
working-directory: ${{env.BUILD_DIR}}
178181
run: |
179182
${{ matrix.compiler.cxx == 'icpx' && '. /opt/intel/oneapi/setvars.sh' || true }}
180-
ctest --output-on-failure --test-dir test
183+
ctest --output-on-failure # run all tests for better coverage
184+
185+
- name: Check coverage
186+
if: ${{ matrix.build_type == 'Debug' && matrix.compiler.c == 'gcc' }}
187+
working-directory: ${{env.BUILD_DIR}}
188+
run: |
189+
export COVERAGE_FILE_NAME=${{env.COVERAGE_NAME}}-${{matrix.os}}-shared-${{matrix.shared_library}}-hwloc-${{matrix.disable_hwloc}}
190+
echo "COVERAGE_FILE_NAME: $COVERAGE_FILE_NAME"
191+
../scripts/coverage/coverage_capture.sh $COVERAGE_FILE_NAME
192+
mkdir -p ${{env.COVERAGE_DIR}}
193+
mv ./$COVERAGE_FILE_NAME ${{env.COVERAGE_DIR}}
194+
195+
- uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
196+
if: ${{ matrix.build_type == 'Debug' && matrix.compiler.c == 'gcc' }}
197+
with:
198+
name: ${{env.COVERAGE_NAME}}-${{matrix.os}}-shared-${{matrix.shared_library}}-hwloc-${{matrix.disable_hwloc}}
199+
path: ${{env.COVERAGE_DIR}}
181200

182201
- name: Remove the installation directory
183202
run: rm -rf ${{env.INSTL_DIR}}

.github/workflows/coverage.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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: Download file exports-coverage-basic-ubuntu-20.04-shared-OFF-hwloc-OFF
31+
uses: actions/download-artifact@v4
32+
with:
33+
name: exports-coverage-basic-ubuntu-20.04-shared-OFF-hwloc-OFF
34+
path: coverage
35+
36+
- name: Download file exports-coverage-basic-ubuntu-22.04-shared-OFF-hwloc-OFF
37+
uses: actions/download-artifact@v4
38+
with:
39+
name: exports-coverage-basic-ubuntu-22.04-shared-OFF-hwloc-OFF
40+
path: coverage
41+
42+
- name: Download file exports-coverage-basic-ubuntu-24.04-shared-ON-hwloc-OFF
43+
uses: actions/download-artifact@v4
44+
with:
45+
name: exports-coverage-basic-ubuntu-24.04-shared-ON-hwloc-OFF
46+
path: coverage
47+
48+
- name: Download file exports-coverage-basic-ubuntu-22.04-shared-ON-hwloc-ON
49+
uses: actions/download-artifact@v4
50+
with:
51+
name: exports-coverage-basic-ubuntu-22.04-shared-ON-hwloc-ON
52+
path: coverage
53+
54+
- name: Compute coverage
55+
working-directory: ${{env.COVERAGE_DIR}}
56+
run: |
57+
echo "DIR: $(pwd)" && ls -al
58+
../scripts/coverage/merge_coverage_files.sh exports-coverage total_coverage
59+
genhtml --ignore-errors source -o html_report total_coverage 2>&1 | tee output.txt
60+
tail -n3 output.txt >> $GITHUB_STEP_SUMMARY
61+
62+
- name: Upload coverage report
63+
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
64+
with:
65+
name: coverage_html_report
66+
path: coverage/html_report

.github/workflows/pr_push.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,6 @@ jobs:
110110
MultiNuma:
111111
needs: [Build]
112112
uses: ./.github/workflows/multi_numa.yml
113+
Coverage:
114+
needs: [Spellcheck, CodeStyle, Build]
115+
uses: ./.github/workflows/coverage.yml

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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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 . --exclude "/usr/*" --exclude "*/build/_deps/*" --exclude "*/examples/*" --exclude "*/test/*" --exclude "*/src/critnib/*" --exclude "*/src/ravl/*" --exclude "*proxy_lib_new_delete.h*" --output-file $OUTPUT_NAME || \
13+
( echo && lcov --capture --directory . --exclude "/usr/*" --exclude "*/build/_deps/*" --exclude "*/examples/*" --exclude "*/test/*" --exclude "*/src/critnib/*" --exclude "*/src/ravl/*" --exclude "*proxy_lib_new_delete.h*" --ignore-errors mismatch,unused --output-file $OUTPUT_NAME )
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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 -ex
7+
8+
[ "$1" != "" ] && PREFIX="$1" || PREFIX="exports-coverage"
9+
[ "$2" != "" ] && OUTPUT_NAME="$2" || OUTPUT_NAME="total_coverage"
10+
11+
OPTS=""
12+
for file in $(ls -1 ${PREFIX}-*); do
13+
OPTS="$OPTS -a $file"
14+
done
15+
16+
lcov -o $OUTPUT_NAME $OPTS

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)