|
| 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 | +} |
0 commit comments