From d9a347289487b14d330a652ec5e4d421305a57cb Mon Sep 17 00:00:00 2001 From: fanmin shi Date: Tue, 27 Dec 2016 15:15:57 -0800 Subject: [PATCH 1/2] coverage: rework code coverage for unit and integration tests --- test | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test b/test index 4572dd20c..48e45dbab 100755 --- a/test +++ b/test @@ -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 From 74e7614759fb25ce14512de1a93d16fa1e2289f8 Mon Sep 17 00:00:00 2001 From: fanmin shi Date: Thu, 29 Dec 2016 16:38:48 -0800 Subject: [PATCH 2/2] testutil: whitelist thread created by go cover --- pkg/testutil/leak.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/testutil/leak.go b/pkg/testutil/leak.go index ca659430c..80bc0eebc 100644 --- a/pkg/testutil/leak.go +++ b/pkg/testutil/leak.go @@ -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(") ||