MCPcopy Index your code
hub / github.com/coder/envbox / TestGPUs

Function TestGPUs

xunix/gpu_test.go:46–133  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

44}
45
46func TestGPUs(t *testing.T) {
47 t.Parallel()
48
49 t.Run("OK", func(t *testing.T) {
50 t.Parallel()
51
52 var (
53 fs = &xunixfake.MemFS{MemMapFs: &afero.MemMapFs{}}
54 mounter = &mount.FakeMounter{}
55 log = slogtest.Make(t, nil)
56 usrLibMountpoint = "/var/coder/usr/lib"
57 // expectedUsrLibFiles are files that we expect to be returned bind mounts
58 // for.
59 expectedUsrLibFiles = []string{
60 filepath.Join(usrLibMountpoint, "nvidia", "libglxserver_nvidia.so"),
61 filepath.Join(usrLibMountpoint, "libnvidia-ml.so"),
62 filepath.Join(usrLibMountpoint, "nvidia", "libglxserver_nvidia.so.1"),
63 }
64
65 // fakeUsrLibFiles are files that we do not expect to be returned
66 // bind mounts for.
67 fakeUsrLibFiles = []string{
68 filepath.Join(usrLibMountpoint, "libcurl-gnutls.so"),
69 filepath.Join(usrLibMountpoint, "libglib.so"),
70 }
71
72 // allUsrLibFiles are all the files that should be written to the
73 // "mounted" /usr/lib directory. It includes files that shouldn't
74 // be returned.
75 allUsrLibFiles = append(expectedUsrLibFiles, fakeUsrLibFiles...)
76 )
77
78 ctx := xunix.WithFS(context.Background(), fs)
79 ctx = xunix.WithMounter(ctx, mounter)
80
81 mounter.MountPoints = []mount.MountPoint{
82 {
83 Device: "/dev/sda1",
84 Path: "/usr/local/nvidia",
85 Opts: []string{"ro"},
86 },
87 {
88 Device: "/dev/sda2",
89 Path: "/etc/hosts",
90 },
91 {
92 Path: "/dev/nvidia0",
93 },
94 {
95 Path: "/dev/nvidia1",
96 },
97 }
98
99 err := fs.MkdirAll(filepath.Join(usrLibMountpoint, "nvidia"), 0o755)
100 require.NoError(t, err)
101
102 for _, file := range allUsrLibFiles {
103 _, err = fs.Create(file)

Callers

nothing calls this directly

Calls 5

WithFSFunction · 0.92
WithMounterFunction · 0.92
GPUsFunction · 0.92
LenMethod · 0.80
RunMethod · 0.45

Tested by

no test coverage detected