forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

gpu.rs638 lines, 23.5 KiBHistoryRawDownload
1//! Live GPU tests. Not `#[ignore]`d: this machine has the hardware, and a test
2//! that never runs is not a test. On a machine with no VA-API device every one
3//! of these fails at `Display::open`, which is the honest outcome — the crate
4//! has no meaning without a driver.
5//!
6//! Everything lives in one test binary on purpose (a file per feature is a
7//! serial link-and-run tax). Every test opens its own display and takes
8//! [`serial`], so the two process-wide measurements below stay meaningful.
9//!
10//! Reference: `vainfo` on this box (Mesa 26.1.6, radeonsi gfx1200, RX 9060 XT).
11
12use std::os::fd::AsRawFd;
13use std::rc::Rc;
14use std::sync::{Mutex, MutexGuard, OnceLock};
15use std::time::Duration;
16
17use ec_va::caps::{Entrypoint, Profile};
18use ec_va::va;
19use ec_va::{CapReport, Config, Display, Image, Surface, SurfaceExt, SurfaceSpec, create_pool};
20
21/// Runs the tests in this binary one at a time.
22///
23/// Two of them measure process-wide state — `VmRSS` for the surface-pool leak
24/// check and `/proc/self/fd` for the PRIME export ownership check — and a
25/// sibling test allocating a 1080p pool on another thread would make both
26/// meaningless. Serialising is cheaper and more honest than loosening the
27/// thresholds until concurrency stops mattering.
28fn serial() -> MutexGuard<'static, ()> {
29 static LOCK: OnceLock<Mutex<()>> = OnceLock::new();
30 LOCK.get_or_init(|| Mutex::new(()))
31 .lock()
32 // A panicking test poisons the mutex; the rest are still worth running.
33 .unwrap_or_else(|poisoned| poisoned.into_inner())
34}
35
36fn display() -> Rc<Display> {
37 ec_va::open().expect("no VA-API display; this test needs the GPU")
38}
39
40/// The driver's `VAImageFormat` for `fourcc`.
41fn image_format(display: &Display, fourcc: u32) -> va::VAImageFormat {
42 display
43 .query_image_formats()
44 .expect("vaQueryImageFormats")
45 .into_iter()
46 .find(|f| f.fourcc == fourcc)
47 .expect("driver lacks the image format")
48}
49
50fn pool(display: &Rc<Display>, spec: &SurfaceSpec, n: usize) -> Vec<Surface> {
51 create_pool(display, spec, n).expect("pool")
52}
53
54fn one(display: &Rc<Display>, spec: &SurfaceSpec) -> Surface {
55 pool(display, spec, 1).pop().expect("surface")
56}
57
58// --------------------------------------------------------------------------
59// Display
60// --------------------------------------------------------------------------
61
62// The raw `Display::version` / `device_path` / `is_valid` checks no longer
63// exist in cros-libva; what remains observable is that the open succeeded and
64// the driver answers real queries.
65#[test]
66fn display_opens_on_a_render_node() {
67 let _serial = serial();
68 let display = display();
69 let vendor = ec_va::display::vendor(&display).expect("vendor string");
70 assert!(!vendor.is_empty(), "driver reported an empty vendor string");
71 assert!(
72 !display
73 .query_config_profiles()
74 .expect("profiles")
75 .is_empty()
76 );
77}
78
79// --------------------------------------------------------------------------
80// Capabilities — the table must match `vainfo` on this GPU
81// --------------------------------------------------------------------------
82
83#[test]
84fn caps_match_vainfo_on_this_gpu() {
85 let _serial = serial();
86 let display = display();
87 let caps = CapReport::probe(&display).expect("probe");
88
89 // Decode: every codec the family hands to hardware.
90 for profile in [
91 Profile::H264ConstrainedBaseline,
92 Profile::H264Main,
93 Profile::H264High,
94 Profile::HEVCMain,
95 Profile::HEVCMain10,
96 Profile::VP9Profile0,
97 Profile::VP9Profile2,
98 Profile::AV1Profile0,
99 Profile::AV1Profile2,
100 ] {
101 assert!(
102 caps.supports(profile, Entrypoint::VLD),
103 "{} VLD missing from the probe but present in vainfo",
104 profile.name()
105 );
106 }
107
108 // Encode: H.264 and HEVC are the two the family ships (AV1 encode exists on
109 // this GPU too, but stays opt-in — see the family plan).
110 for profile in [
111 Profile::H264ConstrainedBaseline,
112 Profile::H264Main,
113 Profile::H264High,
114 Profile::HEVCMain,
115 Profile::HEVCMain10,
116 ] {
117 assert!(
118 caps.supports(profile, Entrypoint::EncSlice),
119 "{} EncSlice missing from the probe but present in vainfo",
120 profile.name()
121 );
122 }
123
124 // Post-processing, used later for colour conversion.
125 assert!(caps.supports(Profile::None, Entrypoint::VideoProc));
126
127 // A pair this GPU genuinely lacks must be absent, not silently invented:
128 // vainfo lists VP9 profiles 0 and 2 only.
129 assert!(!caps.supports(Profile::VP9Profile1, Entrypoint::VLD));
130 assert!(!caps.supports(Profile::VP9Profile3, Entrypoint::VLD));
131 assert!(!caps.supports(Profile::VP9Profile0, Entrypoint::EncSlice));
132
133 // 10-bit decode must advertise a 10-bit RT format, or `ec-hw` would derive
134 // an 8-bit context for Main10 — the incumbent's D2 defect.
135 let main10 = caps
136 .entry(Profile::HEVCMain10, Entrypoint::VLD)
137 .expect("HEVC Main10 VLD");
138 assert!(
139 main10.supports_rt_format(va::VA_RT_FORMAT_YUV420_10),
140 "HEVC Main10 VLD advertised rt_formats 0x{:08x} without a 10-bit format",
141 main10.rt_formats
142 );
143 let p010_supported = main10
144 .surfaces
145 .as_ref()
146 .expect("surface caps")
147 .supports_fourcc(va::VA_FOURCC_P010);
148 assert!(p010_supported, "Main10 cannot allocate P010 surfaces");
149
150 // 8-bit decode: NV12 everywhere.
151 let h264 = caps
152 .entry(Profile::H264Main, Entrypoint::VLD)
153 .expect("H264 Main VLD");
154 assert!(h264.supports_rt_format(va::VA_RT_FORMAT_YUV420));
155 assert!(
156 h264.surfaces
157 .as_ref()
158 .expect("surface caps")
159 .supports_fourcc(va::VA_FOURCC_NV12)
160 );
161
162 // Readback formats: `vaGetImage` must be able to produce NV12 and P010.
163 assert!(caps.image_formats.contains(&va::VA_FOURCC_NV12));
164 assert!(caps.image_formats.contains(&va::VA_FOURCC_P010));
165
166 assert!(
167 caps.profiles_for(Entrypoint::VLD).len() >= 9,
168 "expected at least 9 decode profiles, got {:?}",
169 caps.profiles_for(Entrypoint::VLD)
170 );
171}
172
173#[test]
174fn caps_report_driver_legal_surface_sizes() {
175 let _serial = serial();
176 let display = display();
177 let caps = CapReport::probe(&display).expect("probe");
178 let entry = caps
179 .entry(Profile::H264Main, Entrypoint::VLD)
180 .expect("H264 Main VLD");
181 let surfaces = entry.surfaces.as_ref().expect("surface caps");
182
183 // radeonsi rejects decode surfaces below 64x64. Probing with a hardcoded
184 // 16x16 config is what used to panic here, so the minimum is reported
185 // rather than assumed.
186 assert_eq!(surfaces.min_width, Some(64));
187 assert_eq!(surfaces.min_height, Some(64));
188 assert!(surfaces.max_width.unwrap() >= 4096);
189 assert!(
190 !surfaces.allows(16, 16),
191 "16x16 must be refused by the caps"
192 );
193 assert!(surfaces.allows(1920, 1088));
194
195 // DRM PRIME 2 export must be advertised: that is how frames leave the GPU.
196 assert!(
197 surfaces.memory_types & va::VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2 != 0,
198 "memory types 0x{:08x} lack DRM_PRIME_2",
199 surfaces.memory_types
200 );
201}
202
203#[test]
204fn unsupported_pair_is_refused_by_the_driver() {
205 let _serial = serial();
206 // A refusal is a claim: prove the capability is genuinely absent rather
207 // than assumed absent.
208 let display = display();
209 let caps = CapReport::probe(&display).expect("probe");
210 assert!(!caps.supports(Profile::VP9Profile1, Entrypoint::VLD));
211
212 let err = Config::new(&display, Profile::VP9Profile1, Entrypoint::VLD, &[])
213 .err()
214 .expect("VP9 Profile1 decode does not exist on this GPU");
215 let status = err.status().expect("a VAStatus-carrying error");
216 assert!(
217 status == va::VA_STATUS_ERROR_UNSUPPORTED_PROFILE as i32
218 || status == va::VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT as i32,
219 "unexpected refusal: {err}"
220 );
221 assert!(err.to_string().contains("vaCreateConfig"), "{err}");
222}
223
224// --------------------------------------------------------------------------
225// Surfaces
226// --------------------------------------------------------------------------
227
228#[test]
229fn surface_pool_create_and_destroy_is_leak_free() {
230 let _serial = serial();
231 let display = display();
232 let spec = SurfaceSpec::nv12(64, 64);
233
234 // Warm up so first-touch allocations are not counted as a leak.
235 for _ in 0..4 {
236 let p = pool(&display, &spec, 16);
237 assert_eq!(p.len(), 16);
238 drop(p);
239 }
240
241 let before = vm_rss_kb();
242 for _ in 0..100 {
243 let p = pool(&display, &spec, 16);
244 // Every id must be distinct and valid, or the pool is aliasing memory.
245 let mut ids: Vec<_> = p.iter().map(|s| s.id()).collect();
246 ids.sort_unstable();
247 ids.dedup();
248 assert_eq!(ids.len(), 16, "vaCreateSurfaces returned duplicate ids");
249 assert!(ids.iter().all(|&id| id != va::VA_INVALID_SURFACE));
250 drop(p);
251 }
252 let after = vm_rss_kb();
253
254 // 1600 surfaces created and destroyed. A per-surface leak would be obvious
255 // at this scale; the incumbent's unmatched map leaked ~3MB per frame.
256 let delta_kb = after.saturating_sub(before);
257 assert!(
258 delta_kb < 50 * 1024,
259 "VmRSS grew {delta_kb} kB over 100 create/destroy cycles"
260 );
261}
262
263#[test]
264fn derive_image_maps_and_reads_back() {
265 let _serial = serial();
266 let display = display();
267 let surface = one(&display, &SurfaceSpec::nv12(64, 64));
268 let mut image = Image::derive_from(&surface, (64, 64)).expect("vaDeriveImage");
269
270 let va_image = *image.image();
271 assert_eq!(va_image.format.fourcc, va::VA_FOURCC_NV12);
272 assert_eq!(image.display_resolution(), (64, 64));
273 assert!(image.is_derived());
274 assert_eq!(va_image.num_planes, 2, "NV12 is luma + interleaved chroma");
275 let pitch = va_image.pitches[0] as usize;
276 assert!(pitch >= 64, "luma pitch {pitch} is narrower than the image");
277 assert!(va_image.pitches[1] > 0, "chroma pitch missing");
278 let luma_off = va_image.offsets[0] as usize;
279 let chroma_off = va_image.offsets[1] as usize;
280 assert!(
281 chroma_off >= luma_off + pitch * 64,
282 "luma plane must be at least pitch * height"
283 );
284
285 {
286 let bytes: &mut [u8] = image.as_mut();
287 assert!(
288 bytes.len() > chroma_off,
289 "mapping shorter than chroma plane"
290 );
291 for (i, byte) in bytes[luma_off..luma_off + pitch * 64]
292 .iter_mut()
293 .enumerate()
294 {
295 *byte = (i % 251) as u8;
296 }
297 let luma = &bytes[luma_off..];
298 assert_eq!(luma[0], 0);
299 assert_eq!(luma[250], 250);
300 assert_eq!(luma[251], 0, "write did not survive within the mapping");
301 }
302 drop(image);
303
304 // Re-deriving after the drop proves the unmap/destroy actually happened.
305 //
306 // What is deliberately *not* asserted: that the bytes written above are
307 // readable through this second mapping. On radeonsi 26.1 a derived-image
308 // mapping is write-oriented staging — the write reaches the surface (see
309 // `created_image_reads_a_surface_back`), but a fresh map reads back zeros.
310 let again = Image::derive_from(&surface, (64, 64)).expect("second vaDeriveImage");
311 assert_eq!(
312 again.image().pitches[0] as usize,
313 pitch,
314 "second mapping has a different geometry"
315 );
316 assert!(!AsRef::<[u8]>::as_ref(&again).is_empty());
317}
318
319#[test]
320fn created_image_reads_a_surface_back() {
321 let _serial = serial();
322 let display = display();
323 let surface = one(&display, &SurfaceSpec::nv12(64, 64));
324 // Paint through the derived image so there is something known to read back.
325 {
326 let mut derived = Image::derive_from(&surface, (64, 64)).expect("derive");
327 let luma_off = derived.image().offsets[0] as usize;
328 let pitch = derived.image().pitches[0] as usize;
329 let bytes: &mut [u8] = derived.as_mut();
330 for byte in &mut bytes[luma_off..luma_off + pitch * 64] {
331 *byte = 0x5a;
332 }
333 }
334 surface.sync().expect("sync");
335
336 let fmt = image_format(&display, va::VA_FOURCC_NV12);
337 let image = Image::create_from(&surface, fmt, (64, 64), (64, 64)).expect("vaGetImage");
338 let luma_off = image.image().offsets[0] as usize;
339 let bytes: &[u8] = image.as_ref();
340 assert!(
341 bytes[luma_off..luma_off + 64].iter().all(|&b| b == 0x5a),
342 "vaGetImage did not return the painted luma"
343 );
344 drop(image);
345
346 // A region larger than the surface must be refused, not read out of bounds.
347 let fmt = image_format(&display, va::VA_FOURCC_NV12);
348 let refused = Image::create_from(&surface, fmt, (128, 128), (128, 128));
349 assert!(
350 refused.is_err(),
351 "region larger than the surface must be refused"
352 );
353}
354
355#[test]
356fn prime_export_owns_and_releases_its_descriptors() {
357 let _serial = serial();
358 let display = display();
359 let surface = one(&display, &SurfaceSpec::nv12(64, 64));
360 surface
361 .sync_timeout(Duration::from_secs(5))
362 .expect("sync before export");
363
364 let baseline = open_fd_count();
365 let exported = surface.export().expect("vaExportSurfaceHandle");
366
367 assert_eq!(exported.fourcc, va::VA_FOURCC_NV12);
368 assert_eq!((exported.width, exported.height), (64, 64));
369 assert!(!exported.objects.is_empty(), "no DRM objects exported");
370 assert!(!exported.layers.is_empty(), "no layers exported");
371 for object in &exported.objects {
372 assert!(object.fd.as_raw_fd() >= 0);
373 assert!(object.size > 0);
374 }
375 for layer in &exported.layers {
376 assert!(!layer.planes.is_empty());
377 for &(object_index, _offset, pitch) in &layer.planes {
378 assert!((object_index as usize) < exported.objects.len());
379 assert!(pitch > 0);
380 }
381 }
382
383 let with_export = open_fd_count();
384 assert_eq!(
385 with_export - baseline,
386 exported.objects.len(),
387 "exported fd count does not match the descriptor"
388 );
389 drop(exported);
390 assert_eq!(
391 open_fd_count(),
392 baseline,
393 "dropping the export leaked file descriptors"
394 );
395}
396
397// --------------------------------------------------------------------------
398// Context / picture protocol
399// --------------------------------------------------------------------------
400
401#[test]
402fn picture_typestate_walks_the_va_protocol() {
403 let _serial = serial();
404 let display = display();
405 let config = Config::new(&display, Profile::H264Main, Entrypoint::VLD, &[]).expect("config");
406 let targets = pool(&display, &SurfaceSpec::nv12(1920, 1088), 2);
407 let context = ec_va::create_context(&display, &config, 1920, 1088, Some(&targets), true)
408 .expect("context");
409 let targets: Vec<Rc<Surface>> = targets.into_iter().map(Rc::new).collect();
410
411 // New -> Begin. Each transition consumes the picture, so nothing can call
412 // `begin` twice or reach `sync` without `end`.
413 let picture = ec_va::Picture::new(0, Rc::clone(&context), Rc::clone(&targets[0]));
414 let picture = picture.begin::<()>().expect("vaBeginPicture");
415 assert_eq!(picture.surface::<()>().id(), targets[0].id());
416
417 // Begin -> Render -> End. Submitting a picture with no parameter buffers
418 // is a driver-level error here (mesa creates the decoder lazily from the
419 // picture parameters); what matters is that it surfaces as a typed error
420 // instead of a panic, an abort or a GPU hang. Real submissions carry
421 // parameter/slice buffers and are `ec-hw`'s job.
422 let failed = picture.render().and_then(|p| p.end());
423 let err = failed
424 .err()
425 .expect("empty submission is rejected by radeonsi");
426 assert_eq!(
427 err.va_status(),
428 va::VA_STATUS_ERROR_INVALID_CONTEXT as i32,
429 "{err}"
430 );
431
432 // The display is still usable afterwards: an abandoned picture must not
433 // wedge the context.
434 let picture = ec_va::Picture::new(0, Rc::clone(&context), Rc::clone(&targets[1]))
435 .begin::<()>()
436 .expect("second vaBeginPicture after a failed end");
437 drop(picture);
438 assert!(display.query_vendor_string().is_ok());
439}
440
441#[test]
442fn buffers_map_unmap_and_destroy() {
443 let _serial = serial();
444 let display = display();
445 let config =
446 Config::new(&display, Profile::H264Main, Entrypoint::EncSlice, &[]).expect("config");
447 let targets = pool(&display, &SurfaceSpec::nv12(1920, 1088), 1);
448 let context = ec_va::create_context(&display, &config, 1920, 1088, Some(&targets), true)
449 .expect("context");
450
451 // Coded-output buffer: allocated empty, mapped, unmapped, dropped.
452 const CODED_SIZE: usize = 1 << 20;
453 let coded = context
454 .create_enc_coded(CODED_SIZE)
455 .expect("vaCreateBuffer");
456 assert_ne!(coded.id(), va::VA_INVALID_ID);
457 {
458 let mapped = va::MappedCodedBuffer::new(&coded).expect("vaMapBuffer");
459 // Never filled by an encode: no segment carries payload bytes.
460 assert!(mapped.iter().all(|s| s.buf.is_empty()));
461 }
462 // Mapping again proves the guard released the mapping.
463 drop(va::MappedCodedBuffer::new(&coded).expect("second vaMapBuffer after unmap"));
464
465 // Parameter buffer: data is copied into driver memory during the call.
466 let buffer = ec_va::picture::buffer(
467 &context,
468 va::BufferType::EncMiscParameter(va::EncMiscParameter::FrameRate(
469 va::EncMiscParameterFrameRate::new(30, 0),
470 )),
471 )
472 .expect("vaCreateBuffer from a typed parameter");
473 drop(buffer);
474 drop(coded);
475}
476
477#[test]
478fn context_keeps_its_dependencies_alive() {
479 let _serial = serial();
480 // Dropping the config and the surfaces while the context lives must be
481 // safe: the context holds `Rc`s, so libva's destruction order (buffers ->
482 // context -> surfaces -> config -> display) cannot be violated.
483 let display = display();
484 let config = Config::new(&display, Profile::H264Main, Entrypoint::VLD, &[]).expect("config");
485 let targets = pool(&display, &SurfaceSpec::nv12(1920, 1088), 2);
486 let context = ec_va::create_context(&display, &config, 1920, 1088, Some(&targets), true)
487 .expect("context");
488 let target = Rc::new(targets.into_iter().next().expect("target"));
489 drop(config);
490
491 let picture = ec_va::Picture::new(0, Rc::clone(&context), target)
492 .begin::<()>()
493 .expect("begin");
494 drop(picture);
495 drop(context);
496 assert!(display.query_vendor_string().is_ok());
497}
498
499// --------------------------------------------------------------------------
500// VPP
501// --------------------------------------------------------------------------
502
503// `vaQueryVideoProcFilters` is no longer wrapped (cros-libva has no such
504// call), so the filter list cannot be printed. The equivalent: a pipeline
505// still opens on the real display and runs a whole-surface NV12 pass.
506#[test]
507fn vpp_filters_probe() {
508 let _serial = serial();
509 let display = display();
510 let targets = pool(&display, &SurfaceSpec::nv12(1920, 1080), 2);
511 let vpp = ec_va::Vpp::new(&display, va::VA_RT_FORMAT_YUV420, 1920, 1080).expect("vpp opens");
512 let mut it = targets.into_iter();
513 let src = it.next().expect("src");
514 let dst = Rc::new(it.next().expect("dst"));
515 vpp.convert(&src, dst).expect("vpp pipeline runs");
516}
517
518/// `Vpp::convert` end to end: a P010 source surface into an NV12 destination,
519/// no readback — the conversion `ec-hw`'s `encode_frame` relies on for a
520/// 10-bit source.
521#[test]
522fn vpp_converts_p010_to_nv12() {
523 let _serial = serial();
524 let display = display();
525 let source = one(&display, &SurfaceSpec::p010(64, 64));
526 let dest = Rc::new(one(&display, &SurfaceSpec::nv12(64, 64)));
527 let vpp = ec_va::Vpp::new(
528 &display,
529 va::VA_RT_FORMAT_YUV420 | va::VA_RT_FORMAT_YUV420_10,
530 64,
531 64,
532 )
533 .expect("vpp opens");
534 let out = vpp.convert(&source, Rc::clone(&dest)).expect("convert");
535 assert_eq!(out.id(), dest.id());
536}
537
538// --------------------------------------------------------------------------
539// helpers
540// --------------------------------------------------------------------------
541
542fn vm_rss_kb() -> u64 {
543 let status = std::fs::read_to_string("/proc/self/status").expect("/proc/self/status");
544 for line in status.lines() {
545 if let Some(rest) = line.strip_prefix("VmRSS:") {
546 return rest
547 .split_whitespace()
548 .next()
549 .and_then(|v| v.parse().ok())
550 .expect("VmRSS value");
551 }
552 }
553 panic!("VmRSS not found in /proc/self/status");
554}
555
556fn open_fd_count() -> usize {
557 std::fs::read_dir("/proc/self/fd")
558 .expect("/proc/self/fd")
559 .count()
560}
561
562/// Export a painted NV12 surface as DMA-BUFs, import the fds as a new surface,
563/// and read both back: the two must be byte-identical plane for plane. The
564/// import also has to leave no fds behind once it is dropped.
565#[test]
566fn dma_buf_import_reads_back_identical_pixels() {
567 let _serial = serial();
568 let display = display();
569 let (width, height) = (256u32, 192u32);
570 let surface = one(&display, &SurfaceSpec::nv12(width, height));
571 let fmt = image_format(&display, va::VA_FOURCC_NV12);
572
573 // A pattern that varies by row and column, so a shifted or swapped plane
574 // cannot read back equal by accident. The image is written back to the
575 // surface (vaPutImage) when it drops.
576 {
577 let mut source =
578 Image::create_from(&surface, fmt, (width, height), (width, height)).expect("image");
579 let va_image = *source.image();
580 let bytes: &mut [u8] = source.as_mut();
581 for plane in 0..2usize {
582 let pitch = va_image.pitches[plane] as usize;
583 let off = va_image.offsets[plane] as usize;
584 let rows = if plane == 0 { height } else { height / 2 } as usize;
585 for row in 0..rows {
586 for col in 0..pitch {
587 bytes[off + row * pitch + col] = (row * 7 + col * 3 + plane * 101) as u8;
588 }
589 }
590 }
591 }
592 surface.sync().expect("sync");
593
594 let baseline = open_fd_count();
595 let exported = surface.export().expect("export");
596 let imported =
597 ec_va::surface::import_prime(&display, &exported).expect("import the exported fds");
598 imported.sync().expect("sync the import");
599
600 let from_original =
601 Image::create_from(&surface, fmt, (width, height), (width, height)).expect("read original");
602 let from_import = Image::create_from(&imported, fmt, (width, height), (width, height))
603 .expect("read imported");
604
605 let (io, ic) = (*from_original.image(), *from_import.image());
606 let (original, copy): (&[u8], &[u8]) = (from_original.as_ref(), from_import.as_ref());
607 for plane in 0..2usize {
608 let rows = if plane == 0 { height } else { height / 2 } as usize;
609 let (po, pc) = (io.pitches[plane] as usize, ic.pitches[plane] as usize);
610 let (oo, oc) = (io.offsets[plane] as usize, ic.offsets[plane] as usize);
611 assert_eq!(po, pc, "plane {plane}: pitches differ");
612 let want = &original[oo..oo + po * rows];
613 let got = &copy[oc..oc + pc * rows];
614 assert!(
615 want.iter().any(|&b| b != 0),
616 "plane {plane}: the source read back empty, so the comparison proves nothing"
617 );
618 assert_eq!(
619 want, got,
620 "plane {plane}: the import reads back different pixels"
621 );
622 }
623 drop(from_original);
624 drop(from_import);
625
626 // The export owns its fds: they close with the descriptor, not before.
627 assert!(
628 open_fd_count() >= baseline,
629 "the import closed its fds early"
630 );
631 drop(imported);
632 drop(exported);
633 assert_eq!(
634 open_fd_count(),
635 baseline,
636 "dropping the import and the export leaked file descriptors"
637 );
638}