MCPcopy Create free account
hub / github.com/containerd/nerdctl / TestRunGPU

Function TestRunGPU

cmd/nerdctl/container/container_run_linux_test.go:728–828  ·  view source on GitHub ↗

TestRunGPU tests GPU injection using the --gpus flag.

(t *testing.T)

Source from the content-addressed store, hash-verified

726
727// TestRunGPU tests GPU injection using the --gpus flag.
728func TestRunGPU(t *testing.T) {
729 t.Parallel()
730 // Although CDI injection is supported by Docker, specifying the --cdi-spec-dirs on the command line is not.
731 testutil.DockerIncompatible(t)
732 const nvidiaSpec = `
733cdiVersion: "0.5.0"
734kind: "nvidia.com/gpu"
735devices:
736- name: "0"
737 containerEdits:
738 env:
739 - NVIDIA_GPU_0=injected
740- name: "1"
741 containerEdits:
742 env:
743 - NVIDIA_GPU_1=injected
744`
745 const amdSpec = `
746cdiVersion: "0.5.0"
747kind: "amd.com/gpu"
748devices:
749- name: "0"
750 containerEdits:
751 env:
752 - AMD_GPU_0=injected
753- name: "1"
754 containerEdits:
755 env:
756 - AMD_GPU_1=injected
757`
758 const unknownSpec = `
759cdiVersion: "0.5.0"
760kind: "unknown.com/gpu"
761devices:
762- name: "0"
763 containerEdits:
764 env:
765 - UNKNOWN_GPU_0=injected
766`
767
768 testCases := []struct {
769 name string
770 specs map[string]string
771 gpuFlags []string
772 expectedEnvs []string
773 expectFail bool
774 }{
775 {
776 name: "nvidia device injection",
777 specs: map[string]string{"nvidia.yaml": nvidiaSpec},
778 gpuFlags: []string{"--gpus", "2"},
779 expectedEnvs: []string{"NVIDIA_GPU_0=injected", "NVIDIA_GPU_1=injected"},
780 },
781 {
782 name: "amd device injection",
783 specs: map[string]string{"amd.yaml": amdSpec},
784 gpuFlags: []string{"--gpus", "2"},
785 expectedEnvs: []string{"AMD_GPU_0=injected", "AMD_GPU_1=injected"},

Callers

nothing calls this directly

Calls 8

CmdMethod · 0.95
DockerIncompatibleFunction · 0.92
NewBaseFunction · 0.92
writeTestCDISpecFunction · 0.85
AssertFailMethod · 0.80
AssertOutWithFuncMethod · 0.80
RunMethod · 0.65
TempDirMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…