use crate::{GpuConfig, effective_gpu_config, gpu_config_applied};
#[test]
fn presets_differ_from_each_other() {
let default = GpuConfig::default();
let low = GpuConfig::low_memory();
let high = GpuConfig::high_performance();
let minimal = GpuConfig::minimal();
assert!(low.buffer_pool.max_pool_memory < default.buffer_pool.max_pool_memory, "low_memory must pool less than default ({} vs {})", low.buffer_pool.max_pool_memory, default.buffer_pool.max_pool_memory);
assert!(high.buffer_pool.max_pool_memory > default.buffer_pool.max_pool_memory, "high_performance must pool more than default ({} vs {})", high.buffer_pool.max_pool_memory, default.buffer_pool.max_pool_memory);
assert!(minimal.buffer_pool.max_pool_memory <= low.buffer_pool.max_pool_memory, "minimal must not pool more than low_memory");
assert!(high.num_staging_buffers >= default.num_staging_buffers, "high_performance must not stage fewer buffers than default");
}
#[test]
fn effective_config_is_readable_and_defaults_when_unset() {
let effective = effective_gpu_config();
if gpu_config_applied() {
return;
}
let default = GpuConfig::default();
assert_eq!(effective.buffer_pool.max_pool_memory, default.buffer_pool.max_pool_memory, "unset means default pool size");
assert_eq!(effective.buffer_pool.eviction_timeout_secs, default.buffer_pool.eviction_timeout_secs, "unset means default eviction timeout");
assert_eq!(effective.num_staging_buffers, default.num_staging_buffers, "unset means default staging buffer count");
}
#[test]
fn requesting_a_config_is_recorded_or_honestly_refused() {
let wanted = GpuConfig::low_memory();
match crate::prewarm_gpu_with_config(wanted.clone()) {
Ok(()) => {
eprintln!("GPU CONFIG PATH: applied (config reached the interpolator)");
assert!(gpu_config_applied(), "a successful request must report the configuration as applied");
let effective = effective_gpu_config();
assert_eq!(effective.buffer_pool.max_pool_memory, wanted.buffer_pool.max_pool_memory, "the effective configuration must be the one that was requested");
assert_eq!(effective.num_staging_buffers, wanted.num_staging_buffers);
}
Err(e) => {
let msg = e.to_string();
eprintln!("GPU CONFIG PATH: refused -> {msg}");
assert!(msg.contains("already initialized") || msg.contains("already requested") || msg.contains("adapter") || msg.contains("GPU"), "a refusal must say why; got: {msg}");
}
}
}