Skip to content

Commit 4cd8be5

Browse files
Add an xtask to run the CTS (#7719)
1 parent 661b172 commit 4cd8be5

File tree

4 files changed

+108
-12
lines changed

4 files changed

+108
-12
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ unicode-ident = "1.0.5"
190190
walkdir = "2.3"
191191
winit = { version = "0.29", features = ["android-native-activity"] }
192192
which = "7"
193-
xshell = "0.2"
193+
xshell = "0.2.2"
194194

195195
# Metal dependencies
196196
metal = "0.32"

README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -216,26 +216,30 @@ WebGPU includes a Conformance Test Suite to validate that implementations are wo
216216

217217
To have GitHub run the CTS against a pull request, you can add the `PR: run CTS` label to the PR.
218218

219-
To run the CTS locally, first, you need to check it out:
219+
To run the CTS locally, run:
220220

221221
```
222-
# In the root of your wgpu tree:
223-
git clone https://github.com/gpuweb/cts.git
224-
cd cts
225-
# works in bash and powershell
226-
git checkout $(cat ../cts_runner/revision.txt)
222+
cargo xtask cts
227223
```
228224

229-
To run a given set of tests:
225+
This will clone the CTS into the `cts` directory, check out the
226+
[pinned version](./cts_runner/revision.txt), and run the
227+
[default list of enabled tests](./cts_runner/test.lst).
228+
229+
You can also specify a test selector on the command line:
230230

231231
```
232-
# Must be inside the `cts` folder we just checked out, else this will fail
233-
cargo run --manifest-path ../Cargo.toml -p cts_runner --bin cts_runner -- ./tools/run_deno --verbose "<test string>"
232+
cargo xtask cts 'webgpu:api,operation,command_buffer,basic:*'
234233
```
235234

236-
To find the full list of tests, go to the [online cts viewer](https://gpuweb.github.io/cts/standalone/?runnow=0&worker=0&debug=0&q=webgpu:*).
235+
Or supply your own test list in a file:
236+
237+
```
238+
cargo xtask cts -f your_tests.lst
239+
```
237240

238-
The list of currently enabled CTS tests can be found [here](./cts_runner/test.lst).
241+
To find the full list of tests, go to the
242+
[web version of the CTS](https://gpuweb.github.io/cts/standalone/?runnow=0&worker=0&debug=0&q=webgpu:*).
239243

240244
## Tracking the WebGPU and WGSL draft specifications
241245

xtask/src/cts.rs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
use anyhow::Context;
2+
use pico_args::Arguments;
3+
use std::ffi::OsString;
4+
use xshell::Shell;
5+
6+
/// Path within the repository where the CTS will be checked out.
7+
const CTS_CHECKOUT_PATH: &str = "cts";
8+
9+
/// Path within the repository to a file containing the git revision of the CTS to check out.
10+
const CTS_REVISION_PATH: &str = "cts_runner/revision.txt";
11+
12+
/// URL of the CTS git repository.
13+
const CTS_GIT_URL: &str = "https://github.com/gpuweb/cts.git";
14+
15+
/// Path to default CTS test list.
16+
const CTS_DEFAULT_TEST_LIST: &str = "cts_runner/test.lst";
17+
18+
pub fn run_cts(shell: Shell, mut args: Arguments) -> anyhow::Result<()> {
19+
let mut list_files = Vec::<OsString>::new();
20+
21+
while let Some(file) = args.opt_value_from_str("-f")? {
22+
list_files.push(file);
23+
}
24+
25+
let mut tests = args.finish();
26+
27+
if tests.is_empty() && list_files.is_empty() {
28+
log::info!("Reading default test list from {CTS_DEFAULT_TEST_LIST}");
29+
list_files.push(OsString::from(CTS_DEFAULT_TEST_LIST));
30+
}
31+
32+
for file in list_files {
33+
tests.extend(shell.read_file(file)?.lines().filter_map(|line| {
34+
let trimmed = line.trim();
35+
let is_comment = trimmed.starts_with("//") || trimmed.starts_with("#");
36+
(!is_comment).then(|| OsString::from(trimmed))
37+
}))
38+
}
39+
40+
let cts_revision = shell
41+
.read_file(CTS_REVISION_PATH)
42+
.context(format!(
43+
"Failed to read CTS git SHA from {CTS_REVISION_PATH}"
44+
))?
45+
.trim()
46+
.to_string();
47+
48+
if !shell.path_exists(CTS_CHECKOUT_PATH) {
49+
log::info!("Cloning CTS");
50+
shell
51+
.cmd("git")
52+
.args(["clone", CTS_GIT_URL, CTS_CHECKOUT_PATH])
53+
.quiet()
54+
.run()
55+
.context("Failed to clone CTS")?;
56+
}
57+
58+
shell.change_dir(CTS_CHECKOUT_PATH);
59+
60+
log::info!("Checking out CTS");
61+
shell
62+
.cmd("git")
63+
.args(["checkout", "--quiet", &cts_revision])
64+
.quiet()
65+
.run()
66+
.context("Failed to check out CTS")?;
67+
68+
log::info!("Running CTS");
69+
for test in &tests {
70+
shell
71+
.cmd("cargo")
72+
.args(["run"])
73+
.args(["--manifest-path", "../Cargo.toml"])
74+
.args(["-p", "cts_runner"])
75+
.args(["--bin", "cts_runner"])
76+
.args(["--", "./tools/run_deno", "--verbose"])
77+
.args([test])
78+
.run()
79+
.context("CTS failed")?;
80+
}
81+
82+
if tests.len() > 1 {
83+
log::info!("Summary reflects only tests from the last selector, not the entire run.");
84+
}
85+
86+
Ok(())
87+
}

xtask/src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::process::ExitCode;
66
use anyhow::Context;
77
use pico_args::Arguments;
88

9+
mod cts;
910
mod run_wasm;
1011
mod test;
1112
mod util;
@@ -15,6 +16,9 @@ const HELP: &str = "\
1516
Usage: xtask <COMMAND>
1617
1718
Commands:
19+
cts [<test selector> | -f <test list file>]...
20+
Check out, build, and run CTS tests
21+
1822
run-wasm
1923
Build and run web examples
2024
@@ -76,6 +80,7 @@ fn main() -> anyhow::Result<ExitCode> {
7680
shell.change_dir(String::from(env!("CARGO_MANIFEST_DIR")) + "/..");
7781

7882
match subcommand.as_deref() {
83+
Some("cts") => cts::run_cts(shell, args)?,
7984
Some("run-wasm") => run_wasm::run_wasm(shell, args)?,
8085
Some("test") => test::run_tests(shell, args)?,
8186
Some("vendor-web-sys") => vendor_web_sys::run_vendor_web_sys(shell, args)?,

0 commit comments

Comments
 (0)