Merge branch 'lane-tmpsweep': close out the shared-temp-path race class
Browse files at this commit1 changed file +16 -3
crates/ec-h264/tests/encode.rsmodified+16 -3
| @@ -437,9 +437,17 @@ fn have_ffmpeg() -> bool { | |||
| 437 | 437 | ||
| 438 | /// Decode an Annex B stream with ffmpeg, returning one I420 triple per picture. | 438 | /// Decode an Annex B stream with ffmpeg, returning one I420 triple per picture. |
| 439 | fn ffmpeg_decode(stream: &[u8], w: usize, h: usize, extra: &[&str]) -> Option<Vec<Planes>> { | 439 | fn ffmpeg_decode(stream: &[u8], w: usize, h: usize, extra: &[&str]) -> Option<Vec<Planes>> { |
| 440 | + // Distinct per call, not per process: several #[test]s in this binary | ||
| 441 | + // call this on parallel threads, and a path keyed only on stream length | ||
| 442 | + // lets one call's cleanup delete another's still-being-read file. | ||
| 443 | + static SEQ: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0); | ||
| 440 | let dir = std::env::temp_dir().join(format!("ec-h264-enc-{}", std::process::id())); | 444 | let dir = std::env::temp_dir().join(format!("ec-h264-enc-{}", std::process::id())); |
| 441 | std::fs::create_dir_all(&dir).ok()?; | 445 | std::fs::create_dir_all(&dir).ok()?; |
| 442 | - let path = dir.join(format!("s{}.264", stream.len())); | 446 | + let path = dir.join(format!( |
| 447 | + "s{}-{}.264", | ||
| 448 | + stream.len(), | ||
| 449 | + SEQ.fetch_add(1, std::sync::atomic::Ordering::Relaxed) | ||
| 450 | + )); | ||
| 443 | std::fs::write(&path, stream).ok()?; | 451 | std::fs::write(&path, stream).ok()?; |
| 444 | let mut cmd = std::process::Command::new("ffmpeg"); | 452 | let mut cmd = std::process::Command::new("ffmpeg"); |
| 445 | cmd.args(["-v", "error"]); | 453 | cmd.args(["-v", "error"]); |
| @@ -1010,10 +1018,15 @@ fn have_x264() -> bool { | |||
| 1010 | /// off so both encoders spend bits by the same rule. Returns the Annex B | 1018 | /// off so both encoders spend bits by the same rule. Returns the Annex B |
| 1011 | /// stream. | 1019 | /// stream. |
| 1012 | fn x264_encode_qp(sources: &[Planes], w: usize, h: usize, qp: i32, gop: u32) -> Option<Vec<u8>> { | 1020 | fn x264_encode_qp(sources: &[Planes], w: usize, h: usize, qp: i32, gop: u32) -> Option<Vec<u8>> { |
| 1021 | + // Distinct per call, not per process: two #[test]s in this binary call | ||
| 1022 | + // this on parallel threads with overlapping qp values, and a path keyed | ||
| 1023 | + // only on qp lets one call's cleanup delete another's still-in-use file. | ||
| 1024 | + static SEQ: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0); | ||
| 1025 | + let seq = SEQ.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | ||
| 1013 | let dir = std::env::temp_dir().join(format!("ec-h264-x264-{}", std::process::id())); | 1026 | let dir = std::env::temp_dir().join(format!("ec-h264-x264-{}", std::process::id())); |
| 1014 | std::fs::create_dir_all(&dir).ok()?; | 1027 | std::fs::create_dir_all(&dir).ok()?; |
| 1015 | - let raw = dir.join(format!("in-q{qp}.yuv")); | 1028 | + let raw = dir.join(format!("in-q{qp}-{seq}.yuv")); |
| 1016 | - let out = dir.join(format!("out-q{qp}.264")); | 1029 | + let out = dir.join(format!("out-q{qp}-{seq}.264")); |
| 1017 | let mut buf = Vec::with_capacity(sources.len() * w * h * 3 / 2); | 1030 | let mut buf = Vec::with_capacity(sources.len() * w * h * 3 / 2); |
| 1018 | for (y, u, v) in sources { | 1031 | for (y, u, v) in sources { |
| 1019 | buf.extend_from_slice(y); | 1032 | buf.extend_from_slice(y); |