1#!/bin/bash
2
3# author: Ole Schuett
4
5if (( $# != 1 )) ; then
6    echo "Usage: test_coverage.sh <VERSION>"
7    exit 1
8fi
9
10ARCH=local_coverage
11VERSION=$1
12
13# shellcheck disable=SC1091
14source /opt/cp2k-toolchain/install/setup
15
16echo -e "\n========== Running Regtests =========="
17cd /workspace/cp2k
18CP2K_REVISION=$(./tools/build_utils/get_revision_number ./src)
19rm -rf "obj/${ARCH}/${VERSION}"/*.gcda   # remove old gcov statistics
20
21make ARCH="${ARCH}" VERSION="${VERSION}" TESTOPTS="${TESTOPTS}" test
22
23# gcov gets stuck on some files...
24# Maybe related: https://bugs.launchpad.net/gcc-arm-embedded/+bug/1694644
25# As a workaround we'll simply remove the offending files for now.
26rm -f "/workspace/cp2k/obj/${ARCH}/${VERSION}"/exts/*/*.gcda
27cd /tmp
28GCOV_TIMEOUT="10s"
29for fn in /workspace/cp2k/obj/${ARCH}/${VERSION}/*.gcda; do
30    if ! timeout "${GCOV_TIMEOUT}" gcov "$fn" &> /dev/null ; then
31        echo "Skipping ${fn} because gcov took longer than ${GCOV_TIMEOUT}."
32        rm "${fn}"
33    fi
34done
35
36# collect coverage stats
37mkdir -p /workspace/artifacts/coverage
38cd /workspace/artifacts/coverage
39lcov --directory "/workspace/cp2k/obj/${ARCH}/${VERSION}" --capture --output-file coverage.info > lcov.log
40lcov --summary coverage.info
41
42# generate html report
43genhtml --title "CP2K Regtests (${CP2K_REVISION})" coverage.info > genhtml.log
44
45# plot
46LINE_COV=$(lcov --summary coverage.info | grep lines | awk '{print substr($2, 1, length($2)-1)}')
47FUNC_COV=$(lcov --summary coverage.info | grep funct | awk '{print substr($2, 1, length($2)-1)}')
48echo 'Plot: name="cov", title="Test Coverage", ylabel="Coverage %"'
49echo "PlotPoint: name='lines', plot='cov', label='Lines', y=$LINE_COV, yerr=0"
50echo "PlotPoint: name='funcs', plot='cov', label='Functions', y=$FUNC_COV, yerr=0"
51
52#EOF
53