mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-29 03:45:46 +08:00
test(fuzz): record reproducible run seeds (#6547)
This commit is contained in:
+44
-4
@@ -25,6 +25,7 @@
|
||||
# Environment variables:
|
||||
# FUZZ_TARGET — run only this target (default: all smoke targets)
|
||||
# MAX_TOTAL_TIME — seconds to fuzz per target (default: 60)
|
||||
# FUZZ_SEED — replay one libFuzzer seed (default: generate and record one per target)
|
||||
# ARTIFACT_ROOT — artifact output directory (default: artifacts)
|
||||
# BUILD_ONLY — set to 1 to skip fuzz runs (default: 0)
|
||||
# SKIP_BUILD — set to 1 to skip build phase (default: 0)
|
||||
@@ -37,6 +38,7 @@ SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||
REPO_ROOT=$(CDPATH= cd -- "$SCRIPT_DIR/../.." && pwd)
|
||||
FUZZ_DIR="$REPO_ROOT/fuzz"
|
||||
MAX_TOTAL_TIME=${MAX_TOTAL_TIME:-60}
|
||||
FUZZ_SEED=${FUZZ_SEED:-}
|
||||
ARTIFACT_ROOT=${ARTIFACT_ROOT:-artifacts}
|
||||
FUZZ_TARGET=${FUZZ_TARGET:-}
|
||||
BUILD_ONLY=${BUILD_ONLY:-0}
|
||||
@@ -44,6 +46,15 @@ SKIP_BUILD=${SKIP_BUILD:-0}
|
||||
USE_PREBUILT_BINARY=${USE_PREBUILT_BINARY:-0}
|
||||
PREBUILT_BINARY_DIR=${PREBUILT_BINARY_DIR:-}
|
||||
|
||||
if [ -n "$FUZZ_SEED" ]; then
|
||||
case "$FUZZ_SEED" in
|
||||
0*|*[!0-9]*)
|
||||
echo "FUZZ_SEED must be a positive decimal integer without leading zeroes: $FUZZ_SEED" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
cd "$FUZZ_DIR"
|
||||
mkdir -p "$ARTIFACT_ROOT"
|
||||
|
||||
@@ -75,6 +86,35 @@ for target in $targets; do
|
||||
mkdir -p "$artifact_dir"
|
||||
mkdir -p "$corpus_dir"
|
||||
|
||||
seed="$FUZZ_SEED"
|
||||
if [ -z "$seed" ]; then
|
||||
seed=$(printf '%s\n' "${GITHUB_RUN_ID:-local}:${GITHUB_RUN_ATTEMPT:-0}:$target:$(date +%s):$$" | cksum | awk '{print $1}')
|
||||
if [ "$seed" = "0" ]; then
|
||||
seed=1
|
||||
fi
|
||||
fi
|
||||
revision=$(git -C "$REPO_ROOT" rev-parse HEAD 2>/dev/null || printf 'unknown')
|
||||
if [ "$revision" = "unknown" ]; then
|
||||
git_dirty="unknown"
|
||||
elif [ -n "$(git -C "$REPO_ROOT" status --porcelain --untracked-files=normal 2>/dev/null)" ]; then
|
||||
git_dirty="true"
|
||||
else
|
||||
git_dirty="false"
|
||||
fi
|
||||
if [ "$USE_PREBUILT_BINARY" = "1" ]; then
|
||||
runner_mode="prebuilt"
|
||||
else
|
||||
runner_mode="cargo-fuzz"
|
||||
fi
|
||||
{
|
||||
printf 'target=%s\n' "$target"
|
||||
printf 'seed=%s\n' "$seed"
|
||||
printf 'max_total_time=%s\n' "$MAX_TOTAL_TIME"
|
||||
printf 'git_revision=%s\n' "$revision"
|
||||
printf 'git_dirty=%s\n' "$git_dirty"
|
||||
printf 'runner_mode=%s\n' "$runner_mode"
|
||||
} > "$artifact_dir/run-manifest.txt"
|
||||
|
||||
if [ "$USE_PREBUILT_BINARY" = "1" ]; then
|
||||
binary_dir="$PREBUILT_BINARY_DIR"
|
||||
if [ -z "$binary_dir" ]; then
|
||||
@@ -89,11 +129,11 @@ for target in $targets; do
|
||||
echo "Missing executable prebuilt fuzz binary: $binary_path" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "==> $binary_path (-max_total_time=$MAX_TOTAL_TIME, -artifact_prefix=$artifact_dir/, corpus=$corpus_dir)"
|
||||
"$binary_path" -max_total_time="$MAX_TOTAL_TIME" -artifact_prefix="$artifact_dir/" "$corpus_dir"
|
||||
echo "==> $binary_path (-max_total_time=$MAX_TOTAL_TIME, -seed=$seed, -artifact_prefix=$artifact_dir/, corpus=$corpus_dir)"
|
||||
"$binary_path" -max_total_time="$MAX_TOTAL_TIME" -seed="$seed" -artifact_prefix="$artifact_dir/" "$corpus_dir"
|
||||
continue
|
||||
fi
|
||||
|
||||
echo "==> cargo +nightly fuzz run $target (-max_total_time=$MAX_TOTAL_TIME, -artifact_prefix=$artifact_dir/)"
|
||||
cargo +nightly fuzz run "$target" -- -max_total_time="$MAX_TOTAL_TIME" -artifact_prefix="$artifact_dir/"
|
||||
echo "==> cargo +nightly fuzz run $target (-max_total_time=$MAX_TOTAL_TIME, -seed=$seed, -artifact_prefix=$artifact_dir/)"
|
||||
cargo +nightly fuzz run "$target" -- -max_total_time="$MAX_TOTAL_TIME" -seed="$seed" -artifact_prefix="$artifact_dir/"
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user