Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/assert-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
needs: compilers
runs-on: ubuntu-latest
timeout-minutes: 40
continue-on-error: ${{ !inputs.nightly && matrix.job == 'sweep' }}
continue-on-error: ${{ !inputs.nightly && (matrix.job == 'sweep' || matrix.job == 'fuzz-targeted') }}
strategy:
fail-fast: false
matrix:
Expand All @@ -73,6 +73,8 @@ jobs:
name: Direct-call fuzz findings
- job: fuzz-bytes
name: Byte-shift fuzz findings
- job: fuzz-targeted
name: Register-argument and range fuzz (advisory)
steps:
- uses: actions/checkout@v4
with:
Expand Down
122 changes: 122 additions & 0 deletions .github/workflows/nightly-fuzz.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
name: Nightly extended fuzz

# fuzz_diff.py on ez80/z80n (direct-call, plain and --signed), fuzz_ptr.py,
# fuzz_nowrap.py and fuzz_regargs.py (z80/ez80/z80n). Each plan entry runs a
# fixed regression window (seeds 0..reg-1) and a rolling window that moves every
# night, starting at 10000 + (run_number - 1) * roll, so coverage accumulates.
# The blocking Z80 direct-call fuzz (seeds 0-9999) stays in nightly.yml.
#
# Sizes (4-vCPU runner, 2x the rate measured on an 8-core laptop at -j 4):
# fuzz_diff ~0.07 s/seed fuzz_ptr ~0.28 s/seed (C host build per seed)
# fuzz_nowrap ~0.04 s/seed fuzz_regargs ~0.01 s/seed
# Estimated ~26 min of runner time in total, spread over four parallel jobs.
# Reproduce a failure: see "Reproducing a nightly fuzz failure" in scripts/README.md.

on:
schedule:
- cron: '47 3 * * *'
workflow_dispatch:
inputs:
seed:
description: 'First seed of a chosen range (empty: nightly windows)'
required: false
type: string
count:
description: 'Number of seeds when a chosen range is given'
required: false
default: '1000'
type: string
only:
description: 'With a chosen range: run only plan entries whose label contains this text (e.g. ptr, regargs-ez80, diff-z80n-signed)'
required: false
type: string

permissions:
contents: read

concurrency:
group: nightly-extended-fuzz
cancel-in-progress: false

jobs:
fuzz:
name: Nightly fuzz ${{ matrix.name }}
runs-on: ubuntu-latest
timeout-minutes: 25
strategy:
fail-fast: false
matrix:
include:
# label fuzzer target regression-count rolling-count [extra fuzzer args]
- name: fuzz_diff ez80
plan: |
diff-ez80 diff ez80 250 1000
diff-ez80-signed diff ez80 250 1000 --signed
- name: fuzz_diff z80n
plan: |
diff-z80n diff z80n 250 1000
diff-z80n-signed diff z80n 250 1000 --signed
- name: z80 signed and register arguments
plan: |
diff-z80-signed diff z80 250 1000 --signed
regargs-z80 regargs z80 1000 4000
- name: ptr, nowrap, register arguments ez80/z80n
plan: |
ptr ptr ez80 100 300
nowrap nowrap ez80 500 2000
regargs-ez80 regargs ez80 1000 4000
regargs-z80n regargs z80n 1000 4000
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: minzc/go.mod
cache-dependency-path: minzc/go.sum
- name: Build compiler
working-directory: minzc
run: go build -o "$RUNNER_TEMP/mz" ./cmd/minzc
- name: Run fuzz windows
env:
PLAN: ${{ matrix.plan }}
MZ: ${{ runner.temp }}/mz
RUN_NUMBER: ${{ github.run_number }}
IN_SEED: ${{ inputs.seed }}
IN_COUNT: ${{ inputs.count }}
IN_ONLY: ${{ inputs.only }}
REPORTS: ${{ runner.temp }}/nightly-fuzz
run: |
failed=0
while read -r label fuzzer target reg roll extra; do
[[ -n $label ]] || continue
if [[ -n $IN_SEED ]]; then
[[ -z $IN_ONLY || $label == *"$IN_ONLY"* ]] || continue
reg=0; roll=$IN_COUNT; start=$IN_SEED
else
start=$((10000 + (RUN_NUMBER - 1) * roll))
fi
echo "=== $label: regression 0..$((reg - 1)), rolling $start..$((start + roll - 1))"
# shellcheck disable=SC2086
REPORT_DIR="$REPORTS/$label" REG_COUNT=$reg ROLL_START=$start ROLL_COUNT=$roll \
bash scripts/ci/nightly_fuzz.sh "$fuzzer" "$target" $extra || failed=1
done <<< "$PLAN"
{
echo "### Nightly fuzz: ${{ matrix.name }}"
echo
if [[ -n $IN_SEED ]]; then echo "Chosen range from seed $IN_SEED, count $IN_COUNT."
else echo "Rolling windows start at 10000 + (run $RUN_NUMBER - 1) * window size."; fi
echo
if cat "$REPORTS"/*/failing-seeds.txt 2>/dev/null | grep -q .; then
echo 'Failing seeds:'; echo '```'; cat "$REPORTS"/*/failing-seeds.txt; echo '```'
else
echo 'No findings.'
fi
} >> "$GITHUB_STEP_SUMMARY"
exit "$failed"
- name: Upload logs and reproducers
if: always()
uses: actions/upload-artifact@v4
with:
name: nightly-fuzz-${{ strategy.job-index }}
path: ${{ runner.temp }}/nightly-fuzz/
if-no-files-found: warn
retention-days: 14
35 changes: 35 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,41 @@ fuzzer's `--fail-on all` policy in both folded and direct-call modes.
Matrix, self-test, sweep and both fuzz jobs fail the nightly audit on findings
or tool errors; there is no blanket nightly `continue-on-error`.

**Nightly extended fuzz** (`.github/workflows/nightly-fuzz.yml`, 03:47 UTC, also
`workflow_dispatch`) runs `fuzz_diff.py` direct-call on ez80 and z80n (plain and
`--signed`) and z80 `--signed`, `fuzz_ptr.py`, `fuzz_nowrap.py` and
`fuzz_regargs.py` on z80, ez80 and z80n, in four parallel jobs (about 26 minutes
of runner time). Each entry runs a fixed regression window (seeds 0..N-1) and a
rolling window of the same kind starting at `10000 + (run_number - 1) * window`.
A failure fails the job, lists the seeds in the step summary and uploads
`seed-N.*` reproducers, `results.json` and logs (artifact `nightly-fuzz-<n>`,
14 days). `workflow_dispatch` takes `seed`, `count` and `only` (a label such as
`ptr` or `diff-z80n-signed`) to run a chosen range. The PR-time
**Register-argument and range fuzz (advisory)** job runs `fuzz_regargs.py`
(z80, ez80; seeds 0-299) and `fuzz_nowrap.py` (seeds 0-199) in about 15 s;
it is `continue-on-error` on PRs.

### Reproducing a nightly fuzz failure

The log line `seed N: <status>` and the step summary give the seed, the
fuzzer and target (`diff-z80n-signed`, `ptr`, ...). Build and rerun that seed:

```sh
cd minzc && go build -o /tmp/mz ./cmd/minzc && cd ..
python3 scripts/fuzz_diff.py --mz /tmp/mz --seed N --count 1 --mode direct-call \
--target ez80 [--signed] --fail-on all --output /tmp/repro # reduces by default
python3 scripts/fuzz_ptr.py --mz /tmp/mz --seed N --count 1 --output /tmp/repro
python3 scripts/fuzz_ptr.py --mz /tmp/mz --seed N --reduce nanz --output /tmp/repro
python3 scripts/fuzz_nowrap.py --mz /tmp/mz --seed N --count 1 --output /tmp/repro # --print shows the source
python3 scripts/fuzz_regargs.py --mz /tmp/mz --seed N --count 1 --target z80n --output /tmp/repro
```

The same wrapper CI uses also works locally:
`MZ=/tmp/mz REPORT_DIR=/tmp/repro REG_COUNT=0 ROLL_START=N ROLL_COUNT=1 bash scripts/ci/nightly_fuzz.sh regargs z80n`.
Use the seed from the artifact name or log, not from the run number: the run
number only fixes the window start. Check out the commit the run tested
(`github.sha` of the run) before reproducing.

**Advisory Go lint** runs only on PRs from the `minzc/` module using a cached,
pinned
`golangci-lint v2.13.2` (built with Go 1.26.8). Its minimal configuration
Expand Down
65 changes: 65 additions & 0 deletions scripts/ci/nightly_fuzz.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bash
# Nightly extended fuzz: one fuzzer on one target, over a fixed regression
# window (seeds 0..REG_COUNT-1) and a rolling window (ROLL_START..+ROLL_COUNT-1).
#
# MZ=path/to/mz scripts/ci/nightly_fuzz.sh <fuzzer> <target> [extra fuzzer args...]
#
# fuzzer: diff (fuzz_diff.py direct-call), ptr, nowrap, regargs
# target: z80, ez80 or z80n (ptr and nowrap are ez80-only and ignore it)
#
# Environment: MZ, REPORT_DIR, REG_COUNT, ROLL_START, ROLL_COUNT, JOBS.
# Exit status is non-zero if either window has a finding. Failing seeds are
# printed (and written to $REPORT_DIR/failing-seeds.txt) with the exact command
# that reproduces each window; reproducer sources stay under $REPORT_DIR.
set -uo pipefail
fuzzer=${1:?diff, ptr, nowrap or regargs}
target=${2:?z80, ez80 or z80n}
shift 2
: "${MZ:?}"
report=${REPORT_DIR:-${RUNNER_TEMP:-/tmp}/nightly-fuzz/$fuzzer-$target}
reg_count=${REG_COUNT:-0}
roll_start=${ROLL_START:-0}
roll_count=${ROLL_COUNT:-0}
jobs=${JOBS:-$( (nproc 2>/dev/null || sysctl -n hw.ncpu) )}
mkdir -p "$report"
: > "$report/failing-seeds.txt"
status=0

command_for() { # window name, start, count
case "$fuzzer" in
diff) echo python3 scripts/fuzz_diff.py --mz "$MZ" --seed "$2" --count "$3" -j "$jobs" --no-reduce --fail-on all --mode direct-call --target "$target" --output "$report/$1" "${@:4}" ;;
ptr) echo python3 scripts/fuzz_ptr.py --mz "$MZ" --seed "$2" --count "$3" -j "$jobs" --output "$report/$1" "${@:4}" ;;
nowrap) echo python3 scripts/fuzz_nowrap.py --mz "$MZ" --seed "$2" --count "$3" -j "$jobs" --output "$report/$1" "${@:4}" ;;
regargs) echo python3 scripts/fuzz_regargs.py --mz "$MZ" --seed "$2" --count "$3" -j "$jobs" --target "$target" --output "$report/$1" "${@:4}" ;;
*) echo "unknown fuzzer: $fuzzer" >&2; return 2 ;;
esac
}

run_window() { # name start count
local name=$1 start=$2 count=$3 cmd t0 rc
(( count > 0 )) || return 0
cmd=$(command_for "$name" "$start" "$count" "${@:4}") || return 2
echo "::group::$fuzzer/$target $name window: seeds $start..$((start + count - 1))"
echo "+ $cmd"
t0=$SECONDS
$cmd 2>&1 | tee "$report/$name.log"
rc=${PIPESTATUS[0]}
echo "$fuzzer/$target $name: exit $rc, $count seeds, $((SECONDS - t0))s wall"
echo "::endgroup::"
if (( rc != 0 )); then
status=1
# Every fuzzer prints "seed N: <status>..." per finding.
grep -Eo '^seed [0-9]+' "$report/$name.log" | awk -v w="$name" -v f="$fuzzer" -v t="$target" '{print f"/"t" "w" seed "$2}' >> "$report/failing-seeds.txt"
echo "::error title=nightly fuzz $fuzzer/$target $name window failed::seeds $start..$((start + count - 1)); reproduce: scripts/ci/nightly_fuzz.sh $fuzzer $target with REG_COUNT/ROLL_START/ROLL_COUNT, or: $cmd"
fi
}

extra=("$@")
run_window regression 0 "$reg_count" ${extra[@]+"${extra[@]}"}
run_window rolling "$roll_start" "$roll_count" ${extra[@]+"${extra[@]}"}

if [[ -s "$report/failing-seeds.txt" ]]; then
echo "Failing seeds:"
cat "$report/failing-seeds.txt"
fi
exit "$status"
18 changes: 17 additions & 1 deletion scripts/ci/run.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -euo pipefail
: "${CI_BIN:?}"
job=${1:?matrix, judges, sweep, fuzz, fuzz-direct, or fuzz-bytes}
job=${1:?matrix, judges, sweep, fuzz, fuzz-direct, fuzz-bytes, or fuzz-targeted}
report_dir=${REPORT_DIR:-$CI_BIN/reports/$job}
mkdir -p "$report_dir"
chmod +x "$CI_BIN/candidate-mz" "$CI_BIN/baseline-mz"
Expand Down Expand Up @@ -58,6 +58,22 @@ case "$job" in
--output "$report_dir" "${extra[@]}" 2>&1 | tee "$report_dir/log.txt"
status=${PIPESTATUS[0]}
;;
fuzz-targeted)
# Short fixed windows of the register-argument and range-fact fuzzers (z80 and
# ez80), about 15 s of wall time; the long windows run in nightly-fuzz.yml.
status=0
for spec in "regargs z80" "regargs ez80" "nowrap ez80"; do
set -- $spec
if [[ $1 == regargs ]]; then
python3 scripts/fuzz_regargs.py --mz "$CI_BIN/candidate-mz" --seed 0 --count 300 \
-j "$jobs" --target "$2" --output "$report_dir/$1-$2" 2>&1 | tee -a "$report_dir/log.txt"
else
python3 scripts/fuzz_nowrap.py --mz "$CI_BIN/candidate-mz" --seed 0 --count 200 \
-j "$jobs" --output "$report_dir/$1-$2" 2>&1 | tee -a "$report_dir/log.txt"
fi
(( ${PIPESTATUS[0]} != 0 )) && status=1
done
;;
*) echo "Unknown job: $job" >&2; exit 2 ;;
esac
set -e
Expand Down
4 changes: 2 additions & 2 deletions scripts/ci/simulate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ run_gate() {
"$@" > "$CI_BIN/$name.log" 2>&1 || status=$?
printf '%s: exit %s, wall %ss (log: %s)\n' "$name" "$status" "$((SECONDS-start))" "$CI_BIN/$name.log" | tee -a "$CI_BIN/timings.txt"
if [[ $status != 0 && $name != lint ]]; then
if [[ $name != sweep || ${NIGHTLY:-false} == true ]]; then failed=1; fi
if [[ ($name != sweep && $name != fuzz-targeted) || ${NIGHTLY:-false} == true ]]; then failed=1; fi
fi
}
run_gate actionlint actionlint .github/workflows/*.yml
run_gate build bash scripts/ci/build.sh
for job in matrix judges sweep fuzz fuzz-direct fuzz-bytes; do
for job in matrix judges sweep fuzz fuzz-direct fuzz-bytes fuzz-targeted; do
export REPORT_DIR="$CI_BIN/reports/$job"
run_gate "$job" bash scripts/ci/run.sh "$job"
done
Expand Down
Loading