Refactoring, making error messages nicer, & lcov

Directory name for bro core coverage changed to "coverage", error
messages made nicer. Use `make html` in testing/coverage to create
logs in HTML format when lcov exists on the system.
This commit is contained in:
Chung Min Kim 2018-07-24 13:19:14 -07:00
parent 4cdf1e39bb
commit 4ca4b05043
5 changed files with 35 additions and 9 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
build
tmp
*.gcov

View file

@ -8,7 +8,7 @@ brief: make-brief coverage
distclean:
@rm -f coverage.log
$(MAKE) -C btest $@
$(MAKE) -C bro-core-coverage $@
$(MAKE) -C coverage $@
make-verbose:
@for repo in $(DIRS); do (cd $$repo && make -s ); done
@ -23,5 +23,5 @@ coverage:
@echo "Complete test suite code coverage:"
@./scripts/coverage-calc "brocov.tmp.*" coverage.log `pwd`/../scripts
@rm -f brocov.tmp.*
@cd bro-core-coverage && make coverage
@cd coverage && make coverage

View file

@ -7,3 +7,9 @@ cleanup:
distclean: cleanup
@find ../../ -name "*.gcno" -exec rm {} \;
html:
@(cd ../../; if which lcov; then\
lcov --capture --directory . --output-file coverage.info \
&& genhtml coverage.info && rm coverage.info; \
fi)

13
testing/coverage/README Normal file
View file

@ -0,0 +1,13 @@
On a Bro build configured with --enable-coverage, this script produces a code coverage report after Bro has been invoked. The intended application of this script is after the btest testsuite has run. This combination (btests first, coverage computation afterward) happens automatically when running "make" in the testing directory. This script puts .gcov files (which are included in .gitignore) alongside the corresponding source files.
This depends on gcov, which should come with your gcc. If gcov is not installed, the script will abort with an error message.
TODO: Use `make html` as make target in this directory to output the html files that gcov can create (must have lcov on system).
The goal of code-coverage.sh script is to automate code coverage testing. See the following steps for the code structure:
1. Run test suite
2. Check for .gcda files existing.
3a. Run gcov (-p to preserve path)
3b. Prune .gcov files for objects outside of the Bro tree
4a. Analyze .gcov files generated and create summary file
4b. Send .gcov files to appropriate path

View file

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
#
# On a Bro build configured with --enable-coverage, this script
# produces a code coverage report after Bro has been invoked. The
@ -17,7 +17,7 @@
# 4b. Send .gcov files to appropriate path
#
CURR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # Location of script
BASE="$(realpath "${CURR}/../../")"
BASE="$(readlink -f "${CURR}/../../")"
TMP="${CURR}/tmp.$$"
mkdir -p $TMP
@ -96,14 +96,20 @@ done
echo "ok"
# 3a. Run gcov (-p to preserve path) and move into tmp directory
# ... if system does not have gcov installed, exit with message.
echo -n "Creating coverage files... "
( cd "$TMP" && find "$BASE" -name "*.o" -exec gcov -p {} > /dev/null 2>&1 \; )
NUM_GCOVS=$(ls "$TMP"/*.gcov | wc -l)
if [ $NUM_GCOVS -eq 0 ]; then
if which gcov; then
( cd "$TMP" && find "$BASE" -name "*.o" -exec gcov -p {} > /dev/null 2>&1 \; )
NUM_GCOVS=$(find "$TMP" -name *.gcov | wc -l)
if [ $NUM_GCOVS -eq 0 ]; then
echo "no gcov files produced, aborting"
exit 1
fi
echo "ok, $NUM_GCOVS coverage files"
else
echo "gcov is not installed on system, aborting"
exit 1
fi
echo "ok, $NUM_GCOVS coverage files"
# 3b. Prune gcov files that fall outside of the Bro tree:
# Look for files containing gcov's slash substitution character "#"