Skip to content

Commit 244438a

Browse files
Automated regression testing for the NVIDIA Container Toolkit
Signed-off-by: Carlos Eduardo Arango Gutierrez <[email protected]>
1 parent b6d360f commit 244438a

File tree

663 files changed

+425843
-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

+425843
-0
lines changed

test/e2e/Makefile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
GO_FMT ?= gofmt
17+
18+
include $(CURDIR)/versions.mk
19+
20+
E2E_RUNTIME ?= docker
21+
22+
.PHONY: test
23+
test:
24+
cd $(CURDIR)/test/e2e && $(GO_CMD) test -v . -args \
25+
-ginkgo.focus="$(E2E_RUNTIME)" \
26+
-test.timeout=1h \
27+
-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: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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+
BeforeAll(func(ctx context.Context) {
34+
_, err := runScript("docker pull ubuntu")
35+
Expect(err).ToNot(HaveOccurred())
36+
})
37+
38+
It("it should show the same output from outside a container", func(ctx context.Context) {
39+
// collect the output of nvidia-smi -L
40+
rawOut, err := runScript("nvidia-smi -L")
41+
Expect(err).ToNot(HaveOccurred())
42+
43+
// collect the output of nvidia-smi -L inside a container with --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=all
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+
47+
// compare the outputs
48+
Expect(outContainer).To(Equal(rawOut))
49+
50+
// collect the output of nvidia-smi -L inside a container with --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=runtime.nvidia.com/gpu=all
51+
outContainer, err = runScript("docker run --rm -i --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=runtime.nvidia.com/gpu=all ubuntu nvidia-smi -L")
52+
Expect(err).ToNot(HaveOccurred())
53+
54+
// compare the outputs
55+
Expect(outContainer).To(Equal(rawOut))
56+
57+
// collect the output of nvidia-smi -L inside a container with --runtime=nvidia --gpus all
58+
outContainer, err = runScript("docker run --rm -i --runtime=nvidia --gpus all ubuntu nvidia-smi -L")
59+
Expect(err).ToNot(HaveOccurred())
60+
61+
// compare the outputs
62+
Expect(outContainer).To(Equal(rawOut))
63+
})
64+
})
65+
66+
// A vectorAdd sample runs in a container with access to all GPUs.
67+
// The following should all produce the same result.
68+
When("Running the cuda-vectorAdd sample", Ordered, func() {
69+
BeforeAll(func(ctx context.Context) {
70+
_, err := runScript("docker pull nvcr.io/nvidia/k8s/cuda-sample:vectoradd-cuda12.5.0")
71+
Expect(err).ToNot(HaveOccurred())
72+
})
73+
74+
It("it should show the same output from each run", func(ctx context.Context) {
75+
out1, err := runScript("docker run --rm -i --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=all nvcr.io/nvidia/k8s/cuda-sample:vectoradd-cuda12.5.0")
76+
Expect(err).ToNot(HaveOccurred())
77+
78+
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")
79+
Expect(err).ToNot(HaveOccurred())
80+
81+
out3, err := runScript("docker run --rm -i --runtime=nvidia --gpus all nvcr.io/nvidia/k8s/cuda-sample:vectoradd-cuda12.5.0")
82+
Expect(err).ToNot(HaveOccurred())
83+
84+
// compare the outputs
85+
Expect(out1).To(Equal(out2))
86+
Expect(out2).To(Equal(out3))
87+
})
88+
})
89+
90+
// A deviceQuery sample runs in a container with access to all GPUs
91+
// The following should all produce the same result.
92+
When("Running the cuda-deviceQuery sample", Ordered, func() {
93+
BeforeAll(func(ctx context.Context) {
94+
_, err := runScript("docker pull nvcr.io/nvidia/k8s/cuda-sample:devicequery-cuda12.5.0")
95+
Expect(err).ToNot(HaveOccurred())
96+
})
97+
98+
It("it should show the same output from each run", func(ctx context.Context) {
99+
out1, err := runScript("docker run --rm -i --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=all nvcr.io/nvidia/k8s/cuda-sample:devicequery-cuda12.5.0")
100+
Expect(err).ToNot(HaveOccurred())
101+
102+
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")
103+
Expect(err).ToNot(HaveOccurred())
104+
105+
out3, err := runScript("docker run --rm -i --runtime=nvidia --gpus all nvcr.io/nvidia/k8s/cuda-sample:devicequery-cuda12.5.0")
106+
Expect(err).ToNot(HaveOccurred())
107+
108+
// compare the outputs
109+
Expect(out1).To(Equal(out2))
110+
Expect(out2).To(Equal(out3))
111+
})
112+
})
113+
})

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)