Skip to content

Commit b22dfd8

Browse files
Automated regression testing for the NVIDIA Container Toolkit
Signed-off-by: Carlos Eduardo Arango Gutierrez <eduardoa@nvidia.com>
1 parent b6d360f commit b22dfd8

File tree

663 files changed

+425866
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

663 files changed

+425866
-0
lines changed

test/e2e/Makefile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
GO_CMD ?= go
16+
17+
include $(CURDIR)/versions.mk
18+
19+
E2E_RUNTIME ?= docker
20+
21+
.PHONY: test
22+
test:
23+
cd $(CURDIR)/test/e2e && $(GO_CMD) test -v . -args \
24+
-ginkgo.focus="$(E2E_RUNTIME)" \
25+
-test.timeout=1h \
26+
-ginkgo.v

test/e2e/e2e_test.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package e2e
18+
19+
import (
20+
"bytes"
21+
"context"
22+
"errors"
23+
"os/exec"
24+
"testing"
25+
26+
. "github.com/onsi/ginkgo/v2"
27+
. "github.com/onsi/gomega"
28+
)
29+
30+
// Test context
31+
var (
32+
ctx context.Context
33+
)
34+
35+
func TestMain(t *testing.T) {
36+
suiteName := "NVIDIA Container Toolkit E2E"
37+
38+
RegisterFailHandler(Fail)
39+
RunSpecs(t,
40+
suiteName,
41+
)
42+
}
43+
44+
// BeforeSuite runs before the test suite
45+
var _ = BeforeSuite(func() {
46+
ctx = context.Background()
47+
48+
})
49+
50+
func runScript(script string) (string, error) {
51+
// Create a command to run the script using bash
52+
cmd := exec.Command("bash", "-c", script)
53+
54+
// Buffer to capture standard output
55+
var stdout bytes.Buffer
56+
cmd.Stdout = &stdout
57+
58+
// Buffer to capture standard error
59+
var stderr bytes.Buffer
60+
cmd.Stderr = &stderr
61+
62+
// Run the command
63+
err := cmd.Run()
64+
if err != nil {
65+
return "", errors.New(stderr.String())
66+
}
67+
68+
// Return the captured stdout and nil error
69+
return stdout.String(), nil
70+
}
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*
2+
* Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package e2e
18+
19+
import (
20+
"context"
21+
22+
. "github.com/onsi/ginkgo/v2"
23+
. "github.com/onsi/gomega"
24+
)
25+
26+
// Integration tests for Docker runtime
27+
var _ = Describe("docker", func() {
28+
// GPUs are accessible in a container: Running nvidia-smi -L inside the
29+
// container shows the same output inside the container as outside the
30+
// container. This means that the following commands must all produce
31+
// the same output
32+
When("running nvidia-smi -L", Ordered, func() {
33+
var rawOut string
34+
35+
BeforeAll(func(ctx context.Context) {
36+
_, err := runScript("docker pull ubuntu")
37+
Expect(err).ToNot(HaveOccurred())
38+
39+
rawOut, err = runScript("nvidia-smi -L")
40+
Expect(err).ToNot(HaveOccurred())
41+
})
42+
43+
It("should match when using --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=all", func(ctx context.Context) {
44+
outContainer, err := runScript("docker run --rm -i --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=all ubuntu nvidia-smi -L")
45+
Expect(err).ToNot(HaveOccurred())
46+
Expect(outContainer).To(Equal(rawOut))
47+
})
48+
49+
It("should match when using --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=runtime.nvidia.com/gpu=all", func(ctx context.Context) {
50+
outContainer, err := runScript("docker run --rm -i --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=runtime.nvidia.com/gpu=all ubuntu nvidia-smi -L")
51+
Expect(err).ToNot(HaveOccurred())
52+
Expect(outContainer).To(Equal(rawOut))
53+
})
54+
55+
It("should match when using --runtime=nvidia --gpus all", func(ctx context.Context) {
56+
outContainer, err := runScript("docker run --rm -i --runtime=nvidia --gpus all ubuntu nvidia-smi -L")
57+
Expect(err).ToNot(HaveOccurred())
58+
Expect(outContainer).To(Equal(rawOut))
59+
})
60+
})
61+
62+
// A vectorAdd sample runs in a container with access to all GPUs.
63+
// The following should all produce the same result.
64+
When("Running the cuda-vectorAdd sample", Ordered, func() {
65+
BeforeAll(func(ctx context.Context) {
66+
_, err := runScript("docker pull nvcr.io/nvidia/k8s/cuda-sample:vectoradd-cuda12.5.0")
67+
Expect(err).ToNot(HaveOccurred())
68+
})
69+
70+
var (
71+
out1 string
72+
out2 string
73+
out3 string
74+
)
75+
76+
It("should run with NVIDIA_VISIBLE_DEVICES=all and capture output", func(ctx context.Context) {
77+
var err error
78+
out1, err = runScript("docker run --rm -i --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=all nvcr.io/nvidia/k8s/cuda-sample:vectoradd-cuda12.5.0")
79+
Expect(err).ToNot(HaveOccurred())
80+
})
81+
82+
It("should run with NVIDIA_VISIBLE_DEVICES=runtime.nvidia.com/gpu=all and capture output", func(ctx context.Context) {
83+
var err error
84+
out2, err = runScript("docker run --rm -i --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=runtime.nvidia.com/gpu=all nvcr.io/nvidia/k8s/cuda-sample:vectoradd-cuda12.5.0")
85+
Expect(err).ToNot(HaveOccurred())
86+
})
87+
88+
It("should run with --gpus all and capture output", func(ctx context.Context) {
89+
var err error
90+
out3, err = runScript("docker run --rm -i --runtime=nvidia --gpus all nvcr.io/nvidia/k8s/cuda-sample:vectoradd-cuda12.5.0")
91+
Expect(err).ToNot(HaveOccurred())
92+
})
93+
94+
It("should ensure all outputs are identical", func(ctx context.Context) {
95+
Expect(out1).To(Equal(out2))
96+
Expect(out2).To(Equal(out3))
97+
})
98+
})
99+
100+
// A deviceQuery sample runs in a container with access to all GPUs
101+
// The following should all produce the same result.
102+
When("Running the cuda-deviceQuery sample", Ordered, func() {
103+
BeforeAll(func(ctx context.Context) {
104+
_, err := runScript("docker pull nvcr.io/nvidia/k8s/cuda-sample:devicequery-cuda12.5.0")
105+
Expect(err).ToNot(HaveOccurred())
106+
})
107+
108+
var (
109+
out1 string
110+
out2 string
111+
out3 string
112+
)
113+
114+
It("should run with NVIDIA_VISIBLE_DEVICES=all and capture output", func(ctx context.Context) {
115+
var err error
116+
out1, err = runScript("docker run --rm -i --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=all nvcr.io/nvidia/k8s/cuda-sample:devicequery-cuda12.5.0")
117+
Expect(err).ToNot(HaveOccurred())
118+
})
119+
120+
It("should run with NVIDIA_VISIBLE_DEVICES=runtime.nvidia.com/gpu=all and capture output", func(ctx context.Context) {
121+
var err error
122+
out2, err = runScript("docker run --rm -i --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=runtime.nvidia.com/gpu=all nvcr.io/nvidia/k8s/cuda-sample:devicequery-cuda12.5.0")
123+
Expect(err).ToNot(HaveOccurred())
124+
})
125+
126+
It("should run with --gpus all and capture output", func(ctx context.Context) {
127+
var err error
128+
out3, err = runScript("docker run --rm -i --runtime=nvidia --gpus all nvcr.io/nvidia/k8s/cuda-sample:devicequery-cuda12.5.0")
129+
Expect(err).ToNot(HaveOccurred())
130+
})
131+
132+
It("should ensure all outputs are identical", func(ctx context.Context) {
133+
Expect(out1).To(Equal(out2))
134+
Expect(out2).To(Equal(out3))
135+
})
136+
})
137+
})

test/go.mod

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module github.com/NVIDIA/nvidia-container-toolkit/test
2+
3+
go 1.23.2
4+
5+
require (
6+
github.com/onsi/ginkgo/v2 v2.22.2
7+
github.com/onsi/gomega v1.36.2
8+
)
9+
10+
require (
11+
github.com/go-logr/logr v1.4.2 // indirect
12+
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
13+
github.com/google/go-cmp v0.6.0 // indirect
14+
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect
15+
golang.org/x/net v0.33.0 // indirect
16+
golang.org/x/sys v0.28.0 // indirect
17+
golang.org/x/text v0.21.0 // indirect
18+
golang.org/x/tools v0.28.0 // indirect
19+
gopkg.in/yaml.v3 v3.0.1 // indirect
20+
)

test/go.sum

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
4+
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
5+
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
6+
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
7+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
8+
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
9+
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad h1:a6HEuzUHeKH6hwfN/ZoQgRgVIWFJljSWa/zetS2WTvg=
10+
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
11+
github.com/onsi/ginkgo/v2 v2.22.2 h1:/3X8Panh8/WwhU/3Ssa6rCKqPLuAkVY2I0RoyDLySlU=
12+
github.com/onsi/ginkgo/v2 v2.22.2/go.mod h1:oeMosUL+8LtarXBHu/c0bx2D/K9zyQ6uX3cTyztHwsk=
13+
github.com/onsi/gomega v1.36.2 h1:koNYke6TVk6ZmnyHrCXba/T/MoLBXFjeC1PtvYgw0A8=
14+
github.com/onsi/gomega v1.36.2/go.mod h1:DdwyADRjrc825LhMEkD76cHR5+pUnjhUN8GlHlRPHzY=
15+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
16+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
17+
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
18+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
19+
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
20+
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
21+
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
22+
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
23+
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
24+
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
25+
golang.org/x/tools v0.28.0 h1:WuB6qZ4RPCQo5aP3WdKZS7i595EdWqWR8vqJTlwTVK8=
26+
golang.org/x/tools v0.28.0/go.mod h1:dcIOrVd3mfQKTgrDVQHqCPMWy6lnhfhtX3hLXYVLfRw=
27+
google.golang.org/protobuf v1.36.1 h1:yBPeRvTftaleIgM3PZ/WBIZ7XM/eEYAaEyCwvyjq/gk=
28+
google.golang.org/protobuf v1.36.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
29+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
30+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
31+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
32+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

test/vendor/github.com/go-logr/logr/.golangci.yaml

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/vendor/github.com/go-logr/logr/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/vendor/github.com/go-logr/logr/CONTRIBUTING.md

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)