From ffc44e8a6f68af0285da7ecc453c70a94ddaf996 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Fri, 10 May 2024 11:11:10 -0400 Subject: [PATCH 01/10] refactor: better names for `SCOPE_DIR_*` constants --- moz-webgpu-cts/src/shared.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/moz-webgpu-cts/src/shared.rs b/moz-webgpu-cts/src/shared.rs index eaf5f030..1af7d309 100644 --- a/moz-webgpu-cts/src/shared.rs +++ b/moz-webgpu-cts/src/shared.rs @@ -435,12 +435,12 @@ pub(crate) struct TestPath<'a> { pub variant: Option>, } -const SCOPE_DIR_FX_PRIVATE_STR: &str = "testing/web-platform/mozilla"; -const SCOPE_DIR_FX_PRIVATE_COMPONENTS: &[&str] = &["testing", "web-platform", "mozilla"]; -const SCOPE_DIR_FX_PUBLIC_STR: &str = "testing/web-platform"; -const SCOPE_DIR_FX_PUBLIC_COMPONENTS: &[&str] = &["testing", "web-platform"]; -const SCOPE_DIR_SERVO_PUBLIC_STR: &str = "tests/wpt/webgpu"; -const SCOPE_DIR_SERVO_PUBLIC_COMPONENTS: &[&str] = &["tests", "wpt", "webgpu"]; +const SCOPE_DIR_FX_MOZILLA_STR: &str = "testing/web-platform/mozilla"; +const SCOPE_DIR_FX_MOZILLA_COMPONENTS: &[&str] = &["testing", "web-platform", "mozilla"]; +const SCOPE_DIR_FX_UPSTREAM_STR: &str = "testing/web-platform"; +const SCOPE_DIR_FX_UPSTREAM_COMPONENTS: &[&str] = &["testing", "web-platform"]; +const SCOPE_DIR_SERVO_WEBGPU_STR: &str = "tests/wpt/webgpu"; +const SCOPE_DIR_SERVO_WEBGPU_COMPONENTS: &[&str] = &["tests", "wpt", "webgpu"]; impl<'a> TestPath<'a> { pub fn from_execution_report( @@ -511,8 +511,8 @@ impl<'a> TestPath<'a> { ); let (private_path, public_path) = match browser { - Browser::Firefox => (SCOPE_DIR_FX_PRIVATE_STR, SCOPE_DIR_FX_PUBLIC_STR), - Browser::Servo => (SCOPE_DIR_FX_PRIVATE_STR, SCOPE_DIR_SERVO_PUBLIC_STR), + Browser::Firefox => (SCOPE_DIR_FX_MOZILLA_STR, SCOPE_DIR_FX_UPSTREAM_STR), + Browser::Servo => (SCOPE_DIR_FX_MOZILLA_STR, SCOPE_DIR_SERVO_WEBGPU_STR), }; let (visibility, path) = if let Ok(path) = rel_meta_file_path.strip_prefix(private_path) { (TestVisibility::Private, path) @@ -621,9 +621,9 @@ impl<'a> TestPath<'a> { visibility, } = scope; let scope_dir = match (browser, visibility) { - (Browser::Firefox, TestVisibility::Public) => SCOPE_DIR_FX_PUBLIC_COMPONENTS, - (Browser::Firefox, TestVisibility::Private) => SCOPE_DIR_FX_PRIVATE_COMPONENTS, - (Browser::Servo, TestVisibility::Public) => SCOPE_DIR_SERVO_PUBLIC_COMPONENTS, + (Browser::Firefox, TestVisibility::Public) => SCOPE_DIR_FX_UPSTREAM_COMPONENTS, + (Browser::Firefox, TestVisibility::Private) => SCOPE_DIR_FX_MOZILLA_COMPONENTS, + (Browser::Servo, TestVisibility::Public) => SCOPE_DIR_SERVO_WEBGPU_COMPONENTS, (Browser::Servo, TestVisibility::Private) => todo!(), } .iter() From 8b351853d05eb916f6c326044966a02066df7013 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Fri, 10 May 2024 11:15:05 -0400 Subject: [PATCH 02/10] refactor: s/try_strip_with/strip_prefix --- moz-webgpu-cts/src/shared.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/moz-webgpu-cts/src/shared.rs b/moz-webgpu-cts/src/shared.rs index 1af7d309..958e34b2 100644 --- a/moz-webgpu-cts/src/shared.rs +++ b/moz-webgpu-cts/src/shared.rs @@ -449,16 +449,16 @@ impl<'a> TestPath<'a> { ) -> Result> { let err = || ExecutionReportPathError { test_url_path }; - let try_strip_with = |prefix, visibility| { + let strip_prefix = |prefix, visibility| { test_url_path .strip_prefix(prefix) .map(|stripped| (visibility, stripped)) }; let vis_and_path = match browser { - Browser::Firefox => try_strip_with("/_mozilla/", TestVisibility::Private), - Browser::Servo => try_strip_with("/_webgpu/", TestVisibility::Public), + Browser::Firefox => strip_prefix("/_mozilla/", TestVisibility::Private), + Browser::Servo => strip_prefix("/_webgpu/", TestVisibility::Public), } - .or_else(|| try_strip_with("/", TestVisibility::Public)); + .or_else(|| strip_prefix("/", TestVisibility::Public)); let Some((visibility, path)) = vis_and_path else { return Err(err()); }; From a5d6e9a5d1b354ab5fa3cbcde84ef0ec89f35dbe Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Fri, 10 May 2024 11:16:18 -0400 Subject: [PATCH 03/10] refactor: `TestPath::from_execution_reports`: Option::ok_or_else` instead of `let-else` --- moz-webgpu-cts/src/shared.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/moz-webgpu-cts/src/shared.rs b/moz-webgpu-cts/src/shared.rs index 958e34b2..2fff32f2 100644 --- a/moz-webgpu-cts/src/shared.rs +++ b/moz-webgpu-cts/src/shared.rs @@ -454,14 +454,12 @@ impl<'a> TestPath<'a> { .strip_prefix(prefix) .map(|stripped| (visibility, stripped)) }; - let vis_and_path = match browser { + let (visibility, path) = match browser { Browser::Firefox => strip_prefix("/_mozilla/", TestVisibility::Private), Browser::Servo => strip_prefix("/_webgpu/", TestVisibility::Public), } - .or_else(|| strip_prefix("/", TestVisibility::Public)); - let Some((visibility, path)) = vis_and_path else { - return Err(err()); - }; + .or_else(|| strip_prefix("/", TestVisibility::Public)) + .ok_or_else(err)?; let scope = TestScope { browser, visibility, From e02a9fd6f2f2676ef3893f4eb942916d7f1a0cca Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Fri, 10 May 2024 11:19:15 -0400 Subject: [PATCH 04/10] refactor: `TestPath::from_metadata_test`: `strip_prefix` helper --- moz-webgpu-cts/src/shared.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/moz-webgpu-cts/src/shared.rs b/moz-webgpu-cts/src/shared.rs index 2fff32f2..fb08a08d 100644 --- a/moz-webgpu-cts/src/shared.rs +++ b/moz-webgpu-cts/src/shared.rs @@ -508,17 +508,18 @@ impl<'a> TestPath<'a> { .ok_or(err())?, ); + let strip_prefix = |prefix, visibility| { + rel_meta_file_path + .strip_prefix(prefix) + .map(|stripped| (visibility, stripped)) + }; let (private_path, public_path) = match browser { Browser::Firefox => (SCOPE_DIR_FX_MOZILLA_STR, SCOPE_DIR_FX_UPSTREAM_STR), Browser::Servo => (SCOPE_DIR_FX_MOZILLA_STR, SCOPE_DIR_SERVO_WEBGPU_STR), }; - let (visibility, path) = if let Ok(path) = rel_meta_file_path.strip_prefix(private_path) { - (TestVisibility::Private, path) - } else if let Ok(path) = rel_meta_file_path.strip_prefix(public_path) { - (TestVisibility::Public, path) - } else { - return Err(err()); - }; + let (visibility, path) = strip_prefix(private_path, TestVisibility::Private) + .or_else(|_| strip_prefix(public_path, TestVisibility::Public)) + .map_err(|_e| err())?; let scope = TestScope { browser, visibility, From fe825bd12445393babc677bd06b9be24d505f418 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Fri, 10 May 2024 11:21:43 -0400 Subject: [PATCH 05/10] refactor: remove unnecessary `Utf8Path::new` --- moz-webgpu-cts/src/shared.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moz-webgpu-cts/src/shared.rs b/moz-webgpu-cts/src/shared.rs index fb08a08d..aebcbf4a 100644 --- a/moz-webgpu-cts/src/shared.rs +++ b/moz-webgpu-cts/src/shared.rs @@ -537,7 +537,7 @@ impl<'a> TestPath<'a> { Ok(Self { scope, - path: Utf8Path::new(path).into(), + path: path.into(), variant: variant.map(Into::into), }) } From 2497cb937615976468201775f767511c8f80b574 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Fri, 10 May 2024 11:28:03 -0400 Subject: [PATCH 06/10] refactor: rework `TestScope` to match Servo's usage --- moz-webgpu-cts/src/shared.rs | 120 +++++++++++++++++------------------ 1 file changed, 59 insertions(+), 61 deletions(-) diff --git a/moz-webgpu-cts/src/shared.rs b/moz-webgpu-cts/src/shared.rs index aebcbf4a..8dae8a41 100644 --- a/moz-webgpu-cts/src/shared.rs +++ b/moz-webgpu-cts/src/shared.rs @@ -449,21 +449,17 @@ impl<'a> TestPath<'a> { ) -> Result> { let err = || ExecutionReportPathError { test_url_path }; - let strip_prefix = |prefix, visibility| { + let strip_prefix = |prefix, scope| { test_url_path .strip_prefix(prefix) - .map(|stripped| (visibility, stripped)) + .map(|stripped| (scope, stripped)) }; - let (visibility, path) = match browser { - Browser::Firefox => strip_prefix("/_mozilla/", TestVisibility::Private), - Browser::Servo => strip_prefix("/_webgpu/", TestVisibility::Public), + let (scope, path) = match browser { + Browser::Firefox => strip_prefix("/_mozilla/", FirefoxTestScope::Mozilla.into()) + .or_else(|| strip_prefix("/", FirefoxTestScope::Upstream.into())), + Browser::Servo => strip_prefix("/_webgpu/", ServoTestScope::WebGpu.into()), } - .or_else(|| strip_prefix("/", TestVisibility::Public)) .ok_or_else(err)?; - let scope = TestScope { - browser, - visibility, - }; if path.contains('\\') { return Err(err()); @@ -508,22 +504,22 @@ impl<'a> TestPath<'a> { .ok_or(err())?, ); - let strip_prefix = |prefix, visibility| { + let strip_prefix = |prefix, scope| { rel_meta_file_path .strip_prefix(prefix) - .map(|stripped| (visibility, stripped)) - }; - let (private_path, public_path) = match browser { - Browser::Firefox => (SCOPE_DIR_FX_MOZILLA_STR, SCOPE_DIR_FX_UPSTREAM_STR), - Browser::Servo => (SCOPE_DIR_FX_MOZILLA_STR, SCOPE_DIR_SERVO_WEBGPU_STR), - }; - let (visibility, path) = strip_prefix(private_path, TestVisibility::Private) - .or_else(|_| strip_prefix(public_path, TestVisibility::Public)) - .map_err(|_e| err())?; - let scope = TestScope { - browser, - visibility, + .map(|stripped| (scope, stripped)) }; + let (scope, path) = match browser { + Browser::Firefox => { + strip_prefix(SCOPE_DIR_FX_MOZILLA_STR, FirefoxTestScope::Mozilla.into()).or_else( + |_| strip_prefix(SCOPE_DIR_FX_UPSTREAM_STR, FirefoxTestScope::Upstream.into()), + ) + } + Browser::Servo => { + strip_prefix(SCOPE_DIR_SERVO_WEBGPU_STR, ServoTestScope::WebGpu.into()) + } + } + .map_err(|_e| err())?; let Ok(path) = path.strip_prefix("meta/") else { return Err(err()); @@ -590,15 +586,12 @@ impl<'a> TestPath<'a> { scope, } = self; lazy_format!(move |f| { - let TestScope { - browser, - visibility, - } = scope; - let scope_prefix = match (browser, visibility) { - (Browser::Firefox, TestVisibility::Public) => "", - (Browser::Firefox, TestVisibility::Private) => "_mozilla/", - (Browser::Servo, TestVisibility::Public) => "_webgpu/", - (Browser::Servo, TestVisibility::Private) => todo!(), + let scope_prefix = match scope { + TestScope::Firefox(scope) => match scope { + FirefoxTestScope::Upstream => "", + FirefoxTestScope::Mozilla => "_mozilla/", + }, + TestScope::Servo(ServoTestScope::WebGpu) => "_webgpu/", }; write!(f, "{scope_prefix}{}", path.components().join_with('/'))?; if let Some(variant) = variant.as_ref() { @@ -615,15 +608,12 @@ impl<'a> TestPath<'a> { scope, } = self; - let TestScope { - browser, - visibility, - } = scope; - let scope_dir = match (browser, visibility) { - (Browser::Firefox, TestVisibility::Public) => SCOPE_DIR_FX_UPSTREAM_COMPONENTS, - (Browser::Firefox, TestVisibility::Private) => SCOPE_DIR_FX_MOZILLA_COMPONENTS, - (Browser::Servo, TestVisibility::Public) => SCOPE_DIR_SERVO_WEBGPU_COMPONENTS, - (Browser::Servo, TestVisibility::Private) => todo!(), + let scope_dir = match scope { + TestScope::Firefox(scope) => match scope { + FirefoxTestScope::Upstream => SCOPE_DIR_FX_UPSTREAM_COMPONENTS, + FirefoxTestScope::Mozilla => SCOPE_DIR_FX_MOZILLA_COMPONENTS, + }, + TestScope::Servo(ServoTestScope::WebGpu) => SCOPE_DIR_SERVO_WEBGPU_COMPONENTS, } .iter() .chain(&["meta"]) @@ -678,22 +668,39 @@ pub(crate) enum Browser { Servo, } -#[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub(crate) enum TestVisibility { +#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +pub(crate) enum FirefoxTestScope { /// A public test available at some point in the history of [WPT upstream]. Note that while /// a test may be public, metadata associated with it is in a private location. /// /// [WPT upstream]: https://github.com/web-platform-tests/wpt - Public, - /// A private test specific to browser. - Private, + Upstream, + /// A private test specific to Firefox. + Mozilla, +} + +impl From for TestScope { + fn from(value: FirefoxTestScope) -> Self { + Self::Firefox(value) + } +} + +#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +pub(crate) enum ServoTestScope { + WebGpu, +} + +impl From for TestScope { + fn from(value: ServoTestScope) -> Self { + Self::Servo(value) + } } /// Symbolically represents a file root from which tests and metadata are based. #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub(crate) struct TestScope { - browser: Browser, - visibility: TestVisibility, +pub(crate) enum TestScope { + Firefox(FirefoxTestScope), + Servo(ServoTestScope), } #[test] @@ -706,10 +713,7 @@ fn parse_test_path() { ) .unwrap(), TestPath { - scope: TestScope { - browser: Browser::Firefox, - visibility: TestVisibility::Private - }, + scope: FirefoxTestScope::Mozilla.into(), path: Utf8Path::new("blarg/cts.https.html").into(), variant: Some("?stuff=things".into()), } @@ -723,10 +727,7 @@ fn parse_test_path() { ) .unwrap(), TestPath { - scope: TestScope { - browser: Browser::Firefox, - visibility: TestVisibility::Public - }, + scope: FirefoxTestScope::Upstream.into(), path: Utf8Path::new("stuff/things/cts.https.html").into(), variant: None, } @@ -740,10 +741,7 @@ fn parse_test_path() { ) .unwrap(), TestPath { - scope: TestScope { - browser: Browser::Servo, - visibility: TestVisibility::Public - }, + scope: ServoTestScope::WebGpu.into(), path: Utf8Path::new("webgpu/cts.https.html").into(), variant: Some("?stuff=things".into()), } From d815b74965caecbcc4cec1e85b844d194b1d8389 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Fri, 10 May 2024 11:31:08 -0400 Subject: [PATCH 07/10] refactor: move `TestScope` to be before subsets --- moz-webgpu-cts/src/shared.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/moz-webgpu-cts/src/shared.rs b/moz-webgpu-cts/src/shared.rs index 8dae8a41..66b6c3ff 100644 --- a/moz-webgpu-cts/src/shared.rs +++ b/moz-webgpu-cts/src/shared.rs @@ -668,6 +668,12 @@ pub(crate) enum Browser { Servo, } +#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +pub(crate) enum TestScope { + Firefox(FirefoxTestScope), + Servo(ServoTestScope), +} + #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub(crate) enum FirefoxTestScope { /// A public test available at some point in the history of [WPT upstream]. Note that while @@ -696,13 +702,6 @@ impl From for TestScope { } } -/// Symbolically represents a file root from which tests and metadata are based. -#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub(crate) enum TestScope { - Firefox(FirefoxTestScope), - Servo(ServoTestScope), -} - #[test] fn parse_test_path() { assert_eq!( From ed245bed61a61faeec17b085b1f200feb123ce39 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Fri, 10 May 2024 11:31:31 -0400 Subject: [PATCH 08/10] docs: document `TestScope` APIs --- moz-webgpu-cts/src/shared.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/moz-webgpu-cts/src/shared.rs b/moz-webgpu-cts/src/shared.rs index 66b6c3ff..7e67b9ed 100644 --- a/moz-webgpu-cts/src/shared.rs +++ b/moz-webgpu-cts/src/shared.rs @@ -662,18 +662,22 @@ impl Display for MetadataTestPathError<'_> { } } +/// A browser supported by [super::main], used for [`TestPath`]s. #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, ValueEnum)] pub(crate) enum Browser { Firefox, Servo, } +/// Symbolically represents a file root from which tests and metadata are based. Scopes are based +/// on a specific [`Browser`]. #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub(crate) enum TestScope { Firefox(FirefoxTestScope), Servo(ServoTestScope), } +/// Subset of [`TestScope`] for [`Browser::Firefox`]. #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub(crate) enum FirefoxTestScope { /// A public test available at some point in the history of [WPT upstream]. Note that while @@ -691,8 +695,10 @@ impl From for TestScope { } } +/// Subset of [`TestScope`] for [`Browser::Servo`]. #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub(crate) enum ServoTestScope { + /// A WebGPU CTS test vendored into Servo's source tree. WebGpu, } From 293f7a4b1c2032edc175344a8b37e2ec615c6c97 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Fri, 10 May 2024 12:01:17 -0400 Subject: [PATCH 09/10] refactor: move `Browser` and `TestScope` matching to methods --- moz-webgpu-cts/src/shared.rs | 125 ++++++++++++++++++++++------------- 1 file changed, 80 insertions(+), 45 deletions(-) diff --git a/moz-webgpu-cts/src/shared.rs b/moz-webgpu-cts/src/shared.rs index 7e67b9ed..59366668 100644 --- a/moz-webgpu-cts/src/shared.rs +++ b/moz-webgpu-cts/src/shared.rs @@ -449,17 +449,9 @@ impl<'a> TestPath<'a> { ) -> Result> { let err = || ExecutionReportPathError { test_url_path }; - let strip_prefix = |prefix, scope| { - test_url_path - .strip_prefix(prefix) - .map(|stripped| (scope, stripped)) - }; - let (scope, path) = match browser { - Browser::Firefox => strip_prefix("/_mozilla/", FirefoxTestScope::Mozilla.into()) - .or_else(|| strip_prefix("/", FirefoxTestScope::Upstream.into())), - Browser::Servo => strip_prefix("/_webgpu/", ServoTestScope::WebGpu.into()), - } - .ok_or_else(err)?; + let (scope, path) = browser + .strip_scope_url_prefix(test_url_path) + .ok_or_else(err)?; if path.contains('\\') { return Err(err()); @@ -504,22 +496,9 @@ impl<'a> TestPath<'a> { .ok_or(err())?, ); - let strip_prefix = |prefix, scope| { - rel_meta_file_path - .strip_prefix(prefix) - .map(|stripped| (scope, stripped)) - }; - let (scope, path) = match browser { - Browser::Firefox => { - strip_prefix(SCOPE_DIR_FX_MOZILLA_STR, FirefoxTestScope::Mozilla.into()).or_else( - |_| strip_prefix(SCOPE_DIR_FX_UPSTREAM_STR, FirefoxTestScope::Upstream.into()), - ) - } - Browser::Servo => { - strip_prefix(SCOPE_DIR_SERVO_WEBGPU_STR, ServoTestScope::WebGpu.into()) - } - } - .map_err(|_e| err())?; + let (scope, path) = browser + .strip_scope_metadata_parent_path(rel_meta_file_path) + .map_err(|_e| err())?; let Ok(path) = path.strip_prefix("meta/") else { return Err(err()); @@ -586,14 +565,12 @@ impl<'a> TestPath<'a> { scope, } = self; lazy_format!(move |f| { - let scope_prefix = match scope { - TestScope::Firefox(scope) => match scope { - FirefoxTestScope::Upstream => "", - FirefoxTestScope::Mozilla => "_mozilla/", - }, - TestScope::Servo(ServoTestScope::WebGpu) => "_webgpu/", - }; - write!(f, "{scope_prefix}{}", path.components().join_with('/'))?; + write!( + f, + "{}{}", + scope.url_prefix(), + path.components().join_with('/') + )?; if let Some(variant) = variant.as_ref() { write!(f, "{}", variant)?; } @@ -608,16 +585,10 @@ impl<'a> TestPath<'a> { scope, } = self; - let scope_dir = match scope { - TestScope::Firefox(scope) => match scope { - FirefoxTestScope::Upstream => SCOPE_DIR_FX_UPSTREAM_COMPONENTS, - FirefoxTestScope::Mozilla => SCOPE_DIR_FX_MOZILLA_COMPONENTS, - }, - TestScope::Servo(ServoTestScope::WebGpu) => SCOPE_DIR_SERVO_WEBGPU_COMPONENTS, - } - .iter() - .chain(&["meta"]) - .join_with(std::path::MAIN_SEPARATOR); + let scope_dir = scope + .metadata_parent_path_components() + .chain(["meta"].iter().cloned()) + .join_with(std::path::MAIN_SEPARATOR); lazy_format!(move |f| { write!(f, "{scope_dir}{}{path}.ini", std::path::MAIN_SEPARATOR) }) } @@ -669,6 +640,44 @@ pub(crate) enum Browser { Servo, } +impl Browser { + /// NOTE: Keep this implementation in sync with [`TestScope::url_prefix`]. + pub(crate) fn strip_scope_url_prefix<'a>( + &self, + url_path: &'a str, + ) -> Option<(TestScope, &'a str)> { + let strip_prefix = |prefix, scope| { + url_path + .strip_prefix(prefix) + .map(|stripped| (scope, stripped)) + }; + match self { + Browser::Firefox => strip_prefix("/_mozilla/", FirefoxTestScope::Mozilla.into()) + .or_else(|| strip_prefix("/", FirefoxTestScope::Upstream.into())), + Browser::Servo => strip_prefix("/_webgpu/", ServoTestScope::WebGpu.into()), + } + } + + /// NOTE: Keep this implementation in sync with [`TestScope::metadata_parent_path_components`]. + pub(crate) fn strip_scope_metadata_parent_path<'a>( + &self, + path: &'a Utf8Path, + ) -> Result<(TestScope, &'a Utf8Path), std::path::StripPrefixError> { + let strip_prefix = + |prefix, scope| path.strip_prefix(prefix).map(|stripped| (scope, stripped)); + match self { + Browser::Firefox => { + strip_prefix(SCOPE_DIR_FX_MOZILLA_STR, FirefoxTestScope::Mozilla.into()).or_else( + |_| strip_prefix(SCOPE_DIR_FX_UPSTREAM_STR, FirefoxTestScope::Upstream.into()), + ) + } + Browser::Servo => { + strip_prefix(SCOPE_DIR_SERVO_WEBGPU_STR, ServoTestScope::WebGpu.into()) + } + } + } +} + /// Symbolically represents a file root from which tests and metadata are based. Scopes are based /// on a specific [`Browser`]. #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] @@ -677,6 +686,32 @@ pub(crate) enum TestScope { Servo(ServoTestScope), } +impl TestScope { + /// NOTE: Keep this implementation in sync with [`Browser::strip_scope_url_prefix`]. + fn url_prefix(&self) -> &str { + match self { + TestScope::Firefox(scope) => match scope { + FirefoxTestScope::Upstream => "", + FirefoxTestScope::Mozilla => "_mozilla/", + }, + TestScope::Servo(ServoTestScope::WebGpu) => "_webgpu/", + } + } + + /// NOTE: Keep this implementation in sync with [`Browser::strip_scope_metadata_parent_path`]. + fn metadata_parent_path_components(&self) -> impl Iterator + Clone { + match self { + TestScope::Firefox(scope) => match scope { + FirefoxTestScope::Upstream => SCOPE_DIR_FX_UPSTREAM_COMPONENTS, + FirefoxTestScope::Mozilla => SCOPE_DIR_FX_MOZILLA_COMPONENTS, + }, + TestScope::Servo(ServoTestScope::WebGpu) => SCOPE_DIR_SERVO_WEBGPU_COMPONENTS, + } + .iter() + .cloned() + } +} + /// Subset of [`TestScope`] for [`Browser::Firefox`]. #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub(crate) enum FirefoxTestScope { From a5fc188a56cad2eb5e346c9a6dcfb2a8010fcc86 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Fri, 10 May 2024 12:02:09 -0400 Subject: [PATCH 10/10] docs: document `{ExecutionReport,MetadataTest}PathError` --- moz-webgpu-cts/src/shared.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/moz-webgpu-cts/src/shared.rs b/moz-webgpu-cts/src/shared.rs index 59366668..4546a2eb 100644 --- a/moz-webgpu-cts/src/shared.rs +++ b/moz-webgpu-cts/src/shared.rs @@ -594,6 +594,7 @@ impl<'a> TestPath<'a> { } } +/// An error encountered during [`TestPath::from_execution_report`]. #[derive(Debug)] pub struct ExecutionReportPathError<'a> { test_url_path: &'a str, @@ -613,6 +614,7 @@ impl Display for ExecutionReportPathError<'_> { } } +/// An error encountered during [`TestPath::from_metadata_test`]. #[derive(Debug)] pub struct MetadataTestPathError<'a> { rel_meta_file_path: &'a Path,