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 a41a92b commit ebbb992
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
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
31 changes: 30 additions & 1 deletion moz-webgpu-cts/src/wpt/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ where
is_disabled,
expected,
implementation_status,
tags,
} = property;

if *is_disabled {
Expand Down Expand Up @@ -839,6 +840,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 +897,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 +909,7 @@ where
is_disabled,
expected,
implementation_status,
tags,
} = self;

let TestProp { kind, span } = prop;
Expand Down Expand Up @@ -966,6 +988,7 @@ where
implementation_status,
val,
),
TestPropKind::Tags(val) => conditional(emitter, span, TAGS_IDENT, tags, val),
}
}
}
Expand Down Expand Up @@ -993,6 +1016,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 +1194,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
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 ebbb992

Please sign in to comment.