Skip to content

Commit 4319e43

Browse files
committed
test: [no-relnote] Add test for running nvidia-smi in Alpine
Signed-off-by: Evan Lezar <[email protected]>
1 parent 22a762f commit 4319e43

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

tests/e2e/nvidia-container-toolkit_test.go

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
var _ = Describe("docker", Ordered, ContinueOnFailure, func() {
3131
var hostDriverVersion string
3232
var hostDriverMajor string
33+
var hostOutput string
3334

3435
// Install the NVIDIA Container Toolkit
3536
BeforeAll(func(ctx context.Context) {
@@ -41,20 +42,17 @@ var _ = Describe("docker", Ordered, ContinueOnFailure, func() {
4142
hostDriverVersion = strings.TrimSpace(parts[1])
4243
Expect(hostDriverVersion).ToNot(BeEmpty())
4344
hostDriverMajor = strings.SplitN(hostDriverVersion, ".", 2)[0]
45+
46+
hostOutput, _, err = runner.Run("nvidia-smi -L")
47+
Expect(err).ToNot(HaveOccurred())
4448
})
4549

4650
// GPUs are accessible in a container: Running nvidia-smi -L inside the
4751
// container shows the same output inside the container as outside the
4852
// container. This means that the following commands must all produce
4953
// the same output
5054
When("running nvidia-smi -L", Ordered, func() {
51-
var hostOutput string
52-
var err error
53-
5455
BeforeAll(func(ctx context.Context) {
55-
hostOutput, _, err = runner.Run("nvidia-smi -L")
56-
Expect(err).ToNot(HaveOccurred())
57-
5856
_, _, err := runner.Run("docker pull ubuntu")
5957
Expect(err).ToNot(HaveOccurred())
6058
})
@@ -589,4 +587,30 @@ EOF`)
589587
Expect(output).To(Equal(expectedOutput))
590588
})
591589
})
590+
591+
When("running an alpine container", Ordered, func() {
592+
BeforeAll(func(ctx context.Context) {
593+
_, _, err := runner.Run(`docker build -t alpinecompat \
594+
- <<EOF
595+
FROM alpine
596+
ENV NVIDIA_VISIBLE_DEVICES=all
597+
RUN apk add --no-cache gcompat
598+
EOF`)
599+
Expect(err).ToNot(HaveOccurred())
600+
})
601+
602+
It("nvidia-smi should succeed when using the nvidia-container-runtime", func(ctx context.Context) {
603+
output, _, err := runner.Run(`docker run --rm --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=all -e NVIDIA_DRIVER_CAPABILITIES=all \
604+
alpinecompat nvidia-smi -L"`)
605+
Expect(err).ToNot(HaveOccurred())
606+
Expect(output).To(Equal(hostOutput))
607+
})
608+
609+
It("nvidia-smi should succeed when using the nvidia-container-runtime-hook", Label("legacy"), func(ctx context.Context) {
610+
output, _, err := runner.Run(`docker run --rm --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=all -e NVIDIA_DRIVER_CAPABILITIES=all \
611+
alpinecompat nvidia-smi -L"`)
612+
Expect(err).ToNot(HaveOccurred())
613+
Expect(output).To(Equal(hostOutput))
614+
})
615+
})
592616
})

0 commit comments

Comments
 (0)