|
| 1 | +// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +#![cfg(feature = "e2e-gpu")] |
| 5 | + |
| 6 | +//! CDI GPU e2e tests. |
| 7 | +//! |
| 8 | +//! Requires a CDI-enabled gateway backed by Docker or Podman. The |
| 9 | +//! `e2e:docker:gpu` and `e2e:podman:gpu` mise tasks start the corresponding |
| 10 | +//! gateway with the default sandbox image unless the task-specific sandbox |
| 11 | +//! image environment variable is set. |
| 12 | +
|
| 13 | +use openshell_e2e::harness::output::strip_ansi; |
| 14 | +use openshell_e2e::harness::sandbox::SandboxGuard; |
| 15 | + |
| 16 | +async fn assert_nvidia_smi(args: &[&str]) { |
| 17 | + let mut create_args = Vec::from(args); |
| 18 | + create_args.extend([ |
| 19 | + "--", |
| 20 | + "sh", |
| 21 | + "-lc", |
| 22 | + "gpu_name=$(nvidia-smi --query-gpu=name --format=csv,noheader | head -n 1); \ |
| 23 | + test -n \"$gpu_name\"; \ |
| 24 | + printf 'gpu-ok:%s\\n' \"$gpu_name\"", |
| 25 | + ]); |
| 26 | + |
| 27 | + let mut guard = SandboxGuard::create(&create_args) |
| 28 | + .await |
| 29 | + .expect("GPU sandbox create should succeed"); |
| 30 | + |
| 31 | + let output = strip_ansi(&guard.create_output); |
| 32 | + assert!( |
| 33 | + output.contains("gpu-ok:"), |
| 34 | + "expected GPU smoke marker in sandbox output:\n{output}" |
| 35 | + ); |
| 36 | + |
| 37 | + guard.cleanup().await; |
| 38 | +} |
| 39 | + |
| 40 | +#[tokio::test] |
| 41 | +async fn cdi_gpu_sandbox_runs_nvidia_smi() { |
| 42 | + assert_nvidia_smi(&["--gpu"]).await; |
| 43 | +} |
| 44 | + |
| 45 | +#[tokio::test] |
| 46 | +async fn cdi_gpu_sandbox_runs_nvidia_smi_with_specific_device() { |
| 47 | + assert_nvidia_smi(&["--gpu", "--gpu-device", "nvidia.com/gpu=0"]).await; |
| 48 | +} |
0 commit comments