cp2k/tools/docker/scripts/test_coverage.sh

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

70 lines
2.1 KiB
Bash
Raw Permalink Normal View History

#!/bin/bash
2018-11-08 13:56:15 +01:00
# author: Ole Schuett
2025-07-25 12:42:09 +02:00
ulimit -c 0 # Disable core dumps as they can take a very long time to write.
# Check available shared memory - needed for MPI inter-process communication.
SHM_AVAIL=$(df --output=avail -m /dev/shm | tail -1)
if ((SHM_AVAIL < 1024)); then
echo "ERROR: Not enough shared memory. If you're running docker use --shm-size=1g."
exit 1
fi
2018-11-08 13:56:15 +01:00
# shellcheck disable=SC1091
source /opt/cp2k-toolchain/install/setup
2025-07-23 16:36:39 +02:00
# Get CP2K revision.
2022-03-11 12:33:27 +01:00
cd /opt/cp2k || exit 1
CP2K_REVISION=$(./tools/build_utils/get_revision_number ./src)
2025-07-25 12:42:09 +02:00
echo -e "\n========== Installing lcov =========="
apt-get update -qq
2025-07-25 12:42:09 +02:00
apt-get install -qq --no-install-recommends lcov libjson-xs-perl
rm -rf /var/lib/apt/lists/*
echo -e "\n========== Running Regtests =========="
2022-03-11 12:33:27 +01:00
cd /opt/cp2k || exit 1
2025-07-25 12:42:09 +02:00
./tests/do_regtest.py --ompthreads=1 ./build/bin/ psmp
2018-11-08 13:56:15 +01:00
# gcov gets stuck on some files...
# Maybe related: https://bugs.launchpad.net/gcc-arm-embedded/+bug/1694644
# As a workaround we'll simply remove the offending files for now.
cd /tmp || exit 1
GCOV_TIMEOUT="10s"
2025-07-23 16:36:39 +02:00
find /opt/cp2k/build/src/ -name "*.gcda" -print0 | while read -r -d $'\0' fn; do
2021-02-17 17:02:43 +01:00
if ! timeout "${GCOV_TIMEOUT}" gcov "$fn" &> /dev/null; then
echo "Skipping ${fn} because gcov took longer than ${GCOV_TIMEOUT}."
rm "${fn}"
fi
done
2018-11-08 13:56:15 +01:00
mkdir -p /workspace/artifacts/coverage
cd /workspace/artifacts/coverage || exit 1
2025-07-23 16:36:39 +02:00
# collect coverage stats
lcov --directory "/opt/cp2k/build/src" \
--exclude "/opt/cp2k-toolchain/*" \
--exclude "/usr/*" \
--capture \
2025-07-25 12:42:09 +02:00
--keep-going \
--output-file coverage.info &> lcov.log
2025-07-23 16:36:39 +02:00
# print summary
2018-11-08 13:56:15 +01:00
lcov --summary coverage.info
# generate html report
2025-07-23 16:36:39 +02:00
genhtml \
2025-07-25 12:42:09 +02:00
--keep-going \
2025-07-23 16:36:39 +02:00
--title "CP2K Regtests (${CP2K_REVISION})" \
2025-07-25 12:42:09 +02:00
coverage.info &> genhtml.log
2018-11-08 13:56:15 +01:00
# plot
LINE_COV=$(lcov --summary coverage.info | grep lines | awk '{print substr($2, 1, length($2)-1)}')
FUNC_COV=$(lcov --summary coverage.info | grep funct | awk '{print substr($2, 1, length($2)-1)}')
echo 'Plot: name="cov", title="Test Coverage", ylabel="Coverage %"'
echo "PlotPoint: name='lines', plot='cov', label='Lines', y=$LINE_COV, yerr=0"
echo "PlotPoint: name='funcs', plot='cov', label='Functions', y=$FUNC_COV, yerr=0"
#EOF