From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- .../checkout/src/common/tools/gen_wpt_cts_html.ts | 122 +++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 dom/webgpu/tests/cts/checkout/src/common/tools/gen_wpt_cts_html.ts (limited to 'dom/webgpu/tests/cts/checkout/src/common/tools/gen_wpt_cts_html.ts') diff --git a/dom/webgpu/tests/cts/checkout/src/common/tools/gen_wpt_cts_html.ts b/dom/webgpu/tests/cts/checkout/src/common/tools/gen_wpt_cts_html.ts new file mode 100644 index 0000000000..28e8fb4437 --- /dev/null +++ b/dom/webgpu/tests/cts/checkout/src/common/tools/gen_wpt_cts_html.ts @@ -0,0 +1,122 @@ +import { promises as fs } from 'fs'; + +import { DefaultTestFileLoader } from '../internal/file_loader.js'; +import { TestQueryMultiFile } from '../internal/query/query.js'; +import { assert } from '../util/util.js'; + +function printUsageAndExit(rc: number): void { + console.error(`\ +Usage: + tools/gen_wpt_cts_html OUTPUT_FILE TEMPLATE_FILE [ARGUMENTS_PREFIXES_FILE EXPECTATIONS_FILE EXPECTATIONS_PREFIX [SUITE]] + tools/gen_wpt_cts_html out-wpt/cts.https.html templates/cts.https.html + tools/gen_wpt_cts_html my/path/to/cts.https.html templates/cts.https.html arguments.txt myexpectations.txt 'path/to/cts.https.html' cts + +where arguments.txt is a file containing a list of arguments prefixes to both generate and expect +in the expectations. The entire variant list generation runs *once per prefix*, so this +multiplies the size of the variant list. + + ?worker=0&q= + ?worker=1&q= + +and myexpectations.txt is a file containing a list of WPT paths to suppress, e.g.: + + path/to/cts.https.html?worker=0&q=webgpu:a/foo:bar={"x":1} + path/to/cts.https.html?worker=1&q=webgpu:a/foo:bar={"x":1} + + path/to/cts.https.html?worker=1&q=webgpu:a/foo:bar={"x":3} +`); + process.exit(rc); +} + +if (process.argv.length !== 4 && process.argv.length !== 7 && process.argv.length !== 8) { + printUsageAndExit(0); +} + +const [ + , + , + outFile, + templateFile, + argsPrefixesFile, + expectationsFile, + expectationsPrefix, + suite = 'webgpu', +] = process.argv; + +(async () => { + let argsPrefixes = ['']; + let expectationLines = new Set(); + + if (process.argv.length >= 7) { + // Prefixes sorted from longest to shortest + const argsPrefixesFromFile = (await fs.readFile(argsPrefixesFile, 'utf8')) + .split(/\r?\n/) + .filter(a => a.length) + .sort((a, b) => b.length - a.length); + if (argsPrefixesFromFile.length) argsPrefixes = argsPrefixesFromFile; + expectationLines = new Set( + (await fs.readFile(expectationsFile, 'utf8')).split(/\r?\n/).filter(l => l.length) + ); + } + + const expectations: Map = new Map(); + for (const prefix of argsPrefixes) { + expectations.set(prefix, []); + } + + expLoop: for (const exp of expectationLines) { + // Take each expectation for the longest prefix it matches. + for (const argsPrefix of argsPrefixes) { + const prefix = expectationsPrefix + argsPrefix; + if (exp.startsWith(prefix)) { + expectations.get(argsPrefix)!.push(exp.substring(prefix.length)); + continue expLoop; + } + } + console.log('note: ignored expectation: ' + exp); + } + + const loader = new DefaultTestFileLoader(); + const lines: Array = []; + for (const prefix of argsPrefixes) { + const rootQuery = new TestQueryMultiFile(suite, []); + const tree = await loader.loadTree(rootQuery, expectations.get(prefix)); + + lines.push(undefined); // output blank line between prefixes + const alwaysExpandThroughLevel = 2; // expand to, at minimum, every test. + for (const { query } of tree.iterateCollapsedNodes({ alwaysExpandThroughLevel })) { + const urlQueryString = prefix + query.toString(); // "?worker=0&q=..." + // 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( + urlQueryString.length < 185, + 'Generated test variant would produce too-long -actual.txt filename. \ +Try broadening suppressions to avoid long test variant names. ' + + urlQueryString + ); + lines.push(urlQueryString); + } + } + await generateFile(lines); +})().catch(ex => { + console.log(ex.stack ?? ex.toString()); + process.exit(1); +}); + +async function generateFile(lines: Array): Promise { + let result = ''; + result += '\n'; + + result += await fs.readFile(templateFile, 'utf8'); + + for (const line of lines) { + if (line === undefined) { + result += '\n'; + } else { + result += `\n`; + } + } + + await fs.writeFile(outFile, result); +} -- cgit v1.2.3