From ad3387c37018683d8082539b7337fe0170e75cb9 Mon Sep 17 00:00:00 2001 From: Hu# Date: Tue, 9 Apr 2024 16:45:21 +0800 Subject: [PATCH] scripts: fix client and tools cover profile (#8020) ref tikv/pd#4399 Signed-off-by: husharp --- client/Makefile | 20 +++++++++++++++----- scripts/ci-subtask.sh | 14 +++++++------- tests/integrations/Makefile | 5 +++-- tests/integrations/realcluster/Makefile | 2 +- tools/Makefile | 8 ++++++-- 5 files changed, 32 insertions(+), 17 deletions(-) diff --git a/client/Makefile b/client/Makefile index dae53222d92..89c4936d179 100644 --- a/client/Makefile +++ b/client/Makefile @@ -12,20 +12,30 @@ # See the License for the specific language governing permissions and # limitations under the License. +ROOT_PATH := $(shell pwd)/.. GO_TOOLS_BIN_PATH := $(shell pwd)/../.tools/bin PATH := $(GO_TOOLS_BIN_PATH):$(PATH) SHELL := env PATH='$(PATH)' GOBIN='$(GO_TOOLS_BIN_PATH)' $(shell which bash) default: static tidy test -test: - CGO_ENABLE=1 go test ./... -race -cover +test: failpoint-enable + CGO_ENABLE=1 go test ./... -v -tags deadlock -race -cover || { $(MAKE) failpoint-disable && exit 1; } + $(MAKE) failpoint-disable -basic-test: - CGO_ENABLE=1 go test ./... +basic-test: failpoint-enable + CGO_ENABLE=1 go test ./... || { $(MAKE) failpoint-disable && exit 1; } + $(MAKE) failpoint-disable ci-test-job: - CGO_ENABLED=1 go test ./... -race -covermode=atomic -coverprofile=covprofile -coverpkg=../... github.com/tikv/pd/client + if [ -f covprofile ]; then rm covprofile; fi + CGO_ENABLED=1 go test ./... -v -tags deadlock -race -cover -covermode=atomic -coverprofile=covprofile -coverpkg=../... + +failpoint-enable: + cd $(ROOT_PATH) && $(MAKE) failpoint-enable + +failpoint-disable: + cd $(ROOT_PATH) && $(MAKE) failpoint-disable install-tools: cd .. && $(MAKE) install-tools diff --git a/scripts/ci-subtask.sh b/scripts/ci-subtask.sh index b9006dda503..effd250965f 100755 --- a/scripts/ci-subtask.sh +++ b/scripts/ci-subtask.sh @@ -2,12 +2,12 @@ # ./ci-subtask.sh -ROOT_PATH=../../ +ROOT_PATH_COV=$(pwd)/covprofile if [[ $2 -gt 9 ]]; then # run tools tests if [[ $2 -eq 10 ]]; then - cd ./tools && make ci-test-job && cd .. && cat ./covprofile >> covprofile || exit 1 + cd ./tools && make ci-test-job && cat covprofile >> $ROOT_PATH_COV || exit 1 exit fi @@ -16,12 +16,12 @@ if [[ $2 -gt 9 ]]; then integrations_tasks=($(find "$integrations_dir" -mindepth 1 -maxdepth 1 -type d)) for t in "${integrations_tasks[@]}"; do if [[ "$t" = "$integrations_dir/client" && $2 -eq 11 ]]; then - cd ./client && make ci-test-job && cd .. && cat ./covprofile >> covprofile || exit 1 - cd $integrations_dir && make ci-test-job test_name=client && cat ./client/covprofile >> "$ROOT_PATH/covprofile" || exit 1 + cd ./client && make ci-test-job && cat covprofile >> $ROOT_PATH_COV && cd .. || exit 1 + cd $integrations_dir && make ci-test-job test_name=client && cat ./client/covprofile >> $ROOT_PATH_COV || exit 1 elif [[ "$t" = "$integrations_dir/tso" && $2 -eq 12 ]]; then - cd $integrations_dir && make ci-test-job test_name=tso && cat ./tso/covprofile >> "$ROOT_PATH/covprofile" || exit 1 + cd $integrations_dir && make ci-test-job test_name=tso && cat ./tso/covprofile >> $ROOT_PATH_COV || exit 1 elif [[ "$t" = "$integrations_dir/mcs" && $2 -eq 13 ]]; then - cd $integrations_dir && make ci-test-job test_name=mcs && cat ./mcs/covprofile >> "$ROOT_PATH/covprofile" || exit 1 + cd $integrations_dir && make ci-test-job test_name=mcs && cat ./mcs/covprofile >> $ROOT_PATH_COV || exit 1 fi done else @@ -61,5 +61,5 @@ else [[ $(($min_i + 1)) -eq $2 ]] && res+=($t) done - CGO_ENABLED=1 go test -timeout=15m -tags deadlock -race -covermode=atomic -coverprofile=covprofile -coverpkg=./... ${res[@]} + CGO_ENABLED=1 go test -timeout=15m -tags deadlock -race -covermode=atomic -coverprofile=$ROOT_PATH_COV -coverpkg=./... ${res[@]} fi diff --git a/tests/integrations/Makefile b/tests/integrations/Makefile index 43b5945baca..b43ecabce7e 100644 --- a/tests/integrations/Makefile +++ b/tests/integrations/Makefile @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -ROOT_PATH := ../.. +ROOT_PATH := $(shell pwd)/../.. GO_TOOLS_BIN_PATH := $(ROOT_PATH)/.tools/bin PATH := $(GO_TOOLS_BIN_PATH):$(PATH) SHELL := env PATH='$(PATH)' GOBIN='$(GO_TOOLS_BIN_PATH)' $(shell which bash) @@ -35,7 +35,8 @@ test: failpoint-enable $(MAKE) failpoint-disable ci-test-job: - CGO_ENABLED=1 go test ./$(value test_name)/... -v -tags deadlock -race -covermode=atomic -coverprofile=./$(value test_name)/covprofile -coverpkg=$(ROOT_PATH)/... + if [ -f covprofile ]; then rm ./$(value test_name)/covprofile; fi + CGO_ENABLED=1 go test ./$(value test_name)/... -v -tags deadlock -race -cover -covermode=atomic -coverprofile=./$(value test_name)/covprofile -coverpkg=$(ROOT_PATH)/... install-tools: cd $(ROOT_PATH) && $(MAKE) install-tools diff --git a/tests/integrations/realcluster/Makefile b/tests/integrations/realcluster/Makefile index 4817b94b5da..278f585feaa 100644 --- a/tests/integrations/realcluster/Makefile +++ b/tests/integrations/realcluster/Makefile @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -ROOT_PATH := ../../.. +ROOT_PATH := $(shell pwd)/../../.. GO_TOOLS_BIN_PATH := $(ROOT_PATH)/.tools/bin PATH := $(GO_TOOLS_BIN_PATH):$(PATH) SHELL := env PATH='$(PATH)' GOBIN='$(GO_TOOLS_BIN_PATH)' $(shell which bash) diff --git a/tools/Makefile b/tools/Makefile index 052f8573b62..336cc536949 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -ROOT_PATH := .. +ROOT_PATH := $(shell pwd)/.. GO_TOOLS_BIN_PATH := $(ROOT_PATH)/.tools/bin PATH := $(GO_TOOLS_BIN_PATH):$(PATH) SHELL := env PATH='$(PATH)' GOBIN='$(GO_TOOLS_BIN_PATH)' $(shell which bash) @@ -33,10 +33,14 @@ tidy: git diff go.mod go.sum | cat git diff --quiet go.mod go.sum -ci-test-job: failpoint-enable +test: failpoint-enable CGO_ENABLED=1 go test ./... -v -tags deadlock -race -cover || { $(MAKE) failpoint-disable && exit 1; } $(MAKE) failpoint-disable +ci-test-job: + if [ -f covprofile ]; then rm covprofile; fi + CGO_ENABLED=1 go test ./... -v -tags deadlock -race -cover -covermode=atomic -coverprofile=covprofile -coverpkg=../... + failpoint-enable: cd $(ROOT_PATH) && $(MAKE) failpoint-enable