mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 04:27:49 +00:00
Merge remote-tracking branch 'upstream/next' into test-speed-3
This commit is contained in:
@@ -44,6 +44,7 @@ jobs:
|
||||
filter: ${{ steps.select.outputs.filter }}
|
||||
audit: ${{ steps.audit.outputs.audit }}
|
||||
profile: ${{ steps.audit.outputs.profile }}
|
||||
deps-profile: ${{ steps.audit.outputs.deps-profile }}
|
||||
steps:
|
||||
- name: Harden runner
|
||||
uses: step-security/harden-runner@v2.22.4
|
||||
@@ -67,6 +68,10 @@ jobs:
|
||||
# passes (scripts/ci-workspace-tests.sh), which names the Workspace legs' cache entries:
|
||||
# rust-cache's key does not hash these files, and an entry built with other overrides would be
|
||||
# rebuilt in full on every run. Other events than a pull request check out only these files.
|
||||
# The macOS and Windows legs cache dependencies only, so `deps-profile` hashes only the
|
||||
# settings that reach a dependency: `[profile.dev]` and `[profile.dev.package."*"]`. Every
|
||||
# other override names a workspace crate (scripts/test-workspace-tests.py), so changing one
|
||||
# keeps those entries, and next's runs restore main's.
|
||||
- uses: actions/checkout@v7.0.1
|
||||
if: github.event_name != 'pull_request'
|
||||
with:
|
||||
@@ -83,6 +88,18 @@ jobs:
|
||||
run: |
|
||||
echo "audit=$(bash scripts/ci-workspace-tests.sh audit)" >> "$GITHUB_OUTPUT"
|
||||
echo "profile=$(cat .config/cargo-dev.toml .config/cargo-ci.toml | sha256sum | cut -c1-12)" >> "$GITHUB_OUTPUT"
|
||||
# An assignment, so a failure stops the step (`bash -e`) instead of naming every entry `v2-`.
|
||||
deps=$(python3 -I - <<'PY'
|
||||
import hashlib, json, tomllib
|
||||
kept = []
|
||||
for path in (".config/cargo-dev.toml", ".config/cargo-ci.toml"):
|
||||
with open(path, "rb") as file:
|
||||
dev = tomllib.load(file)["profile"]["dev"]
|
||||
kept.append([dev, dev.pop("package", {}).get("*", {})])
|
||||
print(hashlib.sha256(json.dumps(kept, sort_keys=True).encode()).hexdigest()[:12])
|
||||
PY
|
||||
)
|
||||
echo "deps-profile=$deps" >> "$GITHUB_OUTPUT"
|
||||
|
||||
# The Linux leg keeps the compiled workspace crates between runs (`cache-workspace-crates`): each
|
||||
# main run saves a rolling cache entry of its own, every run restores the newest one, and Cargo
|
||||
@@ -173,7 +190,8 @@ jobs:
|
||||
with:
|
||||
os: '["windows-latest","macos-latest"]'
|
||||
lint-cache: false
|
||||
cache-version: *cache-version
|
||||
# Named by the dependency settings alone (`deps-profile`), so next restores main's entries.
|
||||
cache-version: v2-${{ needs.platforms.outputs.deps-profile }}
|
||||
timeout-minutes: *timeout
|
||||
tools: *tools
|
||||
craft-fonts-ref: *craft-fonts
|
||||
|
||||
Generated
+6
@@ -2301,6 +2301,7 @@ dependencies = [
|
||||
name = "craft-crw"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"craft-testkit",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sha2 0.10.9",
|
||||
@@ -2947,6 +2948,7 @@ dependencies = [
|
||||
name = "craft-heif"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"craft-testkit",
|
||||
"heic-rs",
|
||||
"proptest",
|
||||
"rayon",
|
||||
@@ -3251,6 +3253,7 @@ dependencies = [
|
||||
name = "craft-material-graph"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"craft-testkit",
|
||||
"libm",
|
||||
"rayon",
|
||||
]
|
||||
@@ -3407,6 +3410,7 @@ dependencies = [
|
||||
"chardetng",
|
||||
"chrono",
|
||||
"craft-codepage",
|
||||
"craft-testkit",
|
||||
"encoding_rs",
|
||||
"proptest",
|
||||
]
|
||||
@@ -3844,6 +3848,7 @@ name = "craft-ps"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"craft-eps",
|
||||
"craft-testkit",
|
||||
"flate2",
|
||||
"kurbo",
|
||||
"miniz_oxide 0.8.9",
|
||||
@@ -4774,6 +4779,7 @@ dependencies = [
|
||||
name = "craft-xcf"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"craft-testkit",
|
||||
"flate2",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
@@ -291,6 +291,7 @@ mod tests {
|
||||
std::thread::scope(|scope| {
|
||||
for e in crate::testutil::sampled_effects() {
|
||||
scope.spawn(move || {
|
||||
let started = std::time::Instant::now();
|
||||
for setting in [0.0f32, 1.0] {
|
||||
let mut fx = (e.create)(SR, 2);
|
||||
for p in e.params {
|
||||
@@ -318,6 +319,9 @@ mod tests {
|
||||
);
|
||||
}
|
||||
}
|
||||
if started.elapsed() > std::time::Duration::from_secs(1) {
|
||||
eprintln!("DIAG extreme settings: {} took {:?}", e.id, started.elapsed());
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -15,6 +15,7 @@ workspace = true
|
||||
thiserror = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
craft-testkit = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
# Pinned digests of the decoded CC0 sample files (tests/samples.rs); not a product dependency.
|
||||
|
||||
@@ -61,11 +61,13 @@ fn crw() -> Vec<u8> {
|
||||
#[test]
|
||||
fn every_truncation_and_single_byte_mutation_survives() {
|
||||
let good = crw();
|
||||
for n in 0..good.len() {
|
||||
// The gate runs every divisor-th position; nightly runs all.
|
||||
let step = craft_testkit::hostile::divisor();
|
||||
for n in (0..good.len()).step_by(step) {
|
||||
let _ = header(&good[..n], &Limits::default());
|
||||
let _ = decode(&good[..n], &Limits::default());
|
||||
}
|
||||
for i in 0..good.len() {
|
||||
for i in (0..good.len()).step_by(step) {
|
||||
let mut bad = good.clone();
|
||||
bad[i] ^= 0xa5;
|
||||
let _ = decode(&bad, &Limits::default());
|
||||
|
||||
@@ -103,8 +103,8 @@ fn reference_render_has_unit_variance_and_no_mean() {
|
||||
fn small_render_is_the_downscaled_reference() {
|
||||
for (size, rough) in [(0.0, 50.0), (25.0, 50.0), (100.0, 50.0), (25.0, 0.0), (25.0, 100.0)] {
|
||||
let t = tile_of(size, rough);
|
||||
for k in [2usize, 4, 8] {
|
||||
let n = 48;
|
||||
for k in [2usize, 8] {
|
||||
let n = 32;
|
||||
let full = patch(&t, REF_LONG, n * k, 0);
|
||||
let down: Vec<f32> = (0..n * n)
|
||||
.map(|q| {
|
||||
@@ -120,6 +120,7 @@ fn small_render_is_the_downscaled_reference() {
|
||||
.collect();
|
||||
let small = patch(&t, REF_LONG / k as f64, n, 0);
|
||||
let worst = down.iter().zip(&small).map(|(a, b)| (a - b).abs()).fold(0.0, f32::max);
|
||||
eprintln!("DIAG downscale size {size} roughness {rough} 1/{k}: worst {worst} (limit 2e-3)");
|
||||
assert!(worst < 2e-3, "size {size} roughness {rough} 1/{k}: differs by {worst}");
|
||||
}
|
||||
}
|
||||
@@ -129,7 +130,7 @@ fn small_render_is_the_downscaled_reference() {
|
||||
fn strength_matches_the_target_at_mid_grey() {
|
||||
for (a, s, r) in [(50.0, 25.0, 50.0), (25.0, 25.0, 50.0), (50.0, 0.0, 50.0), (50.0, 100.0, 50.0), (50.0, 25.0, 0.0)] {
|
||||
let g = CrystalGrain::new(&Grain { amount: a, size: s, roughness: r, seed: 3 }, REF_LONG).expect("grain");
|
||||
let n = 320;
|
||||
let n = 200;
|
||||
let lum: Vec<f32> = (0..n * n)
|
||||
.map(|k| {
|
||||
let (x, y) = ((k % n) as f32 + 0.5, (k / n) as f32 + 0.5);
|
||||
@@ -138,6 +139,7 @@ fn strength_matches_the_target_at_mid_grey() {
|
||||
})
|
||||
.collect();
|
||||
let want = strength_levels(a, s, r);
|
||||
eprintln!("DIAG strength {a}/{s}/{r}: deviation {:.4} (limit 0.06)", std(&lum) / want - 1.0);
|
||||
assert!((std(&lum) / want - 1.0).abs() < 0.06, "{a}/{s}/{r}: {} levels, want {want}", std(&lum));
|
||||
}
|
||||
}
|
||||
@@ -443,8 +445,10 @@ fn a_waiting_render_gets_the_tile_the_cache_evicted() {
|
||||
keep(&OWN, key, drawn.clone());
|
||||
// other renders' tiles push it out of the cache before the waiter wakes
|
||||
// (each its own tile: a waiter that took another key's would fail the check below)
|
||||
// (one tile of another seed under every key: a different `Arc` from the drawn one, drawn once)
|
||||
let other_tile = Arc::new(CrystalTile::new(look, seed + 1).expect("tile"));
|
||||
for other in 1..=CACHE as u32 {
|
||||
keep(&OWN, key_of(look, seed + other), Arc::new(CrystalTile::new(look, seed + other).expect("tile")));
|
||||
keep(&OWN, key_of(look, seed + other), other_tile.clone());
|
||||
}
|
||||
assert!(cached(&OWN, key).is_none(), "the tile is still cached");
|
||||
drop(marker);
|
||||
@@ -477,7 +481,8 @@ fn renders_that_miss_a_tile_together_draw_it_once() {
|
||||
static OWN: Cache = Mutex::new(Vec::new());
|
||||
const N: usize = 8;
|
||||
// the first render's draw waits for the other seven to miss the tile too
|
||||
const SEEDS: u32 = 5;
|
||||
// (each seed is a full trial, as the draw is held until the others wait, so a few are enough)
|
||||
const SEEDS: u32 = 2;
|
||||
HOLDS.lock().unwrap_or_else(PoisonError::into_inner).push((std::ptr::from_ref(&OWN) as usize, N - 1, SEEDS as usize));
|
||||
let look = CrystalLook::new(0.0, 50.0);
|
||||
for seed in 0x0d4a_1000..0x0d4a_1000 + SEEDS {
|
||||
@@ -502,7 +507,8 @@ fn renders_that_miss_a_tile_together_draw_it_once() {
|
||||
fn width_matches_lightroom_classic() {
|
||||
let lrc = [(0.0, 50.0, 0.5), (25.0, 50.0, 1.13), (100.0, 50.0, 3.38), (25.0, 0.0, 0.86), (25.0, 100.0, 1.54)];
|
||||
for (s, r, want) in lrc {
|
||||
let got = half_width(&patch(&tile_of(s, r), REF_LONG, 360, 0), 360);
|
||||
let got = half_width(&patch(&tile_of(s, r), REF_LONG, 256, 0), 256);
|
||||
eprintln!("DIAG width size {s} roughness {r}: {got:.3} want {want} (limit 10 percent)");
|
||||
assert!((got / want - 1.0).abs() < 0.1, "size {s} roughness {r}: width {got:.3}, want {want}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ fn saved(path: impl AsRef<Path>) -> Option<DialogResult<Answer>> {
|
||||
// `a_selected_folder_never_replaces_the_typed_save_name` and `a_removed_selected_file_keeps_its_exact_save_path`, with
|
||||
// `~` and "not found". The extension is the service's policy now, so the chooser answers the name as typed.
|
||||
#[trial]
|
||||
fn the_chooser_lists_and_accepts_like_a_file_panel() {
|
||||
fn a_typed_folder_is_entered_and_a_new_name_is_saved_as_typed() {
|
||||
// A typed folder is entered and its name used up; a new name is answered as typed.
|
||||
let mut save = Chooser::open(PickRequest::save("document").directory("/d"));
|
||||
save.type_name("drafts");
|
||||
@@ -126,7 +126,10 @@ fn the_chooser_lists_and_accepts_like_a_file_panel() {
|
||||
save.type_name("chapter");
|
||||
save.click("Save");
|
||||
assert_eq!(save.answer(), saved("/d/drafts/chapter"), "a new name is saved to as typed");
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn a_listed_file_is_replaced_only_after_the_question() {
|
||||
// A listed file is replaced only after the question, asked once.
|
||||
let mut replace = Chooser::open(PickRequest::save("document").directory("/d/drafts"));
|
||||
replace.type_name("old.docx");
|
||||
@@ -134,7 +137,10 @@ fn the_chooser_lists_and_accepts_like_a_file_panel() {
|
||||
assert_eq!(replace.answer(), None, "the chooser asks before replacing");
|
||||
replace.click("Replace");
|
||||
assert_eq!(replace.answer(), saved("/d/drafts/old.docx"));
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn a_selected_file_keeps_its_exact_name_for_open_and_for_the_save_question() {
|
||||
// A selected file keeps its exact name, leading space and all, for Open and for Save's question.
|
||||
let mut open = Chooser::open(PickRequest::open("document").directory("/d"));
|
||||
open.click(" report.docx");
|
||||
@@ -147,7 +153,10 @@ fn the_chooser_lists_and_accepts_like_a_file_panel() {
|
||||
assert_eq!(save.answer(), None, "Save asks before replacing the selected file");
|
||||
save.click("Replace");
|
||||
assert_eq!(save.answer(), saved("/d/ report.docx"));
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn a_removed_selected_file_keeps_its_exact_save_path() {
|
||||
// A selected file removed meanwhile still names the exact path, and nothing is asked.
|
||||
let mut removed = Chooser::open(PickRequest::save("document").file_name("Draft.docx").directory("/d"));
|
||||
removed.click(" report.docx");
|
||||
@@ -155,7 +164,10 @@ fn the_chooser_lists_and_accepts_like_a_file_panel() {
|
||||
removed.refocus();
|
||||
removed.click("Save");
|
||||
assert_eq!(removed.answer(), saved("/d/ report.docx"), "the removed selection keeps its path, not `report.docx`");
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn a_selected_folder_is_entered_and_never_becomes_the_save_name() {
|
||||
// A selected folder is entered and never becomes the save name; once it is gone, the typed name is saved to.
|
||||
let mut folder = Chooser::open(PickRequest::save("document").file_name("chapter.docx").directory("/d"));
|
||||
folder.click("Chapters");
|
||||
@@ -168,13 +180,19 @@ fn the_chooser_lists_and_accepts_like_a_file_panel() {
|
||||
gone.refocus();
|
||||
gone.click("Save");
|
||||
assert_eq!(gone.answer(), saved("/d/chapter.docx"), "the removed folder is not saved over as `Chapters.docx`");
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn the_home_root_and_a_typed_path_elsewhere_open() {
|
||||
// `~` is the Home root; a typed path elsewhere is listed, then opened.
|
||||
let mut home = Chooser::open(PickRequest::open("document").directory("/d"));
|
||||
home.type_name("~/Letters/aunt.txt");
|
||||
home.click("Open");
|
||||
assert_eq!(home.answer(), picked("/home/u/Letters/aunt.txt"));
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn a_missing_name_on_open_is_refused_and_said() {
|
||||
// A missing name on Open is refused and said.
|
||||
let mut missing = Chooser::open(PickRequest::open("document").directory("/d"));
|
||||
missing.type_name("missing.docx");
|
||||
|
||||
@@ -20,6 +20,7 @@ heic-rs = { version = "=0.1.4", default-features = false, features = ["std", "pa
|
||||
rayon = { workspace = true, optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
craft-testkit = { workspace = true }
|
||||
proptest = { workspace = true }
|
||||
|
||||
[features]
|
||||
|
||||
@@ -186,7 +186,9 @@ fn grid_tiles_are_held_to_the_pixel_budget_together() {
|
||||
fn truncated_and_corrupted_files_are_errors_not_panics() {
|
||||
let bytes = build(&Spec { props: vec![FULL_601, Prop::Irot(1)], thumbnail: Some(&grey), ..Spec::new(64, 64, &grey) });
|
||||
let full = decode(&bytes, &Options::default()).unwrap();
|
||||
for cut in (0..bytes.len()).step_by(7) {
|
||||
// The gate runs a divisor's fraction of the cuts and flips; nightly runs all.
|
||||
let divisor = craft_testkit::hostile::divisor();
|
||||
for cut in (0..bytes.len()).step_by(7 * divisor) {
|
||||
let b = &bytes[..cut];
|
||||
// Cut inside the photo: an error. Cut in the trailing thumbnail: the whole photo.
|
||||
if let (Ok(_), Ok(d)) = (probe(b), decode(b, &Options::default())) {
|
||||
@@ -197,7 +199,7 @@ fn truncated_and_corrupted_files_are_errors_not_panics() {
|
||||
}
|
||||
// Flip bits all over the file: any outcome but a panic.
|
||||
let mut state = 0x2545_f491_u32;
|
||||
for _ in 0..400 {
|
||||
for _ in 0..400 / divisor {
|
||||
let mut b = bytes.clone();
|
||||
for _ in 0..3 {
|
||||
state ^= state << 13;
|
||||
|
||||
@@ -99,9 +99,12 @@ fn byte_overwrites_in_header_never_panic() {
|
||||
let step = craft_media_testkit::hostile::divisor();
|
||||
for (k, (f, bytes)) in samples().into_iter().enumerate() {
|
||||
for i in (0..bytes.len().min(64)).filter(|i| (i + k) % step == 0) {
|
||||
for v in [0x00, 0x7F, 0xFF] {
|
||||
// nightly writes every value to each byte; the gate one per byte, rotating, so the sampled bytes together see all
|
||||
let values = [0x00, 0x7F, 0xFF];
|
||||
let one = [values[(i / step) % 3]];
|
||||
for v in if step == 1 { &values[..] } else { &one[..] } {
|
||||
let mut b = bytes.clone();
|
||||
b[i] = v;
|
||||
b[i] = *v;
|
||||
no_panic(f, &b);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -840,7 +840,11 @@ fn zoo_decodes_and_never_panics_when_cut_or_corrupted() {
|
||||
poke(&f[..cut]);
|
||||
}
|
||||
for i in (0..f.len()).filter(|i| (i + k) % step == 0) {
|
||||
for flip in [0xffu8, 0x80, 0x01] {
|
||||
// nightly flips each byte three ways; the gate one way per byte, rotating, so the sampled bytes together see all
|
||||
let flips = [0xffu8, 0x80, 0x01];
|
||||
let one = [flips[(i / step) % 3]];
|
||||
for flip in if step == 1 { &flips[..] } else { &one[..] } {
|
||||
let flip = *flip;
|
||||
let mut g = f.clone();
|
||||
g[i] ^= flip;
|
||||
poke(&g);
|
||||
|
||||
@@ -15,3 +15,6 @@ workspace = true
|
||||
libm = "0.2.16"
|
||||
# Data-parallel loops (MIT OR Apache-2.0).
|
||||
rayon = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
craft-testkit = { workspace = true }
|
||||
|
||||
@@ -5459,6 +5459,38 @@ mod grey_tests {
|
||||
pub(super) static GREY_RUNS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
|
||||
}
|
||||
|
||||
/// A sample of a sweep of `total` cases: all of them when `craft_testkit::hostile::divisor()` is 1 (nightly), at the
|
||||
/// gate every `per_div * divisor - 1`-th (an odd stride, so every axis of a nested loop varies).
|
||||
struct Sweep {
|
||||
stride: usize,
|
||||
total: usize,
|
||||
seen: usize,
|
||||
visited: usize,
|
||||
}
|
||||
|
||||
impl Sweep {
|
||||
fn new(total: usize, per_div: usize) -> Sweep {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
let div = craft_testkit::hostile::divisor();
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
let div = 1;
|
||||
Sweep { stride: if div == 1 { 1 } else { per_div * div - 1 }, total, seen: 0, visited: 0 }
|
||||
}
|
||||
|
||||
/// Whether the next case of the sweep is in the sample.
|
||||
fn take(&mut self) -> bool {
|
||||
let take = self.seen.is_multiple_of(self.stride);
|
||||
self.seen += 1;
|
||||
self.visited += usize::from(take);
|
||||
take
|
||||
}
|
||||
|
||||
/// What `full` grey runs over all the cases comes to over the cases visited.
|
||||
fn share(&self, full: usize) -> usize {
|
||||
full * self.visited / self.total
|
||||
}
|
||||
}
|
||||
|
||||
fn bits(outs: &BTreeMap<String, Tex>) -> Vec<(String, Vec<u32>)> {
|
||||
outs.iter().map(|(k, t)| (k.clone(), t.px.iter().flat_map(|p| p.map(f32::to_bits)).collect())).collect()
|
||||
}
|
||||
@@ -5532,6 +5564,7 @@ mod grey_tests {
|
||||
"m00=-1 m01=0 m10=0 m11=1",
|
||||
];
|
||||
let bgs = ["", "bg_r=0.5 bg_g=0.5 bg_b=0.5 bg_a=1", "bg_r=0.2 bg_g=0.3 bg_b=0.2 bg_a=1", "bg_a=0.5"];
|
||||
let mut sweep = Sweep::new(2 * mats.len() * bgs.len() * 3 * 4 * 4, 16);
|
||||
let n = greys(|| {
|
||||
for compiled in [false, true] {
|
||||
for m in mats {
|
||||
@@ -5544,6 +5577,9 @@ mod grey_tests {
|
||||
(" osize_log2_x=4 osize_log2_y=5", " ofmt=5"),
|
||||
(" osize_log2_x=6 osize_log2_y=6", " ofmt=6 offset_x=0.13 offset_y=-0.3"),
|
||||
] {
|
||||
if !sweep.take() {
|
||||
continue;
|
||||
}
|
||||
let body = format!("node 10 transform_matrix in=@2 {m} {bg} {tiles} {filt}{osz}{fmt}\noutput out 10\n");
|
||||
same(&body, 32, compiled);
|
||||
}
|
||||
@@ -5553,7 +5589,7 @@ mod grey_tests {
|
||||
}
|
||||
}
|
||||
});
|
||||
assert!(n > 300, "{n} grey runs");
|
||||
assert!(n > sweep.share(300), "{n} grey runs in {} of {} cases", sweep.visited, sweep.total);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -5663,6 +5699,7 @@ mod grey_tests {
|
||||
|
||||
#[test]
|
||||
fn blend_grey_is_rgba() {
|
||||
let mut sweep = Sweep::new(2 * 26 * 5 * 10, 16);
|
||||
let n = greys(|| {
|
||||
for compiled in [false, true] {
|
||||
for mode in (0..=21).chain(32..=35) {
|
||||
@@ -5679,6 +5716,9 @@ mod grey_tests {
|
||||
("0.6", " ofmt=1 tile_x=0.25"),
|
||||
("0.6", " ofmt=7"),
|
||||
] {
|
||||
if !sweep.take() {
|
||||
continue;
|
||||
}
|
||||
let body = format!("node 10 blend fg=@1 bg=@2 mode={mode} alpha_mode={am} opacity={op}{extra}\noutput out 10\n");
|
||||
same(&body, 24, compiled);
|
||||
}
|
||||
@@ -5686,7 +5726,7 @@ mod grey_tests {
|
||||
}
|
||||
}
|
||||
});
|
||||
assert!(n > 300, "{n} grey runs");
|
||||
assert!(n > sweep.share(300), "{n} grey runs in {} of {} cases", sweep.visited, sweep.total);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -8,6 +8,12 @@ use std::fmt::Write;
|
||||
/// The stack of a thread spawned without asking for one (Rust's default), and of rayon's workers.
|
||||
const NORMAL_STACK: usize = 2 << 20;
|
||||
|
||||
/// Stacks too small for a walk that recurses once per node: a frame takes at least tens of bytes (an unoptimised one about
|
||||
/// a kilobyte), so the chains below overflow them if the evaluator recurses, and the chain length needs no more work than
|
||||
/// that.
|
||||
const SMALL_STACK: usize = 128 << 10;
|
||||
const MEDIUM_STACK: usize = 512 << 10;
|
||||
|
||||
/// The stack a function as deep as allowed is run with: the normal one in an optimised build (measured: 2040 nodes in a
|
||||
/// row take under 1 MB); an unoptimised build's frames are about fifteen times larger.
|
||||
const FUNCTION_STACK: usize = if cfg!(debug_assertions) { 32 << 20 } else { NORMAL_STACK };
|
||||
@@ -51,22 +57,22 @@ fn nested(levels: u32) -> String {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_chain_of_a_hundred_thousand_nodes_evaluates_on_a_normal_stack() {
|
||||
let g = Graph::parse(&image_chain(100_000)).expect("parses");
|
||||
fn a_long_chain_evaluates_on_a_small_stack() {
|
||||
let g = Graph::parse(&image_chain(10_000)).expect("parses");
|
||||
let shallow = Graph::parse(&image_chain(2)).expect("parses");
|
||||
let (deep, two) =
|
||||
on_stack(NORMAL_STACK, move || (g.evaluate(None).map_err(|e| e.to_string()), shallow.evaluate(None).map_err(|e| e.to_string())));
|
||||
on_stack(MEDIUM_STACK, move || (g.evaluate(None).map_err(|e| e.to_string()), shallow.evaluate(None).map_err(|e| e.to_string())));
|
||||
let (deep, two) = (deep.expect("evaluates"), two.expect("evaluates"));
|
||||
// an even number of inverts is the gradient again, as two are
|
||||
assert_eq!(deep["o"].px, two["o"].px);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_node_of_a_long_chain_gets_a_thumbnail_on_a_normal_stack() {
|
||||
let g = Graph::parse(&image_chain(20_000)).expect("parses");
|
||||
let all = on_stack(NORMAL_STACK, move || g.evaluate_all(16, &[20_000]));
|
||||
fn every_node_of_a_long_chain_gets_a_thumbnail_on_a_small_stack() {
|
||||
let g = Graph::parse(&image_chain(300)).expect("parses");
|
||||
let all = on_stack(SMALL_STACK, move || g.evaluate_all(16, &[300]));
|
||||
assert!(all.errors.is_empty(), "{:?}", all.errors.iter().next());
|
||||
assert_eq!(all.thumbs.len(), 20_001);
|
||||
assert_eq!(all.thumbs.len(), 301);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -38,13 +38,14 @@ fn in_pool<R: Send>(threads: usize, f: impl FnOnce() -> R + Send) -> R {
|
||||
|
||||
#[test]
|
||||
fn one_thread_and_eight_render_the_same_bytes() {
|
||||
let graphs = demo_graphs();
|
||||
assert!(graphs.len() > 100, "only {} demo graphs", graphs.len());
|
||||
let all = demo_graphs();
|
||||
assert!(all.len() > 100, "only {} demo graphs", all.len());
|
||||
let graphs = crate::sampled(all, 0);
|
||||
let one = in_pool(1, || graphs.iter().map(|(_, g)| render(g)).collect::<Vec<_>>());
|
||||
let eight = in_pool(8, || graphs.iter().map(|(_, g)| render(g)).collect::<Vec<_>>());
|
||||
let differ: Vec<&str> = graphs.iter().zip(one.iter().zip(&eight)).filter(|(_, (a, b))| a != b).map(|((k, _), _)| *k).collect();
|
||||
assert!(differ.is_empty(), "these kinds render differently on 1 and 8 threads: {differ:?}");
|
||||
assert!(one.iter().filter(|r| r.is_ok()).count() > 100, "most demo graphs must render");
|
||||
assert!(one.iter().filter(|r| r.is_ok()).count() * 10 > graphs.len() * 8, "most demo graphs must render");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -52,7 +53,7 @@ fn cached_and_uncached_evaluations_give_the_same_bytes() {
|
||||
let cache = Arc::new(NodeCache::new(256));
|
||||
let mut differ = Vec::new();
|
||||
let mut not_reused = Vec::new();
|
||||
for (kind, g) in demo_graphs() {
|
||||
for (kind, g) in crate::sampled(demo_graphs(), 0) {
|
||||
let keep: Vec<u32> = g.nodes.keys().copied().collect();
|
||||
let fresh = g.evaluate_all(SIDE, &keep);
|
||||
let first = g.evaluate_all_cached(&EvalContext::default(), SIDE, &keep, &cache, None, &mut |_| {});
|
||||
|
||||
@@ -53,11 +53,15 @@ fn a_fix_in_one_operation_leaves_most_kinds_alone() {
|
||||
files.iter().for_each(|f| println!(" {}", f.name));
|
||||
}
|
||||
assert!(files.len() > 20, "{} of {} files reachable", files.len(), all.len());
|
||||
let started = std::time::Instant::now();
|
||||
let tree = SourceTree::scan(&files, DISPATCHERS);
|
||||
eprintln!("DIAG kind_versions first scan {:?}", started.elapsed());
|
||||
let kinds: Vec<String> = tree.kinds().map(str::to_string).collect();
|
||||
assert!(kinds.len() > 100, "the kinds were found: {}", kinds.len());
|
||||
let versions = |t: &SourceTree| kinds.iter().map(|k| t.kind_version(k, SHARED).unwrap()).collect::<Vec<_>>();
|
||||
let started = std::time::Instant::now();
|
||||
let before = versions(&tree);
|
||||
eprintln!("DIAG kind_versions first versions {:?}", started.elapsed());
|
||||
let distinct: std::collections::BTreeSet<_> = before.iter().collect();
|
||||
if std::env::var_os("TC_VERSIONS_DUMP").is_some() {
|
||||
for k in &kinds {
|
||||
@@ -72,24 +76,38 @@ fn a_fix_in_one_operation_leaves_most_kinds_alone() {
|
||||
}
|
||||
assert!(distinct.len() > kinds.len() / 2, "{} distinct versions of {} kinds", distinct.len(), kinds.len());
|
||||
|
||||
let changed_by = |file: &str, from: &str, to: &str| {
|
||||
let changed_by_all = |edits: &[(&str, &str, &str)]| {
|
||||
let edited: Vec<SourceFile> = files
|
||||
.iter()
|
||||
.map(|f| {
|
||||
let text = if f.name == file { f.text.replacen(from, to, 1) } else { f.text.clone() };
|
||||
assert!(f.name != file || text != f.text, "{from} is in {file}");
|
||||
let mut text = f.text.clone();
|
||||
for (file, from, to) in edits.iter().filter(|e| e.0 == f.name) {
|
||||
let next = text.replacen(from, to, 1);
|
||||
assert!(next != text, "{from} is in {file}");
|
||||
text = next;
|
||||
}
|
||||
SourceFile { text, ..f.clone() }
|
||||
})
|
||||
.collect();
|
||||
let after = versions(&SourceTree::scan(&edited, DISPATCHERS));
|
||||
let started = std::time::Instant::now();
|
||||
let scanned = SourceTree::scan(&edited, DISPATCHERS);
|
||||
let scan = started.elapsed();
|
||||
let after = versions(&scanned);
|
||||
eprintln!(
|
||||
"DIAG kind_versions edit of {:?}: scan {scan:?}, versions {:?}",
|
||||
edits.iter().map(|e| e.0).collect::<Vec<_>>(),
|
||||
started.elapsed() - scan
|
||||
);
|
||||
kinds.iter().zip(before.iter().zip(&after)).filter(|(_, (a, b))| a != b).map(|(k, _)| k.clone()).collect::<Vec<String>>()
|
||||
};
|
||||
let changed_by = |file: &str, from: &str, to: &str| changed_by_all(&[(file, from, to)]);
|
||||
|
||||
let added = changed_by("src/compiled_ops.rs", "pub fn compute(kind: &str", "fn __added_helper() -> u8 { 1 }\npub fn compute(kind: &str");
|
||||
assert_eq!(added, Vec::<String>::new(), "an added function nothing uses changes nothing");
|
||||
|
||||
let comment = changed_by("src/atomic.rs", "\"levels_mid\" => {", "\"levels_mid\" => { // a comment\n");
|
||||
assert_eq!(comment, Vec::<String>::new(), "a comment changes nothing");
|
||||
// an added function nothing uses, and a comment: both change nothing (edits in two files, one pass)
|
||||
let unchanged = changed_by_all(&[
|
||||
("src/compiled_ops.rs", "pub fn compute(kind: &str", "fn __added_helper() -> u8 { 1 }\npub fn compute(kind: &str"),
|
||||
("src/atomic.rs", "\"levels_mid\" => {", "\"levels_mid\" => { // a comment\n"),
|
||||
]);
|
||||
assert_eq!(unchanged, Vec::<String>::new(), "an unused added function and a comment change nothing");
|
||||
|
||||
// a fix inside one node's arm
|
||||
let arm = changed_by("src/atomic.rs", "\"levels_mid\" => {", "\"levels_mid\" => { let _fixed = 1;");
|
||||
|
||||
@@ -14,3 +14,21 @@ mod kind_versions;
|
||||
mod nodes;
|
||||
mod seam;
|
||||
mod vector;
|
||||
|
||||
/// The gate's share of a sweep over `items`: every `craft_testkit::hostile::divisor()`-th one from `offset` (all of them
|
||||
/// nightly, where the divisor is 1), so tests sweeping the same list with different offsets together reach more of it.
|
||||
fn sampled<T>(items: impl IntoIterator<Item = T>, offset: usize) -> Vec<T> {
|
||||
let div = divisor();
|
||||
items.into_iter().enumerate().filter(|(i, _)| (i + offset).is_multiple_of(div)).map(|(_, t)| t).collect()
|
||||
}
|
||||
|
||||
fn divisor() -> usize {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
craft_testkit::hostile::divisor()
|
||||
}
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,7 +309,7 @@ fn node_parameters_survive_extreme_values() {
|
||||
use craft_material_graph::graph::{SPECS, demo_graph_for};
|
||||
let mut problems = Vec::new();
|
||||
let mut ran = 0usize;
|
||||
for sp in SPECS {
|
||||
for sp in crate::sampled(SPECS, 0) {
|
||||
let Some(text) = demo_graph_for(sp.kind) else { continue };
|
||||
let doc = sp.doc.split_once(':').map(|x| x.1).unwrap_or("");
|
||||
let names: Vec<String> = doc
|
||||
@@ -338,7 +338,7 @@ fn node_parameters_survive_extreme_values() {
|
||||
}
|
||||
problems.sort();
|
||||
problems.dedup();
|
||||
assert!(ran > 500, "only {ran} parameter cases ran");
|
||||
assert!(ran > 500 / crate::divisor(), "only {ran} parameter cases ran");
|
||||
assert!(problems.is_empty(), "{} parameter problems:\n{}", problems.len(), problems.join("\n"));
|
||||
}
|
||||
|
||||
@@ -446,17 +446,17 @@ fn large_sizes_are_accepted() {
|
||||
fn a_cancelled_evaluation_stops_early() {
|
||||
use craft_material_graph::context::{Cancel, EvalContext};
|
||||
let mut g = Graph::parse(EXAMPLE).unwrap();
|
||||
g.size = 1024;
|
||||
g.size = 256;
|
||||
let keep: Vec<u32> = g.output_nodes().iter().map(|o| o.2).collect();
|
||||
let job = EvalContext::with_cancel(Cancel::new());
|
||||
let t0 = std::time::Instant::now();
|
||||
let full = g.evaluate_all_in(&job, 1024, &keep);
|
||||
let full = g.evaluate_all_in(&job, 256, &keep);
|
||||
let full_time = t0.elapsed();
|
||||
assert!(!full.kept.is_empty(), "a current job must deliver its outputs");
|
||||
// a newer job exists: the old one is cancelled from the start
|
||||
job.cancel.cancel();
|
||||
let t1 = std::time::Instant::now();
|
||||
let r = g.evaluate_all_in(&job, 1024, &keep);
|
||||
let r = g.evaluate_all_in(&job, 256, &keep);
|
||||
assert!(r.kept.is_empty(), "a cancelled run must not deliver outputs");
|
||||
assert!(
|
||||
t1.elapsed() < full_time / 4 + std::time::Duration::from_millis(50),
|
||||
|
||||
@@ -18,7 +18,7 @@ fn seam(t: &Tex) -> (f32, f32) {
|
||||
#[test]
|
||||
fn every_node_is_seamless() {
|
||||
let mut bad = Vec::new();
|
||||
for sp in SPECS {
|
||||
for sp in crate::sampled(SPECS, 0) {
|
||||
let Some(text) = demo_graph_for(sp.kind) else { continue };
|
||||
let g = Graph::parse(&text).unwrap();
|
||||
let out = match g.evaluate(Some(seam_size())) {
|
||||
@@ -83,7 +83,7 @@ fn filters_commute_with_wrapped_shifts() {
|
||||
"quantize",
|
||||
];
|
||||
let mut bad = Vec::new();
|
||||
for c in filters {
|
||||
for c in crate::sampled(filters.iter(), 0) {
|
||||
let kind = c.split(' ').next().unwrap();
|
||||
let mut line = format!("node 1 {c}");
|
||||
// (the nodes that read no `in` are given their inputs in the line)
|
||||
@@ -144,7 +144,7 @@ fn filters_commute_with_wrapped_shifts() {
|
||||
fn every_node_is_seamless_when_not_square() {
|
||||
let mut bad = Vec::new();
|
||||
for (wide, name) in [(true, "2:1"), (false, "1:2")] {
|
||||
for sp in SPECS {
|
||||
for sp in crate::sampled(SPECS, 4) {
|
||||
let Some(text) = demo_graph_for(sp.kind) else { continue };
|
||||
let mut g = Graph::parse(&text).unwrap();
|
||||
let s = g.size;
|
||||
|
||||
@@ -44,15 +44,15 @@ fn review_rig() -> Rig {
|
||||
rig
|
||||
}
|
||||
|
||||
/// Only the lines in view are drawn: the review of 2,000 entries holds a few include boxes, not 2,000.
|
||||
/// Only the lines in view are drawn: a review of several hundred entries holds a few include boxes, not one per entry.
|
||||
#[trial]
|
||||
fn a_large_review_draws_only_the_rows_in_view() {
|
||||
let commands: Vec<String> = (0..2000).map(|i| command(&format!("Entry {i}"), "Cmd+K")).collect();
|
||||
let commands: Vec<String> = (0..400).map(|i| command(&format!("Entry {i}"), "Cmd+K")).collect();
|
||||
let mut rig = Rig::new(keymap(Platform::Mac), options(), None);
|
||||
rig.review(set(&commands), ImportOptions::default());
|
||||
let drawn = rig.names_with(Role::CHECK_BOX, "").len();
|
||||
assert!(drawn > 0, "the lines in view carry include boxes");
|
||||
assert!(drawn < 100, "{drawn} include boxes drawn for 2,000 entries");
|
||||
assert!(drawn < 100, "{drawn} include boxes drawn for 400 entries");
|
||||
}
|
||||
|
||||
/// Start, include and a picked target re-plan the import; a pick and No equivalent reach the app.
|
||||
|
||||
@@ -512,10 +512,10 @@ mod tests {
|
||||
assert_eq!(found.descs[0].attrs.len(), n + 2, "every attribute is read");
|
||||
took
|
||||
};
|
||||
let (n, small_packet, large_packet) = (50_000, packet(50_000), packet(200_000));
|
||||
let (n, small_packet, large_packet) = (20_000, packet(20_000), packet(80_000));
|
||||
// interleaved, so a burst of load slows both sizes rather than one; the fastest run of each counts
|
||||
let (mut small, mut large) = (std::time::Duration::MAX, std::time::Duration::MAX);
|
||||
for _ in 0..5 {
|
||||
for _ in 0..3 {
|
||||
small = small.min(run(&small_packet, n));
|
||||
large = large.min(run(&large_packet, 4 * n));
|
||||
}
|
||||
|
||||
@@ -117,12 +117,20 @@ fn names_instruments_and_lyrics() {
|
||||
assert_eq!((read.smf.tracks.len(), read.instruments), (2, vec!["Sax".to_string(), String::new()]));
|
||||
}
|
||||
|
||||
/// Three bytes a note-on under running status: more events than are read. Built once for the tests that need it.
|
||||
fn event_flood_body() -> &'static [u8] {
|
||||
static BODY: std::sync::OnceLock<Vec<u8>> = std::sync::OnceLock::new();
|
||||
BODY.get_or_init(|| {
|
||||
let mut body = vec![0x00, 0x90, 60, 100];
|
||||
body.extend((0..MAX_EVENTS + 1).flat_map(|i| [0x00, (i % 128) as u8, 1]));
|
||||
body
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_file_of_any_size_is_read_into_a_bounded_number_of_events_and_warnings() {
|
||||
// Three bytes a note-on under running status: more events than are read.
|
||||
let mut body = vec![0x00, 0x90, 60, 100];
|
||||
body.extend((0..MAX_EVENTS + 1000).flat_map(|i| [0x00, (i % 128) as u8, 1]));
|
||||
let LenientRead { smf, warnings, over_limit, .. } = read_smf_lenient(&file(1, 96, &[&body])).unwrap();
|
||||
let body = event_flood_body();
|
||||
let LenientRead { smf, warnings, over_limit, .. } = read_smf_lenient(&file(1, 96, &[body])).unwrap();
|
||||
assert_eq!(smf.tracks[0].sequence.notes.len(), MAX_EVENTS);
|
||||
assert!(warnings.iter().any(|w| w.contains("more events")), "{warnings:?}");
|
||||
assert!(over_limit, "the event limit left events out");
|
||||
@@ -140,10 +148,9 @@ fn a_file_of_any_size_is_read_into_a_bounded_number_of_events_and_warnings() {
|
||||
fn a_limit_reached_after_the_warnings_are_full_is_still_reported() {
|
||||
// MAX_WARNINGS damaged tracks fill the warnings; the track after them holds more events than are
|
||||
// read, so its warning is dropped, and over_limit is what says the file was cut.
|
||||
let mut body = vec![0x00, 0x90, 60, 100];
|
||||
body.extend((0..MAX_EVENTS + 1000).flat_map(|i| [0x00, (i % 128) as u8, 1]));
|
||||
let body = event_flood_body();
|
||||
let mut tracks = vec![&[0x00, 60][..]; MAX_WARNINGS];
|
||||
tracks.push(&body);
|
||||
tracks.push(body);
|
||||
let LenientRead { warnings, over_limit, .. } = read_smf_lenient(&file(1, 96, &tracks)).unwrap();
|
||||
assert_eq!(warnings.len(), MAX_WARNINGS);
|
||||
assert!(!warnings.iter().any(|w| w.contains("more events")), "the test needs the limit's warning dropped: {warnings:?}");
|
||||
|
||||
@@ -24,4 +24,5 @@ chardetng = { version = "1", optional = true }
|
||||
detect = ["dep:chardetng"]
|
||||
|
||||
[dev-dependencies]
|
||||
craft-testkit = { workspace = true }
|
||||
proptest = { workspace = true }
|
||||
|
||||
@@ -145,7 +145,8 @@ fn mutations_read() {
|
||||
};
|
||||
const INTERESTING: &[u8] = b"\0\r\n\t \"\\()<>;:=?-_%*'/@,.\x7f\x80\xff";
|
||||
for original in [sample(), archive()] {
|
||||
for round in 0..4000u32 {
|
||||
// The gate runs a divisor's fraction of the rounds; nightly runs all.
|
||||
for round in 0..4000 / craft_testkit::hostile::divisor() as u32 {
|
||||
let mut bytes = original.clone();
|
||||
for _ in 0..=(round % 4) {
|
||||
let at = (next() as usize) % bytes.len().max(1);
|
||||
|
||||
@@ -512,7 +512,8 @@ fn a_page_gap_change_keeps_the_scroll_offset() {
|
||||
#[trial]
|
||||
fn the_pictures_a_view_holds_stay_bounded_as_it_scrolls_through_many_pages() {
|
||||
let budget = TextureStoreOptions::pages().budget.max_entries;
|
||||
let count = 2 * budget;
|
||||
// Past the budget by half again: the store has to evict for the bound to be tested.
|
||||
let count = budget + budget / 2;
|
||||
let state = Rc::new(RefCell::new(state_with(|s| {
|
||||
s.continuous = true;
|
||||
s.fit = Fit::None;
|
||||
@@ -539,6 +540,7 @@ fn the_pictures_a_view_holds_stay_bounded_as_it_scrolls_through_many_pages() {
|
||||
assert!(drawn > 0, "the view drew pages");
|
||||
// The pages of the last two passes, in view and one row either side, are never evicted.
|
||||
let bound = budget + 2 * (drawn + 2);
|
||||
eprintln!("DIAG pictures_bounded: budget {budget}, count {count}, held {held}, drawn {drawn}");
|
||||
assert!(held > 0 && held <= bound, "{held} pictures held over {count} pages scrolled through, at most {bound} expected");
|
||||
}
|
||||
|
||||
|
||||
@@ -29,13 +29,13 @@ fn a_flood_of_long_lines_ends_the_command() {
|
||||
// 600 lines of 60 KB are more than the 32 MB one command may bring. The gate sends lines that
|
||||
// are not parsed (the cap counts the text read); nightly sends the lines of a real listing.
|
||||
let full = craft_testkit::hostile::divisor() == 1;
|
||||
let server =
|
||||
flood(600, |n| if full { format!("* {n} FETCH (UID {} FLAGS ({pad}))\r\n", n + 1) } else { format!("* OK {pad}\r\n") }) + "A0001 OK done\r\n";
|
||||
let ok_lines = format!("* OK {pad}\r\n").repeat(600);
|
||||
let server = if full { flood(600, |n| format!("* {n} FETCH (UID {} FLAGS ({pad}))\r\n", n + 1)) } else { ok_lines.clone() } + "A0001 OK done\r\n";
|
||||
let mut s = Script::new(server);
|
||||
let err = opened(&mut s, 1000, 2000).uid_fetch_flags("1:*").unwrap_err();
|
||||
assert!(matches!(err, ProtoError::Protocol(ref m) if m.to_string().contains("too much")), "{err:?}");
|
||||
// The same in a list.
|
||||
let server = flood(600, |n| if full { format!("* LIST () \"/\" \"{n}{pad}\"\r\n") } else { format!("* OK {pad}\r\n") }) + "A0001 OK done\r\n";
|
||||
let server = if full { flood(600, |n| format!("* LIST () \"/\" \"{n}{pad}\"\r\n")) } else { ok_lines } + "A0001 OK done\r\n";
|
||||
let mut s = Script::new(server);
|
||||
assert!(matches!(opened(&mut s, 0, 0).list(), Err(ProtoError::Protocol(_))));
|
||||
}
|
||||
|
||||
@@ -24,6 +24,9 @@ skrifa = { workspace = true, optional = true }
|
||||
kurbo = { workspace = true, optional = true }
|
||||
flate2 = { version = "1.1.10", default-features = false, features = ["rust_backend"], optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
craft-testkit = { workspace = true }
|
||||
|
||||
[[example]]
|
||||
name = "eps2pdf"
|
||||
required-features = ["read"]
|
||||
|
||||
@@ -602,9 +602,13 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn numbers_match_base_formatter() {
|
||||
let mut integer_path = 0usize;
|
||||
// The gate walks every `divisor()`-th value (offset by `places` so the places differ); nightly walks all.
|
||||
let step = craft_testkit::hostile::divisor();
|
||||
let (mut integer_path, mut visited) = (0usize, 0usize);
|
||||
let samples = number_samples();
|
||||
for places in 0..=12 {
|
||||
for v in number_samples() {
|
||||
for v in samples.iter().copied().skip(places as usize % step).step_by(step) {
|
||||
visited += 1;
|
||||
let mut expected = String::from("x ");
|
||||
base_push_num_places(&mut expected, v, places);
|
||||
let mut got = String::from("x ");
|
||||
@@ -616,7 +620,8 @@ mod tests {
|
||||
}
|
||||
}
|
||||
// The comparison covers the integer path, not only the fallback.
|
||||
assert!(integer_path > 200_000, "{integer_path} values took the integer path");
|
||||
eprintln!("DIAG numbers_match_base_formatter: visited {visited}, integer path {integer_path}");
|
||||
assert!(integer_path * 20 > visited, "{integer_path} of {visited} values took the integer path");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -781,7 +781,8 @@ mod tests {
|
||||
#[test]
|
||||
fn a_mesh_that_makes_every_triangle_cover_the_output_is_refused() {
|
||||
// A 48×48 custom mesh whose patch corners scatter over the four corners of the
|
||||
// content, so most of the 4608 triangles span the whole 2048² output.
|
||||
// content, so most of the 4608 triangles span the whole output (the work budget grows with
|
||||
// the output's pixels, so the size only sets how much is filled before it runs out).
|
||||
let (cols, rows) = (48usize, 48usize);
|
||||
let stride = cols * 3 + 1;
|
||||
let mut mesh = vec![[0.0, 0.0]; stride * (rows * 3 + 1)];
|
||||
@@ -794,9 +795,9 @@ mod tests {
|
||||
}
|
||||
}
|
||||
let warp = crate::smart::Warp { style: "warpCustom".into(), bounds: [0.0, 0.0, 16.0, 16.0], cols, rows, mesh, ..Default::default() };
|
||||
let s = so([[0.0, 0.0], [2048.0, 0.0], [2048.0, 2048.0], [0.0, 2048.0]], Some(warp));
|
||||
let s = so([[0.0, 0.0], [512.0, 0.0], [512.0, 512.0], [0.0, 512.0]], Some(warp));
|
||||
let content = FloatImage { width: 16, height: 16, data: vec![[1.0, 0.0, 0.0, 1.0]; 256] };
|
||||
assert!(s.render_placed(&content, 1.0, Some((2048, 2048))).is_none());
|
||||
assert!(s.render_placed(&content, 1.0, Some((512, 512))).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -487,7 +487,10 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn a_repeated_large_entity_is_too_large_and_a_namespace_entity_is_not() {
|
||||
let big = "x".repeat(1 << 20);
|
||||
// (the limit is passed in: the same arithmetic as `MAX_ENTITY_EXPANSION` over entities 256 times smaller, which
|
||||
// only expand to 16 references' worth, so the strings the test builds and scans stay small)
|
||||
let big = "x".repeat(1 << 16);
|
||||
let expansion_too_large = |svg: &str| entities_expand_past(svg, 16 << 16);
|
||||
let refs = "&a;".repeat(20);
|
||||
let bomb = format!("<!DOCTYPE svg [<!ENTITY a \"{big}\">]><svg xmlns=\"http://www.w3.org/2000/svg\" id=\"{refs}\"/>");
|
||||
assert!(expansion_too_large(&bomb));
|
||||
@@ -500,6 +503,7 @@ mod tests {
|
||||
let ampersands = format!("<!DOCTYPE svg [<!ENTITY a \"x\">]><svg id=\"{}\"/>", "&".repeat(1 << 20));
|
||||
let start = std::time::Instant::now();
|
||||
assert!(!expansion_too_large(&ersands));
|
||||
eprintln!("DIAG svg ampersand run read in {:?}", start.elapsed());
|
||||
// A quadratic read would take hours; the bound is loose for a loaded machine.
|
||||
assert!(start.elapsed() < std::time::Duration::from_secs(120), "{:?}", start.elapsed());
|
||||
}
|
||||
|
||||
@@ -419,7 +419,21 @@ pub(crate) fn bare_context() -> Context {
|
||||
/// one build to the next.
|
||||
fn test_fonts() -> egui::FontDefinitions {
|
||||
static FONTS: std::sync::OnceLock<egui::FontDefinitions> = std::sync::OnceLock::new();
|
||||
FONTS.get_or_init(crate::fonts::deflated_default_definitions).clone()
|
||||
FONTS
|
||||
.get_or_init(|| {
|
||||
let mut definitions = crate::fonts::deflated_default_definitions();
|
||||
// A fixture reads text through the AccessKit tree and the painted bounds, never the atlas pixels, and
|
||||
// hinting changes only how outlines are rasterized (advances and layout do not read it). Without it no
|
||||
// face builds a hinting instance and no glyph runs the hinter. An app's own stack (`UiFonts::install`)
|
||||
// keeps hinting, which the review renders use.
|
||||
for data in definitions.font_data.values_mut() {
|
||||
let mut face = (**data).clone();
|
||||
face.tweak.hinting = Some(false);
|
||||
*data = Arc::new(face);
|
||||
}
|
||||
definitions
|
||||
})
|
||||
.clone()
|
||||
}
|
||||
|
||||
/// A paragraph of `text` wrapped to the available width.
|
||||
|
||||
@@ -174,6 +174,8 @@ fn panic_text(payload: Box<dyn std::any::Any + Send>) -> String {
|
||||
/// The cases of `group` over the stories of the type `probe` describes, and with `check_exemptions` the check that
|
||||
/// each exemption names a known case. `home`: the stories are the package's that registers the type ([`Subject::home`]).
|
||||
fn run_group(probe: Probe, group: &'static Group, check_exemptions: bool, home: bool, stories: Vec<Story>) -> Result<(), Failed> {
|
||||
// The cases that read the type as a whole look at one story of each kind at the gate; the others keep every story.
|
||||
let stories = if matches!(group.name, "reads" | "variants" | "containers") { nodes::sampled_stories(stories) } else { stories };
|
||||
let subject = Subject::new(&probe, stories, home);
|
||||
let mut failures = Vec::new();
|
||||
if check_exemptions && home {
|
||||
|
||||
@@ -25,6 +25,13 @@ pub(super) const CASES: &[Case] = &[
|
||||
Case::new("press-removal", ANY, removal_cancels_a_press),
|
||||
];
|
||||
|
||||
/// Whether a click path left the component as it found it: no node state changed and no layer opened. The paths of one
|
||||
/// part share a fixture while this holds; a path that moved something starts the next in a fresh fixture, so
|
||||
/// a path never sees another's effect.
|
||||
fn left_as_found(fixture: &Fixture, before: &HashMap<NodeKey, String>, layers: usize) -> bool {
|
||||
signature(fixture.tree()) == *before && crate::runtime::overlay::open_entries(fixture.ctx()).len() == layers
|
||||
}
|
||||
|
||||
/// Enter, Space, AccessKit `Click` and a primary click each give exactly one click on a component that reports
|
||||
/// clicks and carries no value (value types are checked by the values case).
|
||||
fn each_activation_clicks_once(subject: &Subject) -> Result<(), String> {
|
||||
@@ -37,14 +44,20 @@ fn each_activation_clicks_once(subject: &Subject) -> Result<(), String> {
|
||||
if !matches!(plan, Plan::Activate) || !fixture.tree().declares_key(root.node, Declared::Click) {
|
||||
continue;
|
||||
}
|
||||
// The variants share one fixture while each leaves the component as it found it ([`left_as_found`]).
|
||||
let mut shared: Option<Fixture> = None;
|
||||
for variant in variants(plan, subject.probe) {
|
||||
let mut fixture = input_fixture(story);
|
||||
let mut fixture = shared.take().unwrap_or_else(|| input_fixture(story));
|
||||
let (before, layers) = (signature(fixture.tree()), crate::runtime::overlay::open_entries(fixture.ctx()).len());
|
||||
fixture.take_outputs();
|
||||
run(&mut fixture, plan, variant);
|
||||
let clicks = fixture.take_outputs().iter().filter(|output| output.activated()).count();
|
||||
if clicks != 1 {
|
||||
return Err(format!("{}: {} gave {clicks} clicks", story.name, variant_name(plan, variant)));
|
||||
}
|
||||
if left_as_found(&fixture, &before, layers) {
|
||||
shared = Some(fixture);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
@@ -82,12 +95,15 @@ fn each_part_activates_once(subject: &Subject) -> Result<(), String> {
|
||||
(2, "Enter", keys[0].1 && declares(Declared::Focus)),
|
||||
(3, "Space", keys[1].1 && declares(Declared::Focus)),
|
||||
];
|
||||
// The paths of a part share one fixture while each leaves the component as it found it ([`left_as_found`]).
|
||||
let mut shared: Option<Fixture> = None;
|
||||
for (path, name, _) in paths.into_iter().filter(|(_, _, has)| *has) {
|
||||
let mut fixture = input_fixture(story);
|
||||
let mut fixture = shared.take().unwrap_or_else(|| input_fixture(story));
|
||||
let Some(target) = fixture.root_id().and_then(|id| fixture.part(id, part)) else { continue };
|
||||
if fixture.tree().data_of(target.node).is_some_and(|node| node.is_disabled()) {
|
||||
continue;
|
||||
}
|
||||
let (before, layers) = (signature(fixture.tree()), crate::runtime::overlay::open_entries(fixture.ctx()).len());
|
||||
fixture.take_outputs();
|
||||
match path {
|
||||
0 => {
|
||||
@@ -107,6 +123,9 @@ fn each_part_activates_once(subject: &Subject) -> Result<(), String> {
|
||||
if clicks != 1 {
|
||||
return Err(format!("{}: {name} on the part {part:?} gave {clicks} clicks", story.name));
|
||||
}
|
||||
if left_as_found(&fixture, &before, layers) {
|
||||
shared = Some(fixture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
use crate::runtime::access::Role;
|
||||
use crate::runtime::egui::access::{AccessTree, Declared, NodeKey};
|
||||
use crate::testing::fixture::{Fixture, Target};
|
||||
use crate::testing::story::Story;
|
||||
use craft_behavior::PartRef;
|
||||
|
||||
/// `node` and every node below it.
|
||||
@@ -160,3 +161,21 @@ pub(super) fn sampled_actions(tree: &AccessTree, mut pairs: Vec<(NodeKey, Declar
|
||||
}
|
||||
sets.iter().flat_map(|set| sample(set)).collect()
|
||||
}
|
||||
|
||||
/// `stories` cut, when [`samples_repeats`], to the first story of each distinct kind: stories that cover the same
|
||||
/// required states, drive the same way, give the same disabled reason and set command states alike differ only in
|
||||
/// what they show, which the cases that read the type as a whole (`reads`, `variants`, `containers`) see through
|
||||
/// the first of them. The nightly run keeps every story.
|
||||
pub(super) fn sampled_stories(stories: Vec<Story>) -> Vec<Story> {
|
||||
if !samples_repeats() {
|
||||
return stories;
|
||||
}
|
||||
let kind = |story: &Story| (story.covers, std::mem::discriminant(&story.drive), story.disabled_text, story.commands.is_some());
|
||||
let mut kept: Vec<Story> = Vec::new();
|
||||
for story in stories {
|
||||
if !kept.iter().any(|known| kind(known) == kind(&story)) {
|
||||
kept.push(story);
|
||||
}
|
||||
}
|
||||
kept
|
||||
}
|
||||
|
||||
@@ -101,32 +101,28 @@ pub fn text_size_case(story: &Story) -> Result<(), String> {
|
||||
|
||||
/// The text-size case for `story`, whose settled default shot is `base`.
|
||||
fn text_size_from(story: &Story, base: Shot) -> Result<(), String> {
|
||||
let variants: [(&str, Shot); 4] = [
|
||||
(
|
||||
"text size",
|
||||
// The shot at the default density is the base shot, so a density is shot only when it is not the default.
|
||||
let densities = [("compact density", Size::Compact), ("comfortable density", Size::Comfortable)];
|
||||
let mut variants: Vec<(&str, Shot)> = vec![(
|
||||
"text size",
|
||||
shot(story, &|f| {
|
||||
f.text_size(TextSize::Large);
|
||||
}),
|
||||
)];
|
||||
for (name, density) in densities.into_iter().filter(|(_, density)| *density != Size::default()) {
|
||||
variants.push((
|
||||
name,
|
||||
shot(story, &|f| {
|
||||
f.text_size(TextSize::Large);
|
||||
f.density(density);
|
||||
}),
|
||||
),
|
||||
(
|
||||
"compact density",
|
||||
shot(story, &|f| {
|
||||
f.density(Size::Compact);
|
||||
}),
|
||||
),
|
||||
(
|
||||
"comfortable density",
|
||||
shot(story, &|f| {
|
||||
f.density(Size::Comfortable);
|
||||
}),
|
||||
),
|
||||
(
|
||||
"scale 2",
|
||||
shot(story, &|f| {
|
||||
f.scale(Scale(2.0));
|
||||
}),
|
||||
),
|
||||
];
|
||||
));
|
||||
}
|
||||
variants.push((
|
||||
"scale 2",
|
||||
shot(story, &|f| {
|
||||
f.scale(Scale(2.0));
|
||||
}),
|
||||
));
|
||||
let (before, after) = (base.shown.size(), |shot: &Shot| shot.shown.size());
|
||||
for (name, grown) in &variants {
|
||||
let size = after(grown);
|
||||
|
||||
@@ -36,12 +36,15 @@ fn acted(fixture: &mut Fixture, before: &crate::testing::story::StorySnapshot) -
|
||||
fn disabled_changes_nothing(subject: &Subject) -> Result<(), String> {
|
||||
for story in &subject.stories {
|
||||
let plan = subject.base(story).plan;
|
||||
// One fixture takes every drive: a disabled story that acts on one is an error at once, so a drive that
|
||||
// passes leaves it as it was for the next.
|
||||
let mut driven = for_input(Fixture::story_scoped(story, |scope| scope.enabled = Some(false)));
|
||||
for variant in variants(plan, subject.probe).into_iter().filter(|variant| !cancels(plan, *variant)) {
|
||||
let mut fixture = for_input(Fixture::story_scoped(story, |scope| scope.enabled = Some(false)));
|
||||
let fixture = &mut driven;
|
||||
let before = fixture.data().snapshot();
|
||||
fixture.take_outputs();
|
||||
run(&mut fixture, plan, variant);
|
||||
if acted(&mut fixture, &before) {
|
||||
run(fixture, plan, variant);
|
||||
if acted(fixture, &before) {
|
||||
return Err(format!("{}: a disabled story acted on drive {variant}", story.name));
|
||||
}
|
||||
}
|
||||
@@ -87,12 +90,15 @@ fn read_only_changes_nothing(subject: &Subject) -> Result<(), String> {
|
||||
}
|
||||
for story in &subject.stories {
|
||||
let plan = subject.base(story).plan;
|
||||
// One fixture takes every drive: a read-only story that acts on one is an error at once, so a drive that
|
||||
// passes leaves it as it was for the next.
|
||||
let mut driven = for_input(Fixture::story_scoped(story, |scope| scope.read_only = Some(true)));
|
||||
for variant in variants(plan, subject.probe).into_iter().filter(|variant| !cancels(plan, *variant)) {
|
||||
let mut fixture = for_input(Fixture::story_scoped(story, |scope| scope.read_only = Some(true)));
|
||||
let fixture = &mut driven;
|
||||
let before = fixture.data().snapshot();
|
||||
fixture.take_outputs();
|
||||
run(&mut fixture, plan, variant);
|
||||
if acted(&mut fixture, &before) {
|
||||
run(fixture, plan, variant);
|
||||
if acted(fixture, &before) {
|
||||
return Err(format!("{}: a read-only story acted on drive {variant}", story.name));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -708,7 +708,8 @@ fn icon_groups_apart_by_a_rule_show_one_level_rule_between_them() {
|
||||
let between: Vec<_> = level.iter().filter(|(a, _, _)| a.y > last.bottom() && a.y < next.top()).collect();
|
||||
let [(a, b, ink)] = between.as_slice() else { panic!("one rule between the groups: {level:?}") };
|
||||
let (left, right) = (a.x.min(b.x), a.x.max(b.x));
|
||||
assert!(left > 0.0 && right < RAIL && right - left > RAIL / 2.0, "the rule reaches across the column, short of its sides: {a:?} to {b:?}");
|
||||
let span = right - left;
|
||||
assert!(left > 0.0 && right < RAIL && span > RAIL - span, "the rule reaches across the column, short of its sides: {a:?} to {b:?}");
|
||||
let [r, g, bl, al] = border.0;
|
||||
assert_eq!(*ink, egui::Color32::from_rgba_unmultiplied(r, g, bl, al), "the rule is in line.border");
|
||||
}
|
||||
|
||||
@@ -13,3 +13,6 @@ workspace = true
|
||||
[dependencies]
|
||||
flate2 = { version = "1", default-features = false, features = ["rust_backend"] }
|
||||
thiserror = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
craft-testkit = { workspace = true }
|
||||
|
||||
@@ -405,7 +405,8 @@ fn corrupted_files_never_panic() {
|
||||
let bytes = img.write();
|
||||
assert!(read_all(&bytes).is_ok());
|
||||
let mut state = 0x9e37_79b9_u32;
|
||||
for _ in 0..2000 {
|
||||
// The gate runs a divisor's fraction of the rounds; nightly runs all.
|
||||
for _ in 0..2000 / craft_testkit::hostile::divisor() {
|
||||
let mut b = bytes.clone();
|
||||
for _ in 0..3 {
|
||||
state ^= state << 13;
|
||||
|
||||
@@ -314,9 +314,13 @@ class WorkspaceTests(unittest.TestCase):
|
||||
# Only the Linux leg splits into a build job and shards, and only for the audit.
|
||||
self.assertEqual(source.count("test-shards:"), 1)
|
||||
self.assertIn("test-shards: ${{ needs.platforms.outputs.audit == 'true' && 3 || 0 }}", source)
|
||||
# Every Workspace leg's cache entry is named after the profile overrides it was built with.
|
||||
# The Linux leg's entry, which keeps workspace crates, is named after every profile override;
|
||||
# the macOS and Windows legs' dependency-only entries after the settings that reach a
|
||||
# dependency, so next restores main's (test_profile_overrides_name_only_workspace_members).
|
||||
self.assertIn("cache-version: &cache-version v2-${{ needs.platforms.outputs.profile }}\n", source)
|
||||
self.assertIn(" cache-version: *cache-version\n", source)
|
||||
self.assertIn(" cache-version: v2-${{ needs.platforms.outputs.deps-profile }}\n", source)
|
||||
self.assertIn(" deps-profile: ${{ steps.audit.outputs.deps-profile }}\n", source)
|
||||
self.assertNotIn(" cache-version: *cache-version\n", source)
|
||||
# Only the Linux leg keeps workspace crates; the cache budget has no room for the others.
|
||||
self.assertEqual(source.count("cache-workspace-crates: true"), 1)
|
||||
self.assertIn(" msrv:", source)
|
||||
|
||||
Reference in New Issue
Block a user