mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
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:
parent
4cdf1e39bb
commit
4ca4b05043
5 changed files with 35 additions and 9 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
||||||
build
|
build
|
||||||
tmp
|
tmp
|
||||||
|
*.gcov
|
||||||
|
|
|
@ -8,7 +8,7 @@ brief: make-brief coverage
|
||||||
distclean:
|
distclean:
|
||||||
@rm -f coverage.log
|
@rm -f coverage.log
|
||||||
$(MAKE) -C btest $@
|
$(MAKE) -C btest $@
|
||||||
$(MAKE) -C bro-core-coverage $@
|
$(MAKE) -C coverage $@
|
||||||
|
|
||||||
make-verbose:
|
make-verbose:
|
||||||
@for repo in $(DIRS); do (cd $$repo && make -s ); done
|
@for repo in $(DIRS); do (cd $$repo && make -s ); done
|
||||||
|
@ -23,5 +23,5 @@ coverage:
|
||||||
@echo "Complete test suite code coverage:"
|
@echo "Complete test suite code coverage:"
|
||||||
@./scripts/coverage-calc "brocov.tmp.*" coverage.log `pwd`/../scripts
|
@./scripts/coverage-calc "brocov.tmp.*" coverage.log `pwd`/../scripts
|
||||||
@rm -f brocov.tmp.*
|
@rm -f brocov.tmp.*
|
||||||
@cd bro-core-coverage && make coverage
|
@cd coverage && make coverage
|
||||||
|
|
||||||
|
|
|
@ -7,3 +7,9 @@ cleanup:
|
||||||
|
|
||||||
distclean: cleanup
|
distclean: cleanup
|
||||||
@find ../../ -name "*.gcno" -exec rm {} \;
|
@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
13
testing/coverage/README
Normal 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
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
#
|
#
|
||||||
# On a Bro build configured with --enable-coverage, this script
|
# On a Bro build configured with --enable-coverage, this script
|
||||||
# produces a code coverage report after Bro has been invoked. The
|
# produces a code coverage report after Bro has been invoked. The
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
# 4b. Send .gcov files to appropriate path
|
# 4b. Send .gcov files to appropriate path
|
||||||
#
|
#
|
||||||
CURR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # Location of script
|
CURR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # Location of script
|
||||||
BASE="$(realpath "${CURR}/../../")"
|
BASE="$(readlink -f "${CURR}/../../")"
|
||||||
TMP="${CURR}/tmp.$$"
|
TMP="${CURR}/tmp.$$"
|
||||||
mkdir -p $TMP
|
mkdir -p $TMP
|
||||||
|
|
||||||
|
@ -96,14 +96,20 @@ done
|
||||||
echo "ok"
|
echo "ok"
|
||||||
|
|
||||||
# 3a. Run gcov (-p to preserve path) and move into tmp directory
|
# 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... "
|
echo -n "Creating coverage files... "
|
||||||
( cd "$TMP" && find "$BASE" -name "*.o" -exec gcov -p {} > /dev/null 2>&1 \; )
|
if which gcov; then
|
||||||
NUM_GCOVS=$(ls "$TMP"/*.gcov | wc -l)
|
( cd "$TMP" && find "$BASE" -name "*.o" -exec gcov -p {} > /dev/null 2>&1 \; )
|
||||||
if [ $NUM_GCOVS -eq 0 ]; then
|
NUM_GCOVS=$(find "$TMP" -name *.gcov | wc -l)
|
||||||
echo "no gcov files produced, aborting"
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "ok, $NUM_GCOVS coverage files"
|
|
||||||
|
|
||||||
# 3b. Prune gcov files that fall outside of the Bro tree:
|
# 3b. Prune gcov files that fall outside of the Bro tree:
|
||||||
# Look for files containing gcov's slash substitution character "#"
|
# Look for files containing gcov's slash substitution character "#"
|
Loading…
Add table
Add a link
Reference in a new issue