Files
Chad ElliottandClaude Opus 5.5 3e42f2e05c feat(testkit): #1037 tests record why they skip
libtest has no skipped status and hides the output of passing tests, so a
test that returns early without a GPU, a corpus file, a craft-fonts face or
a model passed silently. `lightcraft-testkit` (the testkit slot the layering
table already reserves, dev-dependency only, std only) adds
`skip!(Need, "reason")`: it prints the note as before and, when
LIGHTCRAFT_SKIP_LOG names a file, appends one JSON line (need, reason, test,
binary, file:line). Plain `cargo test` is unchanged. The 61 existing skip
sites use it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 16:33:54 -05:00

42 lines
1.9 KiB
Rust

//! Device-memory bookkeeping: a view's stages are counted, released buffers are pooled within
//! the pool limit, and trimming frees them. Skips when no GPU adapter exists.
use std::sync::Arc;
use lightcraft_develop::DevelopSettings;
use lightcraft_pipeline::{RenderRequest, SourceInfo, StageCache};
#[test]
fn stages_are_counted_and_the_pool_is_bounded_and_trimmed() {
if !lightcraft_gpu::available() {
lightcraft_testkit::skip!(Gpu, "no GPU adapter");
return;
}
let limit = 64u64 << 20;
lightcraft_gpu::set_pool_limit(limit);
let info = SourceInfo { raw: true, ..Default::default() };
let mut s = DevelopSettings::default();
s.effects.clarity = 30.0;
let stages = StageCache::default();
// photos of slightly different sizes, like stepping through a library
for (i, (w, h)) in [(1200usize, 800usize), (1190, 810), (1210, 790), (800, 1200)].into_iter().enumerate() {
let src = Arc::new(lightcraft_scenes::demo_library()[i].render(w, h));
let r = lightcraft_gpu::render(&src, &info, &s, &RenderRequest::fit(w, h), Some(&stages)).expect("gpu render");
assert_eq!((r.image.width, r.image.height), (w, h));
let m = lightcraft_gpu::memory();
assert!(m.pooled <= limit, "pool {} over its limit", m.pooled);
assert_eq!(m.retired, 0, "a finished render leaves nothing retired");
}
let held = lightcraft_gpu::stage_bytes(&stages);
assert!(held >= 1200 * 800 * 3 * 4, "the view's stages hold at least its resampled source: {held}");
let before = lightcraft_gpu::memory().allocated;
stages.clear();
let m = lightcraft_gpu::memory();
assert_eq!(lightcraft_gpu::stage_bytes(&stages), 0);
assert!(m.pooled <= limit && m.allocated <= before);
lightcraft_gpu::trim_pool(0);
let m = lightcraft_gpu::memory();
assert_eq!(m.pooled, 0);
assert!(m.allocated < before, "trimming frees the pooled buffers: {} → {}", before, m.allocated);
}