Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <[email protected]>
  • Loading branch information
HuSharp committed Apr 16, 2024
1 parent 0c47ad0 commit 4b335ff
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 56 deletions.
30 changes: 18 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 ####

Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand Down Expand Up @@ -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...
Expand All @@ -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...
Expand Down
11 changes: 3 additions & 8 deletions scripts/ci-subtask.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
40 changes: 20 additions & 20 deletions tools/pd-ut/README.md → tools/pd-dev/README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
```
File renamed without changes.
54 changes: 38 additions & 16 deletions tools/pd-ut/ut.go → tools/pd-dev/ut.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand Down
File renamed without changes.

0 comments on commit 4b335ff

Please sign in to comment.