Merge pull request #7067 from fanminshi/rework_coverage_unit_integration

coverage: rework coverage for unit and integration tests
This commit is contained in:
fanmin shi 2016-12-30 10:13:07 -08:00 committed by GitHub
commit cbb6ede69d
2 changed files with 36 additions and 0 deletions

View File

@ -106,6 +106,7 @@ func interestingGoroutines() (gs []string) {
}
stack := strings.TrimSpace(sl[1])
if stack == "" ||
strings.Contains(stack, "created by os/signal.init") ||
strings.Contains(stack, "runtime/panic.go") ||
strings.Contains(stack, "created by testing.RunTests") ||
strings.Contains(stack, "testing.Main(") ||

35
test
View File

@ -8,6 +8,9 @@
#
# PKG=./wal ./test
# PKG=snap ./test
#
# Run code coverage
# COVERDIR=coverage PASSES=cov ./test
set -e
source ./build
@ -77,6 +80,38 @@ function integration_pass {
go test -timeout 1m -v ${RACE} -cpu 1,2,4 -run=Example $@ ${TEST}
}
function cov_pass {
echo "Running code coverage..."
# install gocovmerge before running code coverage from github.com/wadey/gocovmerge
# gocovmerge merges coverage files
if ! which gocovmerge >/dev/null; then
echo "gocovmerge not installed"
exit 255
fi
if [ -z "$COVERDIR" ]; then
echo "COVERDIR undeclared"
exit 255
fi
mkdir -p "$COVERDIR"
# PKGS_DELIM contains all the core etcd pkgs delimited by ',' which will be profiled for code coverage.
# Integration tests will generate code coverage for those pkgs
PKGS_DELIM=$(echo $TEST | sed 's/ /,/g')
# TODO create coverage to e2e test
PKGS=`echo "$TEST_PKGS" | egrep -v "(e2e|functional-tester)"`
for t in ${PKGS}; do
tf=`echo $t | tr / _`
# uses -run=Test to skip examples because clientv3/ example tests will leak goroutines
go test -covermode=set -coverpkg $PKGS_DELIM -timeout 15m -run=Test -v -coverprofile "$COVERDIR/${tf}.coverprofile" ${REPO_PATH}/$t
done
gocovmerge "$COVERDIR"/*.coverprofile >"$COVERDIR"/cover.out
}
function e2e_pass {
echo "Running e2e tests..."
go test -timeout 10m -v -cpu 1,2,4 $@ ${REPO_PATH}/e2e