Validation player: command-replay refuses an option a subcommand does not take
Each subcommand names the options it takes beside its required ones, and options() refuses any other with "--NAME is not an option of SUBCOMMAND" before anything runs: exit status 2, the usage printed, as for any bad command line. Before, an unknown --name VALUE pair went into the map and was never read, so a mistyped or retired option played as if absent. The sets are what each subcommand reads: play its four required options and blobs, managed, until-frame, past-range, states-only, state-log, state-threads, state-keys, state-digests, gpu-wait-timeout (the wait module's flag), video-handle, check-presents, read-device-copies, prepass-width, dump-command-buffers and dump-dir; dump and shapes --stream and --blobs (their stream reader reads it; the usage and the module doc now show it); compare-dumps --a and --b; compare-plays --a, --b and --frame; snippet video-surfaces --out and --handle. The module doc and docs/REPLAY-STREAM.md section 10 say so. The audit in the red commit's message found no caller passing an option outside these sets except --probe-dump in two lab probe scripts of one carry, which no commit here ever read. Verified by the job named in the lane's report: the red test at the parent and green here, clippy x3, rustdoc, the validation suite.
This commit is contained in:
1 parent
34d0a859ee
commit
62e9d045c3
2 files changed
+67
-16
No files matched your search
@@ -114,8 +114,8 @@
|
||||
//! read different copies of, then a summary ending `agree` or `DIFFER`. The exit status is 0 where they agree, 1 where they differ, 2 for a bad
|
||||
//! command line or an unreadable dump.
|
||||
//!
|
||||
//! `command-replay dump --stream FILE` prints each call record as a line (a blob as its hash),
|
||||
//! then `cut SEGMENT OFFSET` where the last segment ends in a record cut short.
|
||||
//! `command-replay dump --stream FILE [--blobs DIR]` prints each call record as a line (a blob as
|
||||
//! its hash), then `cut SEGMENT OFFSET` where the last segment ends in a record cut short.
|
||||
//!
|
||||
//! `command-replay snippet video-surfaces --out DIR [--handle dma-buf|opaque-fd|opaque-win32]`
|
||||
//! writes the replay matrix's exported-surface snippet (`replay::video_surfaces`, a stream of our
|
||||
@@ -123,9 +123,12 @@
|
||||
//! (a dma-buf on a Unix host unless it says otherwise, an NT handle on a Windows host). The exit
|
||||
//! status is 0 where it was written, 2 for a bad command line or a failed write.
|
||||
//!
|
||||
//! `command-replay shapes --stream FILE` prints, for each selector, how many calls had each shape
|
||||
//! of arguments and answers (`Value::shape`: kinds and map keys, no data), most first: what a
|
||||
//! stream asks of a player without what it holds.
|
||||
//! `command-replay shapes --stream FILE [--blobs DIR]` prints, for each selector, how many calls
|
||||
//! had each shape of arguments and answers (`Value::shape`: kinds and map keys, no data), most
|
||||
//! first: what a stream asks of a player without what it holds.
|
||||
//!
|
||||
//! Every subcommand takes the options shown for it and no other: an option it does not take is a
|
||||
//! bad command line (`--NAME is not an option of SUBCOMMAND`, exit status 2), and nothing runs.
|
||||
//!
|
||||
//! GUEST DATA: a stream recorded from a guest, its blobs and the reports are the consumer's: they
|
||||
//! stay on the hosts the guest data rule allows and are never committed.
|
||||
@@ -155,23 +158,57 @@ const USAGE: &str = "usage: command-replay play --stream FILE --out DIR --device
|
||||
command-replay compare-dumps --a DIR --b DIR\n \
|
||||
command-replay compare-plays --a REPORT --b REPORT [--frame F]\n \
|
||||
command-replay dump \
|
||||
--stream FILE\n command-replay shapes --stream FILE\n \
|
||||
--stream FILE [--blobs DIR]\n \
|
||||
command-replay shapes --stream FILE [--blobs DIR]\n \
|
||||
command-replay snippet video-surfaces --out DIR \
|
||||
[--handle dma-buf|opaque-fd|opaque-win32]";
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = std::env::args().skip(1).collect();
|
||||
let wait = WAIT_TIMEOUT_FLAG.trim_start_matches("--");
|
||||
let play_options = [
|
||||
"blobs",
|
||||
"managed",
|
||||
"until-frame",
|
||||
"past-range",
|
||||
"states-only",
|
||||
"state-log",
|
||||
"state-threads",
|
||||
"state-keys",
|
||||
"state-digests",
|
||||
wait,
|
||||
"video-handle",
|
||||
"check-presents",
|
||||
"read-device-copies",
|
||||
"prepass-width",
|
||||
"dump-command-buffers",
|
||||
"dump-dir",
|
||||
];
|
||||
let code = match args.first().map(String::as_str) {
|
||||
Some("play") => {
|
||||
let required = ["stream", "out", "device-type", "shader-cache"];
|
||||
with_options(&args[1..], &required, play)
|
||||
with_options("play", &args[1..], &required, &play_options, play)
|
||||
}
|
||||
Some("dump") => with_options(&args[1..], &["stream"], dump),
|
||||
Some("compare-dumps") => with_options(&args[1..], &["a", "b"], compare),
|
||||
Some("compare-plays") => with_options(&args[1..], &["a", "b"], compare_two_plays),
|
||||
Some("shapes") => with_options(&args[1..], &["stream"], shapes),
|
||||
Some("dump") => with_options("dump", &args[1..], &["stream"], &["blobs"], dump),
|
||||
Some("compare-dumps") => {
|
||||
with_options("compare-dumps", &args[1..], &["a", "b"], &[], compare)
|
||||
}
|
||||
Some("compare-plays") => with_options(
|
||||
"compare-plays",
|
||||
&args[1..],
|
||||
&["a", "b"],
|
||||
&["frame"],
|
||||
compare_two_plays,
|
||||
),
|
||||
Some("shapes") => with_options("shapes", &args[1..], &["stream"], &["blobs"], shapes),
|
||||
Some("snippet") if args.get(1).map(String::as_str) == Some("video-surfaces") => {
|
||||
with_options(&args[2..], &["out"], write_video_surfaces)
|
||||
with_options(
|
||||
"snippet video-surfaces",
|
||||
&args[2..],
|
||||
&["out"],
|
||||
&["handle"],
|
||||
write_video_surfaces,
|
||||
)
|
||||
}
|
||||
_ => {
|
||||
eprintln!("{USAGE}");
|
||||
@@ -181,13 +218,17 @@ fn main() {
|
||||
std::process::exit(code);
|
||||
}
|
||||
|
||||
/// `run` on the options `args` give, or 2 where they lack one of `required`.
|
||||
/// `run` on the options `args` give, or 2 where they lack one of `required` or name one that is
|
||||
/// neither required nor `optional`: an option `command` does not take is a bad command line, never
|
||||
/// passed over.
|
||||
fn with_options(
|
||||
command: &str,
|
||||
args: &[String],
|
||||
required: &[&str],
|
||||
optional: &[&str],
|
||||
run: fn(&BTreeMap<String, String>) -> i32,
|
||||
) -> i32 {
|
||||
match options(args, required) {
|
||||
match options(command, args, required, optional) {
|
||||
Ok(options) => run(&options),
|
||||
Err(why) => {
|
||||
eprintln!("command-replay: {why}\n{USAGE}");
|
||||
@@ -196,13 +237,21 @@ fn with_options(
|
||||
}
|
||||
}
|
||||
|
||||
fn options(args: &[String], required: &[&str]) -> Result<BTreeMap<String, String>, String> {
|
||||
fn options(
|
||||
command: &str,
|
||||
args: &[String],
|
||||
required: &[&str],
|
||||
optional: &[&str],
|
||||
) -> Result<BTreeMap<String, String>, String> {
|
||||
let mut out = BTreeMap::new();
|
||||
let mut it = args.iter();
|
||||
while let Some(flag) = it.next() {
|
||||
let name = flag
|
||||
.strip_prefix("--")
|
||||
.ok_or_else(|| format!("unexpected {flag:?}"))?;
|
||||
if !required.contains(&name) && !optional.contains(&name) {
|
||||
return Err(format!("{flag} is not an option of {command}"));
|
||||
}
|
||||
let value = it.next().ok_or_else(|| format!("{flag} needs a value"))?;
|
||||
out.insert(name.to_string(), value.clone());
|
||||
}
|
||||
|
||||
@@ -1332,7 +1332,9 @@ the matrix's own record, so the matrix's rule (`scripts/matrix/results.py`) fail
|
||||
gauge is not 0 at device drop. Such a gauge, or a device that did not quiesce within 30 seconds,
|
||||
also writes `error teardown: WHAT`. The exit status is 0 for `ok`, 1 for a run that stopped or an `ok` followed
|
||||
by `error teardown`, 2 for a harness failure (a bad command line or an unreadable stream) and 3
|
||||
for `ids`, a run that played to the end.
|
||||
for `ids`, a run that played to the end. Each of `command-replay`'s subcommands takes the options
|
||||
its usage names and no other: an option it does not take is a bad command line, `--NAME is not an
|
||||
option of SUBCOMMAND`, and nothing runs.
|
||||
|
||||
With `--dump-command-buffers LIST --dump-dir DIR`, the player also writes, once each command
|
||||
buffer whose stream id `LIST` holds completed (a split command buffer's parts by their own ids),
|
||||
|
||||
Reference in new issue
Block a user