-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_lcov.sh
executable file
·68 lines (57 loc) · 2.37 KB
/
run_lcov.sh
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
66
67
68
#!/bin/bash
#
# Generate HTML-formatted gcov coverage analysis for the smarter_stack_lib_test
# program.
# Largely follows
# https://qiaomuf.wordpress.com/2011/05/26/use-gcov-and-lcov-to-know-your-test-coverage/
set -e
set -u
set -o pipefail
readonly LCOV=/usr/local/bin/lcov
echo "Using $(which lcov)"
if (( $# != 1)); then
echo "Usage: run_lcov.sh <test name>, where 'test name' is that of the test"
echo "binary, not that of the source file."
exit 1
fi
if [ ! -e /usr/bin/lcov ]; then
echo "Please install the lcov package."
exit 1
fi
# Note: .gcno files are created by compilation with --coverage switch.
# .gcda files are created by executing the binary directly or with
# ""$LCOV" -c -o foo.info".
readonly test_name="$1"
echo "test_name is ${test_name}"
readonly target="$(grep "${test_name}:" Makefile)"
echo "Creating coverage data for ${test_name}."
# Actually run the test. Not actually necessary, but test failure will as a
# side benefit terminate the script.
./"$test_name" > /tmp/"$test_name".out
# "man lcov" Capture coverage data; creates info file
# Use the --directory option to capture counts for a user space program.
# Running the binary directly creates .gcda files, but only running this command
# creates .info files. Running the command with existing .gcda files does not
# work.
# See https://github.com/linux-test-project/lcov/issues/192 for discussion of
# problems with googletest and lcov.
"$LCOV" --rc geninfo_unexecuted_blocks=1 --ignore mismatch \
--ignore-errors inconsistent -branch-coverage --base-directory . \
--directory . --capture -o "$test_name".info
# Applications which depend on libraries that have their own tests:
#
# Depend on complex_lib.cc: complex_vector_lib_test, template_stack_lib_test,
# template_rotate_lib_test, template_vector_lib_test, template_list_lib_test
#
# Depend on polynomial_lib.cc: template_cycle_lib_test, template_vector_lib_test
# The blog posting above mentioned the same tracefile as input and output,
# which did not work for me.
# There does not appear to be any way to remove the test binary itself
# from the coverage analysis, which makes the resulting coverage percentages
# too high.
"$LCOV" --remove "$test_name".info \
"/usr/*" \
"/home/alison/gitsrc/googletest/*" \
-o "$test_name"_processed.info
genhtml -o . -t "${test_name} coverage" \
--num-spaces 2 "$test_name"_processed.info