mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-18 00:05:08 +00:00
ci: run a fraction of the fuzz-style tests on pull requests, all of them nightly
craft-testkit's hostile hammer reads CRAFT_HOSTILE_DIVISOR=N: the unmodified seed, every N-th truncation and 1/N of the rounds. hostile::divisor() gives the same value to sweeps written without the hammer; craft-image-codecs' TIFF zoo and malformed-header sweeps use it, with a different offset per input so the inputs together still reach every position. Proptests without their own case count read proptest's PROPTEST_CASES. The Workspace gate and the media, audio, video and PDF workflows set CRAFT_HOSTILE_DIVISOR=8 and PROPTEST_CASES=64. The longest of these tests (craft-media's MXF hostile input, 1,310 s on Windows; craft-pdf's crypt proptests, up to 257 s; the image-codecs sweeps, 140-162 s) drop to about an eighth or a quarter. nightly.yml runs the whole workspace on Linux without either variable, so every case still runs once a day. The gate's test-input setup moves to scripts/ci-test-inputs.sh, shared by both workflows; it uses a corpus that is already present.
This commit is contained in:
1 parent
a97b7948a9
commit
ff502fb75f
15 files changed
+215
-45
No files matched your search
@@ -80,6 +80,7 @@ workflows:
|
||||
- 'actions/checkout@v7.0.1'
|
||||
- 'dtolnay/rust-toolchain@stable'
|
||||
- 'swatinem/rust-cache@v2.9.3'
|
||||
'.github/workflows/nightly.yml': []
|
||||
'.github/workflows/pcraft-format.yml':
|
||||
- 'actions/checkout@v7.0.1'
|
||||
- 'step-security/dtolnay-rust-toolchain@v1.0.0'
|
||||
|
||||
@@ -11,6 +11,11 @@ on:
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
# A fraction of the fuzz-style cases, as in the Workspace gate; nightly.yml runs them in full.
|
||||
env:
|
||||
CRAFT_HOSTILE_DIVISOR: "8"
|
||||
PROPTEST_CASES: "64"
|
||||
|
||||
concurrency:
|
||||
# Pull requests share one group per branch, so a newer push cancels the older run. Every other
|
||||
# run (main, manual) gets its own group: it is never cancelled or replaced while queued, so it
|
||||
|
||||
@@ -11,6 +11,11 @@ on:
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
# A fraction of the fuzz-style cases, as in the Workspace gate; nightly.yml runs them in full.
|
||||
env:
|
||||
CRAFT_HOSTILE_DIVISOR: "8"
|
||||
PROPTEST_CASES: "64"
|
||||
|
||||
concurrency:
|
||||
# Pull requests share one group per branch, so a newer push cancels the older run. Every other
|
||||
# run (main, manual) gets its own group: it is never cancelled or replaced while queued, so it
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
name: Nightly full tests
|
||||
|
||||
# The tests the Workspace gate shortens, in full, once a day: every hostile-input hammer and sweep
|
||||
# without CRAFT_HOSTILE_DIVISOR, and every proptest at its own case count (no PROPTEST_CASES). The
|
||||
# rest of the workspace's tests run with them, on Linux, with the gate's setup.
|
||||
on:
|
||||
schedule:
|
||||
- cron: "37 2 * * *"
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
concurrency:
|
||||
group: nightly-${{ github.ref }}
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
full:
|
||||
name: Full tests
|
||||
uses: storytold/craft-common-actions/.github/workflows/gate.yml@main
|
||||
with:
|
||||
os: '["ubuntu-latest"]'
|
||||
timeout-minutes: 120
|
||||
tools: cargo-nextest@0.9.150
|
||||
packages: mesa-vulkan-drivers libvulkan1
|
||||
craft-fonts-ref: b076417b5880bd4154bd22f00695b1d28c6bea83
|
||||
linux-env: WGPU_BACKEND=vulkan
|
||||
env: CRAFT_PRINT_REQUIRE_QUEUE=0
|
||||
setup-command: bash scripts/ci-test-inputs.sh
|
||||
command: cargo nextest run --workspace --all-features --locked --profile ci
|
||||
@@ -11,6 +11,10 @@ on:
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
# A fraction of the proptest cases, as in the Workspace gate; nightly.yml runs them in full.
|
||||
env:
|
||||
PROPTEST_CASES: "64"
|
||||
|
||||
concurrency:
|
||||
# Pull requests share one group per branch, so a newer push cancels the older run. Every other
|
||||
# run (main, manual) gets its own group: it is never cancelled or replaced while queued, so it
|
||||
|
||||
@@ -11,6 +11,11 @@ on:
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
# A fraction of the fuzz-style cases, as in the Workspace gate; nightly.yml runs them in full.
|
||||
env:
|
||||
CRAFT_HOSTILE_DIVISOR: "8"
|
||||
PROPTEST_CASES: "64"
|
||||
|
||||
concurrency:
|
||||
group: shared-video-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
@@ -31,22 +31,14 @@ jobs:
|
||||
craft-fonts-ref: b076417b5880bd4154bd22f00695b1d28c6bea83
|
||||
linux-env: WGPU_BACKEND=vulkan
|
||||
windows-env: CRAFT_PRINT_REQUIRE_QUEUE=1
|
||||
env: CRAFT_PRINT_REQUIRE_QUEUE=0
|
||||
setup-command: |
|
||||
set -euo pipefail
|
||||
corpus_fetcher=.test-inputs/photocraft
|
||||
mkdir -p "$corpus_fetcher"
|
||||
git -C "$corpus_fetcher" init
|
||||
git -C "$corpus_fetcher" remote add origin https://github.com/storytold/PhotoCraft.git
|
||||
git -C "$corpus_fetcher" fetch --quiet --depth=1 origin 74330157cb601573ae4523a95bb9132822fc3918
|
||||
git -C "$corpus_fetcher" checkout --quiet --detach FETCH_HEAD
|
||||
(cd "$corpus_fetcher" && cargo xtask corpus --psd --psd-tools --atn --exr --heif --pngsuite)
|
||||
mkdir -p corpus
|
||||
cp -a "$corpus_fetcher/corpus/." corpus/
|
||||
python scripts/test-fetch-pdf-test-fonts.py
|
||||
python scripts/fetch-pdf-test-fonts.py "$RUNNER_TEMP/craft-pdf-test-fonts"
|
||||
printf 'CRAFT_PSD_CORPUS=%s\n' "$GITHUB_WORKSPACE/$corpus_fetcher/corpus" >> "$GITHUB_ENV"
|
||||
printf 'CRAFT_PDF_TEST_FONT_DIR=%s\n' "$RUNNER_TEMP/craft-pdf-test-fonts" >> "$GITHUB_ENV"
|
||||
# The fuzz-style tests run a fraction of their cases here: every hostile-input hammer and
|
||||
# sweep 1/8 (craft-testkit's CRAFT_HOSTILE_DIVISOR), every proptest without its own case
|
||||
# count 64 cases instead of 256. nightly.yml runs them all in full.
|
||||
env: |
|
||||
CRAFT_PRINT_REQUIRE_QUEUE=0
|
||||
CRAFT_HOSTILE_DIVISOR=8
|
||||
PROPTEST_CASES=64
|
||||
setup-command: bash scripts/ci-test-inputs.sh
|
||||
command: |
|
||||
python3 scripts/test-workspace-concurrency.py
|
||||
python3 scripts/test-workspace-tests.py
|
||||
|
||||
@@ -76,9 +76,11 @@ fn truncated_files_mostly_error() {
|
||||
|
||||
#[test]
|
||||
fn bit_flips_never_panic() {
|
||||
// CRAFT_HOSTILE_DIVISOR=N (pull requests) runs 1/N of the flips.
|
||||
let rounds = 150usize.div_ceil(craft_media_testkit::hostile::divisor());
|
||||
let mut rng = common::Rng::new(42);
|
||||
for (f, bytes) in samples() {
|
||||
for _ in 0..150 {
|
||||
for _ in 0..rounds {
|
||||
let mut b = bytes.clone();
|
||||
let flips = 1 + (rng.next_u64() % 4) as usize;
|
||||
for _ in 0..flips {
|
||||
@@ -92,8 +94,11 @@ fn bit_flips_never_panic() {
|
||||
|
||||
#[test]
|
||||
fn byte_overwrites_in_header_never_panic() {
|
||||
for (f, bytes) in samples() {
|
||||
for i in 0..bytes.len().min(64) {
|
||||
// CRAFT_HOSTILE_DIVISOR=N (pull requests) overwrites every N-th byte, from a different offset
|
||||
// for each sample, so the samples together still reach every header position.
|
||||
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] {
|
||||
let mut b = bytes.clone();
|
||||
b[i] = v;
|
||||
|
||||
@@ -820,15 +820,18 @@ fn poke(bytes: &[u8]) {
|
||||
|
||||
#[test]
|
||||
fn zoo_decodes_and_never_panics_when_cut_or_corrupted() {
|
||||
for f in zoo() {
|
||||
// CRAFT_HOSTILE_DIVISOR=N (pull requests) runs every N-th cut and flip, from a different offset
|
||||
// for each file, and 1/N of the random rounds.
|
||||
let step = craft_media_testkit::hostile::divisor();
|
||||
for (k, f) in zoo().into_iter().enumerate() {
|
||||
let info = tiff_info(&f).unwrap();
|
||||
for i in 0..info.pages.len() {
|
||||
decode_tiff_page(&f, i, &DecodeOptions::default()).unwrap();
|
||||
}
|
||||
for cut in 0..f.len() {
|
||||
for cut in (0..f.len()).filter(|cut| (cut + k) % step == 0) {
|
||||
poke(&f[..cut]);
|
||||
}
|
||||
for i in 0..f.len() {
|
||||
for i in (0..f.len()).filter(|i| (i + k) % step == 0) {
|
||||
for flip in [0xffu8, 0x80, 0x01] {
|
||||
let mut g = f.clone();
|
||||
g[i] ^= flip;
|
||||
@@ -836,7 +839,7 @@ fn zoo_decodes_and_never_panics_when_cut_or_corrupted() {
|
||||
}
|
||||
}
|
||||
let mut r = Rng::new(f.len() as u64);
|
||||
for _ in 0..300 {
|
||||
for _ in 0..300usize.div_ceil(step) {
|
||||
let mut g = f.clone();
|
||||
for _ in 0..4 {
|
||||
let i = (r.next_u64() as usize) % g.len();
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
//! thread with a time limit for each case. [`Rng`], [`mutations`] and the other names here are
|
||||
//! `craft_testkit`'s.
|
||||
|
||||
pub use craft_testkit::hostile::{DIVISOR_VARIABLE, MAX_CASES, Mutation, Mutations, Rng, mutations};
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub use craft_testkit::hostile::{HammerConfig, HammerError};
|
||||
pub use craft_testkit::hostile::{MAX_CASES, Mutation, Mutations, Rng, mutations};
|
||||
pub use craft_testkit::hostile::{HammerConfig, HammerError, divisor};
|
||||
|
||||
/// The variable that multiplies [`hammer`]'s iterations.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
@@ -17,8 +17,10 @@ const MULTIPLIER_VARIABLE: &str = "CRAFT_MEDIA_HOSTILE_MULT";
|
||||
/// Panics on the first case that panics or does not finish, naming `name`, the case, its length and
|
||||
/// the panic's message.
|
||||
///
|
||||
/// `CRAFT_MEDIA_HOSTILE_MULT=10` runs ten times the iterations (soak runs). A value that is not a
|
||||
/// whole number above zero panics, naming the variable, before `run` is called.
|
||||
/// `CRAFT_MEDIA_HOSTILE_MULT=10` runs ten times the iterations (soak runs), and
|
||||
/// `CRAFT_HOSTILE_DIVISOR=8` every eighth truncation and an eighth of the iterations (pull
|
||||
/// requests). A value that is not a whole number above zero panics, naming the variable, before
|
||||
/// `run` is called.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[track_caller]
|
||||
pub fn hammer(name: &str, seed: &[u8], iters: usize, run: impl Fn(&[u8]) + Send + Sync + 'static) {
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
//!
|
||||
//! [`hostile::hammer`] runs a parser over every truncation and mutations of a valid input and fails
|
||||
//! on a panic or a case that does not finish in time; `CRAFT_MEDIA_HOSTILE_MULT=10` runs ten times
|
||||
//! the iterations. It and [`with_deadline`] call `craft_testkit`.
|
||||
//! the iterations and `CRAFT_HOSTILE_DIVISOR=8` an eighth of them. It and [`with_deadline`] call
|
||||
//! `craft_testkit`.
|
||||
//! [`vmd`] writes Sierra VMD fixtures, which ffmpeg can read but not write.
|
||||
//!
|
||||
//! Failing loudly is what a test helper is for: a wrong `CRAFT_MEDIA_*` setting or an unwritable
|
||||
|
||||
@@ -5,7 +5,7 @@ use std::process::Command;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Duration;
|
||||
|
||||
use craft_media_testkit::hostile::hammer;
|
||||
use craft_media_testkit::hostile::{divisor, hammer};
|
||||
|
||||
/// Set only in the child processes of `run_child`: the value names what `child_hammer` does.
|
||||
const CHILD_VARIABLE: &str = "CRAFT_MEDIA_TESTKIT_HOSTILE_CHILD";
|
||||
@@ -60,10 +60,11 @@ fn a_bad_multiplier_names_the_variable() {
|
||||
|
||||
#[test]
|
||||
fn a_panic_keeps_its_message() {
|
||||
let payload = std::panic::catch_unwind(|| hammer("demo", &[9, 8, 7, 6], 0, |d| assert!(d.len() != 2, "boom at {}", d.len()))).unwrap_err();
|
||||
// Truncation to 0 runs under any CRAFT_HOSTILE_DIVISOR.
|
||||
let payload = std::panic::catch_unwind(|| hammer("demo", &[9, 8, 7, 6], 0, |d| assert!(!d.is_empty(), "boom at {}", d.len()))).unwrap_err();
|
||||
let message = payload.downcast_ref::<String>().cloned().unwrap_or_default();
|
||||
assert!(message.starts_with("demo: truncation to 2 (len 2): the parser panicked: "), "{message}");
|
||||
assert!(message.contains("boom at 2"), "{message}");
|
||||
assert!(message.starts_with("demo: truncation to 0 (len 0): the parser panicked: "), "{message}");
|
||||
assert!(message.contains("boom at 0"), "{message}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -74,8 +75,8 @@ fn every_truncation_of_a_large_seed_runs() {
|
||||
hammer("large", &seed, 0, move |d| {
|
||||
record.lock().unwrap().insert(d.len());
|
||||
});
|
||||
// The seed and its 8,192 truncations.
|
||||
assert_eq!(lengths.lock().unwrap().len(), 8_193);
|
||||
// The seed and its 8,192 truncations, every N-th of them under CRAFT_HOSTILE_DIVISOR=N.
|
||||
assert_eq!(lengths.lock().unwrap().len(), 1 + 8_192usize.div_ceil(divisor()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -192,6 +192,16 @@ A product of the iterations and the multiplier that does not fit in a `usize`, a
|
||||
more than `MAX_CASES` (10,000,000) cases in all, and a limit variable that `deadline` would reject
|
||||
also fail the test before `parse` is called.
|
||||
|
||||
### Quick runs
|
||||
|
||||
`CRAFT_HOSTILE_DIVISOR=N` runs a fraction of every sweep: the unmodified seed, every N-th truncation
|
||||
(lengths 0, N, 2N, ...) and the rounds divided by N, rounded up. It takes the same values as the
|
||||
multiplier. The Workspace gate sets it on every run and the nightly run leaves it unset, so every
|
||||
case still runs once a day. A sweep written without `hammer` reads it with `hostile::divisor()` and
|
||||
runs the cases whose index plus an offset is a multiple of it, with a different offset for each input
|
||||
so that the inputs together still reach every index. A failing case is found again with the same
|
||||
value.
|
||||
|
||||
Changes from `craft-media-testkit`'s `hammer`:
|
||||
|
||||
- A case that does not finish fails the test after its limit with the case's label. Before, a case
|
||||
|
||||
@@ -11,7 +11,10 @@
|
||||
//! mutations, one case after another on a worker thread, with a time limit for each case. It fails
|
||||
//! the test, naming the case and the input length, when the parser panics or does not finish in
|
||||
//! time. The number of rounds is a count the caller gives, multiplied by a variable the caller
|
||||
//! names. [`hammer`] and [`HammerConfig`] are not built for `wasm32`.
|
||||
//! names. [`DIVISOR_VARIABLE`] (`CRAFT_HOSTILE_DIVISOR`) runs a fraction of every sweep for quick
|
||||
//! runs such as pull requests: every N-th truncation and 1/N of the rounds; [`divisor`] reads it
|
||||
//! for sweeps written without [`hammer`]. [`hammer`], [`HammerConfig`] and [`divisor`] are not
|
||||
//! built for `wasm32`.
|
||||
|
||||
use std::fmt::Write as _;
|
||||
|
||||
@@ -40,6 +43,12 @@ const WORKER_NAME: &str = "craft-testkit hostile";
|
||||
/// [`HammerConfig::with_multiplier_variable`] names another.
|
||||
pub const DEFAULT_MULTIPLIER_VARIABLE: &str = "CRAFT_HOSTILE_MULT";
|
||||
|
||||
/// The variable that divides every hostile-input sweep: with `N`, [`hammer`] runs the unmodified
|
||||
/// seed, every N-th truncation (lengths 0, N, 2N, ...) and 1/N of its rounds, rounded up. Unset, or
|
||||
/// 1, runs everything. The Workspace gate sets it and the nightly full run leaves it unset; a
|
||||
/// failing case is found again with the same value.
|
||||
pub const DIVISOR_VARIABLE: &str = "CRAFT_HOSTILE_DIVISOR";
|
||||
|
||||
/// The default limit for one case of [`hammer`]. The limit's variable, `CRAFT_TEST_TIMEOUT_SECS`
|
||||
/// unless [`HammerConfig::with_timeout`] names another, replaces it.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
@@ -339,6 +348,36 @@ fn parse_multiplier(value: &str) -> Result<usize, &'static str> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The value of [`DIVISOR_VARIABLE`], or 1 when it is not set, for a sweep written without
|
||||
/// [`hammer`]: run the cases whose index plus an offset is a multiple of it, and give each input of
|
||||
/// the sweep a different offset so that together they still reach every index. Panics, naming the
|
||||
/// variable, when the value is not a whole number above zero.
|
||||
///
|
||||
/// ```
|
||||
/// let step = craft_testkit::hostile::divisor();
|
||||
/// let positions: Vec<usize> = (0..64).filter(|i| (i + 3) % step == 0).collect();
|
||||
/// assert!(!positions.is_empty());
|
||||
/// ```
|
||||
// Failing the calling test is what this function is for.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[allow(clippy::panic)]
|
||||
#[track_caller]
|
||||
pub fn divisor() -> usize {
|
||||
match divisor_with(read_variable) {
|
||||
Ok(divisor) => divisor,
|
||||
Err(error) => panic!("{error}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// [`divisor`] with the variable lookup passed in.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn divisor_with(lookup: impl FnOnce(&str) -> Option<OsString>) -> Result<usize, HammerError> {
|
||||
let Some(raw) = lookup(DIVISOR_VARIABLE) else { return Ok(1) };
|
||||
let variable = DIVISOR_VARIABLE.to_owned();
|
||||
let value = raw.into_string().map_err(|_| HammerError::NotUnicode { variable: variable.clone() })?;
|
||||
parse_multiplier(&value).map_err(|reason| HammerError::BadValue { variable, value, reason })
|
||||
}
|
||||
|
||||
/// Reads the variable `name` from the process environment.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn read_variable(name: &str) -> Option<OsString> {
|
||||
@@ -388,15 +427,16 @@ where
|
||||
{
|
||||
let label = config.label;
|
||||
let rounds = config.rounds_with(&lookup).map_err(|error| format!("{label}: {error}"))?;
|
||||
let rounds = if seed.is_empty() { 0 } else { rounds };
|
||||
let cases = 1 + seed.len() as u128 + rounds as u128;
|
||||
let divisor = divisor_with(&lookup).map_err(|error| format!("{label}: {error}"))?;
|
||||
let rounds = if seed.is_empty() { 0 } else { rounds.div_ceil(divisor) };
|
||||
let cases = 1 + seed.len().div_ceil(divisor) as u128 + rounds as u128;
|
||||
if cases > MAX_CASES as u128 {
|
||||
return Err(format!("{label}: {}", HammerError::TooManyCases { cases }));
|
||||
}
|
||||
let start = Instant::now();
|
||||
let limit = resolve(&config.timeout, &lookup, start).map(Limit::from).map_err(|error| format!("{label}: {error}"))?;
|
||||
let clock: Clock = Arc::new(move || start.elapsed());
|
||||
run_cases(label.to_owned(), limit, Arc::from(seed), rounds, parse, clock)
|
||||
run_cases(label.to_owned(), limit, Arc::from(seed), rounds, divisor, parse, clock)
|
||||
}
|
||||
|
||||
/// A clock that returns the time since a [`hammer`] call started.
|
||||
@@ -467,7 +507,7 @@ impl Drop for Report {
|
||||
/// Starts the worker that runs every case, then waits for it, failing when a case runs past the
|
||||
/// limit.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn run_cases<F>(label: String, limit: Limit, seed: Arc<[u8]>, rounds: usize, parse: F, clock: Clock) -> Result<(), String>
|
||||
fn run_cases<F>(label: String, limit: Limit, seed: Arc<[u8]>, rounds: usize, divisor: usize, parse: F, clock: Clock) -> Result<(), String>
|
||||
where
|
||||
F: Fn(&[u8]) + Send + Sync + 'static,
|
||||
{
|
||||
@@ -480,7 +520,7 @@ where
|
||||
.name(WORKER_NAME.to_owned())
|
||||
.spawn(move || {
|
||||
let mut report = Report { watch: worker_watch, outcome: Err(format!("{worker_label}: the worker thread stopped without a result")) };
|
||||
report.outcome = run_all(&report.watch, &worker_clock, &worker_label, &worker_limit, &seed, rounds, &parse);
|
||||
report.outcome = run_all(&report.watch, &worker_clock, &worker_label, &worker_limit, &seed, rounds, divisor, &parse);
|
||||
})
|
||||
.map_err(|error| format!("{label}: could not start the worker thread: {error}"))?;
|
||||
let mut state = watch.lock();
|
||||
@@ -498,11 +538,21 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Runs the unmodified seed, its truncations and its mutations in order, stopping at the first
|
||||
/// failure.
|
||||
/// Runs the unmodified seed, every `divisor`-th truncation and its mutations in order, stopping at
|
||||
/// the first failure.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn run_all<F: Fn(&[u8])>(watch: &Watch, clock: &Clock, label: &str, limit: &Limit, seed: &[u8], rounds: usize, parse: &F) -> Result<(), String> {
|
||||
for n in std::iter::once(seed.len()).chain(0..seed.len()) {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn run_all<F: Fn(&[u8])>(
|
||||
watch: &Watch,
|
||||
clock: &Clock,
|
||||
label: &str,
|
||||
limit: &Limit,
|
||||
seed: &[u8],
|
||||
rounds: usize,
|
||||
divisor: usize,
|
||||
parse: &F,
|
||||
) -> Result<(), String> {
|
||||
for n in std::iter::once(seed.len()).chain((0..seed.len()).step_by(divisor)) {
|
||||
let case = if n == seed.len() { "the unmodified seed".to_owned() } else { format!("truncation to {n}") };
|
||||
run_one(watch, clock, label, limit, case, seed.get(..n).unwrap_or_default(), parse)?;
|
||||
}
|
||||
@@ -675,7 +725,7 @@ mod tests {
|
||||
Duration::ZERO
|
||||
});
|
||||
let limit = Limit { limit: Duration::from_secs(5), text: "5s".to_owned() };
|
||||
assert_eq!(run_cases("late start".to_owned(), limit, Arc::from(&[1u8][..]), 0, |_: &[u8]| {}, clock), Ok(()));
|
||||
assert_eq!(run_cases("late start".to_owned(), limit, Arc::from(&[1u8][..]), 0, 1, |_: &[u8]| {}, clock), Ok(()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -742,6 +792,29 @@ mod tests {
|
||||
assert_eq!(config.rounds_with(unset), Ok(7));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn divisor_runs_every_nth_truncation_and_a_fraction_of_the_rounds() {
|
||||
let lookup = |name: &str| (name == DIVISOR_VARIABLE).then(|| OsString::from("4"));
|
||||
let seen = Arc::new(Mutex::new(Vec::new()));
|
||||
let record = Arc::clone(&seen);
|
||||
hammer_with(&config("divided", 10), &[0; 10], move |d| record.lock().unwrap().push(d.len()), lookup).unwrap();
|
||||
let lengths = seen.lock().unwrap().clone();
|
||||
// The seed, truncations to 0, 4 and 8, then 10 / 4 = 3 rounds rounded up.
|
||||
assert_eq!(lengths.len(), 7, "{lengths:?}");
|
||||
assert_eq!(lengths[..4], [10, 0, 4, 8]);
|
||||
assert_eq!(divisor_with(unset), Ok(1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_divisor_fails_before_any_parse() {
|
||||
let called = Arc::new(Mutex::new(false));
|
||||
let flag = Arc::clone(&called);
|
||||
let lookup = |name: &str| (name == DIVISOR_VARIABLE).then(|| OsString::from("0"));
|
||||
let message = hammer_with(&config("bad divisor", 3), &[1, 2], move |_| *flag.lock().unwrap() = true, lookup).unwrap_err();
|
||||
assert_eq!(message, r#"bad divisor: CRAFT_HOSTILE_DIVISOR="0" is zero; set it to a whole number above zero"#);
|
||||
assert!(!*called.lock().unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_multiplier_names_variable() {
|
||||
for (value, reason) in [
|
||||
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env bash
|
||||
# The test inputs the Workspace gate and the nightly full run fetch before their tests: the
|
||||
# PhotoCraft test corpora (PSD, PSD tools, ATN, EXR, HEIF, PngSuite) at a pinned PhotoCraft commit,
|
||||
# and the licensed PDF test fonts. Exports CRAFT_PSD_CORPUS and CRAFT_PDF_TEST_FONT_DIR through
|
||||
# $GITHUB_ENV. Run from the repository root.
|
||||
#
|
||||
# A corpus already in .test-inputs/photocraft/corpus (restored from the CI cache, which is keyed on
|
||||
# this file) is used as it is, without the PhotoCraft checkout and its xtask build.
|
||||
set -euo pipefail
|
||||
|
||||
# The PhotoCraft commit whose `cargo xtask corpus` pins the corpora. Changing it changes this file,
|
||||
# which starts a new corpus cache entry.
|
||||
photocraft=74330157cb601573ae4523a95bb9132822fc3918
|
||||
fetcher=.test-inputs/photocraft
|
||||
|
||||
if [ -z "$(ls -A "$fetcher/corpus" 2>/dev/null)" ]; then
|
||||
rm -rf "$fetcher"
|
||||
mkdir -p "$fetcher"
|
||||
git -C "$fetcher" init --quiet
|
||||
git -C "$fetcher" remote add origin https://github.com/storytold/PhotoCraft.git
|
||||
git -C "$fetcher" fetch --quiet --depth=1 origin "$photocraft"
|
||||
git -C "$fetcher" checkout --quiet --detach FETCH_HEAD
|
||||
(cd "$fetcher" && cargo xtask corpus --psd --psd-tools --atn --exr --heif --pngsuite)
|
||||
fi
|
||||
mkdir -p corpus
|
||||
cp -a "$fetcher/corpus/." corpus/
|
||||
|
||||
python scripts/test-fetch-pdf-test-fonts.py
|
||||
python scripts/fetch-pdf-test-fonts.py "$RUNNER_TEMP/craft-pdf-test-fonts"
|
||||
|
||||
printf 'CRAFT_PSD_CORPUS=%s\n' "$GITHUB_WORKSPACE/$fetcher/corpus" >> "$GITHUB_ENV"
|
||||
printf 'CRAFT_PDF_TEST_FONT_DIR=%s\n' "$RUNNER_TEMP/craft-pdf-test-fonts" >> "$GITHUB_ENV"
|
||||
Reference in new issue
Block a user