diff --git a/Cargo.lock b/Cargo.lock index 4f8d0f3fb..cefa08bf6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2487,6 +2487,7 @@ dependencies = [ "image", "js-sys", "log", + "memory-stats", "serde", "serde_json", "thiserror 2.0.21", @@ -2672,6 +2673,7 @@ dependencies = [ "egui", "egui_kittest", "log", + "memory-stats", "serde", "serde_json", "skrifa 0.47.0", @@ -4951,6 +4953,16 @@ dependencies = [ "autocfg", ] +[[package]] +name = "memory-stats" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c73f5c649995a115e1a0220b35e4df0a1294500477f97a91d0660fb5abeb574a" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "mime" version = "0.3.18" diff --git a/crates/engine/Cargo.toml b/crates/engine/Cargo.toml index 9fddfe024..8b6ac9b57 100644 --- a/crates/engine/Cargo.toml +++ b/crates/engine/Cargo.toml @@ -33,6 +33,7 @@ chrono = { workspace = true } [dev-dependencies] deckcraft-anim = { workspace = true } +memory-stats = "1.2.0" zip = { workspace = true } craft-metafile = { workspace = true, features = ["write"] } diff --git a/crates/engine/src/soak_tests.rs b/crates/engine/src/soak_tests.rs index 2b3154053..d1777ff35 100644 --- a/crates/engine/src/soak_tests.rs +++ b/crates/engine/src/soak_tests.rs @@ -64,6 +64,42 @@ fn params(r: &mut Rng, s: &Session) -> Value { } } +/// Physical memory in use, in bytes: the resident set size on Linux and macOS, the working set on +/// Windows. `None` where the platform cannot say. +fn rss_bytes() -> Option { + memory_stats::memory_stats().map(|m| m.physical_mem as u64) +} + +/// Whether this process may run the named soak itself, so its memory reading is its own. +/// +/// The reading is for the whole process, and plain `cargo test` runs every test of the crate on +/// threads of one process, so other tests' allocations would count against the budget. nextest +/// runs each test in its own process (and sets `NEXTEST`). Anywhere else the test runs itself again +/// in a child process of its own, which takes this branch, and fails if the child does. +fn alone(test: &str) -> bool { + const MARK: &str = "DECKCRAFT_SOAK_ALONE"; + if std::env::var_os("NEXTEST").is_some() || std::env::var_os(MARK).is_some() { + return true; + } + let path = module_path!().split_once("::").map_or(module_path!(), |(_, rest)| rest); + let out = std::process::Command::new(std::env::current_exe().expect("test binary path")) + .args(["--exact", &format!("{path}::{test}"), "--include-ignored", "--test-threads=1", "--nocapture"]) + .env(MARK, "1") + .output() + .expect("run the soak in its own process"); + assert!( + out.status.success(), + "soak {test} failed in its own process:\n{}\n{}", + String::from_utf8_lossy(&out.stdout), + String::from_utf8_lossy(&out.stderr) + ); + false +} + +/// RSS growth allowed between the warmed-up start and the end of a soak, with the test alone in +/// its process (see `alone`). +const MAX_RSS_GROWTH: u64 = 256 << 20; + fn doc(s: &Session) -> Option { s.active().map(|d| (*d.doc).clone()) } @@ -91,7 +127,12 @@ fn soak(seed: u64, steps: usize) { let mut r = Rng(seed | 1); let mut log: VecDeque = VecDeque::new(); let mut edits = 0usize; + let mut rss_start = None; for step in 0..steps { + // Sample after a quarter of the run so one-off caches and allocator arenas are warm. + if step == steps / 4 { + rss_start = rss_bytes(); + } let id = *r.pick(&ids).unwrap(); let p = params(&mut r, &s); log.push_back(format!("{id} {p}")); @@ -140,7 +181,13 @@ fn soak(seed: u64, steps: usize) { } // The soak must really edit, not just bounce off disabled commands. assert!(edits * 10 >= steps, "only {edits} of {steps} steps changed the document; seed {seed}"); - eprintln!("soak seed {seed}: {edits} of {steps} steps edited"); + if let (Some(start), Some(end)) = (rss_start, rss_bytes()) { + let grew = end.saturating_sub(start); + eprintln!("soak seed {seed}: {edits} of {steps} steps edited, memory {} -> {} MiB", start >> 20, end >> 20); + assert!(grew <= MAX_RSS_GROWTH, "memory grew {} MiB over {} MiB; seed {seed}", grew >> 20, MAX_RSS_GROWTH >> 20); + } else { + eprintln!("soak seed {seed}: {edits} of {steps} steps edited"); + } } fn steps(default: usize) -> usize { @@ -149,6 +196,9 @@ fn steps(default: usize) -> usize { #[test] fn soak_random_edits_keep_the_document_valid() { + if !alone("soak_random_edits_keep_the_document_valid") { + return; + } for seed in [1, 0xDEC0_C2AF, 42, 7_777_777] { soak(seed, steps(400)); } @@ -157,6 +207,9 @@ fn soak_random_edits_keep_the_document_valid() { #[test] #[ignore = "long soak; set DECKCRAFT_SOAK_STEPS"] fn soak_long() { + if !alone("soak_long") { + return; + } let seed = std::env::var("DECKCRAFT_SOAK_SEED").ok().and_then(|v| v.parse().ok()).unwrap_or(0x5EED); soak(seed, steps(20_000)); } diff --git a/crates/ui-egui/Cargo.toml b/crates/ui-egui/Cargo.toml index b6457c2d3..29534d93d 100644 --- a/crates/ui-egui/Cargo.toml +++ b/crates/ui-egui/Cargo.toml @@ -40,6 +40,7 @@ skrifa = { workspace = true } # kittest's own dev-dependencies do not propagate; tests need both font features explicitly. egui = { workspace = true, features = ["default_fonts", "monochrome_emoji_fonts"] } egui_kittest = { workspace = true, features = ["wgpu", "snapshot", "eframe"] } +memory-stats = "1.2.0" [build-dependencies] serde_json = { workspace = true } diff --git a/crates/ui-egui/src/ui_soak_tests.rs b/crates/ui-egui/src/ui_soak_tests.rs index 7204b2a50..8e90cf8d7 100644 --- a/crates/ui-egui/src/ui_soak_tests.rs +++ b/crates/ui-egui/src/ui_soak_tests.rs @@ -23,6 +23,16 @@ const MAX_JOURNAL: usize = 10_000; /// Mean wall time per frame, generous for slow CI machines (the test profile is optimized). const MAX_MEAN_FRAME: Duration = Duration::from_millis(250); +/// RSS growth allowed between the warmed-up start and the end of a soak; generous because +/// `cargo test` threads share the process. +const MAX_RSS_GROWTH: u64 = 256 << 20; + +/// Physical memory in use, in bytes: the resident set size on Linux and macOS, the working set on +/// Windows. `None` where the platform cannot say. +fn rss_bytes() -> Option { + memory_stats::memory_stats().map(|m| m.physical_mem as u64) +} + struct Rng(u64); impl Rng { @@ -161,6 +171,7 @@ fn soak(seed: u64, steps: usize) { let mut log = VecDeque::new(); let t0 = Instant::now(); let mut frames = 0usize; + let mut rss_start = None; for step in 0..steps { log.push_back(act(&mut h, &mut r)); if log.len() > 20 { @@ -168,6 +179,11 @@ fn soak(seed: u64, steps: usize) { } h.run_steps(2); frames += 8; + // Sample after a quarter of the run and its frames, so texture caches and allocator arenas + // are warm. Short runs sample only after their first completed action. + if step + 1 == (steps / 4).max(1) { + rss_start = rss_bytes(); + } if step % 10 == 9 { check(&h, seed, step, &log); } @@ -184,6 +200,11 @@ fn soak(seed: u64, steps: usize) { let mean = t0.elapsed() / frames.max(1) as u32; eprintln!("ui soak seed {seed}: {steps} actions, {edits} commands, ~{frames} frames, mean frame {mean:?}"); assert!(mean <= MAX_MEAN_FRAME, "mean frame {mean:?} over {MAX_MEAN_FRAME:?}; seed {seed}"); + if let (Some(start), Some(end)) = (rss_start, rss_bytes()) { + let grew = end.saturating_sub(start); + eprintln!("ui soak seed {seed}: memory {} -> {} MiB", start >> 20, end >> 20); + assert!(grew <= MAX_RSS_GROWTH, "memory grew {} MiB over {} MiB; seed {seed}", grew >> 20, MAX_RSS_GROWTH >> 20); + } } fn env(name: &str, default: u64) -> u64 { diff --git a/docs/gaps.md b/docs/gaps.md index 948c1d8f1..63f25588a 100644 --- a/docs/gaps.md +++ b/docs/gaps.md @@ -49,7 +49,7 @@ revision history. - **Estimate:** 4–8 h (backend probing outside the process or a safe-mode fallback, a software renderer path). Needs a tester with the hardware. **Beta blocker.** -### Soak testing has no memory or timing budgets +### Soak memory budgets run in CI on Linux only - **Evidence:** `crates/engine/src/soak_tests.rs` runs seeded random command sequences over a ~100-slide deck (validity, selection, undo/redo exactness, bounded undo, save/reopen in both formats every 100 steps); `DECKCRAFT_SOAK_STEPS` runs it long. It found a chart `clamp` panic @@ -57,9 +57,13 @@ revision history. seeded random clicks, drags, keys (plain, Ctrl, Shift), typing and scrolling over the sample deck, checking document validity, bounded undo/journal/thumbnail/texture caches, zero caught command and render panics (`Session::panics_caught`, `deckcraft_render::panics_caught`) and a - mean frame under 250 ms; 4 × 3000-action runs are clean. -- **Impact:** long-session crash rate is sampled in CI; RSS is not measured directly. -- **Estimate:** 1–2 h (RSS sampling per platform). + mean frame under 250 ms; 4 × 3000-action runs are clean. Both soaks also sample resident memory + (`memory-stats`: `/proc` on Linux, `GetProcessMemoryInfo` on Windows, Mach task info on macOS) + after a quarter of the run and fail if it then grows by more than 256 MiB. +- **Impact:** long-session crash rate is sampled in CI; the RSS budget is only exercised on Linux + (`ci.yml`), and the Windows and macOS code paths have never run in CI. The engine soak has no + wall-time budget. +- **Estimate:** 1 h (a Windows and macOS test job; a timing budget). ## File formats @@ -370,6 +374,7 @@ Detail in [localization-parity.md](localization-parity.md). | Date | Change | Summary | |---|---|---| +| 2026-10-26 | trivial | The engine and UI soaks fail if resident memory grows by more than 256 MiB after warm-up (through `memory-stats`: Linux, Windows and macOS; only Linux runs in CI) | | 2026-11-02 | trivial | Run alternate-language metadata now survives native and PPTX saves; UI and proofing gaps remain; scores unchanged | | 2026-11-02 | trivial | PPTX reflection geometry is retained through native and PPTX resaves; no rendering parity claim | | 2026-11-02 | trivial | Reused slide geometry and content scale to the destination; picker thumbnails remain the reuse gap |