(t *testing.T)
| 16 | ) |
| 17 | |
| 18 | func TestDocker_Nvidia(t *testing.T) { |
| 19 | t.Parallel() |
| 20 | if val, ok := os.LookupEnv("CODER_TEST_INTEGRATION"); !ok || val != "1" { |
| 21 | t.Skip("integration tests are skipped unless CODER_TEST_INTEGRATION=1") |
| 22 | } |
| 23 | // Only run this test if the nvidia container runtime is detected. |
| 24 | // Check if the nvidia runtime is available using `docker info`. |
| 25 | // The docker client doesn't expose this information so we need to fetch it ourselves. |
| 26 | if !slices.Contains(dockerRuntimes(t), "nvidia") { |
| 27 | t.Skip("this test requires nvidia runtime to be available") |
| 28 | } |
| 29 | |
| 30 | t.Run("Ubuntu", func(t *testing.T) { |
| 31 | t.Parallel() |
| 32 | ctx, cancel := context.WithCancel(context.Background()) |
| 33 | t.Cleanup(cancel) |
| 34 | |
| 35 | // Start the envbox container. |
| 36 | ctID := startEnvboxCmd(ctx, t, integrationtest.UbuntuImage, "root", |
| 37 | "-v", "/usr/lib/x86_64-linux-gnu:/var/coder/usr/lib", |
| 38 | "--env", "CODER_ADD_GPU=true", |
| 39 | "--env", "CODER_USR_LIB_DIR=/var/coder/usr/lib", |
| 40 | "--runtime=nvidia", |
| 41 | "--gpus=all", |
| 42 | ) |
| 43 | |
| 44 | // Assert that we can run nvidia-smi in the inner container. |
| 45 | assertInnerNvidiaSMI(ctx, t, ctID) |
| 46 | }) |
| 47 | |
| 48 | t.Run("Redhat", func(t *testing.T) { |
| 49 | t.Parallel() |
| 50 | ctx, cancel := context.WithCancel(context.Background()) |
| 51 | t.Cleanup(cancel) |
| 52 | |
| 53 | // Start the envbox container. |
| 54 | ctID := startEnvboxCmd(ctx, t, integrationtest.RedhatImage, "root", |
| 55 | "-v", "/usr/lib/x86_64-linux-gnu:/var/coder/usr/lib", |
| 56 | "--env", "CODER_ADD_GPU=true", |
| 57 | "--env", "CODER_USR_LIB_DIR=/var/coder/usr/lib", |
| 58 | "--runtime=nvidia", |
| 59 | "--gpus=all", |
| 60 | ) |
| 61 | |
| 62 | // Assert that we can run nvidia-smi in the inner container. |
| 63 | assertInnerNvidiaSMI(ctx, t, ctID) |
| 64 | |
| 65 | // Make sure dnf still works. This checks for a regression due to |
| 66 | // gpuExtraRegex matching `libglib.so` in the outer container. |
| 67 | // This had a dependency on `libpcre.so.3` which would cause dnf to fail. |
| 68 | out, err := execContainerCmd(ctx, t, ctID, "docker", "exec", "workspace_cvm", "dnf") |
| 69 | if !assert.NoError(t, err, "failed to run dnf in the inner container") { |
| 70 | t.Logf("dnf output:\n%s", strings.TrimSpace(out)) |
| 71 | } |
| 72 | |
| 73 | // Make sure libglib.so is not present in the inner container. |
| 74 | out, err = execContainerCmd(ctx, t, ctID, "docker", "exec", "workspace_cvm", "ls", "-1", "/usr/lib/x86_64-linux-gnu/libglib*") |
| 75 | // An error is expected here. |
nothing calls this directly
no test coverage detected