Wave 311/509: Fillet rig: a regression gate on every pull request that touches fillet code (and 2 more)
3 commits, squashed; the originals stay reachable from tag archive/merge-main-develop. -517fc01dcjyviko: Fillet rig: a regression gate on every pull request that touches fillet code -b91ad9de2jyviko: Splines: every degree a B-rep record holds is evaluated, so a G4 blend of degree 9 gets its pcurves -175b4f2acjyviko: GPU tessellation: the shader's basis slots follow the CPU evaluator's highest degree Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ
This commit is contained in:
1 parent
18ac5bfd45
commit
6537aaa0d0
10 files changed
+328
-34
No files matched your search
@@ -0,0 +1,109 @@
|
||||
# The fillet rig as a regression gate: a pull request that touches fillet code (the paths below)
|
||||
# runs every case in tests/kernel-cases/fillets/ on SMLib, through one release build of
|
||||
# solidcraft-cli, and fails on a regression (a case that fails and
|
||||
# tests/kernel-cases/fillets/KNOWN_FAILING does not list) or on a listed case that now passes
|
||||
# (it is fixed: remove its line, so the list only shrinks). See tests/kernel-cases/README.md.
|
||||
#
|
||||
# GitHub filters a workflow by whole files, so the fillet parts of crates/doc/src/eval*.rs and
|
||||
# crates/engine/src/cmd/features.rs select it whenever those files change. Pushes to main and
|
||||
# develop that touch the same paths run it too and save the compiler cache (a Blacksmith sticky
|
||||
# disk) that pull requests then mount read-only.
|
||||
name: Fillet rig
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened, ready_for_review]
|
||||
paths:
|
||||
- "crates/kernel/src/blend*.rs"
|
||||
- "crates/kernel/src/fillet*.rs"
|
||||
- "crates/kernel/src/*corner*.rs"
|
||||
- "crates/kernel/src/continuity*.rs"
|
||||
- "crates/smlib/**"
|
||||
- "crates/doc/src/eval*.rs"
|
||||
- "crates/engine/src/cmd/features.rs"
|
||||
- "tests/kernel-cases/fillets/**"
|
||||
# The rig itself: the grading, the runner and this workflow.
|
||||
- "apps/solidcraft-cli/src/kernel_cases.rs"
|
||||
- "xtask/src/kernel_cases.rs"
|
||||
- "scripts/fetch-smlib.sh"
|
||||
- ".github/workflows/fillet-rig.yml"
|
||||
push:
|
||||
branches: [main, develop]
|
||||
# The same paths as pull_request.
|
||||
paths:
|
||||
- "crates/kernel/src/blend*.rs"
|
||||
- "crates/kernel/src/fillet*.rs"
|
||||
- "crates/kernel/src/*corner*.rs"
|
||||
- "crates/kernel/src/continuity*.rs"
|
||||
- "crates/smlib/**"
|
||||
- "crates/doc/src/eval*.rs"
|
||||
- "crates/engine/src/cmd/features.rs"
|
||||
- "tests/kernel-cases/fillets/**"
|
||||
# The rig itself: the grading, the runner and this workflow.
|
||||
- "apps/solidcraft-cli/src/kernel_cases.rs"
|
||||
- "xtask/src/kernel_cases.rs"
|
||||
- "scripts/fetch-smlib.sh"
|
||||
- ".github/workflows/fillet-rig.yml"
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
concurrency:
|
||||
group: fillet-rig-${{ github.ref }}
|
||||
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
jobs:
|
||||
fillets:
|
||||
name: Fillet rig
|
||||
# Draft pull requests run no CI, as in ci.yml.
|
||||
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
|
||||
runs-on: blacksmith-8vcpu-ubuntu-2404
|
||||
timeout-minutes: 60
|
||||
env:
|
||||
CARGO_INCREMENTAL: "0"
|
||||
RUSTC_WRAPPER: sccache
|
||||
SCCACHE_DIR: /home/runner/.cache/sccache
|
||||
SCCACHE_CACHE_SIZE: 10G
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
- name: Size parallel compiles to the job's memory
|
||||
run: scripts/ci/build-jobs.sh
|
||||
- uses: dtolnay/rust-toolchain@stable
|
||||
# Only main and develop commit the cache; pull requests and forks mount a clone and never
|
||||
# write back.
|
||||
- name: Mount the compiler cache
|
||||
uses: useblacksmith/stickydisk@3f6be1451e3cad893b778bc93495c80452a5da26 # v1.7.2
|
||||
continue-on-error: true
|
||||
with:
|
||||
key: ${{ github.repository }}-sccache-fillet-rig
|
||||
path: /home/runner/.cache/sccache
|
||||
commit: ${{ (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop') && 'on-change' || 'false' }}
|
||||
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
|
||||
with:
|
||||
key: fillet-rig
|
||||
save-if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' }}
|
||||
- name: Fetch SMLib (crates/smlib/SMLIB_REV)
|
||||
shell: bash
|
||||
run: scripts/fetch-smlib.sh
|
||||
- name: Set up compiler cache
|
||||
uses: mozilla-actions/sccache-action@fc920bf0ec8de6ee65d409111f7ec508035751ba # v0.0.11
|
||||
with:
|
||||
version: v0.16.0
|
||||
- name: Build the CLI (release, SMLib)
|
||||
run: cargo build --release --locked -p solidcraft-cli --features smlib
|
||||
- name: Run the fillet cases against the known-failing list
|
||||
run: >-
|
||||
cargo run -q --locked -p xtask -- kernel-cases --area fillets
|
||||
--cli target/release/solidcraft-cli --out "$RUNNER_TEMP/fillet-rig"
|
||||
--known-failing tests/kernel-cases/fillets/KNOWN_FAILING
|
||||
- name: Keep the results
|
||||
if: always()
|
||||
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
|
||||
with:
|
||||
name: fillet-rig-results
|
||||
path: ${{ runner.temp }}/fillet-rig/results.json
|
||||
if-no-files-found: ignore
|
||||
@@ -284,7 +284,7 @@ fn knots(values: &[f64], count: usize, budget: &mut Budget) -> Result<()> {
|
||||
budget.add(values.len())?;
|
||||
numbers(values.iter().copied())?;
|
||||
let degree = values.len().checked_sub(count.saturating_add(1)).ok_or(Invalid("spline degree"))?;
|
||||
require((2..=4096).contains(&count) && (1..=16).contains(°ree) && degree < count, "spline degree or size")?;
|
||||
require((2..=4096).contains(&count) && (1..=crate::bspline::MAX_SPLINE_DEGREE).contains(°ree) && degree < count, "spline degree or size")?;
|
||||
require(values.windows(2).all(|w| w.first() <= w.get(1)), "unordered knots")?;
|
||||
require(values.get(degree) < values.get(count), "empty spline domain")?;
|
||||
// No knot may have multiplicity greater than degree + 1.
|
||||
|
||||
@@ -78,6 +78,46 @@ fn lines_polylines_and_splines_on_planes_are_their_points_mapped() {
|
||||
assert!(lift_error(&plane, &cubic, [0.5, 1.5], pc) <= 1e-7);
|
||||
}
|
||||
|
||||
/// A G4 blend curve is one Bézier of degree 9 (five conditions at each end): on its sketch's
|
||||
/// plane its pcurve is its points mapped, and on the face extruded from it, of degree (9, 1),
|
||||
/// the kernel's own iso-line trims close the loop and lift onto the edges. Degree 9 was past the
|
||||
/// evaluator's old cap of 7, so both faces were refused ("a spline surface of degree (9, 1)").
|
||||
#[test]
|
||||
fn a_g4_blend_of_degree_9_and_the_face_extruded_from_it_get_exact_pcurves() {
|
||||
let bezier = |z: f64| -> Vec<[f64; 3]> {
|
||||
let along_x = (0..5).map(|k| [10. + k as f64, 0., z]);
|
||||
let along_y = (5..10).map(|k| [20., k as f64 + 1., z]);
|
||||
along_x.chain(along_y).collect()
|
||||
};
|
||||
let knots: Vec<f64> = [[0.; 10], [1.; 10]].concat();
|
||||
let low = Curve::Spline { knots: knots.clone(), points: bezier(0.) };
|
||||
let plane = Surface::Plane { origin: [0.; 3], u_axis: [1., 0., 0.], v_axis: [0., 1., 0.] };
|
||||
let pc = &pcurves(&plane, &one(&low, [0., 1.]), 1e-9).unwrap()[0][0];
|
||||
let Curve2::Spline { knots: k, points } = pc else { panic!("a spline") };
|
||||
assert_eq!((k, points.len()), (&knots, 10), "the curve's own knots and points");
|
||||
assert!(lift_error(&plane, &low, [0., 1.], pc) <= 1e-12);
|
||||
|
||||
let (low_pts, high_pts) = (bezier(0.), bezier(10.));
|
||||
let rows = low_pts.iter().zip(&high_pts).map(|(a, b)| vec![*a, *b]).collect();
|
||||
let wall = Surface::Spline { u_knots: knots.clone(), v_knots: vec![0., 0., 1., 1.], points: rows };
|
||||
let high = Curve::Spline { knots, points: high_pts };
|
||||
let right = Curve::Line { start: [20., 10., 0.], end: [20., 10., 10.] };
|
||||
let left = Curve::Line { start: [10., 0., 10.], end: [10., 0., 0.] };
|
||||
let seg = |a: [f64; 2], b: [f64; 2]| Curve2::Spline { knots: vec![0., 0., 1., 1.], points: vec![a, b] };
|
||||
let given = [seg([0., 0.], [1., 0.]), seg([1., 0.], [1., 1.]), seg([0., 1.], [1., 1.]), seg([0., 1.], [0., 0.])];
|
||||
let edges = [(&low, true), (&right, true), (&high, false), (&left, true)];
|
||||
let l: Vec<EdgeUse<'_>> = edges
|
||||
.iter()
|
||||
.zip(&given)
|
||||
.enumerate()
|
||||
.map(|(e, ((curve, forward), g))| EdgeUse { edge: e as u32, curve, interval: [0., 1.], forward: *forward, tolerance: 0.0, given: Some(g) })
|
||||
.collect();
|
||||
let pcs = pcurves_within(&wall, &[l], 1e-7, Some([[0., 1.], [0., 1.]])).unwrap();
|
||||
for ((curve, _), pc) in edges.iter().zip(&pcs[0]) {
|
||||
assert!(lift_error(&wall, curve, [0., 1.], pc) <= 1e-12, "{curve:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A circle about the axis is a u-line: v fixed, u its angle plus a constant (minus where it
|
||||
/// turns the other way), on cylinders, cones, spheres and tori, in either direction.
|
||||
#[test]
|
||||
|
||||
@@ -15,8 +15,10 @@ use std::ops::{Add, AddAssign, Mul, Sub};
|
||||
|
||||
use crate::Vec3;
|
||||
|
||||
/// Highest polynomial degree accepted in either direction.
|
||||
pub const MAX_SPLINE_DEGREE: usize = 7;
|
||||
/// Highest polynomial degree accepted in either direction: the B-rep record's own bound
|
||||
/// (`Brep::validate`), so every spline a record may hold can be evaluated. A G4 blend is of
|
||||
/// degree 9 (five conditions at each end).
|
||||
pub const MAX_SPLINE_DEGREE: usize = 16;
|
||||
/// Most knots accepted in one knot vector.
|
||||
pub const MAX_KNOTS: usize = 1 << 14;
|
||||
/// Most control points accepted in one tensor surface.
|
||||
|
||||
+35
-26
@@ -514,46 +514,55 @@ pub(crate) fn span_of(knots: &[f64], p: usize, n: usize, t: f64) -> usize {
|
||||
k
|
||||
}
|
||||
|
||||
/// The non-zero basis functions of degree `p` on span `span` (NURBS Book A2.2): element `j` is
|
||||
/// `N_{span−p+j}`.
|
||||
fn basis_funs(knots: &[f64], span: usize, p: usize, t: f64) -> Option<[f64; W]> {
|
||||
if p >= W {
|
||||
return None;
|
||||
}
|
||||
let kn = |i: usize| knots.get(i).copied();
|
||||
let mut n = [0.0f64; W];
|
||||
n[0] = 1.0;
|
||||
for j in 1..=p {
|
||||
let mut saved = 0.0;
|
||||
for (r, nr) in n.iter_mut().enumerate().take(j) {
|
||||
// right[r + 1] and left[j − r] of A2.2.
|
||||
let right = kn(span + r + 1)? - t;
|
||||
let left = t - kn((span + 1 + r).checked_sub(j)?)?;
|
||||
let den = right + left;
|
||||
let temp = if den != 0.0 { *nr / den } else { 0.0 };
|
||||
*nr = saved + right * temp;
|
||||
saved = left * temp;
|
||||
}
|
||||
n[j] = saved;
|
||||
}
|
||||
Some(n)
|
||||
}
|
||||
|
||||
/// Non-zero basis functions of degree `p` on span `span` and their first derivatives
|
||||
/// (NURBS Book A2.3 with n = 1). `ders[0][j]` is `N_{span−p+j}`, `ders[1][j]` its derivative.
|
||||
/// (NURBS Book eq. 2.7, from the degree p − 1 functions on the same span). `ders[0][j]` is
|
||||
/// `N_{span−p+j}`, `ders[1][j]` its derivative. One-dimensional tables, as the GPU twin keeps
|
||||
/// them, so a high degree costs its own work only.
|
||||
pub(crate) fn basis_ders(knots: &[f64], span: usize, p: usize, t: f64) -> Option<[[f64; W]; 2]> {
|
||||
if p == 0 || p >= W {
|
||||
return None;
|
||||
}
|
||||
let kn = |i: usize| knots.get(i).copied();
|
||||
// ndu[j][r]: basis values (upper triangle incl. diagonal), knot differences (lower).
|
||||
let mut ndu = [[0.0f64; W]; W];
|
||||
let (mut left, mut right) = ([0.0f64; W], [0.0f64; W]);
|
||||
ndu[0][0] = 1.0;
|
||||
for j in 1..=p {
|
||||
left[j] = t - kn((span + 1).checked_sub(j)?)?;
|
||||
right[j] = kn(span + j)? - t;
|
||||
let mut saved = 0.0;
|
||||
for r in 0..j {
|
||||
ndu[j][r] = right[r + 1] + left[j - r];
|
||||
let temp = if ndu[j][r] != 0.0 { ndu[r][j - 1] / ndu[j][r] } else { 0.0 };
|
||||
ndu[r][j] = saved + right[r + 1] * temp;
|
||||
saved = left[j - r] * temp;
|
||||
}
|
||||
ndu[j][j] = saved;
|
||||
}
|
||||
let mut ders = [[0.0f64; W]; 2];
|
||||
for j in 0..=p {
|
||||
ders[0][j] = ndu[j][p];
|
||||
}
|
||||
// First derivative: p·(N_{r,p−1}/(u_{r+p}−u_r) − N_{r+1,p−1}/(u_{r+p+1}−u_{r+1})).
|
||||
let lower = basis_funs(knots, span, p - 1, t)?;
|
||||
let mut ders = [basis_funs(knots, span, p, t)?, [0.0f64; W]];
|
||||
// N'_{i,p} = p·(N_{i,p−1}/(u_{i+p}−u_i) − N_{i+1,p−1}/(u_{i+p+1}−u_{i+1})), i = span − p + r.
|
||||
for r in 0..=p {
|
||||
let mut d = 0.0;
|
||||
if r >= 1 {
|
||||
let den = ndu[p][r - 1];
|
||||
let den = kn(span + r)? - kn((span + r).checked_sub(p)?)?;
|
||||
if den != 0.0 {
|
||||
d += ndu[r - 1][p - 1] / den;
|
||||
d += lower[r - 1] / den;
|
||||
}
|
||||
}
|
||||
if r < p {
|
||||
let den = ndu[p][r];
|
||||
let den = kn(span + r + 1)? - kn((span + r + 1).checked_sub(p)?)?;
|
||||
if den != 0.0 {
|
||||
d -= ndu[r][p - 1] / den;
|
||||
d -= lower[r] / den;
|
||||
}
|
||||
}
|
||||
ders[1][r] = d * p as f64;
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
const PLANE: u32 = 0u;
|
||||
const NURBS: u32 = 1u;
|
||||
const REVOLVED: u32 = 2u;
|
||||
// Basis slots for the highest degree (MAX_SPLINE_DEGREE = 7).
|
||||
const W: u32 = 8u;
|
||||
// Basis slots for the highest degree (MAX_SPLINE_DEGREE = 16).
|
||||
const W: u32 = 17u;
|
||||
|
||||
struct Surface {
|
||||
kind: u32,
|
||||
|
||||
@@ -96,6 +96,14 @@ fn the_hlsl_for_fxc_has_no_arrays_fxc_must_unroll_loops_for() {
|
||||
}
|
||||
}
|
||||
|
||||
/// The shader's basis slots hold the highest degree the CPU evaluator takes, so every surface
|
||||
/// the CPU evaluates the GPU evaluates too.
|
||||
#[test]
|
||||
fn the_shader_takes_every_degree_the_cpu_evaluator_does() {
|
||||
let slots = format!("const W: u32 = {}u;", solidcraft_geom::bspline::MAX_SPLINE_DEGREE + 1);
|
||||
assert!(SHADER.contains(&slots), "tess.wgsl must declare `{slots}`");
|
||||
}
|
||||
|
||||
fn ok<T, E: std::fmt::Debug>(r: std::result::Result<T, E>) -> T {
|
||||
match r {
|
||||
Ok(v) => v,
|
||||
|
||||
@@ -97,6 +97,28 @@ the frozen truck-geometry PRs, a `kernel-paused` PR), for the report's coverage
|
||||
| `tolerance` | Optional overrides: `rel`, `abs_mm`, `mesh_mm`, `weld_mm`. |
|
||||
| `missing` | A capability SolidCraft has no command or parameter for yet (`"solid.thread has no start count"`): the case is reported **not supported yet** without running, so the gap stays visible. |
|
||||
|
||||
## The fillet gate
|
||||
|
||||
The fillet cases are the fillet regression suite: each is one small case of one issue, with its
|
||||
exact answer. `.github/workflows/fillet-rig.yml` runs them on every pull request (not a draft)
|
||||
that touches fillet code: `crates/kernel/src/{blend*,fillet*,*corner*,continuity*}.rs`,
|
||||
`crates/smlib/**` (`SMLIB_REV` and `SMLIB_PREBUILT` included), `crates/doc/src/eval*.rs`,
|
||||
`crates/engine/src/cmd/features.rs`, `tests/kernel-cases/fillets/**` and the rig's own code
|
||||
(GitHub filters whole files, so any change to `eval*.rs` or `features.rs` runs it). One release
|
||||
build of `solidcraft-cli`, then:
|
||||
|
||||
```sh
|
||||
cargo xtask kernel-cases --area fillets --cli target/release/solidcraft-cli \
|
||||
--known-failing tests/kernel-cases/fillets/KNOWN_FAILING
|
||||
```
|
||||
|
||||
`fillets/KNOWN_FAILING` lists the cases that fail today, sorted, one a line with its cause
|
||||
(`<case> <why it fails today>`; `#` starts a comment). The gate fails on a **regression**, a case
|
||||
that fails (or crashes, hangs, or is not supported yet) and is not listed, and on a **fixed** case,
|
||||
one listed that passes: a fix removes its line in the same pull request, so the list only shrinks.
|
||||
A new case that fails today goes in with its line. With `--known-failing` the run writes no
|
||||
report; `docs/kernel-cases.md` stays the full run's.
|
||||
|
||||
## The complexity ladder
|
||||
|
||||
`ladder/` orders kernel operations by complexity instead of by where they went wrong: tiers from
|
||||
|
||||
+103
-2
@@ -30,6 +30,8 @@ pub(crate) struct Options {
|
||||
pub(crate) jobs: usize,
|
||||
/// The run's output folder: `results.json` and the SMLib dumps (`dumps/`).
|
||||
out: PathBuf,
|
||||
/// `--known-failing FILE`: run as a regression gate against that baseline (see [`gate`]).
|
||||
known_failing: Option<PathBuf>,
|
||||
}
|
||||
|
||||
/// The run's options; `out` is its output folder unless `--out` gives one.
|
||||
@@ -38,7 +40,11 @@ pub(crate) fn options(rest: &[&str], out: &str) -> Result<Options, String> {
|
||||
let secs = arg("--timeout").map(|t| t.parse::<u64>().map_err(|e| format!("--timeout: {e}"))).transpose()?.unwrap_or(DEFAULT_TIMEOUT_S);
|
||||
let jobs = arg("--jobs").map(|j| j.parse::<usize>().map_err(|e| format!("--jobs: {e}"))).transpose()?.unwrap_or(4).clamp(1, 32);
|
||||
let out = arg("--out").map_or_else(|| root().join(out), PathBuf::from);
|
||||
Ok(Options { cli: arg("--cli"), area: arg("--area"), timeout: Duration::from_secs(secs), jobs, out })
|
||||
let known_failing = arg("--known-failing").map(|p| {
|
||||
let p = PathBuf::from(p);
|
||||
if p.is_absolute() { p } else { root().join(p) }
|
||||
});
|
||||
Ok(Options { cli: arg("--cli"), area: arg("--area"), timeout: Duration::from_secs(secs), jobs, out, known_failing })
|
||||
}
|
||||
|
||||
/// Every case's full result as JSON, into the run's output folder.
|
||||
@@ -270,7 +276,7 @@ fn write_report(dir: &Path, list: &[PathBuf], results: &[Value]) -> Result<Strin
|
||||
);
|
||||
}
|
||||
let mut md = String::from(
|
||||
"# Kernel regression rig\n\nGenerated by `cargo xtask kernel-cases`. Every geometry case the old kernel (truck) got wrong, as an issue, a PR or a crash report recorded it, is a use case in [`tests/kernel-cases/`](../tests/kernel-cases/) with its own right answer: numbers from analysis or a hand calculation (**analytic**) where the geometry has them, and otherwise the invariants (**invariants**): the operation succeeds, or refuses cleanly where that is the right answer; each body is one closed shell that passes the record's structure and geometry checks and SMLib's own check; the expected face, edge and vertex counts. Never a kernel's output, and never a commercial kernel's.\n\nThe cases run on SMLib, SolidCraft's kernel. A failing case stays failing until the kernel is fixed; there is no workaround on SolidCraft's side. A failed SMLib call leaves its inputs for replay in the run's output folder (`target/kernel-cases/dumps/<area>-<case>/`). See [`tests/kernel-cases/README.md`](../tests/kernel-cases/README.md) for the format.\n\n",
|
||||
"# Kernel regression rig\n\nGenerated by `cargo xtask kernel-cases`. Every geometry case the old kernel (truck) got wrong, as an issue, a PR or a crash report recorded it, is a use case in [`tests/kernel-cases/`](../tests/kernel-cases/) with its own right answer: numbers from analysis or a hand calculation (**analytic**) where the geometry has them, and otherwise the invariants (**invariants**): the operation succeeds, or refuses cleanly where that is the right answer; each body is one closed shell that passes the record's structure and geometry checks and SMLib's own check; the expected face, edge and vertex counts. Never a kernel's output, and never a commercial kernel's.\n\nThe cases run on SMLib, SolidCraft's kernel. A failing case stays failing until the kernel is fixed; there is no workaround on SolidCraft's side. A failed SMLib call leaves its inputs for replay in the run's output folder (`target/kernel-cases/dumps/<area>-<case>/`). See [`tests/kernel-cases/README.md`](../tests/kernel-cases/README.md) for the format. The fillet cases are also a regression gate: CI's Fillet rig workflow runs them on every pull request that touches fillet code and fails on a case that fails and [`fillets/KNOWN_FAILING`](../tests/kernel-cases/fillets/KNOWN_FAILING) does not list, or a listed case that passes.\n\n",
|
||||
);
|
||||
md += "## Coverage\n\n| Area | Cases | Results |\n|---|---|---|\n";
|
||||
for (area, (n, statuses)) in &areas {
|
||||
@@ -335,6 +341,101 @@ pub fn run(rest: &[&str]) -> Result<(), String> {
|
||||
}
|
||||
let results = run_all(&o, &list);
|
||||
save_results(&o, &results)?;
|
||||
if let Some(file) = &o.known_failing {
|
||||
// A gate run grades one set against its baseline; the report stays the full run's.
|
||||
let text = std::fs::read_to_string(file).map_err(|e| format!("{}: {e}", file.display()))?;
|
||||
let base = file.parent().unwrap_or(&dir);
|
||||
let paths: Vec<String> = list.iter().map(|c| c.strip_prefix(base).unwrap_or(c).to_string_lossy().replace('\\', "/")).collect();
|
||||
let statuses: Vec<&str> = results.iter().map(|r| r["status"].as_str().unwrap_or("?")).collect();
|
||||
println!("{}", gate(&text, &paths, &statuses).map_err(|e| format!("{}: {e}", file.display()))?);
|
||||
return Ok(());
|
||||
}
|
||||
println!("{}", write_report(&dir, &list, &results)?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The cases a known-failing baseline lists, with their causes: one per line, `<case> <cause>`,
|
||||
/// the case's directory relative to the baseline's own; `#` starts a comment line. The list is
|
||||
/// sorted with no case twice, and every case has a cause.
|
||||
fn known_failing(text: &str) -> Result<Vec<(&str, &str)>, String> {
|
||||
let mut out: Vec<(&str, &str)> = Vec::new();
|
||||
for (n, line) in text.lines().enumerate() {
|
||||
let line = line.trim();
|
||||
if line.is_empty() || line.starts_with('#') {
|
||||
continue;
|
||||
}
|
||||
let (case, cause) = line.split_once(char::is_whitespace).map_or((line, ""), |(c, w)| (c, w.trim()));
|
||||
if cause.is_empty() {
|
||||
return Err(format!("line {}: {case} gives no cause (`<case> <why it fails today>`)", n + 1));
|
||||
}
|
||||
if let Some((last, _)) = out.last()
|
||||
&& *last >= case
|
||||
{
|
||||
return Err(format!(
|
||||
"line {}: {case} is {} {last}: keep the list sorted, each case once",
|
||||
n + 1,
|
||||
if *last == case { "a repeat of" } else { "out of order after" }
|
||||
));
|
||||
}
|
||||
out.push((case, cause));
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// The regression gate: `cases` (paths relative to the baseline's directory) ran with
|
||||
/// `statuses`; every case passes except those the baseline `text` lists. A case that fails and
|
||||
/// is not listed is a regression; a listed case that passes is fixed and must leave the list, so
|
||||
/// the list only shrinks. Either fails the gate, as does a listed case that is not in the set.
|
||||
fn gate(text: &str, cases: &[String], statuses: &[&str]) -> Result<String, String> {
|
||||
let listed = known_failing(text)?;
|
||||
let mut problems = Vec::new();
|
||||
for (case, _) in &listed {
|
||||
if !cases.iter().any(|c| c == case) {
|
||||
problems.push(format!("listed but not a case of this set: {case}"));
|
||||
}
|
||||
}
|
||||
let mut failing = 0;
|
||||
for (case, status) in cases.iter().zip(statuses) {
|
||||
match (listed.iter().find(|(c, _)| c == case), *status == "pass") {
|
||||
(None, false) => problems.push(format!("REGRESSION ({status}): {case}")),
|
||||
(Some(_), true) => problems.push(format!("FIXED, remove it from the known-failing list: {case}")),
|
||||
(Some(_), false) => failing += 1,
|
||||
(None, true) => {}
|
||||
}
|
||||
}
|
||||
if problems.is_empty() {
|
||||
Ok(format!("kernel-cases gate: {} pass, {failing} known failing, no regression", cases.len() - failing))
|
||||
} else {
|
||||
Err(format!("kernel-cases gate:\n {}", problems.join("\n ")))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::gate;
|
||||
|
||||
fn run(text: &str, cases: &[(&str, &str)]) -> Result<String, String> {
|
||||
let names: Vec<String> = cases.iter().map(|(c, _)| c.to_string()).collect();
|
||||
let statuses: Vec<&str> = cases.iter().map(|(_, s)| *s).collect();
|
||||
gate(text, &names, &statuses)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_gate_fails_on_a_regression_and_on_a_fixed_case_still_listed() {
|
||||
let list = "# today\na-case SMLib refuses the corner\nb-case G1 at the corner point\n";
|
||||
assert!(run(list, &[("a-case", "fail"), ("b-case", "crash"), ("c-case", "pass")]).is_ok());
|
||||
let regression = run(list, &[("a-case", "fail"), ("b-case", "fail"), ("c-case", "hang")]).unwrap_err();
|
||||
assert!(regression.contains("REGRESSION (hang): c-case"), "{regression}");
|
||||
let fixed = run(list, &[("a-case", "pass"), ("b-case", "fail"), ("c-case", "pass")]).unwrap_err();
|
||||
assert!(fixed.contains("FIXED, remove it from the known-failing list: a-case"), "{fixed}");
|
||||
let stale = run(list, &[("a-case", "fail"), ("c-case", "pass")]).unwrap_err();
|
||||
assert!(stale.contains("not a case of this set: b-case"), "{stale}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_known_failing_list_is_sorted_with_a_cause_each() {
|
||||
assert!(run("b x\na y\n", &[("a", "fail"), ("b", "fail")]).unwrap_err().contains("out of order"));
|
||||
assert!(run("a x\na y\n", &[("a", "fail")]).unwrap_err().contains("a repeat of"));
|
||||
assert!(run("a\n", &[("a", "fail")]).unwrap_err().contains("gives no cause"));
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -47,12 +47,15 @@ commands:
|
||||
replay the reference tests (tests/oracle/*/recipe.json), compare with each
|
||||
case's expected.json and write docs/oracle.md (--cli: a solidcraft-cli
|
||||
already built, instead of cargo run --release)
|
||||
kernel-cases [--area AREA] [--cli BIN] [--timeout S] [--jobs N] [--out DIR]
|
||||
kernel-cases [--area AREA] [--cli BIN] [--timeout S] [--jobs N] [--out DIR] [--known-failing FILE]
|
||||
the kernel regression rig: run every case in tests/kernel-cases/<area>/<id>/ on
|
||||
SMLib (one process each, killed after --timeout, default 180 s), grade it against
|
||||
the case's own answer and write docs/kernel-cases.md; DIR (default
|
||||
target/kernel-cases) gets results.json and dumps/<area>-<case>/, the inputs of
|
||||
each failing SMLib call (--cli: a solidcraft-cli built with --features smlib)
|
||||
--known-failing FILE: a regression gate instead of the report: fails on a case
|
||||
that fails and FILE does not list, and on a listed case that passes
|
||||
(tests/kernel-cases/fillets/KNOWN_FAILING, CI's fillet rig job)
|
||||
--ladder [--record REASON]: the complexity ladder instead
|
||||
(tests/kernel-cases/ladder/ladder.json, tiers in order), graded and compared
|
||||
with its timing golden (one case at a time unless --jobs), into
|
||||
|
||||
Reference in new issue
Block a user