(t *testing.T)
| 44 | } |
| 45 | |
| 46 | func 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) |
nothing calls this directly
no test coverage detected