Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fullyExpandSubtrees & ability to disable no long path assert #3246

Merged
merged 5 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/common/internal/file_loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,17 @@ export abstract class TestFileLoader extends EventTarget {
query: TestQuery,
{
subqueriesToExpand = [],
fullyExpandSubtrees = [],
maxChunkTime = Infinity,
}: { subqueriesToExpand?: string[]; maxChunkTime?: number } = {}
}: { subqueriesToExpand?: string[]; fullyExpandSubtrees?: string[]; maxChunkTime?: number } = {}
): Promise<TestTree> {
const tree = await loadTreeForQuery(this, query, {
subqueriesToExpand: subqueriesToExpand.map(s => {
const q = parseQuery(s);
assert(q.level >= 2, () => `subqueriesToExpand entries should not be multi-file:\n ${q}`);
return q;
}),
fullyExpandSubtrees: fullyExpandSubtrees.map(s => parseQuery(s)),
maxChunkTime,
});
this.dispatchEvent(new MessageEvent<void>('finish'));
Expand Down
7 changes: 6 additions & 1 deletion src/common/internal/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,9 @@ export async function loadTreeForQuery(
queryToLoad: TestQuery,
{
subqueriesToExpand,
fullyExpandSubtrees = [],
maxChunkTime = Infinity,
}: { subqueriesToExpand: TestQuery[]; maxChunkTime?: number }
}: { subqueriesToExpand: TestQuery[]; fullyExpandSubtrees?: TestQuery[]; maxChunkTime?: number }
): Promise<TestTree> {
const suite = queryToLoad.suite;
const specs = await loader.listing(suite);
Expand All @@ -303,6 +304,10 @@ export async function loadTreeForQuery(
// If toExpand == subquery, no expansion is needed (but it's still "seen").
if (ordering === Ordering.Equal) seenSubqueriesToExpand[i] = true;
return ordering !== Ordering.StrictSubset;
}) &&
fullyExpandSubtrees.every(toExpand => {
const ordering = compareQueries(toExpand, subquery);
return ordering === Ordering.Unordered;
});

// L0 = suite-level, e.g. suite:*
Expand Down
103 changes: 73 additions & 30 deletions src/common/tools/gen_wpt_cts_html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ interface ConfigJSON {
/** The prefix to trim from every line of the expectations_file. */
prefix: string;
};
/** Expend all subtrees for provided queries */
fullyExpandSubtrees?: {
file: string;
prefix: string;
};
/*No long path assert */
noLongPathAssert?: boolean;
}

interface Config {
Expand All @@ -79,10 +86,15 @@ interface Config {
template: string;
maxChunkTimeMS: number;
argumentsPrefixes: string[];
noLongPathAssert: boolean;
expectations?: {
file: string;
prefix: string;
};
fullyExpandSubtrees?: {
file: string;
prefix: string;
};
}

let config: Config;
Expand All @@ -101,13 +113,20 @@ let config: Config;
template: path.resolve(jsonFileDir, configJSON.template),
maxChunkTimeMS: configJSON.maxChunkTimeMS ?? Infinity,
argumentsPrefixes: configJSON.argumentsPrefixes ?? ['?q='],
noLongPathAssert: configJSON.noLongPathAssert ?? false,
};
if (configJSON.expectations) {
config.expectations = {
file: path.resolve(jsonFileDir, configJSON.expectations.file),
prefix: configJSON.expectations.prefix,
};
}
if (configJSON.fullyExpandSubtrees) {
config.fullyExpandSubtrees = {
file: path.resolve(jsonFileDir, configJSON.fullyExpandSubtrees.file),
prefix: configJSON.fullyExpandSubtrees.prefix,
};
}
break;
}
case 4:
Expand All @@ -130,6 +149,7 @@ let config: Config;
suite,
maxChunkTimeMS: Infinity,
argumentsPrefixes: ['?q='],
noLongPathAssert: false,
};
if (process.argv.length >= 7) {
config.argumentsPrefixes = (await fs.readFile(argsPrefixesFile, 'utf8'))
Expand All @@ -153,36 +173,24 @@ let config: Config;
config.argumentsPrefixes.sort((a, b) => b.length - a.length);

// Load expectations (if any)
let expectationLines = new Set<string>();
if (config.expectations) {
expectationLines = new Set(
(await fs.readFile(config.expectations.file, 'utf8')).split(/\r?\n/).filter(l => l.length)
);
}
const expectations: Map<string, string[]> = await loadQueryFile(
config.argumentsPrefixes,
config.expectations
);

const expectations: Map<string, string[]> = new Map();
for (const prefix of config.argumentsPrefixes) {
expectations.set(prefix, []);
}

expLoop: for (const exp of expectationLines) {
// Take each expectation for the longest prefix it matches.
for (const argsPrefix of config.argumentsPrefixes) {
const prefix = config.expectations!.prefix + argsPrefix;
if (exp.startsWith(prefix)) {
expectations.get(argsPrefix)!.push(exp.substring(prefix.length));
continue expLoop;
}
}
console.log('note: ignored expectation: ' + exp);
}
// Load fullyExpandSubtrees queries (if any)
const fullyExpand: Map<string, string[]> = await loadQueryFile(
config.argumentsPrefixes,
config.fullyExpandSubtrees
);

const loader = new DefaultTestFileLoader();
const lines = [];
for (const prefix of config.argumentsPrefixes) {
const rootQuery = new TestQueryMultiFile(config.suite, []);
const tree = await loader.loadTree(rootQuery, {
subqueriesToExpand: expectations.get(prefix),
fullyExpandSubtrees: fullyExpand.get(prefix),
maxChunkTime: config.maxChunkTimeMS,
});

Expand All @@ -199,19 +207,21 @@ let config: Config;
alwaysExpandThroughLevel,
})) {
assert(query instanceof TestQueryMultiCase);
const queryString = query.toString();
// Check for a safe-ish path length limit. Filename must be <= 255, and on Windows the whole
// path must be <= 259. Leave room for e.g.:
// 'c:\b\s\w\xxxxxxxx\layout-test-results\external\wpt\webgpu\cts_worker=0_q=...-actual.txt'
assert(
queryString.length < 185,
`Generated test variant would produce too-long -actual.txt filename. Possible solutions:
if (!config.noLongPathAssert) {
const queryString = query.toString();
// Check for a safe-ish path length limit. Filename must be <= 255, and on Windows the whole
// path must be <= 259. Leave room for e.g.:
// 'c:\b\s\w\xxxxxxxx\layout-test-results\external\wpt\webgpu\cts_worker=0_q=...-actual.txt'
assert(
queryString.length < 185,
`Generated test variant would produce too-long -actual.txt filename. Possible solutions:
- Reduce the length of the parts of the test query
- Reduce the parameterization of the test
- Make the test function faster and regenerate the listing_meta entry
- Reduce the specificity of test expectations (if you're using them)
${queryString}`
);
);
}

lines.push({
urlQueryString: prefix + query.toString(), // "?worker=0&q=..."
Expand All @@ -232,6 +242,39 @@ ${queryString}`
process.exit(1);
});

async function loadQueryFile(
argumentsPrefixes: string[],
queryFile?: {
file: string;
prefix: string;
}
): Promise<Map<string, string[]>> {
let lines = new Set<string>();
if (queryFile) {
lines = new Set(
(await fs.readFile(queryFile.file, 'utf8')).split(/\r?\n/).filter(l => l.length)
);
}

const result: Map<string, string[]> = new Map();
for (const prefix of argumentsPrefixes) {
result.set(prefix, []);
}

expLoop: for (const exp of lines) {
// Take each expectation for the longest prefix it matches.
for (const argsPrefix of argumentsPrefixes) {
const prefix = queryFile!.prefix + argsPrefix;
if (exp.startsWith(prefix)) {
result.get(argsPrefix)!.push(exp.substring(prefix.length));
continue expLoop;
}
}
console.log('note: ignored expectation: ' + exp);
}
return result;
}

async function generateFile(
lines: Array<{ urlQueryString?: string; comment?: string } | undefined>
): Promise<void> {
Expand Down