From ef6b6ee6b85fe5155da09b54b262b6944f26f4b5 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Tue, 26 Mar 2024 22:21:26 -0400 Subject: [PATCH] WIP: feat: add `update-backlog` subcmd. --- moz-webgpu-cts/src/main.rs | 105 +++++++++++++++++++++++++++++++++++ moz-webgpu-cts/src/shared.rs | 26 +++++++++ 2 files changed, 131 insertions(+) diff --git a/moz-webgpu-cts/src/main.rs b/moz-webgpu-cts/src/main.rs index 01eef5b..2f28207 100644 --- a/moz-webgpu-cts/src/main.rs +++ b/moz-webgpu-cts/src/main.rs @@ -96,6 +96,7 @@ enum Subcommand { #[clap(value_enum, long, default_value_t = Default::default())] on_zero_item: OnZeroItem, }, + MarkBacklog, } #[derive(Clone, Copy, Debug, ValueEnum)] @@ -1411,6 +1412,110 @@ fn run(cli: Cli) -> ExitCode { println!("Full analysis: {analysis:#?}"); ExitCode::SUCCESS } + Subcommand::MarkBacklog => { + let tests_by_name = { + let mut found_parse_err = false; + let raw_test_files_by_path = match read_metadata() { + Ok(paths) => paths, + Err(AlreadyReportedToCommandline) => return ExitCode::FAILURE, + }; + let extracted = raw_test_files_by_path + .iter() + .filter_map(|(path, file_contents)| { + match chumsky::Parser::parse(&metadata::File::parser(), file_contents) + .into_result() + { + Ok(File { + properties: _, + tests, + }) => Some(tests.into_iter().map({ + let gecko_checkout = &gecko_checkout; + move |(name, test)| { + let SectionHeader(name) = &name; + let test_path = TestPath::from_fx_metadata_test( + path.strip_prefix(gecko_checkout).unwrap(), + name, + ) + .unwrap(); + (test_path.into_owned(), test) + } + })), + Err(errors) => { + found_parse_err = true; + render_metadata_parse_errors(path, file_contents, errors); + None + } + } + }) + .flatten() + .collect::>(); + if found_parse_err { + log::error!(concat!( + "found one or more failures while parsing metadata, ", + "see above for more details" + )); + return ExitCode::FAILURE; + } + extracted + }; + + #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] + enum Case { + #[default] + PermaPass, + PermaFail, + Other, + } + println!("file\ttest\tsubtest"); + for (test_path, test) in tests_by_name.iter() { + let Test { + properties, + subtests, + } = test; + if subtests.is_empty() { + let prop = properties + .expectations + .as_ref() + .map(|exps| { + exps.map_ref(|exps| match exps.as_permanent() { + Some(TestOutcome::Ok) => Case::PermaPass, + _ => Case::Other, + }) + }) + .unwrap_or_default(); + if prop == Default::default() { + println!( + "{}\t{}\t", + test_path.rel_metadata_path_fx(), + test_path.test_name() + ); + } + } else { + for (subtest_name, subtest) in subtests { + let Subtest { properties } = subtest; + let prop = properties + .expectations + .as_ref() + .map(|exps| { + exps.map_ref(|exps| match exps.as_permanent() { + Some(SubtestOutcome::Pass) => Case::PermaPass, + Some(SubtestOutcome::Fail) => Case::PermaFail, + _ => Case::Other, + }) + }) + .unwrap_or_default(); + if prop == Default::default() { + println!( + "{}\t{}\t{subtest_name:?}", + test_path.rel_metadata_path_fx(), + test_path.test_name(), + ); + } + } + } + } + ExitCode::SUCCESS + } } } diff --git a/moz-webgpu-cts/src/shared.rs b/moz-webgpu-cts/src/shared.rs index 9e213f9..d60c62f 100644 --- a/moz-webgpu-cts/src/shared.rs +++ b/moz-webgpu-cts/src/shared.rs @@ -213,6 +213,22 @@ impl MaybeCollapsed> { MaybeCollapsed::Expanded(exp) => exp.get(key), } } + + fn map_ref_normalized(&self, f: F) -> MaybeCollapsed> + where + K: Clone + IntoEnumIterator + Ord, + T: Clone + Default + Eq, + F: FnMut(&V) -> T, + { + let mut f = f; + match self { + MaybeCollapsed::Collapsed(coll) => MaybeCollapsed::Collapsed(f(coll)), + MaybeCollapsed::Expanded(exp) => { + let new_values = exp.iter().map(|(k, v)| (k.clone(), f(v))).collect(); + normalize(new_values, std::convert::identity) + } + } + } } impl Default for MaybeCollapsed @@ -444,6 +460,16 @@ where .copied() .unwrap_or_default() } + + pub fn map_ref(&self, f: F) -> NormalizedPropertyValueData + where + T: Clone + Default + Eq, + F: FnMut(&Expectation) -> T, + { + let mut f = f; + self.inner() + .map_ref_normalized(|exps| exps.map_ref_normalized(|exps| f(exps))) + } } fn normalize(mut map: BTreeMap, mut f: F) -> MaybeCollapsed>