The seat a test cycles is one no other test is sitting in
Browse files at this commit88ce23e611e1737e09c317bd940fcb1da36a9346Parent: 3e11643- fix
- the seat a test cycles is one no other test is sitting in
4 changed files +134 -52
- crates/engine-hw/src/lib.rs +7 -5
- crates/engine/src/export.rs +1 -8
- crates/engine/src/hwproc.rs +22 -9
- crates/engine/tests/export.rs +104 -30
crates/engine-hw/src/lib.rsmodified+7 -5
| @@ -10,11 +10,13 @@ | |||
| 10 | //! reach whatever the panic strategy is: Mesa runs its own C worker threads and | 10 | //! reach whatever the panic strategy is: Mesa runs its own C worker threads and |
| 11 | //! calls libc `abort()` from them when the video ring resets (measured | 11 | //! calls libc `abort()` from them when the video ring resets (measured |
| 12 | //! 2026-08-13, `vcn_unified_0`, mesa 26.1.6). No `catch_unwind` can see a | 12 | //! 2026-08-13, `vcn_unified_0`, mesa 26.1.6). No `catch_unwind` can see a |
| 13 | -//! foreign thread's `abort`. So the *encode* half of this plugin is no longer | 13 | +//! foreign thread's `abort`. So no *encode* entry point of this plugin is |
| 14 | -//! loaded by the editor at all: it is `dlopen`ed by the `hw-encode-child` | 14 | +//! called in the editor's process any more: the editor still `dlopen`s the |
| 15 | -//! helper, one process per session, and a driver that aborts now costs an export | 15 | +//! library to see whether the `vh_enc_*` symbols are there at all, which opens |
| 16 | -//! its seat rather than costing a person their session | 16 | +//! no VA-API display and starts no driver thread, and every call through them is |
| 17 | -//! ([`engine::hwproc`](../engine/hwproc/index.html)). | 17 | +//! made by the `hw-encode-child` helper, one process per session. A driver that |
| 18 | +//! aborts now costs an export its seat rather than costing a person their | ||
| 19 | +//! session ([`engine::hwproc`](../engine/hwproc/index.html)). | ||
| 18 | //! | 20 | //! |
| 19 | //! corner-cut: *decode* is still in the editor's own address space, where the | 21 | //! corner-cut: *decode* is still in the editor's own address space, where the |
| 20 | //! same abort would still be fatal -- and the same ring hangs it (mmhub page | 22 | //! same abort would still be fatal -- and the same ring hangs it (mmhub page |
crates/engine/src/export.rsmodified+1 -8
| @@ -609,14 +609,7 @@ fn audio_kbps_of(settings: &ExportSettings) -> u32 { | |||
| 609 | /// ([`Enc::open`] runs ahead of the muxer), which is what makes the refusal | 609 | /// ([`Enc::open`] runs ahead of the muxer), which is what makes the refusal |
| 610 | /// free. | 610 | /// free. |
| 611 | fn hw_seat(meta: &VideoMeta, settings: &ExportSettings) -> crate::Result<Option<HwEncoder>> { | 611 | fn hw_seat(meta: &VideoMeta, settings: &ExportSettings) -> crate::Result<Option<HwEncoder>> { |
| 612 | - // `VE_HW_TEST_FAKE` is the containment tests' stand-in seat -- a child that | 612 | + if settings.seat == EncoderSeat::Software || forced("VE_SW_ENC") { |
| 613 | - // opens no driver at all -- and it is not what a software pin is pinning | ||
| 614 | - // away: the pin says "do not use this machine's GPU", and that seat is not | ||
| 615 | - // this machine's GPU. Without this the suite could only prove the fallback | ||
| 616 | - // on a run with no other export test in it. | ||
| 617 | - if settings.seat == EncoderSeat::Software | ||
| 618 | - || (forced("VE_SW_ENC") && !crate::hwproc::faked()) | ||
| 619 | - { | ||
| 620 | return Ok(None); | 613 | return Ok(None); |
| 621 | } | 614 | } |
| 622 | let opened = open_hw_seat(meta, settings); | 615 | let opened = open_hw_seat(meta, settings); |
crates/engine/src/hwproc.rsmodified+22 -9
| @@ -462,18 +462,31 @@ impl Remote { | |||
| 462 | 462 | ||
| 463 | /// What the child's encoder codes in, or `None` where it has no zero-copy | 463 | /// What the child's encoder codes in, or `None` where it has no zero-copy |
| 464 | /// door. | 464 | /// door. |
| 465 | + /// | ||
| 466 | + /// The two `None`s are not the same thing and only one of them is an | ||
| 467 | + /// answer. A child that *says* it has no door costs the caller a read-back | ||
| 468 | + /// and nothing else; a child that does not answer at all is gone, and is | ||
| 469 | + /// reaped right here -- otherwise the next picture would spend a whole | ||
| 470 | + /// second timeout discovering what this call already knows. | ||
| 465 | pub fn dma_geometry(&mut self) -> Option<(u32, u32)> { | 471 | pub fn dma_geometry(&mut self) -> Option<(u32, u32)> { |
| 466 | self.request(&[T_GEOM], &[]).ok()?; | 472 | self.request(&[T_GEOM], &[]).ok()?; |
| 467 | - let (tag, _) = recv_tag(&self.sock).ok()?; | ||
| 468 | - if tag != R_AU { | ||
| 469 | - return None; | ||
| 470 | - } | ||
| 471 | let mut buf = [0u8; 8]; | 473 | let mut buf = [0u8; 8]; |
| 472 | - self.sock.read_exact(&mut buf).ok()?; | 474 | + let answered = match recv_tag(&self.sock) { |
| 473 | - Some(( | 475 | + Ok((R_AU, _)) => self.sock.read_exact(&mut buf).map(|()| true), |
| 474 | - u32::from_le_bytes(buf[..4].try_into().ok()?), | 476 | + Ok(_) => Ok(false), |
| 475 | - u32::from_le_bytes(buf[4..].try_into().ok()?), | 477 | + Err(e) => Err(e), |
| 476 | - )) | 478 | + }; |
| 479 | + match answered { | ||
| 480 | + Ok(true) => Some(( | ||
| 481 | + u32::from_le_bytes(buf[..4].try_into().ok()?), | ||
| 482 | + u32::from_le_bytes(buf[4..].try_into().ok()?), | ||
| 483 | + )), | ||
| 484 | + Ok(false) => None, | ||
| 485 | + Err(e) => { | ||
| 486 | + self.bury(&e.to_string()); | ||
| 487 | + None | ||
| 488 | + } | ||
| 489 | + } | ||
| 477 | } | 490 | } |
| 478 | 491 | ||
| 479 | /// Feeds one packed I420 picture through the shared mapping. | 492 | /// Feeds one packed I420 picture through the shared mapping. |
crates/engine/tests/export.rsmodified+104 -30
| @@ -53,23 +53,48 @@ fn part_path(out: &Path) -> PathBuf { | |||
| 53 | PathBuf::from(format!("{}.part", out.display())) | 53 | PathBuf::from(format!("{}.part", out.display())) |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | +/// Which seat an export takes is decided by *process-wide* environment | ||
| 57 | +/// variables, so it is a shared resource and every test in this binary borrows | ||
| 58 | +/// it rather than assuming it. | ||
| 59 | +/// | ||
| 60 | +/// Readers share: the whole software suite wants the same pin and may run at | ||
| 61 | +/// once, exactly as it always did. A test that has to *change* the pin -- | ||
| 62 | +/// there is one family, the encoder-death ones at the end of this file -- takes | ||
| 63 | +/// it exclusively, so no export is ever in flight while the seat is being | ||
| 64 | +/// cycled underneath it. A borrow held only for the seat's opening would not do: | ||
| 65 | +/// [`engine::export::start`] falls back and re-opens mid-run, so the pin has to | ||
| 66 | +/// hold for the whole export. | ||
| 67 | +static SEAT: std::sync::RwLock<()> = std::sync::RwLock::new(()); | ||
| 68 | + | ||
| 69 | +type Shared = std::sync::RwLockReadGuard<'static, ()>; | ||
| 70 | + | ||
| 56 | /// Pins both paths to software for the whole test binary, so the default suite | 71 | /// Pins both paths to software for the whole test binary, so the default suite |
| 57 | -/// proves the fallback that every machine has. | 72 | +/// proves the fallback that every machine has. Bind the guard: it is the borrow |
| 58 | -fn pin_software() { | 73 | +/// above, and dropping it early puts the export back in the race this exists to |
| 74 | +/// end. | ||
| 75 | +#[must_use = "the seat pin holds only while its guard is alive"] | ||
| 76 | +fn pin_software() -> Shared { | ||
| 77 | + let borrowed = SEAT.read().unwrap_or_else(|poisoned| poisoned.into_inner()); | ||
| 59 | static PIN: Once = Once::new(); | 78 | static PIN: Once = Once::new(); |
| 60 | PIN.call_once(|| unsafe { | 79 | PIN.call_once(|| unsafe { |
| 61 | std::env::set_var("VE_SW", "1"); | 80 | std::env::set_var("VE_SW", "1"); |
| 62 | std::env::set_var("VE_SW_ENC", "1"); | 81 | std::env::set_var("VE_SW_ENC", "1"); |
| 63 | }); | 82 | }); |
| 83 | + borrowed | ||
| 64 | } | 84 | } |
| 65 | 85 | ||
| 66 | -/// Removes both pins, for the hardware twins. | 86 | +/// Removes both pins, for the hardware twins -- which run in their own |
| 67 | -fn pin_hardware() { | 87 | +/// `--ignored --test-threads=1` pass, so they never share this binary with the |
| 88 | +/// software ones. | ||
| 89 | +#[must_use = "the seat pin holds only while its guard is alive"] | ||
| 90 | +fn pin_hardware() -> Shared { | ||
| 91 | + let borrowed = SEAT.read().unwrap_or_else(|poisoned| poisoned.into_inner()); | ||
| 68 | static PIN: Once = Once::new(); | 92 | static PIN: Once = Once::new(); |
| 69 | PIN.call_once(|| unsafe { | 93 | PIN.call_once(|| unsafe { |
| 70 | std::env::remove_var("VE_SW"); | 94 | std::env::remove_var("VE_SW"); |
| 71 | std::env::remove_var("VE_SW_ENC"); | 95 | std::env::remove_var("VE_SW_ENC"); |
| 72 | }); | 96 | }); |
| 97 | + borrowed | ||
| 73 | } | 98 | } |
| 74 | 99 | ||
| 75 | /// `[0,30) + [60,150)` of the source: two cuts and a delete, so the export has | 100 | /// `[0,30) + [60,150)` of the source: two cuts and a delete, so the export has |
| @@ -180,7 +205,7 @@ fn round_trip(name: &str, limit: Duration) { | |||
| 180 | 205 | ||
| 181 | #[test] | 206 | #[test] |
| 182 | fn exports_an_edited_timeline_in_software() { | 207 | fn exports_an_edited_timeline_in_software() { |
| 183 | - pin_software(); | 208 | + let _seat = pin_software(); |
| 184 | round_trip("sw", Duration::from_secs(120)); | 209 | round_trip("sw", Duration::from_secs(120)); |
| 185 | } | 210 | } |
| 186 | 211 | ||
| @@ -189,7 +214,7 @@ fn exports_an_edited_timeline_in_software() { | |||
| 189 | #[test] | 214 | #[test] |
| 190 | #[ignore] | 215 | #[ignore] |
| 191 | fn exports_an_edited_timeline_in_hardware() { | 216 | fn exports_an_edited_timeline_in_hardware() { |
| 192 | - pin_hardware(); | 217 | + let _seat = pin_hardware(); |
| 193 | round_trip("hw", Duration::from_secs(60)); | 218 | round_trip("hw", Duration::from_secs(60)); |
| 194 | } | 219 | } |
| 195 | 220 | ||
| @@ -202,7 +227,7 @@ fn exports_an_edited_timeline_in_hardware() { | |||
| 202 | /// (`playback.rs: a_fitted_clip_is_letterboxed_and_a_filled_one_is_not`). | 227 | /// (`playback.rs: a_fitted_clip_is_letterboxed_and_a_filled_one_is_not`). |
| 203 | #[test] | 228 | #[test] |
| 204 | fn exports_at_the_project_resolution_with_the_watched_geometry() { | 229 | fn exports_at_the_project_resolution_with_the_watched_geometry() { |
| 205 | - pin_software(); | 230 | + let _seat = pin_software(); |
| 206 | let clip = |source: usize, start: u32| engine::Clip { | 231 | let clip = |source: usize, start: u32| engine::Clip { |
| 207 | start, | 232 | start, |
| 208 | in_frame: 0, | 233 | in_frame: 0, |
| @@ -282,7 +307,7 @@ fn exports_at_the_project_resolution_with_the_watched_geometry() { | |||
| 282 | /// header. Software only: the picture is beside the point here. | 307 | /// header. Software only: the picture is beside the point here. |
| 283 | #[test] | 308 | #[test] |
| 284 | fn exports_the_audio_stream_the_timeline_plays() { | 309 | fn exports_the_audio_stream_the_timeline_plays() { |
| 285 | - pin_software(); | 310 | + let _seat = pin_software(); |
| 286 | let multi = asset("test_multiaudio.mp4"); | 311 | let multi = asset("test_multiaudio.mp4"); |
| 287 | let (meta, _) = engine::demux::Demuxer::open(&multi).expect("open the fixture"); | 312 | let (meta, _) = engine::demux::Demuxer::open(&multi).expect("open the fixture"); |
| 288 | let whole = engine::Clip { | 313 | let whole = engine::Clip { |
| @@ -456,14 +481,14 @@ fn multi_source_round_trip(name: &str, limit: Duration) { | |||
| 456 | 481 | ||
| 457 | #[test] | 482 | #[test] |
| 458 | fn exports_two_sources_as_one_timeline_in_software() { | 483 | fn exports_two_sources_as_one_timeline_in_software() { |
| 459 | - pin_software(); | 484 | + let _seat = pin_software(); |
| 460 | multi_source_round_trip("multi_sw", Duration::from_secs(180)); | 485 | multi_source_round_trip("multi_sw", Duration::from_secs(180)); |
| 461 | } | 486 | } |
| 462 | 487 | ||
| 463 | #[test] | 488 | #[test] |
| 464 | #[ignore] | 489 | #[ignore] |
| 465 | fn exports_two_sources_as_one_timeline_in_hardware() { | 490 | fn exports_two_sources_as_one_timeline_in_hardware() { |
| 466 | - pin_hardware(); | 491 | + let _seat = pin_hardware(); |
| 467 | multi_source_round_trip("multi_hw", Duration::from_secs(60)); | 492 | multi_source_round_trip("multi_hw", Duration::from_secs(60)); |
| 468 | } | 493 | } |
| 469 | 494 | ||
| @@ -473,7 +498,7 @@ fn exports_two_sources_as_one_timeline_in_hardware() { | |||
| 473 | /// whose rate control is the one every machine has. | 498 | /// whose rate control is the one every machine has. |
| 474 | #[test] | 499 | #[test] |
| 475 | fn a_higher_bitrate_writes_a_bigger_file() { | 500 | fn a_higher_bitrate_writes_a_bigger_file() { |
| 476 | - pin_software(); | 501 | + let _seat = pin_software(); |
| 477 | let mut sizes = Vec::new(); | 502 | let mut sizes = Vec::new(); |
| 478 | for bitrate in [1_000_000u64, 4_000_000, 8_000_000] { | 503 | for bitrate in [1_000_000u64, 4_000_000, 8_000_000] { |
| 479 | let mut session = edited(&asset("test_baseline.mp4")); | 504 | let mut session = edited(&asset("test_baseline.mp4")); |
| @@ -503,7 +528,7 @@ fn a_higher_bitrate_writes_a_bigger_file() { | |||
| 503 | /// (the audio pass never touches the second file). | 528 | /// (the audio pass never touches the second file). |
| 504 | #[test] | 529 | #[test] |
| 505 | fn a_vanished_source_fails_the_export() { | 530 | fn a_vanished_source_fails_the_export() { |
| 506 | - pin_software(); | 531 | + let _seat = pin_software(); |
| 507 | let baseline = asset("test_baseline.mp4"); | 532 | let baseline = asset("test_baseline.mp4"); |
| 508 | let doomed = Scratch::file("ve_export_vanished_source", "mp4"); | 533 | let doomed = Scratch::file("ve_export_vanished_source", "mp4"); |
| 509 | std::fs::copy(&baseline, &doomed).expect("copy a second source"); | 534 | std::fs::copy(&baseline, &doomed).expect("copy a second source"); |
| @@ -537,7 +562,7 @@ fn a_vanished_source_fails_the_export() { | |||
| 537 | /// thing a user would otherwise try to play. | 562 | /// thing a user would otherwise try to play. |
| 538 | #[test] | 563 | #[test] |
| 539 | fn cancelling_leaves_no_file() { | 564 | fn cancelling_leaves_no_file() { |
| 540 | - pin_software(); | 565 | + let _seat = pin_software(); |
| 541 | let mut session = edited(&asset("test_baseline.mp4")); | 566 | let mut session = edited(&asset("test_baseline.mp4")); |
| 542 | session.pause(); | 567 | session.pause(); |
| 543 | let out = out_path("cancel"); | 568 | let out = out_path("cancel"); |
| @@ -572,7 +597,7 @@ fn cancelling_leaves_no_file() { | |||
| 572 | /// file, never a `.part`. | 597 | /// file, never a `.part`. |
| 573 | #[test] | 598 | #[test] |
| 574 | fn cancelling_after_the_last_frame_leaves_no_file() { | 599 | fn cancelling_after_the_last_frame_leaves_no_file() { |
| 575 | - pin_software(); | 600 | + let _seat = pin_software(); |
| 576 | let out = out_path("late"); | 601 | let out = out_path("late"); |
| 577 | let part = part_path(&out); | 602 | let part = part_path(&out); |
| 578 | for attempt in 1..=5 { | 603 | for attempt in 1..=5 { |
| @@ -615,7 +640,7 @@ fn cancelling_after_the_last_frame_leaves_no_file() { | |||
| 615 | #[test] | 640 | #[test] |
| 616 | #[ignore] | 641 | #[ignore] |
| 617 | fn exports_audio_alongside_the_video() { | 642 | fn exports_audio_alongside_the_video() { |
| 618 | - pin_hardware(); | 643 | + let _seat = pin_hardware(); |
| 619 | let source = asset("test_av.mp4"); | 644 | let source = asset("test_av.mp4"); |
| 620 | let mut session = PlaybackSession::open(&source).expect("open source"); | 645 | let mut session = PlaybackSession::open(&source).expect("open source"); |
| 621 | // One cut: the timeline is unchanged but the audio copy now runs as two | 646 | // One cut: the timeline is unchanged but the audio copy now runs as two |
| @@ -749,7 +774,7 @@ fn synthetic(index: u32, width: usize, height: usize) -> (Vec<u8>, Vec<u8>, Vec< | |||
| 749 | /// early, which is a lip sync error for the whole export. | 774 | /// early, which is a lip sync error for the whole export. |
| 750 | #[test] | 775 | #[test] |
| 751 | fn a_leading_audio_gap_keeps_the_sound_after_it_in_place() { | 776 | fn a_leading_audio_gap_keeps_the_sound_after_it_in_place() { |
| 752 | - pin_software(); | 777 | + let _seat = pin_software(); |
| 753 | let source = asset("test_av.mp4"); | 778 | let source = asset("test_av.mp4"); |
| 754 | let mut session = PlaybackSession::open(&source).expect("open source"); | 779 | let mut session = PlaybackSession::open(&source).expect("open source"); |
| 755 | assert!(session.cut_at(1.0), "cut at 1 s"); | 780 | assert!(session.cut_at(1.0), "cut at 1 s"); |
| @@ -797,7 +822,7 @@ fn a_leading_audio_gap_keeps_the_sound_after_it_in_place() { | |||
| 797 | /// a second early. | 822 | /// a second early. |
| 798 | #[test] | 823 | #[test] |
| 799 | fn exports_a_gapped_timeline_as_black_and_silence() { | 824 | fn exports_a_gapped_timeline_as_black_and_silence() { |
| 800 | - pin_software(); | 825 | + let _seat = pin_software(); |
| 801 | let source = asset("test_av.mp4"); | 826 | let source = asset("test_av.mp4"); |
| 802 | let mut session = PlaybackSession::open(&source).expect("open source"); | 827 | let mut session = PlaybackSession::open(&source).expect("open source"); |
| 803 | assert!(session.cut_at(1.0), "split at 1 s"); | 828 | assert!(session.cut_at(1.0), "split at 1 s"); |
| @@ -887,7 +912,7 @@ fn exports_a_gapped_timeline_as_black_and_silence() { | |||
| 887 | /// hardware one buys is speed, and that is the ignored test below. | 912 | /// hardware one buys is speed, and that is the ignored test below. |
| 888 | #[test] | 913 | #[test] |
| 889 | fn a_proxy_is_picture_only_every_frame_a_starting_point_and_cached() { | 914 | fn a_proxy_is_picture_only_every_frame_a_starting_point_and_cached() { |
| 890 | - pin_software(); | 915 | + let _seat = pin_software(); |
| 891 | let source = asset("test_av.mp4"); | 916 | let source = asset("test_av.mp4"); |
| 892 | let out = engine::proxy::path_for(&source).expect("a cache directory"); | 917 | let out = engine::proxy::path_for(&source).expect("a cache directory"); |
| 893 | // A proxy left by an earlier run would make this test assert about a file | 918 | // A proxy left by an earlier run would make this test assert about a file |
| @@ -1021,7 +1046,7 @@ fn a_proxy_is_picture_only_every_frame_a_starting_point_and_cached() { | |||
| 1021 | #[test] | 1046 | #[test] |
| 1022 | #[ignore = "needs the VA-API plugin"] | 1047 | #[ignore = "needs the VA-API plugin"] |
| 1023 | fn a_hardware_proxy_is_every_frame_a_starting_point_too() { | 1048 | fn a_hardware_proxy_is_every_frame_a_starting_point_too() { |
| 1024 | - pin_hardware(); | 1049 | + let _seat = pin_hardware(); |
| 1025 | let source = asset("test_av.mp4"); | 1050 | let source = asset("test_av.mp4"); |
| 1026 | let out = engine::proxy::path_for(&source).expect("a cache directory"); | 1051 | let out = engine::proxy::path_for(&source).expect("a cache directory"); |
| 1027 | let _ = std::fs::remove_file(&out); | 1052 | let _ = std::fs::remove_file(&out); |
| @@ -1094,7 +1119,7 @@ fn a_hardware_proxy_is_every_frame_a_starting_point_too() { | |||
| 1094 | #[test] | 1119 | #[test] |
| 1095 | #[ignore = "needs the VA-API plugin and a real library"] | 1120 | #[ignore = "needs the VA-API plugin and a real library"] |
| 1096 | fn a_proxy_of_real_4k_film_is_made_faster_than_it_plays() { | 1121 | fn a_proxy_of_real_4k_film_is_made_faster_than_it_plays() { |
| 1097 | - pin_hardware(); | 1122 | + let _seat = pin_hardware(); |
| 1098 | let Some(film) = engine::real_library::film("hevc_4k_hdr") else { | 1123 | let Some(film) = engine::real_library::film("hevc_4k_hdr") else { |
| 1099 | return; | 1124 | return; |
| 1100 | }; | 1125 | }; |
| @@ -1174,14 +1199,23 @@ fn a_proxy_of_real_4k_film_is_made_faster_than_it_plays() { | |||
| 1174 | // opens a stand-in seat in the child that touches no driver; | 1199 | // opens a stand-in seat in the child that touches no driver; |
| 1175 | // `VE_HW_TEST_ABORT` / `VE_HW_TEST_HANG` say where it dies or stops. | 1200 | // `VE_HW_TEST_ABORT` / `VE_HW_TEST_HANG` say where it dies or stops. |
| 1176 | 1201 | ||
| 1177 | -/// The stand-in-seat variables are process-wide, so the tests below take turns | 1202 | +/// The one place in this binary that *changes* the seat rather than reading it, |
| 1178 | -/// with them; nothing else in this binary reads them, and every one is removed | 1203 | +/// so it takes [`SEAT`] exclusively: while it holds, no other export in this |
| 1179 | -/// again before the turn is given up. | 1204 | +/// process is in flight, and every variable it set is gone again before it lets |
| 1205 | +/// go. Which is the whole of the bug this shape exists to make impossible -- | ||
| 1206 | +/// a stand-in encoder seat cycled underneath a software test that had already | ||
| 1207 | +/// opened its own is a hang, not a failure, and it does not reproduce. | ||
| 1208 | +/// | ||
| 1209 | +/// It also lifts the software *encode* pin for its own exports, because the | ||
| 1210 | +/// question here is what an export does when its hardware seat dies. Decode | ||
| 1211 | +/// stays pinned to software: it is not what is under test and the fixture must | ||
| 1212 | +/// decode the same way it does everywhere else in this file. | ||
| 1180 | fn injected<T>(abort: Option<&str>, hang: Option<&str>, body: impl FnOnce() -> T) -> T { | 1213 | fn injected<T>(abort: Option<&str>, hang: Option<&str>, body: impl FnOnce() -> T) -> T { |
| 1181 | - use std::sync::Mutex; | 1214 | + let _exclusive = SEAT.write().unwrap_or_else(|poisoned| poisoned.into_inner()); |
| 1182 | - static TURN: Mutex<()> = Mutex::new(()); | 1215 | + let restore = std::env::var_os("VE_SW_ENC"); |
| 1183 | - let _turn = TURN.lock().unwrap_or_else(|poisoned| poisoned.into_inner()); | ||
| 1184 | unsafe { | 1216 | unsafe { |
| 1217 | + std::env::set_var("VE_SW", "1"); | ||
| 1218 | + std::env::remove_var("VE_SW_ENC"); | ||
| 1185 | std::env::set_var("VE_HW_TEST_FAKE", "1"); | 1219 | std::env::set_var("VE_HW_TEST_FAKE", "1"); |
| 1186 | std::env::set_var("VE_HW_CHILD_BIN", env!("CARGO_BIN_EXE_hw-encode-child")); | 1220 | std::env::set_var("VE_HW_CHILD_BIN", env!("CARGO_BIN_EXE_hw-encode-child")); |
| 1187 | // Short, because one of these is waiting out a child that has stopped | 1221 | // Short, because one of these is waiting out a child that has stopped |
| @@ -1207,6 +1241,12 @@ fn injected<T>(abort: Option<&str>, hang: Option<&str>, body: impl FnOnce() -> T | |||
| 1207 | ] { | 1241 | ] { |
| 1208 | std::env::remove_var(var); | 1242 | std::env::remove_var(var); |
| 1209 | } | 1243 | } |
| 1244 | + // Put the software suite's pin back exactly as it was found -- it is | ||
| 1245 | + // set once for the whole binary and this is the only thing that ever | ||
| 1246 | + // takes it away. | ||
| 1247 | + if let Some(pinned) = restore { | ||
| 1248 | + std::env::set_var("VE_SW_ENC", pinned); | ||
| 1249 | + } | ||
| 1210 | } | 1250 | } |
| 1211 | match out { | 1251 | match out { |
| 1212 | Ok(value) => value, | 1252 | Ok(value) => value, |
| @@ -1234,7 +1274,6 @@ fn short_edit(source: &Path, frames: u32) -> (Project, engine::VideoMeta) { | |||
| 1234 | /// presses, and this is that same call with a driver dying under it. | 1274 | /// presses, and this is that same call with a driver dying under it. |
| 1235 | #[test] | 1275 | #[test] |
| 1236 | fn a_hardware_encoder_killed_mid_export_costs_the_file_nothing() { | 1276 | fn a_hardware_encoder_killed_mid_export_costs_the_file_nothing() { |
| 1237 | - pin_software(); | ||
| 1238 | let source = asset("test_baseline.mp4"); | 1277 | let source = asset("test_baseline.mp4"); |
| 1239 | let (project, meta) = short_edit(&source, 20); | 1278 | let (project, meta) = short_edit(&source, 20); |
| 1240 | let out = out_path("hw_child_abort"); | 1279 | let out = out_path("hw_child_abort"); |
| @@ -1264,7 +1303,6 @@ fn a_hardware_encoder_killed_mid_export_costs_the_file_nothing() { | |||
| 1264 | /// the first frame. A refusal, not a crash, and the file is whole. | 1303 | /// the first frame. A refusal, not a crash, and the file is whole. |
| 1265 | #[test] | 1304 | #[test] |
| 1266 | fn a_hardware_encoder_killed_at_its_open_is_simply_no_seat() { | 1305 | fn a_hardware_encoder_killed_at_its_open_is_simply_no_seat() { |
| 1267 | - pin_software(); | ||
| 1268 | let source = asset("test_baseline.mp4"); | 1306 | let source = asset("test_baseline.mp4"); |
| 1269 | let (project, meta) = short_edit(&source, 12); | 1307 | let (project, meta) = short_edit(&source, 12); |
| 1270 | let out = out_path("hw_child_abort_init"); | 1308 | let out = out_path("hw_child_abort_init"); |
| @@ -1283,7 +1321,6 @@ fn a_hardware_encoder_killed_at_its_open_is_simply_no_seat() { | |||
| 1283 | /// picture is fed and the encoder is being flushed when it dies. | 1321 | /// picture is fed and the encoder is being flushed when it dies. |
| 1284 | #[test] | 1322 | #[test] |
| 1285 | fn a_hardware_encoder_killed_at_the_drain_costs_the_file_nothing() { | 1323 | fn a_hardware_encoder_killed_at_the_drain_costs_the_file_nothing() { |
| 1286 | - pin_software(); | ||
| 1287 | let source = asset("test_baseline.mp4"); | 1324 | let source = asset("test_baseline.mp4"); |
| 1288 | let (project, meta) = short_edit(&source, 12); | 1325 | let (project, meta) = short_edit(&source, 12); |
| 1289 | let out = out_path("hw_child_abort_drain"); | 1326 | let out = out_path("hw_child_abort_drain"); |
| @@ -1306,7 +1343,6 @@ fn a_hardware_encoder_killed_at_the_drain_costs_the_file_nothing() { | |||
| 1306 | /// that sat on a stuck child forever would be the hang this refuses. | 1343 | /// that sat on a stuck child forever would be the hang this refuses. |
| 1307 | #[test] | 1344 | #[test] |
| 1308 | fn a_hardware_encoder_that_stops_answering_is_killed_and_replaced() { | 1345 | fn a_hardware_encoder_that_stops_answering_is_killed_and_replaced() { |
| 1309 | - pin_software(); | ||
| 1310 | let source = asset("test_baseline.mp4"); | 1346 | let source = asset("test_baseline.mp4"); |
| 1311 | let (project, meta) = short_edit(&source, 12); | 1347 | let (project, meta) = short_edit(&source, 12); |
| 1312 | let out = out_path("hw_child_hang"); | 1348 | let out = out_path("hw_child_hang"); |
| @@ -1327,6 +1363,44 @@ fn a_hardware_encoder_that_stops_answering_is_killed_and_replaced() { | |||
| 1327 | std::fs::remove_file(&out).unwrap(); | 1363 | std::fs::remove_file(&out).unwrap(); |
| 1328 | } | 1364 | } |
| 1329 | 1365 | ||
| 1366 | +/// ...and the export that does **not** get written again: a person who picked | ||
| 1367 | +/// the GPU on the export card asked for it by name, so a dead hardware seat is | ||
| 1368 | +/// refused in words rather than answered with an hour in an encoder nobody | ||
| 1369 | +/// chose. The same posture [`engine::export::start`] already takes for a machine | ||
| 1370 | +/// with no hardware seat at all -- and the guard that separates the two is the | ||
| 1371 | +/// one every test above depends on being narrow. | ||
| 1372 | +/// | ||
| 1373 | +/// The process is alive either way, which is the invariant; what differs is who | ||
| 1374 | +/// is told. | ||
| 1375 | +#[test] | ||
| 1376 | +fn an_export_that_asked_for_the_gpu_by_name_refuses_instead_of_falling_back() { | ||
| 1377 | + let source = asset("test_baseline.mp4"); | ||
| 1378 | + let (project, meta) = short_edit(&source, 12); | ||
| 1379 | + let out = out_path("hw_child_named_seat"); | ||
| 1380 | + | ||
| 1381 | + let error = injected(Some("2"), None, || { | ||
| 1382 | + let settings = ExportSettings { | ||
| 1383 | + seat: engine::export::EncoderSeat::Hardware, | ||
| 1384 | + ..Default::default() | ||
| 1385 | + }; | ||
| 1386 | + let handle = engine::export::start(project, meta, &out, &settings); | ||
| 1387 | + wait(&handle, Duration::from_secs(180)) | ||
| 1388 | + .expect_err("a named hardware seat that died is not written again in software") | ||
| 1389 | + }); | ||
| 1390 | + | ||
| 1391 | + println!("named hardware seat: {error}"); | ||
| 1392 | + assert!( | ||
| 1393 | + engine::hwproc::is_lost(&error), | ||
| 1394 | + "the refusal has to name the hardware failure: {error}" | ||
| 1395 | + ); | ||
| 1396 | + assert!( | ||
| 1397 | + !out.exists(), | ||
| 1398 | + "a refused export still wrote {}", | ||
| 1399 | + out.display() | ||
| 1400 | + ); | ||
| 1401 | + assert!(!part_path(&out).exists(), "the .part outlived the refusal"); | ||
| 1402 | +} | ||
| 1403 | + | ||
| 1330 | /// The seat's own contract, under the same injection and with no export around | 1404 | /// The seat's own contract, under the same injection and with no export around |
| 1331 | /// it: a killed child comes back as an error carrying | 1405 | /// it: a killed child comes back as an error carrying |
| 1332 | /// [`engine::hwproc::HW_LOST`], every later call gives the same answer instead | 1406 | /// [`engine::hwproc::HW_LOST`], every later call gives the same answer instead |