From 824f34b68e37e8845bb6e9ade4e24ed0efa2110d Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Fri, 4 Dec 2026 13:44:05 -0800 Subject: [PATCH] Validation tests: command-replay refuses an option given twice, and compare-dumps an option it does not take (red) command-replay's options() refuses an option a subcommand does not take (62e9d045c3), but an option given twice still goes into its map in silence, the last value winning: `play ... --until-frame 3 --until-frame 5` plays to frame 5. A script that splices options from its environment after its own (`--until-frame X ${PLAY_ARGS}`) would play the splice's value with nothing to say so. A repeated option should be a bad command line instead. replay_options::every_subcommand_refuses_an_option_given_twice runs each of the six subcommands with one option given twice, required or not (play --until-frame, dump --stream, shapes --blobs, snippet video-surfaces --handle, compare-dumps --a, compare-plays --frame), and expects exit status 2, a standard error line "--X is given twice", no play report and no snippet written. Red here: dump, shapes and the snippet run to exit 0, and play writes its report. every_subcommand_refuses_an_option_it_does_not_take now runs compare-dumps too (--frame), the one subcommand it left out. It passes here, as the refusal is in place; its red is a negative control, the fix's commit names it. The two tests share their setup and their checks. --- .../tests/integration/replay_options.rs | 257 ++++++++++++------ 1 file changed, 178 insertions(+), 79 deletions(-) diff --git a/crates/metal2vulkan-validation/tests/integration/replay_options.rs b/crates/metal2vulkan-validation/tests/integration/replay_options.rs index 651b4de18..cb056a0c8 100644 --- a/crates/metal2vulkan-validation/tests/integration/replay_options.rs +++ b/crates/metal2vulkan-validation/tests/integration/replay_options.rs @@ -1,100 +1,199 @@ -//! Every `command-replay` subcommand refuses an option it does not take: the command line is bad, -//! the exit status is 2 and nothing runs, so a mistyped or retired option never plays as if it -//! were absent (`docs/REPLAY-STREAM.md`, section 10). +//! Every `command-replay` subcommand refuses an option it does not take, and an option given +//! twice: the command line is bad, the exit status is 2 and nothing runs, so a mistyped, retired +//! or repeated option never plays as if it were absent or as its last value +//! (`docs/REPLAY-STREAM.md`, section 10). use metal2vulkan_validation::replay::StreamWriter; use metal2vulkan_validation::ScratchDir; use std::fs::File; +use std::path::Path; use std::process::Command; -/// Each subcommand with the options it requires, plus one it does not take: the exit status is -/// 2, the standard error names the option, and `play` writes no report. -#[test] -fn every_subcommand_refuses_an_option_it_does_not_take() { - let dir = ScratchDir::new("replay-options").unwrap(); - let stream = dir.path().join("s.0000.m2vr"); +/// The paths a run names, under `dir`: a stream of one commit, a play's out directory, a shader +/// cache and a snippet's out directory. +struct Paths { + stream: String, + out: String, + cache: String, + snippet: String, +} + +fn paths(dir: &Path) -> Paths { + let stream = dir.join("s.0000.m2vr"); let mut writer = StreamWriter::new(File::create(&stream).unwrap()).unwrap(); writer.call("commit", 1, 0, &[], &[]).unwrap(); writer.finish().unwrap(); - let stream = stream.to_str().unwrap().to_owned(); - let out = dir.path().join("out"); - let out = out.to_str().unwrap().to_owned(); - let cache = dir.path().join("cache"); - let cache = cache.to_str().unwrap().to_owned(); - let snippet = dir.path().join("snippet"); - let snippet = snippet.to_str().unwrap().to_owned(); - let runs: [(&str, &str, Vec<&str>); 5] = [ - ( - "play", - "--name", - vec![ - "play", - "--stream", - &stream, - "--out", - &out, - "--device-type", - "none", - "--shader-cache", - &cache, - "--name", - "run", - ], - ), - ( - "dump", - "--frame", - vec!["dump", "--stream", &stream, "--frame", "3"], - ), - ( - "shapes", - "--until-frame", - vec!["shapes", "--stream", &stream, "--until-frame", "3"], - ), - ( - "snippet video-surfaces", - "--stream", - vec![ - "snippet", - "video-surfaces", - "--out", - &snippet, - "--stream", - &stream, - ], - ), - ( - "compare-plays", - "--until-frame", - vec![ - "compare-plays", - "--a", - &out, - "--b", - &out, - "--until-frame", - "3", - ], - ), - ]; - for (command, option, args) in runs { + fn named(path: &Path) -> String { + path.to_str().unwrap().to_owned() + } + Paths { + stream: named(&stream), + out: named(&dir.join("out")), + cache: named(&dir.join("cache")), + snippet: named(&dir.join("snippet")), + } +} + +/// Each run of `runs` exits 2 with a standard error line naming its refusal, `play` writes no +/// report under `dir` and the snippet is not written. +fn refused(dir: &Path, runs: Vec<(String, Vec<&str>)>) { + for (refusal, args) in runs { let ran = Command::new(bin_exe!("command-replay")) .args(&args) .output() .unwrap(); let stderr = String::from_utf8_lossy(&ran.stderr); assert_eq!(ran.status.code(), Some(2), "{args:?}: {stderr}"); - assert!( - stderr.contains(&format!("{option} is not an option of {command}")), - "{args:?}: {stderr}" - ); + assert!(stderr.contains(&refusal), "{args:?}: {stderr}"); } assert!( - !dir.path().join("out").join("report.txt").exists(), - "a play with an option it does not take began" + !dir.join("out").join("report.txt").exists(), + "a refused play began" ); assert!( - !dir.path().join("snippet").exists(), - "a snippet with an option it does not take was written" + !dir.join("snippet").exists(), + "a refused snippet was written" ); } + +/// Each subcommand with the options it requires, plus one it does not take: the standard error +/// names the option. +#[test] +fn every_subcommand_refuses_an_option_it_does_not_take() { + let dir = ScratchDir::new("replay-options").unwrap(); + let p = paths(dir.path()); + let not = |option: &str, command: &str| format!("{option} is not an option of {command}"); + let runs = vec![ + ( + not("--name", "play"), + vec![ + "play", + "--stream", + &p.stream, + "--out", + &p.out, + "--device-type", + "none", + "--shader-cache", + &p.cache, + "--name", + "run", + ], + ), + ( + not("--frame", "dump"), + vec!["dump", "--stream", &p.stream, "--frame", "3"], + ), + ( + not("--until-frame", "shapes"), + vec!["shapes", "--stream", &p.stream, "--until-frame", "3"], + ), + ( + not("--stream", "snippet video-surfaces"), + vec![ + "snippet", + "video-surfaces", + "--out", + &p.snippet, + "--stream", + &p.stream, + ], + ), + ( + not("--frame", "compare-dumps"), + vec![ + "compare-dumps", + "--a", + &p.out, + "--b", + &p.out, + "--frame", + "3", + ], + ), + ( + not("--until-frame", "compare-plays"), + vec![ + "compare-plays", + "--a", + &p.out, + "--b", + &p.out, + "--until-frame", + "3", + ], + ), + ]; + refused(dir.path(), runs); +} + +/// Each subcommand with one option, required or not, given twice: the standard error names the +/// option, and neither value is taken. +#[test] +fn every_subcommand_refuses_an_option_given_twice() { + let dir = ScratchDir::new("replay-options-twice").unwrap(); + let p = paths(dir.path()); + let twice = |option: &str| format!("{option} is given twice"); + let runs = vec![ + ( + twice("--until-frame"), + vec![ + "play", + "--stream", + &p.stream, + "--out", + &p.out, + "--device-type", + "none", + "--shader-cache", + &p.cache, + "--until-frame", + "3", + "--until-frame", + "5", + ], + ), + ( + twice("--stream"), + vec!["dump", "--stream", &p.stream, "--stream", &p.stream], + ), + ( + twice("--blobs"), + vec![ + "shapes", "--stream", &p.stream, "--blobs", &p.cache, "--blobs", &p.cache, + ], + ), + ( + twice("--handle"), + vec![ + "snippet", + "video-surfaces", + "--out", + &p.snippet, + "--handle", + "opaque-fd", + "--handle", + "dma-buf", + ], + ), + ( + twice("--a"), + vec!["compare-dumps", "--a", &p.out, "--b", &p.out, "--a", &p.out], + ), + ( + twice("--frame"), + vec![ + "compare-plays", + "--a", + &p.out, + "--b", + &p.out, + "--frame", + "3", + "--frame", + "4", + ], + ), + ]; + refused(dir.path(), runs); +}