Skip to content

Commit

Permalink
WIP: feat: support *.worker.js tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ErichDonGubler committed Jun 21, 2024
1 parent 20f25fc commit 223e007
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions moz-webgpu-cts/src/wpt/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,19 @@ pub(crate) struct SpecPath<'a> {
pub r#type: SpecType,
}

/// The type of tests that can be specified in a [`SpecPath`].
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub(crate) enum SpecType {
/// A JavaScript test.
///
/// See also:
///
/// * [WPT upstream docs.' "JavaScript Tests (`testharness.js`)" section][upstream] for
/// background.
/// * [`JsExecScope`], which will be set in test entries specified in a file with this type.
///
/// [upstream]: https://web-platform-tests.org/writing-tests/testharness.html
Js(JsSpecType),
/// A catch-all for all `*.html` test spec. files. This is likely incorrect, but it works well
/// enough for now!
Html,
Expand All @@ -83,10 +94,19 @@ impl SpecType {

pub fn file_extension(&self) -> &'static str {
match self {
SpecType::Js(JsSpecType::DedicatedWorker) => ".worker.js",
SpecType::Html => ".html",
}
}
}

/// A subtype of [`SpecType::Js`].
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub(crate) enum JsSpecType {
/// A `*.worker.js` test.
DedicatedWorker,
}

/// A symbolic path to an executed WPT test entry and its metadata, contained in a test
/// specification (see also [`SpecPath`]). In combination with [`SpecPath`], this is useful for
/// correlating entries from [`ExecutionReport`]s and [`metadata::File`]s.
Expand All @@ -95,6 +115,17 @@ impl SpecType {
/// [`metadata::File`]: crate::wpt::metadata::File
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub(crate) struct TestEntry<'a> {
/// Set if this is a JS test, which causes the test entry to have slightly different naming
/// from its specification file (see also [`SpecPath`]).
///
/// JS tests are converted to `*.html` tests at test execution time and reported as such.
/// The set of values observable here are determined by this entry's spec.'s
/// [`SpecPath::r#type`] and its
///
/// See also [WPT upstream's docs.' "Test Features" section][upstream]
///
/// [upstream]: https://web-platform-tests.org/writing-tests/file-names.html#test-features
pub js_exec_scope: Option<JsExecScope>,
/// The variant of this particular test from this test's source code. If set, you should be
/// able to correlate this with
///
Expand All @@ -104,6 +135,18 @@ pub(crate) struct TestEntry<'a> {
pub variant: Option<Cow<'a, str>>,
}

/// An executed JS test entry's test type, viz., a [`TestEntry::js_exec_scope`].
///
/// [upstream]: https://web-platform-tests.org/writing-tests/testharness.html
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub(crate) enum JsExecScope {
/// A `*.worker.js` test. See also [WPT upstream docs.' "Dedicated worker test (`.worker.js`)"
/// section][upstream].
///
/// [upstream]: https://web-platform-tests.org/writing-tests/testharness.html#dedicated-worker-tests-worker-js
DedicatedWorker,
}

const ROOT_DIR_FX_MOZILLA_STR: &str = "testing/web-platform/mozilla";
const ROOT_DIR_FX_MOZILLA_COMPONENTS: &[&str] = &["testing", "web-platform", "mozilla"];
const ROOT_DIR_FX_UPSTREAM_STR: &str = "testing/web-platform";
Expand Down Expand Up @@ -156,6 +199,7 @@ impl<'a> TestEntryPath<'a> {
r#type: spec_type,
},
test_entry: TestEntry {
js_exec_scope: None,
variant: variant.map(Into::into),
},
})
Expand Down Expand Up @@ -199,6 +243,7 @@ impl<'a> TestEntryPath<'a> {
let (base_name, variant) = Self::split_test_base_name_from_variant(test_name);

let base_name = match spec_type {
SpecType::Js(_) => todo!(),
SpecType::Html => base_name.strip_suffix(".html").ok_or_else(err)?,
};

Expand Down

0 comments on commit 223e007

Please sign in to comment.