use all_smi::prelude::*;
#[test]
fn test_allsmi_creation() {
let result = AllSmi::new();
assert!(result.is_ok(), "AllSmi::new() should not fail");
}
#[test]
fn test_allsmi_with_config() {
let config = AllSmiConfig::new().sample_interval(500).verbose(false);
let result = AllSmi::with_config(config);
assert!(result.is_ok(), "AllSmi::with_config() should not fail");
}
#[test]
fn test_gpu_info_does_not_panic() {
let smi = AllSmi::new().expect("Failed to create AllSmi");
let gpus = smi.get_gpu_info();
println!("Found {} GPU(s)", gpus.len());
}
#[test]
fn test_cpu_info_does_not_panic() {
let smi = AllSmi::new().expect("Failed to create AllSmi");
let cpus = smi.get_cpu_info();
println!("Found {} CPU(s)", cpus.len());
}
#[test]
fn test_memory_info_does_not_panic() {
let smi = AllSmi::new().expect("Failed to create AllSmi");
let memory = smi.get_memory_info();
println!("Found {} memory info(s)", memory.len());
}
#[test]
fn test_process_info_does_not_panic() {
let smi = AllSmi::new().expect("Failed to create AllSmi");
let processes = smi.get_process_info();
println!("Found {} GPU process(es)", processes.len());
}
#[test]
fn test_chassis_info_does_not_panic() {
let smi = AllSmi::new().expect("Failed to create AllSmi");
let chassis = smi.get_chassis_info();
println!("Chassis info: {:?}", chassis.is_some());
}
#[test]
fn test_helper_methods() {
let smi = AllSmi::new().expect("Failed to create AllSmi");
let _ = smi.gpu_reader_count();
let _ = smi.has_gpus();
let _ = smi.has_cpu_monitoring();
let _ = smi.has_memory_monitoring();
}
#[test]
fn test_allsmi_is_send() {
fn assert_send<T: Send>() {}
assert_send::<AllSmi>();
}
#[test]
fn test_allsmi_is_sync() {
fn assert_sync<T: Sync>() {}
assert_sync::<AllSmi>();
}
#[test]
fn test_error_is_send_sync() {
fn assert_send_sync<T: Send + Sync>() {}
assert_send_sync::<Error>();
}
#[test]
fn test_config_builder_pattern() {
let config = AllSmiConfig::new().sample_interval(100).verbose(true);
assert_eq!(config.sample_interval_ms, 100);
assert!(config.verbose);
}
#[test]
fn test_device_type_display() {
assert_eq!(DeviceType::NvidiaGpu.to_string(), "NVIDIA GPU");
assert_eq!(DeviceType::AmdGpu.to_string(), "AMD GPU");
assert_eq!(DeviceType::AppleSiliconGpu.to_string(), "Apple Silicon GPU");
assert_eq!(DeviceType::IntelGaudi.to_string(), "Intel Gaudi");
assert_eq!(DeviceType::GoogleTpu.to_string(), "Google TPU");
}
#[test]
fn test_error_display() {
let err = Error::PlatformInit("test error".to_string());
assert!(err.to_string().contains("Platform initialization failed"));
assert!(err.to_string().contains("test error"));
let err = Error::NoDevicesFound;
assert!(err.to_string().contains("No supported devices found"));
let err = Error::DeviceAccess("device 0".to_string());
assert!(err.to_string().contains("Device access error"));
let err = Error::PermissionDenied("root required".to_string());
assert!(err.to_string().contains("Permission denied"));
let err = Error::NotSupported("feature X".to_string());
assert!(err.to_string().contains("not supported"));
}
#[test]
fn test_prelude_exports() {
fn _check_types() {
let _: fn() -> Result<AllSmi> = || AllSmi::new();
let _: AllSmiConfig = AllSmiConfig::default();
let _: DeviceType = DeviceType::NvidiaGpu;
}
}
#[test]
fn test_multiple_allsmi_instances() {
let smi1 = AllSmi::new().expect("First AllSmi instance");
let smi2 = AllSmi::new().expect("Second AllSmi instance");
let _ = smi1.get_gpu_info();
let _ = smi2.get_gpu_info();
}
#[test]
fn test_allsmi_drop() {
{
let smi = AllSmi::new().expect("AllSmi instance");
let _ = smi.get_gpu_info();
}
let smi = AllSmi::new().expect("Second AllSmi instance after drop");
let _ = smi.get_cpu_info();
}