> Documentation version: 0.8.0. [HTML page](https://lukewilliamboswell.github.io/roc-fuzz/campaigns.html)

<a id="run-and-maintain-fuzzing-campaigns"></a>

# Run and maintain fuzzing campaigns

After the first target works, use these guides to choose bounds, interpret
status output, retain useful inputs, investigate unstable failures, and prepare
longer searches. The same commands run every target, including those made from
a ` Model `. The [internals chapter](internals.md#understand-roc-fuzz-internals-and-advanced-features) covers the embedded engine
and its raw interface.

<a id="tune-a-run"></a>

## Tune a run

Give every new target a short, bounded smoke run before a long campaign:

``` sh
TARGET run \
  --time=60 \
  --max-input-size=4096 \
  --timeout=5 \
  --memory-limit=2048 \
  --print-final-stats
```

The most useful limits are:

| Option | Meaning | Starting point |
| --- | --- | --- |
| ` --time=N ` | Stop after ` N ` seconds; ` 0 ` is unbounded. | Defaults to ` 60 `. |
| ` --runs=N ` | Stop after ` N ` attempted inputs. | Useful for repeatable CI checks. |
| ` --max-input-size=N ` | Limit corpus input bytes, including framing, for entropy and encoded values. | Start small and raise only when needed. |
| ` --timeout=N ` | Treat one input taking longer than ` N ` seconds as a failure. | A few seconds for a normally fast target. |
| ` --memory-limit=N ` | Stop when the process exceeds this many MB. | Set from the expected working set. |
| ` --dictionary=FILE ` | Add important byte tokens to mutations. | Useful for text or binary formats. |
| ` --seed=N ` | Select the engine’s random seed. | Useful for repeating a campaign with the same runner build and configuration. |
| ` --print-final-stats ` | Print final execution and resource counters. | Useful in CI and smoke tests. |

` --max-input-size ` bounds the binary input, not necessarily every typed list or
string it produces. Generators control search bias; encoded examples and their
mutations bypass them. Enforce domain and resource limits in property
preconditions or validated input types for both forms, and return ` Fuzz.reject `
before an operation becomes too expensive. Generator bounds help the entropy
path reach those valid values efficiently.

Do not confuse the campaign seed with a saved input. Different engine
builds, coverage layouts, or configurations may generate different
mutation sequences from ` --seed `. Reproduce a failure with its saved
artifact and ` replay `, not with the campaign seed alone.

The captured ` run.log ` contains libFuzzer’s compact status fields:

- ` NEW `: an input reached behavior not represented by the corpus and was
  saved.

- ` REDUCE `: a smaller input preserved previously found behavior.


- ` cov `: covered edges or blocks.


- ` corp `: number and total byte size of in-memory corpus entries.


- ` exec/s `: target executions per second.


- ` rss `: current process memory use.


- ` DONE `: the run reached its time or iteration limit.


Coverage growth shows that the fuzzer is exploring. A plateau is a
reason to inspect the target, generator, seeds, and dictionary, not
proof that the code has no bugs. Very low ` exec/s `, steadily growing
` rss `, or repeated timeouts usually calls for a narrower target or
tighter bounds.

<a id="maintain-a-corpus"></a>

## Maintain a corpus

A corpus is a collection of small binary inputs that collectively reach
useful code. It is not a directory of every attempted input. Use a
stable corpus directory across campaigns:

``` sh
TARGET run quality/corpus/my-target --time=3600 --max-input-size=4096
```

Declare a few small ` Fuzz.example ` values that reach meaningfully different
behavior; they become encoded corpus seeds that the fuzzer can mutate. Use
` Fuzz.saved ` for original entropy or encoded witnesses. Both forms reach the
same property, and their binary bytes need not resemble the value printed by
` show `. Check manually created seeds with the target executable.

Reduce a large corpus into a new, initially empty directory while
preserving coverage:

``` sh
TARGET reduce-corpus quality/corpus/my-target quality/corpus/my-target-small
```

For a target with [goals](observations.md#campaign-goals), the reduced corpus
still holds an input for every goal the original reached.

Keep valuable seeds and fixed crash inputs with the target in version
control. Use a deliberate directory such as ` fuzz/corpus/<target>/ `,
document why each seed matters, and replay it in tests. Generated
` .roc-fuzz/ ` directories are ignored at every depth; keep evolving
campaign corpora in local storage or CI caches, and preserve findings as
CI artifacts until reduced to regressions. Run them after code changes
so the target does not silently stop compiling or exercising the
intended behavior.

Dictionaries are most effective when recognizable bytes flow fairly
directly into a parser. They may help less when a structural generator
heavily transforms the raw input.

Changing a generator can change the typed values produced by entropy witnesses.
Encoded witnesses use the format parser instead. Keep the relevant generator,
parser and input type stable when practical, and use ` show ` to check saved inputs
after a change. Preserve original bytes when storage shape matters.

<a id="diagnose-an-unstable-failure"></a>

## Diagnose an unstable failure

Always replay a saved failure in a fresh process. If it does not
reproduce, investigate:

- a generator or target change that altered the typed value or property;


- a different or truncated raw input file;


- an executable built from different target code; or


- a compiler or runtime defect.


Treat the failure as actionable once its conditions are understood and,
ideally, it reproduces from a clean process.

<a id="know-what-counts-as-a-failure"></a>

## Know what counts as a failure

Coverage feedback tells the engine which inputs explore new behavior; it
does not tell the runner whether a result is correct. The property in
the target is the correctness oracle.

roc-fuzz saves explicit Roc ` crash ` and failed ` expect ` calls, per-input
timeouts, and process memory-limit failures. A wrong answer that does
not break the target’s property is invisible to the fuzzer, which is why
choosing a strong property matters more than simply calling the function
under test.

<a id="prepare-a-long-campaign"></a>

## Prepare a long campaign

Before committing substantial CPU time, check that:

- the target tests one named behavior with a meaningful property;


- invalid input returns normally unless invalid input crashing is the
  bug;

- the generator creates useful values without excessive rejection;


- input sizes and allocations are bounded;


- every generated input terminates or is caught by the timeout;


- a one-minute run gains coverage without immediate hangs or memory
  growth;

- a deliberate temporary ` crash ` is saved, shown, replayed, and
  minimized as expected; and

- the corpus and fixed failures have a clear place in the repository and
  CI.

<a id="command-reference"></a>

## Command reference

| Command | Behavior |
| --- | --- |
| ` TARGET ` or ` TARGET run [CORPUS] [OPTIONS] ` | Check examples and baseline, then explore, with one report. |
| ` TARGET check [OPTIONS] ` | Run each declared example once in a fresh process and compare the baseline. |
| ` TARGET accept [OPTIONS] ` | Explicitly accept the complete valid allocation observations. |
| ` TARGET explore [CORPUS] [OPTIONS] ` | Run coverage-guided exploration independently. |
| ` TARGET examples ` | List names, revisions and input digests. |
| ` TARGET show INPUT ` | Display the decoded representative. |
| ` TARGET replay INPUT [--detailed] ` | Reproduce one input under the supervisor. |
| ` TARGET measure INPUT ` | Print one input’s named allocation observations as JSON. |
| ` TARGET retain INPUT --name NAME --output DIR ` | Keep original bytes and print a source declaration. |
| ` TARGET minimize INPUT OUTPUT [OPTIONS] ` | Minimize a reproducing finding within the campaign budget. |
| ` TARGET reduce-corpus INPUT OUTPUT ` | Retain coverage-relevant inputs in OUTPUT. |
| ` TARGET raw ... ` | Advanced libFuzzer controls. |

Friendly execution options include:

| Option | Meaning |
| --- | --- |
| ` --time=N ` | Exploration budget in seconds; default 60, 0 unbounded. |
| ` --runs=N ` | Exploration execution bound. |
| ` --timeout=N ` | Invocation deadline in seconds; default 10. |
| ` --max-input-size=N ` | Bound corpus input bytes, from 1 byte through 2 MiB. |
| ` --memory-limit=N ` | Exploration process RSS limit in MiB. |
| ` --dictionary=FILE ` | Mutation tokens. |
| ` --seed=N ` | Exploration random seed; retain input bytes for reproduction. |
| ` --report-dir=DIR ` | Absent or empty destination for the complete report. |
| ` --baseline=PATH ` | Override ` <declared-target-name>_baseline.json `. |
| ` --profile=NAME ` | Select the named baseline profile. |
| ` --detailed ` | Capture a detailed logical trace for replay. |
| ` --no-detect-leaks ` | Disable the broader invocation leak check. |
| ` --allow-unreached-goals ` | Report unreached goals without making the campaign inconclusive. |

Provenance options are ` --source-revision `, ` --roc-version `,
` --platform-release ` and ` --platform-sha256 `, each supplied as ` --name=value `.
See [Read the evidence](quality.md#read-the-evidence) for the report these
options are recorded in, and
[Accept an exact allocation baseline](observations.md#allocation-ratchets)
for ` --baseline ` and ` --profile `.

Minimization and corpus reduction accept ` --time `, ` --runs `, ` --timeout ` and
` --report-dir `. They default to a 60-second campaign budget and require a positive
` --time `; unbounded exploration remains available with ` run --time=0 ` or
` explore --time=0 `. A successful minimization writes the best witness, including
the unchanged original if no reduction was found. Failed minimization preserves
an existing output. Corpus reduction requires an absent or empty output directory
that does not overlap the input directory.

