diff --git a/crates/image-codecs/tests/jxl_decode.rs b/crates/image-codecs/tests/it/jxl_decode.rs similarity index 100% rename from crates/image-codecs/tests/jxl_decode.rs rename to crates/image-codecs/tests/it/jxl_decode.rs diff --git a/crates/image-codecs/tests/jxl_export.rs b/crates/image-codecs/tests/it/jxl_export.rs similarity index 100% rename from crates/image-codecs/tests/jxl_export.rs rename to crates/image-codecs/tests/it/jxl_export.rs diff --git a/crates/image-codecs/tests/legacy_tiff_raw.rs b/crates/image-codecs/tests/it/legacy_tiff_raw.rs similarity index 100% rename from crates/image-codecs/tests/legacy_tiff_raw.rs rename to crates/image-codecs/tests/it/legacy_tiff_raw.rs diff --git a/crates/image-codecs/tests/it/main.rs b/crates/image-codecs/tests/it/main.rs index e3c0feaaf..8fba454b9 100644 --- a/crates/image-codecs/tests/it/main.rs +++ b/crates/image-codecs/tests/it/main.rs @@ -25,6 +25,8 @@ mod orientation; mod pcx; mod png_jpeg; mod pnm_headers; +#[cfg(target_os = "linux")] +mod pnm_peak_memory; mod resolution; mod roundtrip; mod source_settings; @@ -41,3 +43,7 @@ mod tiff_ycbcr; mod webp_frames; mod webp_lossy; mod xpm; + +mod jxl_decode; +mod jxl_export; +mod legacy_tiff_raw; diff --git a/crates/image-codecs/tests/pnm_peak_memory.rs b/crates/image-codecs/tests/it/pnm_peak_memory.rs similarity index 57% rename from crates/image-codecs/tests/pnm_peak_memory.rs rename to crates/image-codecs/tests/it/pnm_peak_memory.rs index 33bf39b3c..5a9cfecd9 100644 --- a/crates/image-codecs/tests/pnm_peak_memory.rs +++ b/crates/image-codecs/tests/it/pnm_peak_memory.rs @@ -1,10 +1,9 @@ //! #2938: `Limits::max_alloc` budgets the decoded pixel buffer, so the PNM decoder must not build a //! wider scratch copy (it used to collect one `u32` per sample, four times an 8-bit image) next to it. //! -//! This file holds a single test so it runs in its own process: it reads the process's peak RSS +//! This probe re-runs the test in an isolated process: it reads the process's peak RSS //! (`VmHWM`, Linux only) and nothing else may allocate meanwhile. -#[cfg(target_os = "linux")] fn peak_rss_bytes() -> Option { let status = std::fs::read_to_string("/proc/self/status").ok()?; let line = status.lines().find(|l| l.starts_with("VmHWM:"))?; @@ -12,9 +11,30 @@ fn peak_rss_bytes() -> Option { Some(kib * 1024) } -#[cfg(target_os = "linux")] #[test] fn pnm_decode_peak_memory_stays_near_the_output_size() { + const CHILD: &str = "CRAFT_IMAGE_CODECS_PNM_RSS_CHILD"; + const DONE: &str = "PNM RSS probe completed"; + if std::env::var_os(CHILD).is_some() { + measure_peak_memory(); + println!("{DONE}"); + return; + } + + // Cargo can run other tests concurrently in this harness. Start a fresh process + // with only this test selected so its allocations are the only ones being measured. + let output = std::process::Command::new(std::env::current_exe().expect("image codec test executable")) + .args(["--exact", "pnm_peak_memory::pnm_decode_peak_memory_stays_near_the_output_size", "--nocapture", "--test-threads=1"]) + .env(CHILD, "1") + .output() + .expect("start isolated PNM RSS probe"); + let stdout = String::from_utf8_lossy(&output.stdout); + let stderr = String::from_utf8_lossy(&output.stderr); + // A stale filter can select zero tests and exit successfully. + assert!(output.status.success() && stdout.lines().any(|line| line.ends_with(DONE)), "{stdout}\n{stderr}"); +} + +fn measure_peak_memory() { use craft_image_codecs::*; const SIDE: u32 = 4096; // 16 MiB of 8-bit gray output diff --git a/crates/metadata/tests/ifd0_orientation_compat.rs b/crates/metadata/tests/it/ifd0_orientation_compat.rs similarity index 100% rename from crates/metadata/tests/ifd0_orientation_compat.rs rename to crates/metadata/tests/it/ifd0_orientation_compat.rs diff --git a/crates/metadata/tests/it/main.rs b/crates/metadata/tests/it/main.rs index 4e460020c..8a2291727 100644 --- a/crates/metadata/tests/it/main.rs +++ b/crates/metadata/tests/it/main.rs @@ -5,3 +5,5 @@ mod edit_orientation; mod edit_pixel_size; mod edit_resolution; mod robust; + +mod ifd0_orientation_compat; diff --git a/crates/psd/tests/atn_sidecar.rs b/crates/psd/tests/it/atn_sidecar.rs similarity index 100% rename from crates/psd/tests/atn_sidecar.rs rename to crates/psd/tests/it/atn_sidecar.rs diff --git a/crates/psd/tests/csh.rs b/crates/psd/tests/it/csh.rs similarity index 100% rename from crates/psd/tests/csh.rs rename to crates/psd/tests/it/csh.rs diff --git a/crates/psd/tests/it/main.rs b/crates/psd/tests/it/main.rs index 3bb60a8d9..4e78641e6 100644 --- a/crates/psd/tests/it/main.rs +++ b/crates/psd/tests/it/main.rs @@ -32,3 +32,8 @@ fn tests_build_with_the_test_support_feature() { assert_eq!(file.header.version, craft_psd::Version::Psd); let _sample: fn(u32, u32, u32, bool) -> u8 = craft_psd::fixtures::sample; } + +mod atn_sidecar; +mod csh; +mod metadata_resources; +mod resource_limits; diff --git a/crates/psd/tests/metadata_resources.rs b/crates/psd/tests/it/metadata_resources.rs similarity index 100% rename from crates/psd/tests/metadata_resources.rs rename to crates/psd/tests/it/metadata_resources.rs diff --git a/crates/psd/tests/resource_limits.rs b/crates/psd/tests/it/resource_limits.rs similarity index 100% rename from crates/psd/tests/resource_limits.rs rename to crates/psd/tests/it/resource_limits.rs