craft-audio tests: hostile sweeps run 1/N at the gate, encoder mode sweeps use 1 s signals

This commit is contained in:
aiongg
2026-11-24 19:48:08 +00:00
parent 59ad7eb28b
commit b0695c24f7
7 changed files with 32 additions and 18 deletions
+2 -1
View File
@@ -493,7 +493,8 @@ mod tests {
};
let mut e = Element::new(1, RATE);
let mut pair = Element::new(2, RATE);
for i in 0..600 {
// CRAFT_HOSTILE_DIVISOR=N (pull requests) runs 1/N of the rounds.
for i in 0..600usize.div_ceil(craft_media_testkit::hostile::divisor()) {
let mut data = good.clone();
for _ in 0..1 + next() % 6 {
let bit = next() as usize % (8 * data.len());
+8 -2
View File
@@ -105,8 +105,14 @@ fn dec3_describes_dependent_rear_pair_and_aggregate_rate() -> Result<(), Box<dyn
#[test]
fn actual_decoder_positions_satisfy_all_three_ac3_bit_budgets() -> Result<(), Box<dyn std::error::Error>> {
for rate in [32000, 44100, 48000] {
for bitrate in super::super::BITRATES {
// CRAFT_HOSTILE_DIVISOR=N (pull requests) runs every N-th bit rate, from a different offset for
// each sample rate, so the rates together still reach every bit rate.
let step = craft_media_testkit::hostile::divisor();
for (ri, rate) in [32000, 44100, 48000].into_iter().enumerate() {
for (bi, bitrate) in super::super::BITRATES.into_iter().enumerate() {
if (bi + ri) % step != 0 {
continue;
}
for mode in [CodingMode::Mono, CodingMode::ThreeFrontTwoSurround] {
let cfg =
Config { codec: Codec::Ac3, sample_rate: rate, bitrate_kbps: bitrate, mode, lfe: mode == CodingMode::ThreeFrontTwoSurround };
+2 -1
View File
@@ -28,7 +28,8 @@ fn mutated_access_units_never_panic() {
let mut errors = 0usize;
for (asc, aus) in corpus() {
let mut dec = Decoder::new(&asc).unwrap();
for round in 0..3000 {
// CRAFT_HOSTILE_DIVISOR=N (pull requests) runs 1/N of the rounds.
for round in 0..3000usize.div_ceil(craft_media_testkit::hostile::divisor()) {
let mut au = aus[rand(aus.len())].clone();
match round % 6 {
0 => {
+2 -1
View File
@@ -26,7 +26,8 @@ fn random_garbage_never_panics() {
for channels in 1..=2 {
let mut dec = StreamDecoder::new(rate, channels).unwrap();
let mut out = Vec::new();
for i in 0..3000 {
// CRAFT_HOSTILE_DIVISOR=N (pull requests) runs 1/N of the packets.
for i in 0..3000usize.div_ceil(craft_media_testkit::hostile::divisor()) {
let len = (rng.next() % 400) as usize;
let mut pkt: Vec<u8> = (0..len).map(|_| rng.next() as u8).collect();
if let Some(t) = pkt.first_mut() {
+11 -9
View File
@@ -49,12 +49,14 @@ fn band_edge(bw: Bandwidth) -> f64 {
}
const LEN: usize = 96_000;
/// The length of the sweeps over many encodes: one second.
const SHORT: usize = 48_000;
#[test]
fn every_mode_and_bandwidth_decodes() {
let sp = speech(LEN + 40_000, 11);
let left = sp[..LEN].to_vec();
let right: Vec<f32> = sp[40_000..].iter().map(|v| v * 0.6).collect();
let sp = speech(SHORT + 20_000, 11);
let left = sp[..SHORT].to_vec();
let right: Vec<f32> = sp[20_000..].iter().map(|v| v * 0.6).collect();
for (mode, bw, config, rate) in [
(Mode::Silk, Bandwidth::Narrowband, 1u8, 8_000u32),
(Mode::Silk, Bandwidth::Mediumband, 5, 11_000),
@@ -149,8 +151,8 @@ fn silk_music_quality() {
#[test]
fn bitrate_tracking() {
let sp = speech(LEN, 13);
let mu = music(LEN);
let sp = speech(SHORT, 13);
let mu = music(SHORT);
for (name, x) in [("speech", &sp), ("music", &mu)] {
for (mode, bw, rate) in [
(Mode::Silk, Bandwidth::Narrowband, 6_000u32),
@@ -178,10 +180,10 @@ fn bitrate_tracking() {
#[test]
fn stereo_silk_and_hybrid() {
let sp = speech(LEN + 40_000, 21);
let a = sp[..LEN].to_vec();
let b: Vec<f32> = sp[40_000..].iter().map(|v| v * 0.7).collect();
let mu = music(LEN);
let sp = speech(SHORT + 20_000, 21);
let a = sp[..SHORT].to_vec();
let b: Vec<f32> = sp[20_000..].iter().map(|v| v * 0.7).collect();
let mu = music(SHORT);
let cases: Vec<(&str, Vec<f32>, Vec<f32>)> = vec![
("dual mono", a.clone(), a.clone()),
("panned", a.iter().map(|v| v * 0.9).collect(), a.iter().map(|v| v * 0.35).collect()),
+5 -3
View File
@@ -132,15 +132,17 @@ fn track_decoder_uses_streaminfo_layout_and_packet_length() {
#[test]
fn hostile_input_is_an_error_not_a_panic() {
let src = signal(2, 6000, 16, 11);
// CRAFT_HOSTILE_DIVISOR=N (pull requests) runs every N-th cut and flipped byte.
let step = craft_media_testkit::hostile::divisor();
let src = signal(2, 3500, 16, 11);
let file = encode(&src, 44_100, 16, 1152, 5);
for n in 0..file.len().min(3000) {
for n in (0..file.len().min(3000)).step_by(step) {
let _ = decode(&file[..n]);
}
// A cut file is truncated, not silently shorter.
assert!(decode(&file[..file.len() - 5]).is_err());
// Every bit flip in the first frames is caught by a CRC or another check, never a panic.
for i in 0..file.len().min(2500) {
for i in (0..file.len().min(2500)).step_by(step) {
for bit in 0..8 {
let mut c = file.clone();
c[i] ^= 1 << bit;
+2 -1
View File
@@ -57,7 +57,8 @@ fn damaged_headers_never_panic() {
let mut seed = 99u32;
for which in [0usize, 2] {
let len = p.headers[which].len();
for _ in 0..800 {
// CRAFT_HOSTILE_DIVISOR=N (pull requests) runs 1/N of the mutations.
for _ in 0..800usize.div_ceil(craft_media_testkit::hostile::divisor()) {
let mut h = p.headers.clone();
for _ in 0..1 + xorshift(&mut seed) % 3 {
let at = xorshift(&mut seed) as usize % len;