Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 16 additions & 13 deletions integration/client/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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()
}
19 changes: 19 additions & 0 deletions pkg/testutil/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"flag"
"fmt"
"os"
"os/user"
"path/filepath"
"strconv"
"testing"
Expand All @@ -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.
Expand Down
Loading