Skip to content

Commit

Permalink
WIP: feat: tags property on tests and subtests
Browse files Browse the repository at this point in the history
TODO: Worried about perf. from extra memory usage in tests. Conditional
values defeat the purpose of tags, too.
  • Loading branch information
ErichDonGubler committed Aug 5, 2024
1 parent ffcd60b commit c1b1739
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 2 deletions.
2 changes: 2 additions & 0 deletions moz-webgpu-cts/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ fn run(cli: Cli) -> ExitCode {
is_disabled,
expected,
implementation_status: _,
tags: _,
} = properties;

let test_name = Arc::new(test_name);
Expand Down Expand Up @@ -703,6 +704,7 @@ fn run(cli: Cli) -> ExitCode {
is_disabled,
expected,
implementation_status: _,
tags: _,
} = properties;

if is_disabled {
Expand Down
170 changes: 168 additions & 2 deletions moz-webgpu-cts/src/wpt/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,34 @@ fn tags_parser<'a, T>(
helper: &mut PropertiesParseHelper<'a>,
conditional_term: impl Parser<'a, &'a str, T, ParseError<'a>>,
) -> impl Parser<'a, &'a str, PropertyValue<T, Vec<String>>, ParseError<'a>> {
use crate::chumsky::{error::Error, util::MaybeRef};

let tag_ident = {
let underscore_or_hyphen = |c| matches!(c, '_' | '-');
any::<'a, &'a str, ParseError<'a>>()
.try_map(move |c: char, span| {
if c.is_ascii_alphabetic() || underscore_or_hyphen(c) {
Ok(c)
} else {
Err(Error::<&'a str>::expected_found(
[],
Some(MaybeRef::Val(c)),
span,
))
}
})
.then(
any()
.filter(move |c: &char| c.is_ascii_alphanumeric() || underscore_or_hyphen(*c))
.repeated(),
)
.to_slice()
};
helper
.parser(
keyword("tags").to(()),
conditional_term,
ascii::ident()
tag_ident
.map(|i: &str| i.to_owned())
.separated_by(just(',').padded_by(inline_whitespace()))
.collect()
Expand Down Expand Up @@ -759,6 +782,7 @@ where
is_disabled,
expected,
implementation_status,
tags,
} = property;

if *is_disabled {
Expand Down Expand Up @@ -839,6 +863,25 @@ where
Ok(())
}

if let Some(tags) = tags {
use std::borrow::Cow;

#[derive(Clone, Debug, Default, Eq, PartialEq)]
struct TagsDisplay<'a>(Cow<'a, Vec<String>>);

impl Display for TagsDisplay<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let Self(tags) = self;
Display::fmt(&tags.iter().join_with(", "), f)
}
}

let tags_ref = tags.as_ref();
let tags_ref = tags_ref.map(Cow::Borrowed).map(TagsDisplay);

write_normalized(f, &indent, TAGS_IDENT, tags_ref)?;
}

if let Some(implementation_status) = implementation_status {
write_normalized(
f,
Expand Down Expand Up @@ -877,6 +920,7 @@ where
pub is_disabled: bool,
pub expected: Option<ExpandedPropertyValue<Expected<Out>>>,
pub implementation_status: Option<ExpandedPropertyValue<ImplementationStatus>>,
pub tags: Option<ExpandedPropertyValue<Vec<String>>>,
}

impl<'a, Out> TestProps<Out>
Expand All @@ -888,6 +932,7 @@ where
is_disabled,
expected,
implementation_status,
tags,
} = self;

let TestProp { kind, span } = prop;
Expand Down Expand Up @@ -966,6 +1011,7 @@ where
implementation_status,
val,
),
TestPropKind::Tags(val) => conditional(emitter, span, TAGS_IDENT, tags, val),
}
}
}
Expand Down Expand Up @@ -993,6 +1039,7 @@ where
Expected(PropertyValue<Applicability, Expected<Out>>),
Disabled,
ImplementationStatus(PropertyValue<Applicability, ImplementationStatus>),
Tags(PropertyValue<Applicability, Vec<String>>),
}

impl<Out> TestProp<Out>
Expand Down Expand Up @@ -1170,18 +1217,23 @@ where
helper
.parser(
ImplementationStatus::property_ident_parser(),
conditional_term,
conditional_term.clone(),
ImplementationStatus::property_value_parser(),
)
.map_with(|((), val), e| TestProp {
span: e.span(),
kind: TestPropKind::ImplementationStatus(val),
}),
tags_parser(helper, conditional_term).map_with(|val, e| TestProp {
span: e.span(),
kind: TestPropKind::Tags(val),
}),
))
}
}

pub(crate) const EXPECTED_IDENT: &str = "expected";
pub(crate) const TAGS_IDENT: &str = "expected";
pub(crate) const PASS: &str = "PASS";
pub(crate) const FAIL: &str = "FAIL";
pub(crate) const NOTRUN: &str = "NOTRUN";
Expand Down Expand Up @@ -1345,6 +1397,7 @@ r#"
is_disabled: false,
expected: None,
implementation_status: None,
tags: None,
},
subtests: {},
},
Expand Down Expand Up @@ -1379,13 +1432,15 @@ r#"
is_disabled: false,
expected: None,
implementation_status: None,
tags: None,
},
subtests: {
"blarg": Subtest {
properties: TestProps {
is_disabled: false,
expected: None,
implementation_status: None,
tags: None,
},
},
},
Expand Down Expand Up @@ -1422,6 +1477,7 @@ r#"
is_disabled: false,
expected: None,
implementation_status: None,
tags: None,
},
subtests: {
"blarg": Subtest {
Expand Down Expand Up @@ -1458,6 +1514,7 @@ r#"
),
),
implementation_status: None,
tags: None,
},
},
},
Expand Down Expand Up @@ -1490,6 +1547,7 @@ r#"
is_disabled: false,
expected: None,
implementation_status: None,
tags: None,
},
subtests: {
"blarg": Subtest {
Expand Down Expand Up @@ -1532,6 +1590,7 @@ r#"
),
),
implementation_status: None,
tags: None,
},
},
},
Expand Down Expand Up @@ -1591,6 +1650,7 @@ r#"
),
),
implementation_status: None,
tags: None,
},
subtests: {
"blarg": Subtest {
Expand Down Expand Up @@ -1627,6 +1687,7 @@ r#"
),
),
implementation_status: None,
tags: None,
},
},
},
Expand Down Expand Up @@ -1657,6 +1718,7 @@ r#"
is_disabled: false,
expected: None,
implementation_status: None,
tags: None,
},
subtests: {
"blarg": Subtest {
Expand Down Expand Up @@ -1693,6 +1755,7 @@ r#"
),
),
implementation_status: None,
tags: None,
},
},
},
Expand Down Expand Up @@ -1724,6 +1787,7 @@ r#"
is_disabled: false,
expected: None,
implementation_status: None,
tags: None,
},
subtests: {
"blarg": Subtest {
Expand Down Expand Up @@ -1760,6 +1824,7 @@ r#"
),
),
implementation_status: None,
tags: None,
},
},
},
Expand Down Expand Up @@ -1789,6 +1854,7 @@ r#"
is_disabled: false,
expected: None,
implementation_status: None,
tags: None,
},
subtests: {
":": Subtest {
Expand Down Expand Up @@ -1825,6 +1891,7 @@ r#"
),
),
implementation_status: None,
tags: None,
},
},
},
Expand Down Expand Up @@ -1888,6 +1955,105 @@ r#"
),
),
implementation_status: None,
tags: None,
},
subtests: {},
},
),
),
errs: [],
}
"###
);
assert_debug_snapshot!(
parser().parse(
r#"
[this_is_tagged.https.html]
tags: [webgpu, webgpu-long]
expected: [PASS, TIMEOUT]
"#
),
@r###"
ParseResult {
output: Some(
(
"this_is_tagged.https.html",
Test {
properties: TestProps {
is_disabled: false,
expected: Some(
ExpandedPropertyValue(
{
Windows: {
Debug: [
Pass,
Timeout,
],
Optimized: [
Pass,
Timeout,
],
},
Linux: {
Debug: [
Pass,
Timeout,
],
Optimized: [
Pass,
Timeout,
],
},
MacOs: {
Debug: [
Pass,
Timeout,
],
Optimized: [
Pass,
Timeout,
],
},
},
),
),
implementation_status: None,
tags: Some(
ExpandedPropertyValue(
{
Windows: {
Debug: [
"webgpu",
"webgpu-long",
],
Optimized: [
"webgpu",
"webgpu-long",
],
},
Linux: {
Debug: [
"webgpu",
"webgpu-long",
],
Optimized: [
"webgpu",
"webgpu-long",
],
},
MacOs: {
Debug: [
"webgpu",
"webgpu-long",
],
Optimized: [
"webgpu",
"webgpu-long",
],
},
},
),
),
},
subtests: {},
},
Expand Down
6 changes: 6 additions & 0 deletions moz-webgpu-cts/src/wpt/metadata/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@ impl<T> ExpandedPropertyValue<T> {
let Self(inner) = self;
inner
}

pub(crate) fn as_ref(&self) -> ExpandedPropertyValue<&T> {
ExpandedPropertyValue::from_query(|platform, build_profile| {
&self[(platform, build_profile)]
})
}
}

impl<T> ExpandedPropertyValue<T> {
Expand Down

0 comments on commit c1b1739

Please sign in to comment.