diff --git a/Makefile b/Makefile index 985bdfd81ab8..cd1aca3511fe 100644 --- a/Makefile +++ b/Makefile @@ -80,7 +80,7 @@ BUILD_BIN_PATH := $(ROOT_PATH)/bin build: pd-server pd-ctl pd-recover -tools: pd-tso-bench pd-heartbeat-bench regions-dump stores-dump pd-api-bench pd-ut +tools: pd-tso-bench pd-heartbeat-bench regions-dump stores-dump pd-api-bench pd-dev PD_SERVER_DEP := ifeq ($(SWAGGER), 1) @@ -126,12 +126,12 @@ regions-dump: cd tools && CGO_ENABLED=0 go build -gcflags '$(GCFLAGS)' -ldflags '$(LDFLAGS)' -o $(BUILD_BIN_PATH)/regions-dump regions-dump/main.go stores-dump: cd tools && CGO_ENABLED=0 go build -gcflags '$(GCFLAGS)' -ldflags '$(LDFLAGS)' -o $(BUILD_BIN_PATH)/stores-dump stores-dump/main.go -pd-ut: pd-xprog - cd tools && GOEXPERIMENT=$(BUILD_GOEXPERIMENT) CGO_ENABLED=$(BUILD_TOOL_CGO_ENABLED) go build -gcflags '$(GCFLAGS)' -ldflags '$(LDFLAGS)' -o $(BUILD_BIN_PATH)/pd-ut pd-ut/ut.go pd-ut/coverProfile.go +pd-dev: pd-xprog + cd tools && GOEXPERIMENT=$(BUILD_GOEXPERIMENT) CGO_ENABLED=$(BUILD_TOOL_CGO_ENABLED) go build -gcflags '$(GCFLAGS)' -ldflags '$(LDFLAGS)' -o $(BUILD_BIN_PATH)/pd-dev pd-dev/ut.go pd-dev/coverProfile.go pd-xprog: - cd tools && GOEXPERIMENT=$(BUILD_GOEXPERIMENT) CGO_ENABLED=$(BUILD_TOOL_CGO_ENABLED) go build -tags xprog -gcflags '$(GCFLAGS)' -ldflags '$(LDFLAGS)' -o $(BUILD_BIN_PATH)/xprog pd-ut/xprog.go + cd tools && GOEXPERIMENT=$(BUILD_GOEXPERIMENT) CGO_ENABLED=$(BUILD_TOOL_CGO_ENABLED) go build -tags xprog -gcflags '$(GCFLAGS)' -ldflags '$(LDFLAGS)' -o $(BUILD_BIN_PATH)/xprog pd-dev/xprog.go -.PHONY: pd-ctl pd-tso-bench pd-recover pd-analysis pd-heartbeat-bench simulator regions-dump stores-dump pd-api-bench pd-ut +.PHONY: pd-ctl pd-tso-bench pd-recover pd-analysis pd-heartbeat-bench simulator regions-dump stores-dump pd-api-bench pd-dev #### Docker image #### @@ -225,10 +225,16 @@ failpoint-disable: install-tools #### Test #### -ut: pd-ut +ut: pd-dev @$(FAILPOINT_ENABLE) - ./bin/pd-ut run --race - @$(CLEAN_UT_BINARY) + ./bin/pd-dev run --race + @$(CLEAN_DEV_BINARY) + @$(FAILPOINT_DISABLE) + +dev-it: pd-dev + @$(FAILPOINT_ENABLE) + ./bin/pd-dev it run --race + @$(CLEAN_DEV_BINARY) @$(FAILPOINT_DISABLE) PACKAGE_DIRECTORIES := $(subst $(PD_PKG)/,,$(PACKAGES)) @@ -251,10 +257,10 @@ basic-test: install-tools go test $(BASIC_TEST_PKGS) || { $(FAILPOINT_DISABLE); exit 1; } @$(FAILPOINT_DISABLE) -ci-test-job: install-tools dashboard-ui pd-ut +ci-test-job: install-tools dashboard-ui pd-dev @$(FAILPOINT_ENABLE) ./scripts/ci-subtask.sh $(JOB_INDEX) || { $(FAILPOINT_DISABLE); exit 1; } - @$(CLEAN_UT_BINARY) + @$(CLEAN_DEV_BINARY) @$(FAILPOINT_DISABLE) TSO_INTEGRATION_TEST_PKGS := $(PD_PKG)/tests/server/tso @@ -310,7 +316,7 @@ split: clean: failpoint-disable clean-test clean-build -CLEAN_UT_BINARY := find . -name '*.test.bin'| xargs rm -f +CLEAN_DEV_BINARY := find . -name '*.test.bin'| xargs rm -f clean-test: # Cleaning test tmp... @@ -319,7 +325,7 @@ clean-test: rm -rf /tmp/test_etcd* rm -f $(REAL_CLUSTER_TEST_PATH)/playground.log go clean -testcache - @$(CLEAN_UT_BINARY) + @$(CLEAN_DEV_BINARY) clean-build: # Cleaning building files... diff --git a/scripts/ci-subtask.sh b/scripts/ci-subtask.sh index 48dfec18af76..f587b39ff09c 100755 --- a/scripts/ci-subtask.sh +++ b/scripts/ci-subtask.sh @@ -9,7 +9,7 @@ integrations_dir=$(pwd)/tests/integrations case $1 in 1) # unit tests - ./bin/pd-ut run --race --coverprofile $ROOT_PATH_COV || exit 1 + ./bin/pd-dev run --race --coverprofile $ROOT_PATH_COV || exit 1 ;; 2) # tools tests @@ -18,14 +18,9 @@ case $1 in 3) # integration test client cd ./client && make ci-test-job && cat covprofile >> $ROOT_PATH_COV || exit 1 - cd $integrations_dir && make ci-test-job test_name=client && cat ./client/covprofile >> $ROOT_PATH_COV || exit 1 ;; 4) - # integration test tso - cd $integrations_dir && make ci-test-job test_name=tso && cat ./tso/covprofile >> $ROOT_PATH_COV || exit 1 - ;; - 5) - # integration test mcs - cd $integrations_dir && make ci-test-job test_name=mcs && cat ./mcs/covprofile >> $ROOT_PATH_COV || exit 1 + # integration tests + ./bin/pd-dev it run --race --coverprofile $ROOT_PATH_COV || exit 1 ;; esac diff --git a/tools/pd-ut/README.md b/tools/pd-dev/README.md similarity index 64% rename from tools/pd-ut/README.md rename to tools/pd-dev/README.md index 4610d542950c..09e98cf71924 100644 --- a/tools/pd-ut/README.md +++ b/tools/pd-dev/README.md @@ -1,23 +1,23 @@ -# pd-ut +# pd-dev -pd-ut is a tool to run unit tests for PD. +pd-dev is a tool to run tests for PD. ## Build 1. [Go](https://golang.org/) Version 1.21 or later -2. In the root directory of the [PD project](https://github.com/tikv/pd), use the `make pd-ut` command to compile and generate `bin/pd-ut` +2. In the root directory of the [PD project](https://github.com/tikv/pd), use the `make pd-dev` command to compile and generate `bin/pd-dev` ## Usage -This section describes how to use the pd-ut tool. +This section describes how to use the pd-dev tool. ### brief run all tests ```shell -make ut +make ut ``` -### run by pd-ut +### run by pd-dev - You should `make failpoint-enable` before running the tests. - And after running the tests, you should `make failpoint-disable` and `make clean-test` to disable the failpoint and clean the environment. @@ -26,45 +26,45 @@ make ut ```shell // run all tests -pd-ut +pd-dev // show usage -pd-ut -h +pd-dev -h // list all packages -pd-ut list +pd-dev list // list test cases of a single package -pd-ut list $package +pd-dev list $package // list test cases that match a pattern -pd-ut list $package 'r:$regex' +pd-dev list $package 'r:$regex' // run all tests -pd-ut run +pd-dev run // run test all cases of a single package -pd-ut run $package +pd-dev run $package // run test cases of a single package -pd-ut run $package $test +pd-dev run $package $test // run test cases that match a pattern -pd-ut run $package 'r:$regex' +pd-dev run $package 'r:$regex' // build all test package -pd-ut build +pd-dev build // build a test package -pd-ut build xxx +pd-dev build xxx // write the junitfile -pd-ut run --junitfile xxx +pd-dev run --junitfile xxx // test with race flag -pd-ut run --race +pd-dev run --race // test with coverprofile -pd-ut run --coverprofile xxx +pd-dev run --coverprofile xxx go tool cover --func=xxx ``` diff --git a/tools/pd-ut/coverProfile.go b/tools/pd-dev/coverProfile.go similarity index 100% rename from tools/pd-ut/coverProfile.go rename to tools/pd-dev/coverProfile.go diff --git a/tools/pd-ut/ut.go b/tools/pd-dev/ut.go similarity index 94% rename from tools/pd-ut/ut.go rename to tools/pd-dev/ut.go index 4a2257744b1b..12db6191522e 100644 --- a/tools/pd-ut/ut.go +++ b/tools/pd-dev/ut.go @@ -38,53 +38,54 @@ import ( func usage() bool { msg := `// run all tests -pd-ut +pd-dev // show usage -pd-ut -h +pd-dev -h // list all packages -pd-ut list +pd-dev list // list test cases of a single package -pd-ut list $package +pd-dev list $package // list test cases that match a pattern -pd-ut list $package 'r:$regex' +pd-dev list $package 'r:$regex' // run all tests -pd-ut run +pd-dev run // run test all cases of a single package -pd-ut run $package +pd-dev run $package // run test cases of a single package -pd-ut run $package $test +pd-dev run $package $test // run test cases that match a pattern -pd-ut run $package 'r:$regex' +pd-dev run $package 'r:$regex' // build all test package -pd-ut build +pd-dev build // build a test package -pd-ut build xxx +pd-dev build xxx // write the junitfile -pd-ut run --junitfile xxx +pd-dev run --junitfile xxx // test with race flag -pd-ut run --race +pd-dev run --race // test with coverprofile -pd-ut run --coverprofile xxx +pd-dev run --coverprofile xxx go tool cover --func=xxx` fmt.Println(msg) return true } -const modulePath = "github.com/tikv/pd" +var modulePath = "github.com/tikv/pd" +var integrationsTestPath = "tests/integrations" var ( // runtime @@ -137,6 +138,22 @@ func main() { isSucceed = cmdBuild(os.Args[2:]...) case "run": isSucceed = cmdRun(os.Args[2:]...) + case "it": + // run integration tests + if len(os.Args) >= 3 { + modulePath = path.Join(modulePath, integrationsTestPath) + workDir = path.Join(workDir, integrationsTestPath) + switch os.Args[2] { + case "list": + isSucceed = cmdList(os.Args[3:]...) + case "build": + isSucceed = cmdBuild(os.Args[3:]...) + case "run": + isSucceed = cmdRun(os.Args[3:]...) + default: + isSucceed = usage() + } + } default: isSucceed = usage() } @@ -442,6 +459,7 @@ func filterTestCases(tasks []task, arg1 string) ([]task, error) { func listPackages() ([]string, error) { cmd := exec.Command("go", "list", "./...") + cmd.Dir = workDir ss, err := cmdToLines(cmd) if err != nil { return nil, withTrace(err) @@ -610,7 +628,7 @@ func (*numa) testCommand(pkg string, fn string) *exec.Cmd { } func skipDIR(pkg string) bool { - skipDir := []string{"tests/integrations", "bin", "cmd"} + skipDir := []string{"bin", "cmd"} for _, ignore := range skipDir { if strings.HasPrefix(pkg, ignore) { return true @@ -622,7 +640,11 @@ func skipDIR(pkg string) bool { // buildTestBinaryMulti is much faster than build the test packages one by one. func buildTestBinaryMulti(pkgs []string) error { // go test --exec=xprog --tags=tso_function_test,deadlock -vet=off --count=0 $(pkgs) + // workPath just like `/data/nvme0n1/husharp/proj/pd/tests/integrations` xprogPath := path.Join(workDir, "bin/xprog") + if strings.Contains(workDir, integrationsTestPath) { + xprogPath = path.Join(workDir[:strings.LastIndex(workDir, integrationsTestPath)], "bin/xprog") + } packages := make([]string, 0, len(pkgs)) for _, pkg := range pkgs { packages = append(packages, path.Join(modulePath, pkg)) diff --git a/tools/pd-ut/xprog.go b/tools/pd-dev/xprog.go similarity index 100% rename from tools/pd-ut/xprog.go rename to tools/pd-dev/xprog.go