diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 003b1a4b8b..a326851e6c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -153,10 +153,15 @@ jobs: craft-fonts-ref: cc9269cd8d8258785dac603fba3122e5d2556795 # Cargo.toml's dev profile already keeps line tables only. dev-debug: "" + # PHOTOCRAFT_GATE_GPU_GROUP=separate: `cargo xtask ci` leaves nextest's `gpu` group to + # scripts/ci-gpu-lavapipe.py, the last step of `command` below, which runs it on lavapipe and + # fails on a skipped comparison. Without it the group ran twice on the same adapter (#15445). + # The two belong together: xtask's gate_gpu tests fail if the variable stays and the script goes. env: | PHOTOCRAFT_FULL_SWEEP=${{ inputs.full_sweep && '1' || '0' }} PHOTOCRAFT_NO_PRINT=1 LPDEST=photocraft-no-such-printer + PHOTOCRAFT_GATE_GPU_GROUP=separate timeout-minutes: 100 # On main, a `cache warm` leg builds the tests and saves the dependency cache as soon as the # build succeeds; the gate legs then only restore, so a failing test cannot keep the entry diff --git a/docs/development.md b/docs/development.md index 3b14f7dbc2..e8d2949109 100644 --- a/docs/development.md +++ b/docs/development.md @@ -113,7 +113,7 @@ the opted-in test; an unset variable leaves the ordinary behavior tests availabl After review, remove only the two generated PNGs and their owned temporary directory. The same Rust test and variable work on Windows with the native shell's environment-variable syntax. -**GPU tests without a GPU.** Linux CI uses the shared `craft-common-actions` gate with Mesa's Vulkan driver installed. After the regular gate, `python3 scripts/ci-gpu-lavapipe.py` reruns the configured `gpu` group with `WGPU_BACKEND=vulkan` and the lavapipe ICD explicitly selected. It requires Vulkan parity evidence and rejects authored skips, except the documented software-adapter timing exceptions. It reads the filter from `.config/nextest.toml`, so no second filter needs maintaining. To run locally on Linux, install `mesa-vulkan-drivers libvulkan1` and run the same script. Windows uses WARP; this check does not certify Windows skip coverage. +**GPU tests without a GPU.** Linux CI uses the shared `craft-common-actions` gate with Mesa's Vulkan driver installed. The gate sets `PHOTOCRAFT_GATE_GPU_GROUP=separate`, so its `cargo xtask ci` runs the tests outside the configured `gpu` group, and `python3 scripts/ci-gpu-lavapipe.py` then runs that group once, with `WGPU_BACKEND=vulkan` and the lavapipe ICD explicitly selected. A local `cargo xtask ci` does not set the variable and runs the group with the other tests. The lavapipe script requires Vulkan parity evidence and rejects authored skips, except the documented software-adapter timing exceptions. It reads the filter from `.config/nextest.toml`, so no second filter needs maintaining. To run locally on Linux, install `mesa-vulkan-drivers libvulkan1` and run the same script. Windows uses WARP; this check does not certify Windows skip coverage. ## Fonts (craft-fonts) diff --git a/xtask/src/gate_gpu.rs b/xtask/src/gate_gpu.rs new file mode 100644 index 0000000000..285e6c510e --- /dev/null +++ b/xtask/src/gate_gpu.rs @@ -0,0 +1,153 @@ +//! The nextest `gpu` test group, for the CI gate. +//! +//! The gate runs that group in `scripts/ci-gpu-lavapipe.py`, on lavapipe with Vulkan forced, where +//! a skipped GPU comparison fails the run. `cargo xtask ci` therefore leaves the group out when the +//! gate says so, instead of running every GPU test a second time (#15445). Both sides read the +//! group's filters from `.config/nextest.toml`, so the two runs always split the same way. + +use serde::Deserialize; + +/// The nextest configuration, relative to the workspace root. +pub const CONFIG: &str = ".config/nextest.toml"; + +/// Set to [`SEPARATE`] by a caller that runs the `gpu` group itself after `cargo xtask ci`. +pub const GROUP_VAR: &str = "PHOTOCRAFT_GATE_GPU_GROUP"; +/// The value of [`GROUP_VAR`] that leaves the group out of the gate's tests. +pub const SEPARATE: &str = "separate"; + +#[derive(Deserialize)] +struct Nextest { + profile: Profiles, +} + +#[derive(Deserialize)] +struct Profiles { + default: Profile, +} + +#[derive(Deserialize)] +struct Profile { + #[serde(default)] + overrides: Vec, +} + +#[derive(Deserialize)] +struct Override { + filter: Option, + #[serde(rename = "test-group")] + test_group: Option, +} + +/// The filterset of the `gpu` group: the default profile's overrides that assign it, joined as +/// `scripts/ci-gpu-lavapipe.py` joins them. No such override is an error, not an empty filter: +/// excluding nothing here would look like success while the group ran twice, and selecting +/// nothing there is already refused. A `gpu` override without a filter is an error on both sides. +fn gpu_group_filter(nextest_toml: &str) -> Result { + let config: Nextest = toml::from_str(nextest_toml).map_err(|e| format!("{CONFIG}: {e}"))?; + let mut filters = Vec::new(); + for row in config.profile.default.overrides.iter().filter(|row| row.test_group.as_deref() == Some("gpu")) { + let filter = row.filter.as_deref().ok_or_else(|| format!("{CONFIG}: a gpu test group override has no filter"))?; + filters.push(format!("({filter})")); + } + if filters.is_empty() { + return Err(format!("{CONFIG}: the gpu test group has no filters")); + } + Ok(filters.join(" | ")) +} + +/// The filterset of every test outside the `gpu` group. +pub fn without_gpu_group(nextest_toml: &str) -> Result { + Ok(format!("not ({})", gpu_group_filter(nextest_toml)?)) +} + +#[cfg(test)] +mod tests { + use super::*; + + const TWO_GPU_ROWS: &str = r#" +[test-groups] +gpu = { max-threads = 4 } + +[[profile.default.overrides]] +filter = 'package(a)' +test-group = 'gpu' + +[[profile.default.overrides]] +filter = 'package(b)' +test-group = 'cpu' + +[[profile.default.overrides]] +filter = 'test(c)' +test-group = 'gpu' + +[profile.ci] +fail-fast = false +"#; + + #[test] + fn gpu_rows_are_joined_as_the_lavapipe_script_joins_them() { + assert_eq!(gpu_group_filter(TWO_GPU_ROWS).unwrap(), "(package(a)) | (test(c))"); + assert_eq!(without_gpu_group(TWO_GPU_ROWS).unwrap(), "not ((package(a)) | (test(c)))"); + } + + #[test] + fn a_config_without_a_gpu_row_is_refused() { + let none = "[[profile.default.overrides]]\nfilter = 'package(b)'\ntest-group = 'cpu'\n"; + assert!(gpu_group_filter(none).unwrap_err().contains("no filters")); + assert!(without_gpu_group("[profile.default]\n").is_err()); + } + + #[test] + fn a_gpu_row_without_a_filter_is_refused() { + let unfiltered = "[[profile.default.overrides]]\ntest-group = 'gpu'\n"; + assert!(gpu_group_filter(unfiltered).unwrap_err().contains("no filter")); + } + + /// What is wrong with a workflow that leaves the `gpu` group out of `cargo xtask ci`, if + /// anything. Leaving it out is only safe while the same command goes on to the checked run: + /// the variable and `scripts/ci-gpu-lavapipe.py` are two lines of `ci.yml`, and deleting the + /// second alone would stop every GPU test on the Linux gate with nothing turning red. + fn handoff_problem(workflow: &str) -> Option<&'static str> { + let lines = || workflow.lines().map(str::trim); + if !lines().any(|line| line == format!("{GROUP_VAR}={SEPARATE}")) { + return None; + } + let Some(command) = lines().filter_map(|line| line.strip_prefix("command: ")).find(|command| command.contains("cargo xtask ci")) else { + return Some("the gpu group is left out, but no command runs `cargo xtask ci`"); + }; + if command.contains("cargo xtask ci && python3 scripts/ci-gpu-lavapipe.py") { + None + } else { + Some("the gpu group is left out of `cargo xtask ci`, but the command does not go on to scripts/ci-gpu-lavapipe.py") + } + } + + const GATE: &str = + " env: |\n PHOTOCRAFT_GATE_GPU_GROUP=separate\n command: python3 a.py && cargo xtask ci && python3 scripts/ci-gpu-lavapipe.py\n"; + + #[test] + fn leaving_the_gpu_group_out_needs_the_checked_run_in_the_same_command() { + assert_eq!(handoff_problem(GATE), None); + // The checked run deleted, or no longer reached only when the gate passed. + assert!(handoff_problem(&GATE.replace(" && python3 scripts/ci-gpu-lavapipe.py", "")).is_some()); + assert!(handoff_problem(&GATE.replace("ci && python3 scripts", "ci || python3 scripts")).is_some()); + assert!(handoff_problem(&GATE.replace("command: ", "warm-command: ")).is_some()); + // Not left out: `cargo xtask ci` runs the group itself, with or without the checked run. + let all_here = GATE.replace(" PHOTOCRAFT_GATE_GPU_GROUP=separate\n", ""); + assert_eq!(handoff_problem(&all_here), None); + assert_eq!(handoff_problem(&all_here.replace(" && python3 scripts/ci-gpu-lavapipe.py", "")), None); + } + + #[test] + fn the_ci_workflow_hands_the_gpu_group_to_the_checked_run() { + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../.github/workflows/ci.yml"); + assert_eq!(handoff_problem(&std::fs::read_to_string(path).unwrap()), None); + } + + #[test] + fn the_workspace_config_has_a_gpu_group() { + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("..").join(CONFIG); + let filter = gpu_group_filter(&std::fs::read_to_string(path).unwrap()).unwrap(); + assert!(filter.contains("package(photocraft-gpu)"), "{filter}"); + } +} diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 3fe247e33c..a258dcebc8 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -5,6 +5,7 @@ mod corpus; mod corpus_pins; +mod gate_gpu; mod i18n_report; mod ico; mod layers; @@ -244,12 +245,19 @@ const GATE_ARGS: [&str; 4] = ["--workspace", "--locked", "--features", "heif"]; /// The gate's tests. nextest's `ci` profile stops at the first failure and terminates hung tests /// (.config/nextest.toml). `panic_hunt` runs only the engine's `#[ignore]`d panic hunt (AGENTS.md /// Rule 9) with the same packages, features and targets as the tests, so nothing rebuilds. +/// +/// With `PHOTOCRAFT_GATE_GPU_GROUP=separate` the tests leave out nextest's `gpu` group: the caller +/// runs it afterwards (the CI gate does, in `scripts/ci-gpu-lavapipe.py`, see `gate_gpu`). Unset, +/// as in a local `cargo xtask ci`, the group runs here with the other tests. fn cmd_gate_tests(panic_hunt: bool) -> Result<(), String> { let mut c = cargo(); if nextest_available() { c.args(["nextest", "run", "--profile", "ci"]).args(GATE_ARGS).args(&TEST_TARGETS[1..]); if panic_hunt { c.args(["--run-ignored", "only", "-E", "binary_id(photocraft-engine::panic_hunt)"]); + } else if std::env::var(gate_gpu::GROUP_VAR).is_ok_and(|v| v == gate_gpu::SEPARATE) { + let config = std::fs::read_to_string(root().join(gate_gpu::CONFIG)).map_err(|e| format!("{}: {e}", gate_gpu::CONFIG))?; + c.arg("-E").arg(gate_gpu::without_gpu_group(&config)?); } } else if panic_hunt { // `-- --ignored` across the workspace would run every ignored test, not only the hunt. The