Files
leleka/desktop-core/tests/planning.rs
T
Pavlo Ratushnyi 4013e0c9bd
Desktop foundation / core (ubuntu-latest) (push) Failing after 28s
Desktop foundation / core (macos-latest) (push) Canceled after 0s
Desktop foundation / core (windows-latest) (push) Canceled after 0s
Linux / verify (push) Canceled after 0s
Linux / keyless-cuda (push) Canceled after 0s
Linux / static-cuda-package (push) Canceled after 0s
Linux / hosted-cuda-package (push) Canceled after 0s
Linux / linux-static-cli (push) Canceled after 0s
Linux / linux-cli-container (push) Canceled after 0s
Linux / release-cli (push) Canceled after 0s
Import tracked Strata Next source snapshot
2026-10-05 18:15:08 +02:00

148 lines
4.6 KiB
Rust

use strata_desktop_core::{
hardware::{Accelerator, Hardware, Memory, MemoryKind},
planner::{Requirements, plan},
};
const G: u64 = 1024 * 1024 * 1024;
fn host(vram: Option<u64>) -> Hardware {
Hardware {
schema_version: 1,
sampled_at_unix_ms: 0,
os: "test".into(),
architecture: "test".into(),
cpu_name: "test".into(),
logical_cpus: 8,
cpu_features: vec![],
memory: Memory {
total_bytes: Some(32 * G),
available_bytes: Some(24 * G),
},
warnings: vec![],
accelerators: vec![Accelerator {
id: "gpu".into(),
name: "fixture".into(),
vendor: "fixture".into(),
memory_kind: MemoryKind::Dedicated,
memory: Memory {
total_bytes: vram,
available_bytes: vram,
},
driver: None,
source: "fixture".into(),
}],
}
}
fn req() -> Requirements {
Requirements {
schema_version: 1,
model: "synthetic-runtime-budget".into(),
context_tokens: 1024,
concurrent_requests: 1,
weights_bytes: 10 * G,
kv_bytes_per_token_per_request: G / 1024,
workspace_bytes: G,
load_scratch_bytes: G,
host_overhead_bytes: G,
host_reserve_bytes: 2 * G,
device_reserve_bytes: G,
retains_host_weights: false,
allow_weight_offload: true,
}
}
#[test]
fn eight_gib_needs_offload_sixteen_fits() {
let p = plan(&host(Some(8 * G)), &req()).unwrap();
assert_eq!(p.candidates[1].fit, "insufficient");
assert_eq!(p.candidates.last().unwrap().fit, "fits_estimate");
assert_eq!(p.candidates[1].device_peak_bytes, 13 * G);
assert_eq!(
plan(&host(Some(16 * G)), &req()).unwrap().candidates[1].fit,
"fits_estimate"
);
}
#[test]
fn cannot_offload_into_unavailable_ram() {
let mut h = host(Some(8 * G));
h.memory.available_bytes = Some(3 * G);
assert!(
plan(&h, &req())
.unwrap()
.candidates
.iter()
.all(|c| c.fit == "insufficient")
);
}
#[test]
fn unknown_is_not_a_fit_and_offload_is_explicit() {
let mut r = req();
r.allow_weight_offload = false;
let p = plan(&host(None), &r).unwrap();
assert_eq!(p.candidates.len(), 2);
assert_eq!(p.candidates[1].fit, "unknown");
assert_eq!(p.execution_compatibility, "not_validated");
}
#[test]
fn shared_pool_once_with_separate_device_ceiling() {
let mut h = host(Some(16 * G));
h.accelerators[0].memory_kind = MemoryKind::Shared;
let p = plan(&h, &req()).unwrap();
assert_eq!(p.candidates[1].host_peak_bytes, 14 * G);
assert_eq!(p.candidates[1].device_peak_bytes, 13 * G);
assert_eq!(p.candidates[1].fit, "fits_estimate");
h.memory.available_bytes = Some(15 * G);
assert_eq!(plan(&h, &req()).unwrap().candidates[1].fit, "insufficient");
h.memory.available_bytes = Some(24 * G);
h.accelerators[0].memory.available_bytes = None;
assert_eq!(plan(&h, &req()).unwrap().candidates[1].fit, "unknown");
}
#[test]
fn retained_host_copy_is_not_free() {
let mut r = req();
r.retains_host_weights = true;
let h = host(Some(16 * G));
assert_eq!(plan(&h, &r).unwrap().candidates[1].host_peak_bytes, 12 * G);
let mut shared = h;
shared.accelerators[0].memory_kind = MemoryKind::Shared;
assert_eq!(
plan(&shared, &r).unwrap().candidates[1].host_peak_bytes,
24 * G
);
}
#[test]
fn equality_fits_reserve_and_concurrency_change_admission() {
let mut r = req();
assert_eq!(
plan(&host(Some(14 * G)), &r).unwrap().candidates[1].fit,
"fits_estimate"
);
r.concurrent_requests = 2;
assert_eq!(
plan(&host(Some(14 * G)), &r).unwrap().candidates[1].fit,
"insufficient"
);
}
#[test]
fn overflow_invalid_versions_and_inconsistent_memory_rejected() {
let h = host(Some(16 * G));
let mut r = req();
r.context_tokens = u64::MAX;
assert!(plan(&h, &r).is_err());
r = req();
r.weights_bytes = u64::MAX;
assert!(plan(&h, &r).is_err());
r = req();
r.schema_version = 2;
assert!(plan(&h, &r).is_err());
r = req();
r.concurrent_requests = 0;
assert!(plan(&h, &r).is_err());
let mut bad = h;
bad.memory.available_bytes = Some(100 * G);
assert!(plan(&bad, &req()).is_err());
}
#[test]
fn requirements_reject_typo_instead_of_silently_ignoring_it() {
let mut v = serde_json::to_value(req()).unwrap();
v["weights_bites"] = 1.into();
assert!(serde_json::from_value::<Requirements>(v).is_err());
}