1 //! The probe helper crosses the namespace boundary. It is skipped when Docker2 //! or the local image is absent.3 4 use std::path::Path;5 use std::process::{Command, Stdio};6 7 const IMAGE: &str = "inf3r:local";8 9 fn available() -> bool {10 let status = Command::new("docker")11 .args(["image", "inspect", IMAGE])12 .stdout(Stdio::null())13 .stderr(Stdio::null())14 .status();15 if !status.is_ok_and(|status| status.success()) {16 eprintln!("probe test skipped: {IMAGE} is missing");17 return false;18 }19 true20 }21 22 #[test]23 fn a_probe_container_reports_host_memory_and_free_bytes() {24 if !available() {25 return;26 }27 let probe = inf3r_container::Probe::new(IMAGE, Vec::new());28 let host = probe.host().expect("the probe host");29 assert!(!host.arch.is_empty());30 assert!(host.gpu("cpu:0").is_some());31 32 let rss = probe33 .rss(std::process::id())34 .expect("the probe measures the tree");35 assert!(rss > 0, "{rss}");36 let free = probe.free("cpu:0").expect("the probe reports cpu memory");37 assert!(free > 0, "{free}");38 assert!(Path::new("/tmp").exists());39 }40 41 #[test]42 fn a_probe_with_a_cdi_device_sees_that_gpu() {43 if !available() {44 return;45 }46 let has_gpu = Command::new("nvidia-smi")47 .args(["--query-gpu=index", "--format=csv,noheader"])48 .output()49 .is_ok_and(|output| output.status.success() && !output.stdout.is_empty());50 if !has_gpu {51 eprintln!("probe GPU test skipped: no host GPU");52 return;53 }54 let probe = inf3r_container::Probe::new(IMAGE, vec!["nvidia.com/gpu=0".into()]);55 let host = probe.host().expect("the probe host with CDI");56 assert!(host.gpu("cuda:0").is_some(), "{:?}", host.gpus);57 assert!(host.gpu("cuda:0").and_then(|gpu| gpu.bytes).is_some());58 }