Skip to content

Commit a11e8a9

Browse files
committed
Add a cts command
1 parent a61ad62 commit a11e8a9

File tree

3 files changed

+88
-6
lines changed

3 files changed

+88
-6
lines changed

README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,22 @@ Bugs related to dawn, WebGPU should be filed in the in the
142142

143143
```
144144
npm run build
145-
cd third_party/dawn/third_party/webgpu-cts
146-
npm ci
147-
cd ../..
148-
cp third_party/webgpu-cts/package.json ..
149-
./tools/run run-cts --bin=out/cmake-release 'webgpu:*'
145+
npm run cts
146+
```
147+
148+
You can pass a query an optional cts query. For example
149+
150+
```
151+
npm run cts 'webgpu:shader,execution,expression,call,builtin,textureDimensions:*'
152+
```
153+
154+
You can also pass the path to the CTS, for example if you want to run your own tests
155+
156+
```
157+
npm run cts --cts=/Users/me/src/cts
150158
```
151159

152-
Note: this is no different than running the CTS in dawn itself.
160+
Note: this is no different than running the CTS in dawn itself.
153161

154162
## Updating
155163

build/run-cts.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import fs from 'node:fs';
2+
import util from 'node:util';
3+
4+
import {execute} from './execute.js';
5+
import {
6+
prependPathIfItExists,
7+
} from './utils.js';
8+
import {
9+
kDepotToolsPath,
10+
kDawnPath,
11+
kOutDir,
12+
kBuildPath,
13+
} from './constants.js';
14+
15+
prependPathIfItExists(kDepotToolsPath);
16+
17+
function showHelp(options) {
18+
const longest = Object.entries(options).reduce((max, [k]) => Math.max(max, k.length), 0);
19+
const help = `
20+
Usage: node run cts [options] [query]
21+
22+
Options:
23+
${Object.entries(options).map(([k, v]) => `${k.padEnd(longest)} : ${v.description ?? ''}`).join('\n')}
24+
`;
25+
console.log(help);
26+
}
27+
28+
function parseArgs(options) {
29+
try {
30+
const args = process.argv.slice(2);
31+
const { values, positionals } = util.parseArgs({ args, options });
32+
if (values.help) {
33+
showHelp(options);
34+
process.exit(0);
35+
}
36+
return { values, positionals };
37+
} catch (e) {
38+
console.error(e.message);
39+
showHelp(options);
40+
process.exit(1);
41+
}
42+
}
43+
44+
async function main() {
45+
const kDefaultCTSPath = `${kDawnPath}/third_party/webgpu-cts`;
46+
const options = {
47+
help: { type: 'boolean', short: 'h', description: 'show this help' },
48+
cts: { type: 'string', description: 'path to CTS', default: kDefaultCTSPath},
49+
}
50+
const { values, positionals } = parseArgs(options);
51+
const ctsPath = values.cts;
52+
const ctsQuery = positionals[0] ?? 'webgpu:*';
53+
54+
// hack around the fact that run-cts modifies the listing file (T_T)
55+
// This isn't perfect because Ctrl-C fails to stop run-cts (-_-;)
56+
const listingFilename = `${ctsPath}/src/webgpu/listing_meta.json`;
57+
const listing = fs.readFileSync(listingFilename, {encoding: 'utf-8'});
58+
59+
try {
60+
process.chdir(`${kDawnPath}/third_party/webgpu-cts`);
61+
await execute('npm', ['ci']);
62+
fs.writeFileSync(`${kOutDir}/package.json`, JSON.stringify({
63+
name: "placeholder",
64+
version: "1.0.0",
65+
}));
66+
process.chdir(kDawnPath);
67+
await execute('vpython3', ['tools/run.py', 'run-cts', `--cts=${ctsPath}`,`--bin=${kBuildPath}`, ctsQuery]);
68+
} finally {
69+
fs.writeFileSync(listingFilename, listing);
70+
}
71+
}
72+
73+
main();

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"scripts": {
99
"build": "node build/build.js",
1010
"compile": "node build/build.js --compile-only",
11+
"cts": "node build/run-cts.js",
1112
"test": "node test/test.js",
1213
"update": "node build/update.js"
1314
},

0 commit comments

Comments
 (0)