diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cff694cf08c9e..962068f5698d0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -453,7 +453,7 @@ jobs: GOTESTSUM_JUNITFILE: ${{github.workspace}}/test-unit-root-junit.xml GOTESTSUM_JSONFILE: ${{github.workspace}}/test-unit-root-gotest.json run: | - make test + sudo -E PATH=$PATH make benchmark sudo -E PATH=$PATH make root-test - run: if [ -f *-gotest.json ]; then echo '# Root Test' >> $GITHUB_STEP_SUMMARY; teststat -markdown *-gotest.json >> $GITHUB_STEP_SUMMARY; fi if: always() diff --git a/BUILDING.md b/BUILDING.md index 2318ce1a06f82..438a386869786 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -260,7 +260,7 @@ During the automated CI the unit tests and integration tests are run as part of - `make root-test`: run all non-integration tests which require `root` - `make integration`: run all tests, including integration tests and those which require `root`. `TESTFLAGS_PARALLEL` can be used to control parallelism. For example, `TESTFLAGS_PARALLEL=1 make integration` will lead a non-parallel execution. The default value of `TESTFLAGS_PARALLEL` is **8**. - `make cri-integration`: [CRI Integration Tests](https://github.com/containerd/containerd/blob/main/docs/cri/testing.md#cri-integration-test) run cri integration tests - + - `make benchmark`: ## run benchmarks tests To execute a specific test or set of tests you can use the `go test` capabilities without using the `Makefile` targets. The following examples show how to specify a test name and also how to use the flag directly against `go test` to run root-requiring tests. diff --git a/Makefile b/Makefile index 4d5e2f448f2cc..668d5aa899d4e 100644 --- a/Makefile +++ b/Makefile @@ -249,8 +249,7 @@ bin/loopback-v2: integration/failpoint/cmd/loopback-v2 FORCE benchmark: ## run benchmarks tests @echo "$(WHALE) $@" - @$(GO) test ${TESTFLAGS} -bench . -run Benchmark -test.root - + @$(GO) test ${TESTFLAGS} -bench . -run Benchmark ./... -skip=vendor/... FORCE: define BUILD_BINARY diff --git a/integration/client/benchmark_test.go b/integration/client/benchmark_test.go index 82787c7f57102..7b627f8ef9c13 100644 --- a/integration/client/benchmark_test.go +++ b/integration/client/benchmark_test.go @@ -21,7 +21,6 @@ import ( "testing" . "github.com/containerd/containerd/v2/client" - "github.com/containerd/containerd/v2/core/containers" "github.com/containerd/containerd/v2/pkg/oci" ) @@ -40,11 +39,6 @@ func BenchmarkContainerCreate(b *testing.B) { b.Error(err) return } - spec, err := oci.GenerateSpec(ctx, client, &containers.Container{ID: b.Name()}, oci.WithImageConfig(image), withTrue()) - if err != nil { - b.Error(err) - return - } var containers []Container defer func() { for _, c := range containers { @@ -58,7 +52,7 @@ func BenchmarkContainerCreate(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { id := fmt.Sprintf("%s-%d", b.Name(), i) - container, err := client.NewContainer(ctx, id, WithNewSnapshot(id, image), WithSpec(spec)) + container, err := client.NewContainer(ctx, id, WithNewSnapshot(id, image), WithNewSpec(oci.WithImageConfig(image), withExitStatus(7))) if err != nil { b.Error(err) return @@ -83,11 +77,6 @@ func BenchmarkContainerStart(b *testing.B) { b.Error(err) return } - spec, err := oci.GenerateSpec(ctx, client, &containers.Container{ID: b.Name()}, oci.WithImageConfig(image), withTrue()) - if err != nil { - b.Error(err) - return - } var containers []Container defer func() { for _, c := range containers { @@ -99,7 +88,7 @@ func BenchmarkContainerStart(b *testing.B) { for i := 0; i < b.N; i++ { id := fmt.Sprintf("%s-%d", b.Name(), i) - container, err := client.NewContainer(ctx, id, WithNewSnapshot(id, image), WithSpec(spec)) + container, err := client.NewContainer(ctx, id, WithNewSnapshot(id, image), WithNewSpec(oci.WithImageConfig(image), withExitStatus(7))) if err != nil { b.Error(err) return @@ -115,11 +104,25 @@ func BenchmarkContainerStart(b *testing.B) { b.Error(err) return } + statusC, err := task.Wait(ctx) + if err != nil { + b.Error(err) + return + } defer task.Delete(ctx) if err := task.Start(ctx); err != nil { b.Error(err) return } + status := <-statusC + code, _, err := status.Result() + if err != nil { + b.Error(err) + return + } + if code != 7 { + b.Errorf("expected status 7 from wait but received %d", code) + } } b.StopTimer() } diff --git a/pkg/testutil/helpers.go b/pkg/testutil/helpers.go index 6d2523fec2449..f460e1ed9dba5 100644 --- a/pkg/testutil/helpers.go +++ b/pkg/testutil/helpers.go @@ -20,6 +20,7 @@ import ( "flag" "fmt" "os" + "os/user" "path/filepath" "strconv" "testing" @@ -43,7 +44,25 @@ func init() { break } } + if isRoot, err := IsRootUser(); err == nil { + if isRoot { + rootEnabled = true + } + } + } +} + +func IsRootUser() (bool, error) { + currentUser, err := user.Current() + if err != nil { + return false, err + } + + uid, err := strconv.Atoi(currentUser.Uid) + if err != nil { + return false, err } + return uid == 0, nil } // DumpDir prints the contents of the directory to the testing logger.