-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate code coverage report with llvm-cov (#469)
- Loading branch information
Showing
3 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: Coverage | ||
|
||
on: [pull_request, push] | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
coverage: | ||
name: "Coverage" | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
# TODO: Remove this once clang 15 is default; clang 14 had a stdlib bug | ||
- name: Install clang 15 | ||
run: | | ||
sudo apt-get update -q | ||
sudo apt-get install llvm-15-dev libc++-15-dev | ||
sudo update-alternatives --install \ | ||
/usr/bin/clang clang /usr/bin/clang-15 200 | ||
sudo update-alternatives --install \ | ||
/usr/bin/clang++ clang++ /usr/bin/clang++-15 200 | ||
sudo update-alternatives --install \ | ||
/usr/bin/llvm-cov llvm-cov /usr/bin/llvm-cov-15 200 | ||
sudo update-alternatives --install \ | ||
/usr/bin/llvm-profdata llvm-profdata /usr/bin/llvm-profdata-15 200 | ||
- run: ./tools/coverage-generate.sh SleipnirTest | ||
|
||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: Coverage report | ||
path: ./build-coverage/coverage-line-by-line-SleipnirTest.html | ||
|
||
- name: Write to job summary | ||
run: | | ||
echo '```bash' >> $GITHUB_STEP_SUMMARY | ||
cat ./build-coverage/coverage-report-SleipnirTest.txt >> $GITHUB_STEP_SUMMARY | ||
echo '' >> $GITHUB_STEP_SUMMARY | ||
echo '```' >> $GITHUB_STEP_SUMMARY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
if [ $# -eq 0 ]; then | ||
echo -e "Usage: coverage-generate.sh CMAKE_TARGET\nGenerates coverage of CMake target executable with llvm-cov." | ||
exit 1 | ||
fi | ||
|
||
# Build executable | ||
cmake -B build-coverage -S . -DCMAKE_BUILD_TYPE=Coverage -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ | ||
cmake --build build-coverage --target $1 | ||
|
||
# Run executable and generate reports | ||
pushd build-coverage | ||
./$1 | ||
llvm-profdata merge -sparse default.profraw -o default.profdata | ||
llvm-cov show -ignore-filename-regex=_deps/ ./$1 -instr-profile=default.profdata -format=html > coverage-line-by-line-$1.html | ||
llvm-cov report -ignore-filename-regex=_deps/ ./$1 -instr-profile=default.profdata > coverage-report-$1.txt | ||
popd |