Consolidate related image tests

This commit is contained in:
FredApps
2026-11-19 13:05:37 +01:00
parent c4c3f08490
commit dfe722af62
12 changed files with 36 additions and 3 deletions
+6
View File
@@ -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;
@@ -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<u64> {
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<u64> {
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
+2
View File
@@ -5,3 +5,5 @@ mod edit_orientation;
mod edit_pixel_size;
mod edit_resolution;
mod robust;
mod ifd0_orientation_compat;
+5
View File
@@ -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;