Skip to content

Commit

Permalink
[CI] improve coverage.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
tttapa committed Sep 26, 2023
1 parent ba15647 commit 2c7f969
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/wheel-short-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ jobs:
# LCOV
- name: Install LCOV
run: |
git clone --single-branch --depth=1 --branch "v1.15" \
git clone --single-branch --depth=1 --branch "v2.0" \
https://github.com/linux-test-project/lcov.git
make -C lcov install PREFIX="/usr/local"
working-directory: /tmp
Expand Down Expand Up @@ -247,6 +247,7 @@ jobs:
env:
CMAKE_TOOLCHAIN_FILE: /opt/${{ env.HOST }}/${{ env.HOST }}.toolchain.cmake
GCOV_BIN: /opt/${{ env.HOST }}/x-tools/${{ env.HOST }}/bin/${{ env.HOST }}-gcov
CPPFILT_BIN: /opt/${{ env.HOST }}/x-tools/${{ env.HOST }}/bin/${{ env.HOST }}-c++filt
LD_LIBRARY_PATH: "/opt/${{ env.HOST }}/x-tools/${{ env.HOST }}/${{ env.HOST }}/lib64"
# Commit the new documentation, squash the commits, and push it to GitHub
- name: Commit and push documention
Expand Down
31 changes: 16 additions & 15 deletions scripts/coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,21 @@ if [ -n "$version" ]; then version="-${version}"; fi
echo "Compiler: ${compiler}${version}"

# If the compiler is Clang, use a wrapper around llvm-cov that emulates gcov
# and use the right c++filt
if [ -n "$GCOV_BIN" ]; then
gcov_bin="$GCOV_BIN";
gcov_tool=("--gcov-tool" "$GCOV_BIN");
elif [ "${compiler}" == "clang" ]; then
mkdir -p "${TMPDIR:-/tmp}/clang-cxxfilt-gcov"
echo -e "#!/usr/bin/env sh\nexec llvm-cov${version} gcov \"\$@\"" \
> "${TMPDIR:-/tmp}/clang-cxxfilt-gcov/llvm-cov"
chmod +x "${TMPDIR:-/tmp}/clang-cxxfilt-gcov/llvm-cov"
# Replace the default c++filt program with LLVM/Clang's version
ln -sfn $(which llvm-cxxfilt${version}) ${TMPDIR:-/tmp}/clang-cxxfilt-gcov/c++filt
export PATH="${TMPDIR:-/tmp}/clang-cxxfilt-gcov:$PATH"
gcov_bin="llvm-cov"
gcov_tool=("--gcov-tool" "llvm-cov${version}" "--gcov-tool" "gcov")
else
gcov_bin="gcov${version}"
gcov_tool=("--gcov-tool" "gcov${version}")
fi

# Replace the default c++filt program with LLVM/Clang's version
if [ -n "$CPPFILT_BIN" ]; then
cppfilt_bin="$CPPFILT_BIN"
elif [ "${compiler}" == "clang" ]; then
cppfilt_bin="$(which llvm-cxxfilt${version})"
else
cppfilt_bin="$(which c++filt)"
fi

branches=0
Expand All @@ -55,7 +56,7 @@ lcov \
--include "$proj_dir"'/src/alpaqa/**' \
--include "$proj_dir"'/src/interop/**' \
--output-file "$dest"/coverage_base.info \
--gcov-tool "$gcov_bin" \
"${gcov_tool[@]}" \
--rc lcov_branch_coverage=$branches

# Run tests
Expand All @@ -68,15 +69,15 @@ lcov \
--include "$proj_dir"'/src/alpaqa/**' \
--include "$proj_dir"'/src/interop/**' \
--output-file "$dest"/coverage_test.info \
--gcov-tool "$gcov_bin" \
"${gcov_tool[@]}" \
--rc lcov_branch_coverage=$branches

# Combine captures
lcov \
--add-tracefile "$dest"/coverage_base.info \
--add-tracefile "$dest"/coverage_test.info \
--output-file "$dest"/coverage_total.info \
--gcov-tool "$gcov_bin" \
"${gcov_tool[@]}" \
--rc lcov_branch_coverage=$branches

# Generate HTML coverage report
Expand All @@ -86,7 +87,7 @@ genhtml \
--output-directory="$html_dest" \
--legend --title $(cd "$proj_dir" && git rev-parse HEAD) \
--rc lcov_branch_coverage=$branches \
-s --demangle-cpp \
-s --demangle-cpp "$cppfilt_bin" \
--no-function-coverage # because of the many templates

python3 "$proj_dir/scripts/coverage-badge.py"

0 comments on commit 2c7f969

Please sign in to comment.