Skip to content

Commit b22da1e

Browse files
Write tests in report order after processing reports (#163)
When we process reports, populate test entries in `IndexMaps`, instead of `BTreeMap`s. Then, populate them from reports _before_ they get populated from metadata. That way, when we iterate over them to write back to disk, we do so in the order that tests were reported.
2 parents 5299e97 + c9e6119 commit b22da1e

4 files changed

Lines changed: 96 additions & 95 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

moz-webgpu-cts/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ enum-map = { version = "2.7.3", features = ["serde"] }
2424
enumset = { version = "1.1.3", features = ["serde"] }
2525
env_logger = { workspace = true }
2626
format = { workspace = true }
27-
indexmap = { workspace = true }
27+
indexmap = { workspace = true, features = ["serde"] }
2828
itertools = "0.11.0"
2929
joinery = "3.1.0"
3030
lets_find_up = "0.0.3"

moz-webgpu-cts/src/process_reports.rs

Lines changed: 89 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ where
4646
#[derive(Debug, Default)]
4747
pub(crate) struct TestEntry {
4848
pub entry: Entry<TestOutcome>,
49-
pub subtests: BTreeMap<String, Entry<SubtestOutcome>>,
49+
pub subtests: IndexMap<String, Entry<SubtestOutcome>>,
5050
}
5151

5252
#[derive(Debug)]
@@ -176,93 +176,6 @@ pub(crate) fn process_reports(
176176
let mut other_entries_by_test = IndexMap::<TestEntryPath<'_>, TestEntry>::default();
177177
let old_meta_file_paths = meta_files_by_path.keys().cloned().collect::<Vec<_>>();
178178

179-
log::debug!("loading metadata for comparison to reports…");
180-
for (path, file) in meta_files_by_path {
181-
let File { properties, tests } = file;
182-
183-
let file_rel_path = path.strip_prefix(checkout).unwrap();
184-
185-
file_props_by_file.insert(
186-
Utf8PathBuf::from(file_rel_path.to_str().unwrap()),
187-
properties,
188-
);
189-
190-
for (SectionHeader(name), test) in tests {
191-
let Test {
192-
properties,
193-
subtests,
194-
} = test;
195-
196-
let test_entry_path =
197-
match TestEntryPath::from_metadata_test(browser, file_rel_path, &name) {
198-
Ok(ok) => ok,
199-
Err(e) => {
200-
log::error!("{e}");
201-
return Err(AlreadyReportedToCommandline);
202-
}
203-
};
204-
205-
let freak_out_do_nothing =
206-
|what: &dyn Display| log::error!("hoo boy, not sure what to do yet: {what}");
207-
208-
let mut reported_dupe_already = false;
209-
let mut dupe_err = || {
210-
if !reported_dupe_already {
211-
freak_out_do_nothing(&format_args!(
212-
concat!(
213-
"duplicate entry for {:?}",
214-
"discarding previous entries with ",
215-
"this and further dupes"
216-
),
217-
test_entry_path
218-
))
219-
}
220-
reported_dupe_already = true;
221-
};
222-
223-
let TestEntry {
224-
entry: test_entry,
225-
subtests: subtest_entries,
226-
} = if let Some(cts_path) = cts_path(&test_entry_path) {
227-
let entry = entries_by_cts_path.entry(cts_path).or_default();
228-
if let Some(_old) = entry
229-
.metadata_path
230-
.replace(test_entry_path.clone().into_owned())
231-
{
232-
dupe_err();
233-
}
234-
&mut entry.entry
235-
} else {
236-
other_entries_by_test
237-
.entry(test_entry_path.clone().into_owned())
238-
.or_default()
239-
};
240-
241-
let test_entry_path = &test_entry_path;
242-
243-
if let Some(_old) = test_entry.meta_props.replace(properties) {
244-
dupe_err();
245-
}
246-
247-
for (SectionHeader(subtest_name), subtest) in subtests {
248-
let Subtest { properties } = subtest;
249-
let subtest_entry = subtest_entries.entry(subtest_name.clone()).or_default();
250-
if let Some(_old) = subtest_entry.meta_props.replace(properties) {
251-
if !reported_dupe_already {
252-
freak_out_do_nothing(&format_args!(
253-
concat!(
254-
"duplicate subtest in {:?} named {:?}, ",
255-
"discarding previous entries with ",
256-
"this and further dupes"
257-
),
258-
test_entry_path, subtest_name
259-
));
260-
}
261-
}
262-
}
263-
}
264-
}
265-
266179
log::debug!("gathering reported test outcomes for reconciliation with metadata…");
267180

268181
let (exec_reports_sender, exec_reports_receiver) = channel();
@@ -399,6 +312,93 @@ pub(crate) fn process_reports(
399312
}
400313
}
401314

315+
log::debug!("loading metadata for comparison to reports…");
316+
for (path, file) in meta_files_by_path {
317+
let File { properties, tests } = file;
318+
319+
let file_rel_path = path.strip_prefix(checkout).unwrap();
320+
321+
file_props_by_file.insert(
322+
Utf8PathBuf::from(file_rel_path.to_str().unwrap()),
323+
properties,
324+
);
325+
326+
for (SectionHeader(name), test) in tests {
327+
let Test {
328+
properties,
329+
subtests,
330+
} = test;
331+
332+
let test_entry_path =
333+
match TestEntryPath::from_metadata_test(browser, file_rel_path, &name) {
334+
Ok(ok) => ok,
335+
Err(e) => {
336+
log::error!("{e}");
337+
return Err(AlreadyReportedToCommandline);
338+
}
339+
};
340+
341+
let freak_out_do_nothing =
342+
|what: &dyn Display| log::error!("hoo boy, not sure what to do yet: {what}");
343+
344+
let mut reported_dupe_already = false;
345+
let mut dupe_err = || {
346+
if !reported_dupe_already {
347+
freak_out_do_nothing(&format_args!(
348+
concat!(
349+
"duplicate entry for {:?}",
350+
"discarding previous entries with ",
351+
"this and further dupes"
352+
),
353+
test_entry_path
354+
))
355+
}
356+
reported_dupe_already = true;
357+
};
358+
359+
let TestEntry {
360+
entry: test_entry,
361+
subtests: subtest_entries,
362+
} = if let Some(cts_path) = cts_path(&test_entry_path) {
363+
let entry = entries_by_cts_path.entry(cts_path).or_default();
364+
if let Some(_old) = entry
365+
.metadata_path
366+
.replace(test_entry_path.clone().into_owned())
367+
{
368+
dupe_err();
369+
}
370+
&mut entry.entry
371+
} else {
372+
other_entries_by_test
373+
.entry(test_entry_path.clone().into_owned())
374+
.or_default()
375+
};
376+
377+
let test_entry_path = &test_entry_path;
378+
379+
if let Some(_old) = test_entry.meta_props.replace(properties) {
380+
dupe_err();
381+
}
382+
383+
for (SectionHeader(subtest_name), subtest) in subtests {
384+
let Subtest { properties } = subtest;
385+
let subtest_entry = subtest_entries.entry(subtest_name.clone()).or_default();
386+
if let Some(_old) = subtest_entry.meta_props.replace(properties) {
387+
if !reported_dupe_already {
388+
freak_out_do_nothing(&format_args!(
389+
concat!(
390+
"duplicate subtest in {:?} named {:?}, ",
391+
"discarding previous entries with ",
392+
"this and further dupes"
393+
),
394+
test_entry_path, subtest_name
395+
));
396+
}
397+
}
398+
}
399+
}
400+
}
401+
402402
log::debug!("metadata and reports gathered, now reconciling outcomes…");
403403

404404
let entries_by_cts_path = entries_by_cts_path.into_iter().map(|(_name, entry)| {
@@ -565,7 +565,7 @@ pub(crate) fn process_reports(
565565
},
566566
))
567567
})
568-
.collect::<BTreeMap<_, _>>();
568+
.collect::<IndexMap<_, _>>();
569569

570570
Some((test_entry_path, (properties, subtests)))
571571
},

moz-webgpu-cts/src/wpt/metadata.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::{
2-
collections::BTreeMap,
32
fmt::{self, Display, Formatter},
43
hash::Hash,
54
};
@@ -8,6 +7,7 @@ use clap::ValueEnum;
87
use enum_map::Enum;
98
use enumset::EnumSetType;
109
use format::lazy_format;
10+
use indexmap::IndexMap;
1111
use joinery::JoinableIterator;
1212
use maybe_collapsed::MaybeCollapsed;
1313
use serde::{Deserialize, Serialize};
@@ -43,7 +43,7 @@ pub(crate) mod properties;
4343
#[derive(Clone, Debug, Default, Serialize)]
4444
pub struct File {
4545
pub properties: FileProps,
46-
pub tests: BTreeMap<SectionHeader, Test>,
46+
pub tests: IndexMap<SectionHeader, Test>,
4747
}
4848

4949
impl File {
@@ -647,7 +647,7 @@ impl ImplementationStatus {
647647
}
648648

649649
#[derive(Debug, Default)]
650-
pub struct Tests(BTreeMap<SectionHeader, Test>);
650+
pub struct Tests(IndexMap<SectionHeader, Test>);
651651

652652
impl<'a> metadata::Tests<'a> for Tests {
653653
type Test = Test;
@@ -670,7 +670,7 @@ impl<'a> metadata::Tests<'a> for Tests {
670670
#[derive(Clone, Debug, Default, Serialize)]
671671
pub struct Test {
672672
pub properties: TestProps<TestOutcome>,
673-
pub subtests: BTreeMap<SectionHeader, Subtest>,
673+
pub subtests: IndexMap<SectionHeader, Subtest>,
674674
}
675675

676676
#[cfg(test)]
@@ -694,7 +694,7 @@ impl metadata::Test<'_> for Test {
694694
}
695695

696696
#[derive(Default)]
697-
pub struct Subtests(BTreeMap<SectionHeader, Subtest>);
697+
pub struct Subtests(IndexMap<SectionHeader, Subtest>);
698698

699699
impl<'a> metadata::Subtests<'a> for Subtests {
700700
type Subtest = Subtest;

0 commit comments

Comments
 (0)