Skip to content

Commit 751359c

Browse files
committed
Added codecov integration to stdBLAS
Closes NavalNuclearLab#7
1 parent 70c5127 commit 751359c

4 files changed

Lines changed: 142 additions & 0 deletions

File tree

.github/workflows/coverage.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Coverage
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
coverage:
9+
runs-on: ubuntu-latest
10+
11+
strategy:
12+
matrix:
13+
std: [17, 20]
14+
15+
env:
16+
COVERAGE_ROOT: ${{ github.workspace }}/.coverage
17+
LLVM_PREFIX: /usr
18+
LLVM_PROFILE_FILE: "$COVERAGE_ROOT/cxx${{ matrix.std }}/%p.profraw"
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Install LLVM
24+
run: |
25+
sudo apt-get update
26+
sudo apt-get install -y llvm clang
27+
28+
- name: Configure
29+
run: |
30+
cmake -B build \
31+
-DCMAKE_BUILD_TYPE=Debug \
32+
-DCMAKE_CXX_STANDARD=${{ matrix.std }} \
33+
-DLINALG_ENABLE_TESTS=ON \
34+
-DLINALG_ENABLE_COVERAGE=ON \
35+
-DCMAKE_C_COMPILER=clang \
36+
-DCMAKE_CXX_COMPILER=clang++
37+
38+
- name: Build
39+
run: cmake --build build -j
40+
41+
- name: Run tests (gtest)
42+
working-directory: build
43+
run: |
44+
ctest --output-on-failure
45+
46+
- name: Collect profraw
47+
working-directory: build
48+
run: |
49+
mkdir -p $COVERAGE_ROOT/cxx${{ matrix.std }}
50+
51+
find . -name "*.profraw" -exec cp {} $COVERAGE_ROOT/cxx${{ matrix.std }}/ \;
52+
53+
- name: Merge profdata
54+
run: |
55+
llvm-profdata merge -sparse \
56+
$COVERAGE_ROOT/cxx${{ matrix.std }}/*.profraw \
57+
-o $COVERAGE_ROOT/cxx${{ matrix.std }}.profdata
58+
59+
- name: Build binaries list
60+
working-directory: build
61+
run: |
62+
find tests/native -type f -executable > $COVERAGE_ROOT/binaries.txt
63+
64+
- name: Export per-binary LCOV
65+
working-directory: build
66+
run: |
67+
: > $COVERAGE_ROOT/cxx${{ matrix.std }}.lcov
68+
69+
while read exe; do
70+
llvm-cov export "$exe" \
71+
-instr-profile=$COVERAGE_ROOT/cxx${{ matrix.std }}.profdata \
72+
--format=lcov >> $COVERAGE_ROOT/cxx${{ matrix.std }}.lcov
73+
74+
echo >> $COVERAGE_ROOT/cxx${{ matrix.std }}.lcov
75+
done < $COVERAGE_ROOT/binaries.txt
76+
77+
- name: Normalize paths (CRITICAL)
78+
run: |
79+
sed -i "s|$GITHUB_WORKSPACE/||g" \
80+
$COVERAGE_ROOT/cxx${{ matrix.std }}.lcov
81+
82+
- name: Remove external dependencies
83+
run: |
84+
grep -v "_deps" $COVERAGE_ROOT/cxx${{ matrix.std }}.lcov > tmp.lcov
85+
mv tmp.lcov $COVERAGE_ROOT/cxx${{ matrix.std }}.lcov
86+
87+
- name: Upload to Codecov
88+
uses: codecov/codecov-action@v4
89+
with:
90+
files: ${{ env.COVERAGE_ROOT }}/cxx${{ matrix.std }}.lcov
91+
flags: cxx${{ matrix.std }}
92+
name: stdBLAS-${{ matrix.std }}
93+
token: ${{ secrets.CODECOV_TOKEN }}

CMakeLists.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
1111

1212
################################################################################
1313

14+
option(LINALG_ENABLE_COVERAGE "Enable LLVM source-based coverage" Off)
1415
option(LINALG_ENABLE_TESTS "Enable tests." Off)
1516
option(LINALG_ENABLE_EXAMPLES "Build examples." Off)
1617
#option(LINALG_ENABLE_BENCHMARKS "Enable benchmarks." Off)
@@ -206,6 +207,33 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/LinAlgConfig.cmake ${CMAKE_CURRENT_BIN
206207

207208
################################################################################
208209

210+
set(COVERAGE_BINARIES_FILE "${CMAKE_BINARY_DIR}/coverage_binaries.txt")
211+
212+
# Reset file at configure time
213+
file(WRITE ${COVERAGE_BINARIES_FILE} "")
214+
215+
if(LINALG_ENABLE_COVERAGE)
216+
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
217+
message(STATUS "Enabling Clang source-based coverage")
218+
set(COVERAGE_FLAGS "-O0 -g -fprofile-instr-generate -fcoverage-mapping")
219+
220+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_FLAGS}")
221+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COVERAGE_FLAGS}")
222+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-instr-generate")
223+
else()
224+
message(FATAL_ERROR "LINALG_ENABLE_COVERAGE requires Clang")
225+
endif()
226+
endif()
227+
228+
function(register_gtest_coverage target)
229+
add_custom_command(TARGET ${target} POST_BUILD
230+
COMMAND ${CMAKE_COMMAND} -E echo "$<TARGET_FILE:${target}>" >> ${COVERAGE_BINARIES_FILE}
231+
COMMENT "Registering ${target} for coverage"
232+
)
233+
endfunction()
234+
235+
################################################################################
236+
209237
if(LINALG_ENABLE_TESTS)
210238
enable_testing()
211239
add_subdirectory(tests)

codecov.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
codecov:
2+
require_ci_to_pass: yes
3+
4+
coverage:
5+
status:
6+
project:
7+
default:
8+
target: auto
9+
informational: true
10+
11+
flags:
12+
cxx17:
13+
paths:
14+
- include/
15+
- tests/
16+
17+
cxx20:
18+
paths:
19+
- include/
20+
- tests/

tests/native/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ macro(linalg_add_test name)
1010
target_link_libraries(${name} linalg GTest::GTest GTest::Main)
1111
endif()
1212
add_test(${name} ${name})
13+
register_gtest_coverage(${name})
1314
endmacro()
1415

1516
linalg_add_test(abs_if_needed)

0 commit comments

Comments
 (0)