| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | #[cfg(test)] |
| 35 | const NEVER_EXERCISED: &[(&str, &str)] = &[ |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | ( |
| 43 | "enable-intrabc", |
| 44 | "the block vector is decoded and predicted from, but every real stream's intrabc block needs the unread inter var-tx transform tree", |
| 45 | ), |
| 46 | ]; |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | #[cfg(test)] |
| 54 | const TOOL_UNIVERSE: &[&str] = &[ |
| 55 | "enable-1to4-partitions", |
| 56 | "enable-ab-partitions", |
| 57 | "enable-angle-delta", |
| 58 | "enable-cdef", |
| 59 | "enable-cfl-intra", |
| 60 | "enable-dist-wtd-comp", |
| 61 | "enable-dual-filter", |
| 62 | "enable-filter-intra", |
| 63 | "enable-flip-idtx", |
| 64 | "enable-global-motion", |
| 65 | "enable-interintra-comp", |
| 66 | "enable-intra-edge-filter", |
| 67 | "enable-intrabc", |
| 68 | "enable-masked-comp", |
| 69 | "enable-obmc", |
| 70 | "enable-order-hint", |
| 71 | "enable-paeth-intra", |
| 72 | "enable-palette", |
| 73 | "enable-rect-partitions", |
| 74 | "enable-rect-tx", |
| 75 | "enable-ref-frame-mvs", |
| 76 | "enable-restoration", |
| 77 | "enable-smooth-intra", |
| 78 | "enable-superres", |
| 79 | "enable-tx64", |
| 80 | "enable-warped-motion", |
| 81 | ]; |
| 82 | |
| 83 | |
| 84 | #[cfg(test)] |
| 85 | #[derive(Clone, Copy, PartialEq)] |
| 86 | enum On { |
| 87 | |
| 88 | NonZero, |
| 89 | |
| 90 | AtMost(u32), |
| 91 | } |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | #[cfg(test)] |
| 108 | const DEFAULT_ON_TOOLS: &[(&str, &[&str], &str, On)] = &[ |
| 109 | ("enable-tx-size-search", &["enable-tx-size-search"], "1", On::NonZero), |
| 110 | ("enable-directional-intra", &["enable-directional-intra"], "1", On::NonZero), |
| 111 | ("enable-smooth-interintra", &["enable-smooth-interintra"], "1", On::NonZero), |
| 112 | ("enable-interintra-wedge", &["enable-interintra-wedge"], "1", On::NonZero), |
| 113 | ("enable-diff-wtd-comp", &["enable-diff-wtd-comp"], "1", On::NonZero), |
| 114 | ("enable-onesided-comp", &["enable-onesided-comp"], "1", On::NonZero), |
| 115 | ("enable-fwd-kf", &["enable-fwd-kf"], "0", On::NonZero), |
| 116 | ("deblocking", &["loopfilter-control"], "1", On::NonZero), |
| 117 | ("multi-tile", &["tile-columns", "tile-rows"], "0", On::NonZero), |
| 118 | ("intrabc-search", &["cpu-used"], "0", On::AtMost(2)), |
| 119 | ]; |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | #[cfg(test)] |
| 127 | const ALIASES: &[(&str, &str)] = &[("superres-mode", "enable-superres")]; |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | #[cfg(test)] |
| 141 | const NEVER_EXERCISED_8BIT: &[(&str, &str)] = &[ |
| 142 | ( |
| 143 | "enable-1to4-partitions", |
| 144 | "off in 42 gates, on in none: PARTITION_HORZ_4/VERT_4 at 64x64 needs TX_64X16 luma plus 32x8 chroma scans (lane-part32 r5)", |
| 145 | ), |
| 146 | ( |
| 147 | "enable-angle-delta", |
| 148 | "off in 36 gates, on in none: the directional-intra gates pin it off to isolate the base modes", |
| 149 | ), |
| 150 | ( |
| 151 | "enable-cfl-intra", |
| 152 | "off in 41 gates, on in none: chroma-from-luma prediction is unimplemented", |
| 153 | ), |
| 154 | ( |
| 155 | "enable-dist-wtd-comp", |
| 156 | "off in 11 gates, on in none: distance-weighted compound is unimplemented", |
| 157 | ), |
| 158 | ( |
| 159 | "enable-dual-filter", |
| 160 | "never spelled by any gate, so defaulted = unknown; no stream is proven to carry per-direction interp filters", |
| 161 | ), |
| 162 | ( |
| 163 | "enable-flip-idtx", |
| 164 | "never spelled; the flip/identity transform types are unproven by a real stream", |
| 165 | ), |
| 166 | ( |
| 167 | "enable-global-motion", |
| 168 | "off in 5 gates, on in none at 8 bits; lane-gm owns the global-warp prediction that is still missing", |
| 169 | ), |
| 170 | ( |
| 171 | "enable-intrabc", |
| 172 | "the block vector is decoded and predicted from, but every real stream's intrabc block needs the unread inter var-tx transform tree", |
| 173 | ), |
| 174 | ( |
| 175 | "enable-rect-tx", |
| 176 | "never spelled; rect transforms reach the decoder only through partition shape, never through a gate that names the tool", |
| 177 | ), |
| 178 | ( |
| 179 | "enable-ref-frame-mvs", |
| 180 | "off in 27 gates, on in none: temporal MV projection is unimplemented", |
| 181 | ), |
| 182 | ( |
| 183 | "enable-tx64", |
| 184 | "never spelled; TX_64X64 appears only where aomenc's default picks it, which is unknown per stream", |
| 185 | ), |
| 186 | ]; |
| 187 | |
| 188 | #[cfg(test)] |
| 189 | const NEVER_EXERCISED_10BIT: &[(&str, &str)] = &[ |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | ( |
| 205 | "enable-1to4-partitions", |
| 206 | "hole at both depths, see the 8-bit list", |
| 207 | ), |
| 208 | ( |
| 209 | "enable-angle-delta", |
| 210 | "hole at both depths, see the 8-bit list", |
| 211 | ), |
| 212 | ( |
| 213 | "enable-cfl-intra", |
| 214 | "hole at both depths, see the 8-bit list", |
| 215 | ), |
| 216 | ( |
| 217 | "enable-dual-filter", |
| 218 | "hole at both depths, see the 8-bit list", |
| 219 | ), |
| 220 | ( |
| 221 | "enable-flip-idtx", |
| 222 | "hole at both depths, see the 8-bit list", |
| 223 | ), |
| 224 | ("enable-intrabc", "hole at both depths, see the 8-bit list"), |
| 225 | ("enable-rect-tx", "hole at both depths, see the 8-bit list"), |
| 226 | ( |
| 227 | "enable-ref-frame-mvs", |
| 228 | "hole at both depths, see the 8-bit list", |
| 229 | ), |
| 230 | ("enable-tx64", "hole at both depths, see the 8-bit list"), |
| 231 | ]; |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | #[cfg(test)] |
| 239 | const NEVER_ON_8BIT: &[(&str, &str)] = &[ |
| 240 | ( |
| 241 | "deblocking", |
| 242 | "on in no 8-bit gate: 7 pin --loopfilter-control=0, the other 34 default (on) -- and defaulted is unknown, so no stream is proven to run the loop filter", |
| 243 | ), |
| 244 | ( |
| 245 | "enable-diff-wtd-comp", |
| 246 | "on in no 8-bit gate: 6 pin =0, 35 default; difference-weighted compound masks are unproven", |
| 247 | ), |
| 248 | ( |
| 249 | "enable-directional-intra", |
| 250 | "on in no 8-bit gate: pinned =0 in 32 of 41, defaulted in 9 -- the directional gates drive the modes through other flags, never this one", |
| 251 | ), |
| 252 | ( |
| 253 | "enable-fwd-kf", |
| 254 | "on in no 8-bit gate: 11 pin =0, 30 default (aomenc's default is off), so forward keyframes are never coded", |
| 255 | ), |
| 256 | ( |
| 257 | "enable-onesided-comp", |
| 258 | "on in no 8-bit gate: 17 pin =0, 24 default; one-sided compound prediction is unproven", |
| 259 | ), |
| 260 | ( |
| 261 | "enable-tx-size-search", |
| 262 | "on in no 8-bit gate: pinned =0 in 34 of 41 -- the pin that hid a real-stream PANIC from lane-ab16 until TX_MODE_SELECT was landed by lane-txselect; its gates spell the tool through the recipe, not this flag", |
| 263 | ), |
| 264 | ]; |
| 265 | |
| 266 | |
| 267 | #[cfg(test)] |
| 268 | const NEVER_ON_10BIT: &[(&str, &str)] = &[ |
| 269 | ( |
| 270 | "deblocking", |
| 271 | "hole at both depths, see the 8-bit list (1 of the 15 10-bit gates pins =0, 14 default)", |
| 272 | ), |
| 273 | ( |
| 274 | "enable-diff-wtd-comp", |
| 275 | "hole at both depths, see the 8-bit list (1 pinned off, 14 defaulted)", |
| 276 | ), |
| 277 | ( |
| 278 | "enable-fwd-kf", |
| 279 | "hole at both depths, see the 8-bit list (3 pinned off, 12 defaulted)", |
| 280 | ), |
| 281 | ( |
| 282 | "enable-interintra-wedge", |
| 283 | "on in no 10-bit gate: 5 pin =0, 10 default -- wedge interintra masks are exercised at 8 bits only, the shape that cost lane-hbdinter two 10-bit-only defects", |
| 284 | ), |
| 285 | ( |
| 286 | "enable-onesided-comp", |
| 287 | "hole at both depths, see the 8-bit list (5 pinned off, 10 defaulted)", |
| 288 | ), |
| 289 | ( |
| 290 | "enable-tx-size-search", |
| 291 | "hole at both depths, see the 8-bit list (11 of 15 pin =0)", |
| 292 | ), |
| 293 | ( |
| 294 | "multi-tile", |
| 295 | "on in no 10-bit gate: all 15 leave --tile-columns/--tile-rows defaulted at 0, so every 10-bit stream is single-tile and no tile edge or per-tile CDF reset is checked at high bit depth", |
| 296 | ), |
| 297 | ]; |
| 298 | |
| 299 | #[cfg(test)] |
| 300 | mod tests { |
| 301 | use super::{ |
| 302 | ALIASES, DEFAULT_ON_TOOLS, NEVER_EXERCISED, NEVER_EXERCISED_8BIT, NEVER_EXERCISED_10BIT, |
| 303 | NEVER_ON_10BIT, NEVER_ON_8BIT, On, TOOL_UNIVERSE, |
| 304 | }; |
| 305 | use std::collections::{BTreeMap, BTreeSet}; |
| 306 | |
| 307 | |
| 308 | |
| 309 | |
| 310 | fn gate_bodies() -> Vec<&'static str> { |
| 311 | let src = include_str!("stream.rs"); |
| 312 | let gates: Vec<&str> = src |
| 313 | .split("\n #[") |
| 314 | |
| 315 | |
| 316 | |
| 317 | .filter(|body| !body.starts_with("ignore")) |
| 318 | |
| 319 | |
| 320 | .filter(|body| { |
| 321 | body.contains("\"--passes=1\"") |
| 322 | || body.contains("ten_bit_tool_gate(") |
| 323 | || body.contains("encode_10bit_gradients") |
| 324 | }) |
| 325 | .collect(); |
| 326 | assert!( |
| 327 | gates.len() >= 20, |
| 328 | "expected the real-aomenc gates, found {}", |
| 329 | gates.len() |
| 330 | ); |
| 331 | gates |
| 332 | } |
| 333 | |
| 334 | |
| 335 | fn flags_in(gate: &str) -> BTreeMap<String, char> { |
| 336 | let mut here = BTreeMap::new(); |
| 337 | for (i, _) in gate.match_indices("\"--enable-") { |
| 338 | let rest = &gate[i + 3..]; |
| 339 | let Some(end) = rest.find('"') else { continue }; |
| 340 | let Some((flag, value)) = rest[..end].split_once('=') else { |
| 341 | continue; |
| 342 | }; |
| 343 | let Some(value) = value.chars().next() else { |
| 344 | continue; |
| 345 | }; |
| 346 | here.insert(flag.to_owned(), value); |
| 347 | } |
| 348 | here |
| 349 | } |
| 350 | |
| 351 | |
| 352 | |
| 353 | fn settings_in(gate: &str) -> BTreeMap<String, String> { |
| 354 | let mut here = BTreeMap::new(); |
| 355 | for (i, _) in gate.match_indices("\"--") { |
| 356 | let rest = &gate[i + 3..]; |
| 357 | let Some(end) = rest.find('"') else { continue }; |
| 358 | let Some((flag, value)) = rest[..end].split_once('=') else { |
| 359 | continue; |
| 360 | }; |
| 361 | here.insert(flag.to_owned(), value.to_owned()); |
| 362 | } |
| 363 | here |
| 364 | } |
| 365 | |
| 366 | |
| 367 | fn default_on_state(gate: &str, spellings: &[&str], on: On) -> Option<bool> { |
| 368 | let here = settings_in(gate); |
| 369 | let mut state = None; |
| 370 | for spelling in spellings { |
| 371 | let Some(value) = here.get(*spelling) else { |
| 372 | continue; |
| 373 | }; |
| 374 | let Ok(value) = value.parse::<u32>() else { |
| 375 | continue; |
| 376 | }; |
| 377 | let is_on = match on { |
| 378 | On::NonZero => value != 0, |
| 379 | On::AtMost(limit) => value <= limit, |
| 380 | }; |
| 381 | |
| 382 | |
| 383 | state = Some(state.unwrap_or(false) || is_on); |
| 384 | } |
| 385 | state |
| 386 | } |
| 387 | |
| 388 | |
| 389 | |
| 390 | fn tool_settings() -> (usize, BTreeMap<String, (usize, usize, usize)>) { |
| 391 | let gates = gate_bodies(); |
| 392 | |
| 393 | let mut per_tool: BTreeMap<String, (usize, usize, usize)> = BTreeMap::new(); |
| 394 | let mut names: BTreeSet<String> = BTreeSet::new(); |
| 395 | let mut seen: Vec<BTreeMap<String, char>> = Vec::new(); |
| 396 | for gate in &gates { |
| 397 | let here = flags_in(gate); |
| 398 | names.extend(here.keys().cloned()); |
| 399 | seen.push(here); |
| 400 | } |
| 401 | for name in names { |
| 402 | let off = seen.iter().filter(|g| g.get(&name) == Some(&'0')).count(); |
| 403 | let on = seen.iter().filter(|g| g.get(&name) == Some(&'1')).count(); |
| 404 | per_tool.insert(name, (off, on, gates.len() - off - on)); |
| 405 | } |
| 406 | (gates.len(), per_tool) |
| 407 | } |
| 408 | |
| 409 | #[test] |
| 410 | fn every_gate_disabling_a_tool_is_a_listed_coverage_hole() { |
| 411 | let (gate_count, per_tool) = tool_settings(); |
| 412 | |
| 413 | |
| 414 | let derived: BTreeSet<&str> = per_tool |
| 415 | .iter() |
| 416 | .filter(|&(_, &(off, on, defaulted))| off == gate_count && on == 0 && defaulted == 0) |
| 417 | .map(|(name, _)| name.as_str()) |
| 418 | .collect(); |
| 419 | |
| 420 | |
| 421 | |
| 422 | |
| 423 | |
| 424 | let exercised: BTreeSet<&str> = per_tool |
| 425 | .iter() |
| 426 | .filter(|&(_, &(_, on, _))| on > 0) |
| 427 | .map(|(name, _)| name.as_str()) |
| 428 | .collect(); |
| 429 | let listed: BTreeSet<&str> = NEVER_EXERCISED.iter().map(|&(flag, _)| flag).collect(); |
| 430 | |
| 431 | let unlisted: Vec<&&str> = derived.difference(&listed).collect(); |
| 432 | assert!( |
| 433 | unlisted.is_empty(), |
| 434 | "these aomenc tools are switched off in all {gate_count} real-aomenc gates and on in \ |
| 435 | none, so no real stream exercises them, and they are not listed in NEVER_EXERCISED: \ |
| 436 | {unlisted:?} -- either enable the tool with `=1` in its own gate or add it to the \ |
| 437 | list with a reason" |
| 438 | ); |
| 439 | let stale: Vec<&&str> = listed.intersection(&exercised).collect(); |
| 440 | assert!( |
| 441 | stale.is_empty(), |
| 442 | "NEVER_EXERCISED lists {stale:?}, but a gate now passes `=1` for them -- delete \ |
| 443 | those entries, the coverage hole is closed" |
| 444 | ); |
| 445 | } |
| 446 | |
| 447 | |
| 448 | |
| 449 | |
| 450 | #[test] |
| 451 | fn tool_settings_reads_whole_flags() { |
| 452 | let (gate_count, per_tool) = tool_settings(); |
| 453 | assert!( |
| 454 | per_tool.contains_key("enable-cdef"), |
| 455 | "expected --enable-cdef among the gate flags" |
| 456 | ); |
| 457 | for (name, &(off, on, defaulted)) in &per_tool { |
| 458 | assert!( |
| 459 | !name.is_empty() && !name.contains(['"', '=']), |
| 460 | "malformed flag {name:?}" |
| 461 | ); |
| 462 | assert_eq!( |
| 463 | off + on + defaulted, |
| 464 | gate_count, |
| 465 | "{name} counts do not cover every gate" |
| 466 | ); |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | |
| 471 | |
| 472 | |
| 473 | |
| 474 | fn is_ten_bit(body: &str) -> bool { |
| 475 | body.contains("encode_10bit_gradients") |
| 476 | || body.contains("ten_bit_tool_gate(") |
| 477 | || body.contains("--bit-depth=10") |
| 478 | || body.contains("--input-bit-depth=10") |
| 479 | || body.contains("yuv420p10le") |
| 480 | } |
| 481 | |
| 482 | |
| 483 | fn enabled_at(ten_bit: bool) -> BTreeSet<String> { |
| 484 | let mut on = BTreeSet::new(); |
| 485 | for gate in gate_bodies() { |
| 486 | if is_ten_bit(gate) != ten_bit { |
| 487 | continue; |
| 488 | } |
| 489 | for (flag, value) in flags_in(gate) { |
| 490 | if value == '1' { |
| 491 | on.insert(flag); |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | let here = settings_in(gate); |
| 496 | for (alias, tool) in ALIASES { |
| 497 | if here.get(*alias).is_some_and(|v| v != "0") { |
| 498 | on.insert((*tool).to_owned()); |
| 499 | } |
| 500 | } |
| 501 | } |
| 502 | on |
| 503 | } |
| 504 | |
| 505 | |
| 506 | fn never_exercised_at(ten_bit: bool) -> BTreeSet<&'static str> { |
| 507 | let on = enabled_at(ten_bit); |
| 508 | TOOL_UNIVERSE |
| 509 | .iter() |
| 510 | .copied() |
| 511 | .filter(|t| !on.contains(*t)) |
| 512 | .collect() |
| 513 | } |
| 514 | |
| 515 | fn check_depth(ten_bit: bool, listed: &[(&str, &str)]) { |
| 516 | let derived = never_exercised_at(ten_bit); |
| 517 | let listed: BTreeSet<&str> = listed.iter().map(|&(flag, _)| flag).collect(); |
| 518 | let depth = if ten_bit { "10-bit" } else { "8-bit" }; |
| 519 | let unlisted: Vec<&&str> = derived.difference(&listed).collect(); |
| 520 | assert!( |
| 521 | unlisted.is_empty(), |
| 522 | "no {depth} gate passes `=1` for {unlisted:?}, so no real {depth} stream exercises \ |
| 523 | them -- enable the tool in a {depth} gate that asserts it fired, or list it" |
| 524 | ); |
| 525 | let stale: Vec<&&str> = listed.difference(&derived).collect(); |
| 526 | assert!( |
| 527 | stale.is_empty(), |
| 528 | "the {depth} list still names {stale:?}, but a {depth} gate now passes `=1` for them \ |
| 529 | -- delete those entries, the coverage hole is closed" |
| 530 | ); |
| 531 | } |
| 532 | |
| 533 | #[test] |
| 534 | fn never_exercised_8bit_matches_the_gate_recipes() { |
| 535 | check_depth(false, NEVER_EXERCISED_8BIT); |
| 536 | } |
| 537 | |
| 538 | #[test] |
| 539 | fn never_exercised_10bit_matches_the_gate_recipes() { |
| 540 | check_depth(true, NEVER_EXERCISED_10BIT); |
| 541 | } |
| 542 | |
| 543 | |
| 544 | |
| 545 | #[test] |
| 546 | fn print_never_exercised_per_bit_depth() { |
| 547 | let ten: Vec<&str> = gate_bodies() |
| 548 | .into_iter() |
| 549 | .filter(|b| is_ten_bit(b)) |
| 550 | .collect(); |
| 551 | let total = gate_bodies().len(); |
| 552 | println!( |
| 553 | "gate_coverage: {} real-aomenc gates, {} of them 10-bit", |
| 554 | total, |
| 555 | ten.len() |
| 556 | ); |
| 557 | for (label, ten_bit) in [("8BIT", false), ("10BIT", true)] { |
| 558 | let holes = never_exercised_at(ten_bit); |
| 559 | println!( |
| 560 | "NEVER_EXERCISED_{label} ({} of {}):", |
| 561 | holes.len(), |
| 562 | TOOL_UNIVERSE.len() |
| 563 | ); |
| 564 | for flag in &holes { |
| 565 | println!(" --{flag}"); |
| 566 | } |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | |
| 571 | fn default_on_settings(ten_bit: bool) -> (usize, BTreeMap<&'static str, (usize, usize, usize)>) { |
| 572 | let gates: Vec<&str> = gate_bodies() |
| 573 | .into_iter() |
| 574 | .filter(|b| is_ten_bit(b) == ten_bit) |
| 575 | .collect(); |
| 576 | let mut per_tool = BTreeMap::new(); |
| 577 | for &(tool, spellings, _, on) in DEFAULT_ON_TOOLS { |
| 578 | let states: Vec<Option<bool>> = gates |
| 579 | .iter() |
| 580 | .map(|g| default_on_state(g, spellings, on)) |
| 581 | .collect(); |
| 582 | let turned_on = states.iter().filter(|s| **s == Some(true)).count(); |
| 583 | let turned_off = states.iter().filter(|s| **s == Some(false)).count(); |
| 584 | per_tool.insert( |
| 585 | tool, |
| 586 | (turned_off, turned_on, gates.len() - turned_off - turned_on), |
| 587 | ); |
| 588 | } |
| 589 | (gates.len(), per_tool) |
| 590 | } |
| 591 | |
| 592 | |
| 593 | fn never_on_at(ten_bit: bool) -> BTreeSet<&'static str> { |
| 594 | default_on_settings(ten_bit) |
| 595 | .1 |
| 596 | .into_iter() |
| 597 | .filter(|&(_, (_, on, _))| on == 0) |
| 598 | .map(|(tool, _)| tool) |
| 599 | .collect() |
| 600 | } |
| 601 | |
| 602 | fn check_default_on(ten_bit: bool, listed: &[(&str, &str)]) { |
| 603 | let derived = never_on_at(ten_bit); |
| 604 | let listed: BTreeSet<&str> = listed.iter().map(|&(tool, _)| tool).collect(); |
| 605 | let depth = if ten_bit { "10-bit" } else { "8-bit" }; |
| 606 | let unlisted: Vec<&&str> = derived.difference(&listed).collect(); |
| 607 | assert!( |
| 608 | unlisted.is_empty(), |
| 609 | "no {depth} gate spells an on-value for {unlisted:?}, so no real {depth} stream is \ |
| 610 | proven to carry them -- switch the tool on in a {depth} gate that asserts it fired, \ |
| 611 | or list it with a reason" |
| 612 | ); |
| 613 | let stale: Vec<&&str> = listed.difference(&derived).collect(); |
| 614 | assert!( |
| 615 | stale.is_empty(), |
| 616 | "the {depth} default-on list still names {stale:?}, but a {depth} gate now switches \ |
| 617 | them on -- delete those entries, the coverage hole is closed" |
| 618 | ); |
| 619 | } |
| 620 | |
| 621 | #[test] |
| 622 | fn never_on_8bit_matches_the_gate_recipes() { |
| 623 | check_default_on(false, NEVER_ON_8BIT); |
| 624 | } |
| 625 | |
| 626 | #[test] |
| 627 | fn never_on_10bit_matches_the_gate_recipes() { |
| 628 | check_default_on(true, NEVER_ON_10BIT); |
| 629 | } |
| 630 | |
| 631 | |
| 632 | |
| 633 | #[test] |
| 634 | fn default_on_tools_do_not_duplicate_the_universe() { |
| 635 | for &(tool, spellings, _, _) in DEFAULT_ON_TOOLS { |
| 636 | assert!( |
| 637 | !TOOL_UNIVERSE.contains(&tool), |
| 638 | "{tool} is already covered by TOOL_UNIVERSE" |
| 639 | ); |
| 640 | assert!(!spellings.is_empty(), "{tool} has no aomenc spelling"); |
| 641 | } |
| 642 | for (alias, tool) in ALIASES { |
| 643 | assert!( |
| 644 | TOOL_UNIVERSE.contains(tool), |
| 645 | "alias --{alias} names {tool}, which is not a TOOL_UNIVERSE tool" |
| 646 | ); |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | |
| 651 | |
| 652 | #[test] |
| 653 | fn print_never_on_per_bit_depth() { |
| 654 | for (label, ten_bit) in [("8BIT", false), ("10BIT", true)] { |
| 655 | let (gate_count, per_tool) = default_on_settings(ten_bit); |
| 656 | let holes = never_on_at(ten_bit); |
| 657 | println!( |
| 658 | "NEVER_ON_{label} ({} of {}, over {gate_count} {label} gates):", |
| 659 | holes.len(), |
| 660 | DEFAULT_ON_TOOLS.len() |
| 661 | ); |
| 662 | for tool in &holes { |
| 663 | let (off, _, defaulted) = per_tool[tool]; |
| 664 | let spellings = DEFAULT_ON_TOOLS |
| 665 | .iter() |
| 666 | .find(|e| e.0 == *tool) |
| 667 | .map(|e| e.1.join(",")) |
| 668 | .unwrap_or_default(); |
| 669 | println!( |
| 670 | " {tool} (--{spellings}): off in {off}, defaulted in {defaulted}, on in 0" |
| 671 | ); |
| 672 | } |
| 673 | } |
| 674 | } |
| 675 | } |