use super::*;
#[test]
fn h022_mock_device_thermal_throttling_at_threshold() {
let mock_at_80 = MockDevice::new(0, 0, 0.0, 0.0, 80.0);
assert!(!mock_at_80.is_thermal_throttling().expect("test"));
let mock_at_80_1 = MockDevice::new(0, 0, 0.0, 0.0, 80.1);
assert!(mock_at_80_1.is_thermal_throttling().expect("test"));
}
#[test]
fn h022_mock_device_power_throttling_at_threshold() {
let mock_at_95 = MockDevice::new(0, 0, 95.0, 100.0, 0.0);
assert!(!mock_at_95.is_power_throttling().expect("test"));
let mock_at_95_1 = MockDevice::new(0, 0, 95.1, 100.0, 0.0);
assert!(mock_at_95_1.is_power_throttling().expect("test"));
}
#[test]
fn h022_mock_device_memory_usage_full() {
let mock_full = MockDevice::new(100, 100, 0.0, 0.0, 0.0);
assert!((mock_full.memory_usage_percent().expect("test") - 100.0).abs() < 0.01);
assert_eq!(mock_full.memory_available_bytes().expect("test"), 0);
}
#[test]
fn h023_device_snapshot_field_access() {
let mock = MockDevice::new(
8 * 1024 * 1024 * 1024,
32 * 1024 * 1024 * 1024,
250.0,
350.0,
72.0,
);
let snapshot = DeviceSnapshot::capture(&mock).expect("test");
assert_eq!(snapshot.memory_used_bytes, 8 * 1024 * 1024 * 1024);
assert_eq!(snapshot.memory_total_bytes, 32 * 1024 * 1024 * 1024);
assert!((snapshot.temperature_c - 72.0).abs() < 0.01);
assert!((snapshot.power_watts - 250.0).abs() < 0.01);
assert_eq!(snapshot.clock_mhz, 3000);
assert!((snapshot.memory_usage_percent() - 25.0).abs() < 0.01);
}
#[test]
fn h024_cpu_device_refresh_populates_fields() {
let mut cpu = CpuDevice::new();
let result = cpu.refresh();
assert!(result.is_ok());
let util = cpu.compute_utilization();
assert!(util.is_ok());
let util_val = util.expect("test");
assert!(util_val >= 0.0 && util_val <= 100.0);
let mem = cpu.memory_used_bytes();
assert!(mem.is_ok());
}
#[test]
fn h024_cpu_device_refresh_multiple_times() {
let mut cpu = CpuDevice::new();
for _ in 0..5 {
assert!(cpu.refresh().is_ok());
}
assert!(cpu.compute_utilization().is_ok());
assert!(cpu.memory_used_bytes().is_ok());
}
#[test]
fn h025_cpu_device_read_core_count() {
let cpu = CpuDevice::new();
let count = cpu.compute_unit_count();
assert!(count >= 1, "Should have at least 1 core");
assert!(
count <= 1024,
"Sanity check: should have fewer than 1024 cores"
);
}
#[test]
fn h025_cpu_device_read_total_memory() {
let cpu = CpuDevice::new();
let total = cpu.memory_total_bytes().expect("test");
assert!(total >= 1024 * 1024 * 1024, "Should have at least 1GB");
assert!(total < 100 * 1024 * 1024 * 1024 * 1024, "Sanity: < 100TB");
}
#[test]
fn h025_cpu_device_read_cpu_name() {
let cpu = CpuDevice::new();
let name = cpu.device_name();
assert!(!name.is_empty(), "CPU name should not be empty");
}
#[test]
fn h026_cpu_device_compute_clock_value() {
let cpu = CpuDevice::new();
match cpu.compute_clock_mhz() {
Ok(mhz) => {
assert!(mhz >= 100, "Clock should be at least 100 MHz");
assert!(mhz <= 10000, "Clock should be at most 10 GHz");
}
Err(GpuError::NotSupported(_)) => {
}
Err(e) => panic!("Unexpected error: {:?}", e),
}
}
#[test]
fn h027_cpu_device_temperature_value() {
let mut cpu = CpuDevice::new();
cpu.refresh().expect("test");
match cpu.compute_temperature_c() {
Ok(temp) => {
assert!(temp >= 0.0, "Temperature should be non-negative");
assert!(temp <= 150.0, "Temperature should be at most 150C");
}
Err(GpuError::NotSupported(_)) => {
}
Err(e) => panic!("Unexpected error: {:?}", e),
}
}
#[test]
fn h028_cpu_device_cpu_usage_after_refresh() {
let mut cpu = CpuDevice::new();
cpu.refresh().expect("test");
let usage = cpu.compute_utilization().expect("test");
assert!(usage >= 0.0, "CPU usage should be non-negative");
assert!(usage <= 100.0, "CPU usage should be at most 100%");
}
#[test]
fn h029_cpu_device_memory_used_after_refresh() {
let mut cpu = CpuDevice::new();
cpu.refresh().expect("test");
let used = cpu.memory_used_bytes().expect("test");
let total = cpu.memory_total_bytes().expect("test");
assert!(used <= total, "Used memory should not exceed total");
assert!(used > 0, "Some memory should be in use");
}
#[test]
fn h030_mock_device_device_name() {
let mock = MockDevice::new(0, 0, 0.0, 0.0, 0.0);
assert_eq!(mock.device_name(), "Mock");
}
#[test]
fn h030_mock_device_device_type() {
let mock = MockDevice::new(0, 0, 0.0, 0.0, 0.0);
assert!(matches!(mock.device_type(), DeviceType::Cpu));
}
#[test]
fn h030_mock_device_device_id() {
let mock = MockDevice::new(0, 0, 0.0, 0.0, 0.0);
assert_eq!(mock.device_id(), DeviceId::cpu());
}
#[test]
fn h030_mock_device_compute_utilization() {
let mock = MockDevice::new(0, 0, 0.0, 0.0, 0.0);
assert!((mock.compute_utilization().expect("test") - 50.0).abs() < 0.01);
}
#[test]
fn h030_mock_device_compute_clock() {
let mock = MockDevice::new(0, 0, 0.0, 0.0, 0.0);
assert_eq!(mock.compute_clock_mhz().expect("test"), 3000);
}
#[test]
fn h030_mock_device_compute_temperature() {
let mock = MockDevice::new(0, 0, 0.0, 0.0, 45.0);
assert!((mock.compute_temperature_c().expect("test") - 45.0).abs() < 0.01);
}
#[test]
fn h030_mock_device_compute_power() {
let mock = MockDevice::new(0, 0, 200.0, 300.0, 0.0);
assert!((mock.compute_power_watts().expect("test") - 200.0).abs() < 0.01);
assert!((mock.compute_power_limit_watts().expect("test") - 300.0).abs() < 0.01);
}
#[test]
fn h030_mock_device_compute_unit_count() {
let mock = MockDevice::new(0, 0, 0.0, 0.0, 0.0);
assert_eq!(mock.compute_unit_count(), 8);
}
#[test]
fn h030_mock_device_memory_bytes() {
let mock = MockDevice::new(1000, 2000, 0.0, 0.0, 0.0);
assert_eq!(mock.memory_used_bytes().expect("test"), 1000);
assert_eq!(mock.memory_total_bytes().expect("test"), 2000);
}