|
| 1 | +//go:build windows |
| 2 | +// +build windows |
| 3 | + |
| 4 | +/* |
| 5 | + Copyright The containerd Authors. |
| 6 | +
|
| 7 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + you may not use this file except in compliance with the License. |
| 9 | + You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | + Unless required by applicable law or agreed to in writing, software |
| 14 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + See the License for the specific language governing permissions and |
| 17 | + limitations under the License. |
| 18 | +*/ |
| 19 | + |
| 20 | +package integration |
| 21 | + |
| 22 | +import ( |
| 23 | + "fmt" |
| 24 | + "os" |
| 25 | + "path/filepath" |
| 26 | + "testing" |
| 27 | + "time" |
| 28 | + |
| 29 | + "github.com/stretchr/testify/assert" |
| 30 | + "github.com/stretchr/testify/require" |
| 31 | + runtime "k8s.io/cri-api/pkg/apis/runtime/v1" |
| 32 | +) |
| 33 | + |
| 34 | +func TestWindowsDevice(t *testing.T) { |
| 35 | + testPodLogDir := t.TempDir() |
| 36 | + |
| 37 | + t.Log("Create a sandbox with log directory") |
| 38 | + sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox", "windows-device", |
| 39 | + WithPodLogDirectory(testPodLogDir), |
| 40 | + ) |
| 41 | + |
| 42 | + var ( |
| 43 | + // TODO: An image with the device-dumper |
| 44 | + testImage = GetImage(BusyBox) |
| 45 | + containerName = "test-container" |
| 46 | + ) |
| 47 | + |
| 48 | + const ( |
| 49 | + // Mount this device class to expose host-GPU-accelerated DirectX inside the container |
| 50 | + // https://techcommunity.microsoft.com/t5/containers/bringing-gpu-acceleration-to-windows-containers/ba-p/393939 |
| 51 | + GUID_DEVINTERFACE_DISPLAY_ADAPTER = "5B45201D-F2F2-4F3B-85BB-30FF1F953599" //nolint:revive |
| 52 | + ) |
| 53 | + |
| 54 | + EnsureImageExists(t, testImage) |
| 55 | + |
| 56 | + t.Log("Create a container to run the device test") |
| 57 | + cnConfig := ContainerConfig( |
| 58 | + containerName, |
| 59 | + testImage, |
| 60 | + // Per C:\windows\System32\containers\devices.def, enabling GUID_DEVINTERFACE_DISPLAY_ADAPTER |
| 61 | + // will mount the host driver store into the container at this location. |
| 62 | + WithCommand("sh", "-c", "ls -d /Windows/System32/HostDriverStore/* | grep /Windows/System32/HostDriverStore/FileRepository"), |
| 63 | + WithLogPath(containerName), |
| 64 | + WithDevice("", "class/"+GUID_DEVINTERFACE_DISPLAY_ADAPTER, ""), |
| 65 | + ) |
| 66 | + cn, err := runtimeService.CreateContainer(sb, cnConfig, sbConfig) |
| 67 | + require.NoError(t, err) |
| 68 | + |
| 69 | + t.Log("Start the container") |
| 70 | + require.NoError(t, runtimeService.StartContainer(cn)) |
| 71 | + |
| 72 | + t.Log("Wait for container to finish running") |
| 73 | + require.NoError(t, Eventually(func() (bool, error) { |
| 74 | + s, err := runtimeService.ContainerStatus(cn) |
| 75 | + if err != nil { |
| 76 | + return false, err |
| 77 | + } |
| 78 | + if s.GetState() == runtime.ContainerState_CONTAINER_EXITED { |
| 79 | + return true, nil |
| 80 | + } |
| 81 | + return false, nil |
| 82 | + }, time.Second, 30*time.Second)) |
| 83 | + |
| 84 | + t.Log("Check container log") |
| 85 | + content, err := os.ReadFile(filepath.Join(testPodLogDir, containerName)) |
| 86 | + assert.NoError(t, err) |
| 87 | + checkContainerLog(t, string(content), []string{ |
| 88 | + fmt.Sprintf("%s %s %s", runtime.Stdout, runtime.LogTagFull, "/Windows/System32/HostDriverStore/FileRepository"), |
| 89 | + }) |
| 90 | +} |
0 commit comments