-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathcoverage
executable file
·51 lines (41 loc) · 1.73 KB
/
coverage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env bash
#
# Copyright 2017-2024 AVSystem <[email protected]>
# AVSystem Anjay LwM2M SDK
# All rights reserved.
#
# Licensed under the AVSystem-5-clause License.
# See the attached LICENSE file for details.
set -e
. "$(dirname "$0")/utils.sh"
function die() {
echo -e "$@" >&2
exit 1
}
which gcc || die "gcc not found, exiting"
which lcov || die "lcov not found, exiting"
which genhtml || die "genhtml not found, exiting"
GCC_VERSION=$(gcc --version 2>&1 | head -n 1 | awk 'END {print $NF}')
GCC_MAJOR_VERSION=${GCC_VERSION%%.*}
LCOV_VERSION=$(lcov --version 2>&1 | head -n 1 | awk 'END {print $NF}')
LCOV_MAJOR_VERSION=${LCOV_VERSION%%.*}
if [ "$LCOV_MAJOR_VERSION" -gt 1 ]; then
LCOV_ADDITIONAL_OPTS="--rc branch_coverage=1 --ignore-errors mismatch"
else
LCOV_ADDITIONAL_OPTS="--rc lcov_branch_coverage=1"
fi
[[ "$PROJECT_ROOT" ]] || PROJECT_ROOT="$(dirname "$(dirname "$(canonicalize "$0")")")"
rm -rf "$PROJECT_ROOT/build/coverage"
mkdir -p "$PROJECT_ROOT/build/coverage"
pushd "$PROJECT_ROOT/build/coverage"
"$PROJECT_ROOT/devconfig" --without-analysis --without-memcheck --no-examples -DCMAKE_C_FLAGS="-std=c99 -D_POSIX_C_SOURCE=200809L -g -O0 --coverage" -DCMAKE_EXE_LINKER_FLAGS="--coverage" "$@"
make anjay_check -j$(num_processors)
mkdir -p "$PROJECT_ROOT/coverage"
lcov $LCOV_ADDITIONAL_OPTS -c -d . -o coverage.info --gcov-tool /usr/bin/gcov-$GCC_MAJOR_VERSION
lcov $LCOV_ADDITIONAL_OPTS --remove coverage.info "$PROJECT_ROOT/tests/*" "$PROJECT_ROOT/deps/*" "/usr/*" "$PROJECT_ROOT/include_public/*" -o coverage.info
genhtml coverage.info --branch-coverage --function-coverage --output-directory "$PROJECT_ROOT/coverage"
popd
cat <<EOF
-----
Coverage report generated in $PROJECT_ROOT/coverage
EOF