fuzz
The differential fuzzer for the compiler (issue #352). src/main.lse is
a random-program generator built on packages/gen (ADR 0064): given
LOUISE_FUZZ_SEED it prints one small, deterministic, well-typed Louise
program. crates/louise_codegen_c/tests/fuzz.rs builds the generator
once, then, per seed, runs the program interpreted and natively
(one thread, as the interpreter) and compares:
- stdout, byte for byte;
- the exit: normal, or a panic with the same message (101 natively);
- the leak oracle: the native run reports
louise: live blocks: 0.
Generated programs are deterministic (every choice is made at generation
time; the only std/random use in a program is under random.with_seed)
and terminate by construction (recursion decreases an Int argument that
call sites clamp; lists are small).
Running it
cargo test -p louise_codegen_c --test fuzz # 25 programs from seed 1
LOUISE_FUZZ_SEED=41000 LOUISE_FUZZ_RUNS=500 cargo test -p louise_codegen_c --test fuzz
scripts/ci.sh's full mode runs a bounded lane with a random base seed
it prints. A failure dumps the program to target/fuzz/case-<seed>.lse,
minimizes it (line-chunk deletion while the mismatch still reproduces;
LOUISE_FUZZ_MIN_BUDGET bounds the tries) into case-<seed>.min.lse,
and fails naming the seed. Reproduce with LOUISE_FUZZ_SEED=<seed> LOUISE_FUZZ_RUNS=1. A minimized crasher belongs in tests/run (add the
//> lines the interpreter prints; tests/README.md has the format).
Grammar coverage
- Expressions: Int/Bool/String literals and operators (
+ - * / %, comparisons,==,<>), string interpolation,show,if, single-linematch(on Option, lists, the generated enum, the generated record, Int literals with a guard), closures passed tolist.map/filter/fold/any, tuple construction and.0/.1projection, helper-function calls. - Types: Int, Bool, String, lists, options, pairs; a generated enum
Choice { A, B(Int), C(String) }and a generated recordRwith two or three scalar fields (construction, field access,R(..r, f: x)update) in about half of the programs. - Statements: annotated
let,io.println,if/elseblocks,matchstatements,defer. - Effects and handlers (at most two per program): a
fnoperation (ask), a one-shotctloperation withresume(collect) and without it (cancellation, with adeferin the cancelled body), afinal ctloperation intoResult, and handler installation withuse <-. use/defer:deferin blocks and cancelled bodies;use x <- result.tryin generatedResulthelpers;use x <- list.eachas a final loop;use n <- ref.updateinregionblocks (references,ref.new/get/set).- Std externs:
std/list,std/string(length,to_int),std/result.try,std/ref,std/randomunderwith_seed.
Deliberately out (v1): actors and process (nondeterministic
scheduling), floats, files and real I/O, multi-shot resumptions, BigInt
stress, UInt/bytes. The interpreter and the native backend both run
the optimised Core; the unoptimised differential is covered by the
existing native.rs lanes.
Nothing in a generated program is random at run time, so a seed
reproduces a program exactly: the same seed draws the same bytes, and
gen's generators give smaller programs from smaller bytes.
