Skip to content

Commit cb52e77

Browse files
Merge pull request #860 from ArangoGutierrez/reg_test01
Add basic integration tests for docker runtime
2 parents be001d9 + 8cc672b commit cb52e77

File tree

663 files changed

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

+425869
-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: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
"fmt"
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+
func runScript(script string) (string, error) {
50+
// Create a command to run the script using bash
51+
cmd := exec.Command("bash", "-c", script)
52+
53+
// Buffer to capture standard output
54+
var stdout bytes.Buffer
55+
cmd.Stdout = &stdout
56+
57+
// Buffer to capture standard error
58+
var stderr bytes.Buffer
59+
cmd.Stderr = &stderr
60+
61+
// Run the command
62+
err := cmd.Run()
63+
if err != nil {
64+
return "", fmt.Errorf("script execution failed: %v\nSTDOUT: %s\nSTDERR: %s", err, stdout.String(), stderr.String())
65+
}
66+
67+
// Return the captured stdout and nil error
68+
return stdout.String(), nil
69+
}
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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 hostOutput string
34+
35+
BeforeAll(func(ctx context.Context) {
36+
_, err := runScript("docker pull ubuntu")
37+
Expect(err).ToNot(HaveOccurred())
38+
39+
hostOutput, err = runScript("nvidia-smi -L")
40+
Expect(err).ToNot(HaveOccurred())
41+
})
42+
43+
It("should support NVIDIA_VISIBLE_DEVICES", func(ctx context.Context) {
44+
containerOutput, err := runScript("docker run --rm -i --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=all ubuntu nvidia-smi -L")
45+
Expect(err).ToNot(HaveOccurred())
46+
Expect(containerOutput).To(Equal(hostOutput))
47+
})
48+
49+
It("should support automatic CDI spec generation", func(ctx context.Context) {
50+
containerOutput, 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(containerOutput).To(Equal(hostOutput))
53+
})
54+
55+
It("should support the --gpus flag using the nvidia-container-runtime", func(ctx context.Context) {
56+
containerOutput, err := runScript("docker run --rm -i --runtime=nvidia --gpus all ubuntu nvidia-smi -L")
57+
Expect(err).ToNot(HaveOccurred())
58+
Expect(containerOutput).To(Equal(hostOutput))
59+
})
60+
61+
It("should support the --gpus flag using the nvidia-container-runtime-hook", func(ctx context.Context) {
62+
containerOutput, err := runScript("docker run --rm -i --gpus all ubuntu nvidia-smi -L")
63+
Expect(err).ToNot(HaveOccurred())
64+
Expect(containerOutput).To(Equal(hostOutput))
65+
})
66+
})
67+
68+
// A vectorAdd sample runs in a container with access to all GPUs.
69+
// The following should all produce the same result.
70+
When("Running the cuda-vectorAdd sample", Ordered, func() {
71+
BeforeAll(func(ctx context.Context) {
72+
_, err := runScript("docker pull nvcr.io/nvidia/k8s/cuda-sample:vectoradd-cuda12.5.0")
73+
Expect(err).ToNot(HaveOccurred())
74+
})
75+
76+
var referenceOutput string
77+
78+
It("should support NVIDIA_VISIBLE_DEVICES", func(ctx context.Context) {
79+
var err error
80+
referenceOutput, err = runScript("docker run --rm -i --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=all nvcr.io/nvidia/k8s/cuda-sample:vectoradd-cuda12.5.0")
81+
Expect(err).ToNot(HaveOccurred())
82+
83+
Expect(referenceOutput).To(ContainSubstring("Test PASSED"))
84+
})
85+
86+
It("should support automatic CDI spec generation", func(ctx context.Context) {
87+
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")
88+
Expect(err).ToNot(HaveOccurred())
89+
Expect(referenceOutput).To(Equal(out2))
90+
})
91+
92+
It("should support the --gpus flag using the nvidia-container-runtime", func(ctx context.Context) {
93+
out3, err := runScript("docker run --rm -i --runtime=nvidia --gpus all nvcr.io/nvidia/k8s/cuda-sample:vectoradd-cuda12.5.0")
94+
Expect(err).ToNot(HaveOccurred())
95+
Expect(referenceOutput).To(Equal(out3))
96+
})
97+
98+
It("should support the --gpus flag using the nvidia-container-runtime-hook", func(ctx context.Context) {
99+
out4, err := runScript("docker run --rm -i --gpus all nvcr.io/nvidia/k8s/cuda-sample:vectoradd-cuda12.5.0")
100+
Expect(err).ToNot(HaveOccurred())
101+
Expect(referenceOutput).To(Equal(out4))
102+
})
103+
})
104+
105+
// A deviceQuery sample runs in a container with access to all GPUs
106+
// The following should all produce the same result.
107+
When("Running the cuda-deviceQuery sample", Ordered, func() {
108+
BeforeAll(func(ctx context.Context) {
109+
_, err := runScript("docker pull nvcr.io/nvidia/k8s/cuda-sample:devicequery-cuda12.5.0")
110+
Expect(err).ToNot(HaveOccurred())
111+
})
112+
113+
var referenceOutput string
114+
115+
It("should support NVIDIA_VISIBLE_DEVICES", func(ctx context.Context) {
116+
var err error
117+
referenceOutput, err = runScript("docker run --rm -i --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=all nvcr.io/nvidia/k8s/cuda-sample:devicequery-cuda12.5.0")
118+
Expect(err).ToNot(HaveOccurred())
119+
120+
Expect(referenceOutput).To(ContainSubstring("Result = PASS"))
121+
})
122+
123+
It("should support automatic CDI spec generation", func(ctx context.Context) {
124+
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")
125+
Expect(err).ToNot(HaveOccurred())
126+
Expect(referenceOutput).To(Equal(out2))
127+
})
128+
129+
It("should support the --gpus flag using the nvidia-container-runtime", func(ctx context.Context) {
130+
out3, err := runScript("docker run --rm -i --runtime=nvidia --gpus all nvcr.io/nvidia/k8s/cuda-sample:devicequery-cuda12.5.0")
131+
Expect(err).ToNot(HaveOccurred())
132+
Expect(referenceOutput).To(Equal(out3))
133+
})
134+
135+
It("should support the --gpus flag using the nvidia-container-runtime-hook", func(ctx context.Context) {
136+
out4, err := runScript("docker run --rm -i --gpus all nvcr.io/nvidia/k8s/cuda-sample:devicequery-cuda12.5.0")
137+
Expect(err).ToNot(HaveOccurred())
138+
Expect(referenceOutput).To(Equal(out4))
139+
})
140+
})
141+
})

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)