Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
TODO: figure out design, make things compile
  • Loading branch information
ErichDonGubler committed May 10, 2024
1 parent b16d8f4 commit 476c8f2
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 33 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions moz-webgpu-cts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ thiserror = { workspace = true }
wax = { version = "0.6.0", features = ["miette"], git = "https://github.com/ErichDonGubler/wax", branch = "static-miette-diags"}
whippit = { version = "0.6.0", path = "../whippit", default-features = false }
enum-map = "2.7.3"
arcstr = "1.1.5"

[dev-dependencies]
insta = { workspace = true }
8 changes: 4 additions & 4 deletions moz-webgpu-cts/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -958,14 +958,14 @@ fn run(cli: Cli) -> ExitCode {
} = test;

let TestProps {
is_disabled,
disabled,
expected,
implementation_status: _,
} = properties;

let test_name = Arc::new(test_name);

if is_disabled {
if disabled.is_some() {
analysis.for_each_platform_mut(|analysis| {
analysis
.tests_with_disabled_or_skip
Expand Down Expand Up @@ -1073,12 +1073,12 @@ fn run(cli: Cli) -> ExitCode {

let Subtest { properties } = subtest;
let TestProps {
is_disabled,
disabled,
expected,
implementation_status: _,
} = properties;

if is_disabled {
if disabled.is_some() {
analysis
.windows
.tests_with_disabled_or_skip
Expand Down
52 changes: 23 additions & 29 deletions moz-webgpu-cts/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::{
hash::Hash,
};

use arcstr::ArcStr;
use enum_map::Enum;
use enumset::EnumSetType;
use format::lazy_format;
Expand All @@ -29,7 +30,9 @@ use whippit::{
},
};

use crate::shared::{ExpandedPropertyValue, Expected, MaybeCollapsed, NormalizedPropertyValue};
use crate::shared::{
DisabledString, ExpandedPropertyValue, Expected, MaybeCollapsed, NormalizedPropertyValue,
};

#[cfg(test)]
use insta::assert_debug_snapshot;
Expand Down Expand Up @@ -744,15 +747,11 @@ where
.join_with(" ")
));
let TestProps {
is_disabled,
disabled,
expected,
implementation_status,
} = property;

if *is_disabled {
writeln!(f, "{indent}disabled: true")?;
}

fn write_normalized<T>(
f: &mut Formatter<'_>,
indent: &dyn Display,
Expand Down Expand Up @@ -836,6 +835,10 @@ where
)?;
}

if let Some(disabled) = disabled {
write_normalized(f, &indent, "disabled", disabled)?;
}

if let Some(exps) = expected {
write_normalized(f, &indent, EXPECTED_IDENT, exps)?;
}
Expand All @@ -862,7 +865,7 @@ pub struct TestProps<Out>
where
Out: EnumSetType,
{
pub is_disabled: bool,
pub disabled: Option<ExpandedPropertyValue<DisabledString>>,
pub expected: Option<ExpandedPropertyValue<Expected<Out>>>,
pub implementation_status: Option<ExpandedPropertyValue<ImplementationStatus>>,
}
Expand All @@ -873,7 +876,7 @@ where
{
fn insert(&mut self, prop: TestProp<Out>, emitter: &mut Emitter<Rich<'a, char>>) {
let Self {
is_disabled,
disabled,
expected,
implementation_status,
} = self;
Expand Down Expand Up @@ -941,11 +944,8 @@ where
TestPropKind::Expected(val) => {
conditional(emitter, span, EXPECTED_IDENT, expected, val)
}
TestPropKind::Disabled => {
if *is_disabled {
emitter.emit(Rich::custom(span, "duplicate `disabled` key detected"))
}
*is_disabled = true;
TestPropKind::Disabled(val) => {
conditional(emitter, span, DISABLED_IDENT, disabled, val)
}
TestPropKind::ImplementationStatus(val) => conditional(
emitter,
Expand Down Expand Up @@ -979,7 +979,7 @@ where
Out: EnumSetType,
{
Expected(PropertyValue<Applicability, Expected<Out>>),
Disabled,
Disabled(PropertyValue<Applicability, DisabledString>),
ImplementationStatus(PropertyValue<Applicability, ImplementationStatus>),
}

Expand Down Expand Up @@ -1138,22 +1138,16 @@ where
.parser(
just(DISABLED_IDENT).to(()),
conditional_term.clone(),
just("true").to(()),
any()
.and_is(newline().not())
.repeated()
.to_slice()
.map(ArcStr::from)
.map(DisabledString::new),
)
.validate(|((), val), e, emitter| {
match val {
PropertyValue::Unconditional(()) => (),
PropertyValue::Conditional { .. } => {
emitter.emit(Rich::custom(
e.span(),
"conditional rules for `disabled` aren't supported yet",
));
}
}
TestProp {
span: e.span(),
kind: TestPropKind::Disabled,
}
.map_with(|((), val), e| TestProp {
span: e.span(),
kind: TestPropKind::Disabled(val),
}),
helper
.parser(
Expand Down
26 changes: 26 additions & 0 deletions moz-webgpu-cts/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{
path::Path,
};

use arcstr::ArcStr;
use camino::{Utf8Component, Utf8Path};

use enum_map::EnumMap;
Expand Down Expand Up @@ -211,6 +212,31 @@ where

impl<Out> Eq for Expected<Out> where Out: EnumSetType + Eq {}

#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct DisabledString(Option<ArcStr>);

impl DisabledString {
const FALSE: &'static str = "@False";

pub fn new(inner: ArcStr) -> Self {
Self(if inner == Self::FALSE {
None
} else {
Some(inner)
})
}

pub fn value(&self) -> &str {
self.0.as_deref().unwrap_or(Self::FALSE)
}
}

impl Display for DisabledString {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
Display::fmt(self.value(), f)
}
}

/// Similar to the ubiquitous `enum Either`, but with the implication that `Collapsed` values are
/// abbreviations of equivalent `Expanded` values.
#[derive(Clone, Debug, Eq, PartialEq)]
Expand Down

0 comments on commit 476c8f2

Please sign in to comment.