-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen_coverage_lcov.sh
More file actions
executable file
·65 lines (55 loc) · 2.39 KB
/
gen_coverage_lcov.sh
File metadata and controls
executable file
·65 lines (55 loc) · 2.39 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env bash
set -e
# -----------------------------------------------------------------------------
# Check lcov installation
# -----------------------------------------------------------------------------
if ! command -v lcov >/dev/null 2>&1; then
echo "Error: lcov is not installed."
echo "Install with: sudo apt install lcov"
exit 1
fi
# -----------------------------------------------------------------------------
# Configure project (only if build folder does not exist)
# -----------------------------------------------------------------------------
if [ ! -d build ]; then
cmake -S . -B build \
-DCMAKE_BUILD_TYPE=Debug \
-DENABLE_COVERAGE=ON
fi
# -----------------------------------------------------------------------------
# Build project
# -----------------------------------------------------------------------------
cmake --build build
# -----------------------------------------------------------------------------
# Reset previous coverage
# -----------------------------------------------------------------------------
lcov --directory build --zerocounters
# -----------------------------------------------------------------------------
# Run unit tests
# -----------------------------------------------------------------------------
ctest --test-dir build --output-on-failure
# -----------------------------------------------------------------------------
# Capture coverage
# -----------------------------------------------------------------------------
mkdir -p coverage_lcov
lcov --capture \
--directory build \
--ignore-errors mismatch \
--rc geninfo_unexecuted_blocks=1 \
--output-file coverage_lcov/coverage.info
# Remove system headers
lcov --remove coverage_lcov/coverage.info '/usr/*' \
--output-file coverage_lcov/coverage.info
# -----------------------------------------------------------------------------
# Generate HTML report
# -----------------------------------------------------------------------------
genhtml coverage_lcov/coverage.info \
--output-directory coverage_lcov
# -----------------------------------------------------------------------------
# Open coverage report (skip in headless environments)
# -----------------------------------------------------------------------------
if command -v xdg-open >/dev/null 2>&1; then
xdg-open coverage_lcov/index.html
else
echo "Coverage report generated at: coverage_lcov/index.html"
fi