# Compiler testing tools

Application tests use [`vex test`](vex-test-reference.md). Compiler
development also has dedicated tools for generated inputs, deterministic
reproduction and compiler-phase benchmarks. These tools are built from a
compiler source checkout; their presence in that checkout does not make them
part of every downloaded compiler archive.

## Grammar-aware fuzzing with Steel Dome

`tools/vex-fuzzer` builds the `vex-steel-dome` executable. Its command families
cover structured source generation, raw-input crash checks, parser stress,
seed replay, corpus management, minimization and regression of retained cases.
It also exposes SIR-focused testing modes.

Build it with the LLVM/Rust dependencies described in
[Contributing](../guide/contributing.md), from the compiler checkout root:

```sh
cargo build --release -p vex-steel-dome --target-dir target
target/release/vex-steel-dome --help
```

Use `.exe` on Windows. Record the tool binary and compiler/oracle configuration
alongside the source revision. A seed identifies a sequence for a particular
generator version; it is not a permanent replacement for retaining the actual
generated source.

### Start with a bounded campaign

```sh
target/release/vex-steel-dome fuzz --preset smoke --iterations 16 --threads 1 --seed 42 --output ./fuzz-results --json
```

The structured and `codegen-stress` modes exercise different input strategies.
Inspect the selected mode and oracle in the result before interpreting it.
Keep normal compiler rejection separate from a crash, unexpected diagnostic or
behavior mismatch. The result of a small campaign describes those generated
cases; its iteration count is not a language-coverage percentage.

### Retain inputs before minimizing

For a campaign finding, use its saved source as `reproducer.vx` and rerun that
source or the promoted regression. The `replay` command also provides a
deterministic source-generation workflow of its own:

```sh
target/release/vex-steel-dome replay --seed 42 --iterations 16 --print --output ./replay-42
target/release/vex-steel-dome crash ./reproducer.vx --lexer
target/release/vex-steel-dome minimize ./reproducer.vx --output ./reproducer-minimal.vx
```

Retain the files emitted by `replay` when using that workflow. Its generated
sequence is specific to the replay command; a fuzz campaign's saved input is
the reproduction artifact for that campaign. Confirm that minimization
preserves the same observable failure, then add that input to a focused
regression. A smaller input that fails in a different phase is not the same
reproduction.

### Keep a useful corpus

```sh
target/release/vex-steel-dome corpus --dir ./corpus --stats
target/release/vex-steel-dome corpus --dir ./corpus --import ./replay-42
target/release/vex-steel-dome regression --dir ./crashes --verbose
target/release/vex-steel-dome promoted-regression --dir ./fuzz-results/interesting --verbose
```

Keep passing edge cases as well as failures. Include identifiers, literals,
deep nesting, large declarations, generic bounds, malformed delimiters and
target-sensitive operations. Label cases with their expected outcome and the
compiler phase they are meant to exercise.

## Compiler-phase benchmarks

`tools/vex-bench` is a Cargo benchmark package, not a `vex-bench` command-line
application. Its declared benches include parser work and compile-time staging:

```sh
cargo bench -p vex-bench --bench parser_benchmark --target-dir target
cargo bench -p vex-bench --bench ctfe_staging_benchmark --target-dir target
```

Keep input size and shape, warm/cold cache conditions, compiler profile and
machine configuration with the measurement. Parser throughput and CTFE staging
cost answer different questions from native program throughput. For application
timing, use the [benchmarking guide](../guide/benchmarks.md) and `BenchCtx` instead.

## A regression should explain the contract

Record:

1. The smallest source that still exercises the intended behavior.
2. Whether success means acceptance, a specific diagnostic or a runtime result.
3. The command, target, optimization settings and tool identities.
4. Exact outputs and process status, with bounded resource use.
5. The relationship to the original generated input and any minimized case.

The same method applies when building a language tool with the
[Vex-written tooling libraries](../guide/tooling/language-tools.md). It keeps parser
recovery, source reconstruction, protocol correctness and code generation as
separate contracts that can be tested directly.
