summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiang Dai <long0dai@foxmail.com>2020-09-11 16:07:09 +0800
committerXiang Dai <long0dai@foxmail.com>2021-01-09 09:36:10 +0800
commit41453952e6be69e02b4863617c49d2d566e9c104 (patch)
tree814063873d41aed9d96d082286d174fd1083704c
parentMerge pull request #2437 from Abirdcfly/master (diff)
downloadkubeedge-41453952e6be69e02b4863617c49d2d566e9c104.tar.gz
Generate coverprofile when test
Signed-off-by: Xiang Dai <long0dai@foxmail.com>
-rw-r--r--Makefile5
-rwxr-xr-xhack/lib/golang.sh8
-rwxr-xr-xhack/make-rules/clean.sh1
3 files changed, 13 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 94a602650..ab112ca40 100644
--- a/Makefile
+++ b/Makefile
@@ -82,16 +82,21 @@ define TEST_HELP_INFO
# Args:
# WHAT: Component names to be testd. support: $(COMPONENTS)
# If not specified, "everything" will be tested.
+# PROFILE: Generate profile named as "coverage.out"
#
# Example:
# make test
# make test HELP=y
+# make test PROFILE=y
# make test WHAT=cloud
endef
.PHONY: test
ifeq ($(HELP),y)
test:
@echo "$$TEST_HELP_INFO"
+else ifeq ($(PROFILE),y)
+test: clean
+ PROFILE=coverage.out hack/make-rules/test.sh $(WHAT)
else
test: clean
hack/make-rules/test.sh $(WHAT)
diff --git a/hack/lib/golang.sh b/hack/lib/golang.sh
index 9bba8e1e3..3685166dd 100755
--- a/hack/lib/golang.sh
+++ b/hack/lib/golang.sh
@@ -434,5 +434,11 @@ kubeedge::golang::run_test() {
testdirs+=("${KUBEEDGE_ALL_TESTCASES[@]}")
fi
- go test ${testdirs[@]}
+ local profile=${PROFILE:-""}
+ if [[ $profile ]]; then
+ go test "-coverprofile=${profile}" ${testdirs[@]}
+ go tool cover -func=coverage.out
+ else
+ go test ${testdirs[@]}
+ fi
}
diff --git a/hack/make-rules/clean.sh b/hack/make-rules/clean.sh
index bbeec600e..525c975bd 100755
--- a/hack/make-rules/clean.sh
+++ b/hack/make-rules/clean.sh
@@ -25,6 +25,7 @@ source "${KUBEEDGE_ROOT}/hack/lib/init.sh"
kubeedge::clean::cache(){
unset GOARM
+ go clean -testcache
go clean -cache
}