forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_fuzz.sh
More file actions
executable file
·49 lines (40 loc) · 1.37 KB
/
Copy pathbuild_fuzz.sh
File metadata and controls
executable file
·49 lines (40 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env bash
# First argument is the time, in seconds, to run each fuzz test for.
# If not provided, defaults to 1 second.
#
# Second argument is the directory to run fuzz tests in.
# If not provided, defaults to the current directory.
set -euo pipefail
# Mostly taken from https://github.com/golang/go/issues/46312#issuecomment-1153345129
# Directory above this script
AVALANCHE_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd )
# Load the constants
source "$AVALANCHE_PATH"/scripts/constants.sh
fuzzTime=${1:-1}
fuzzDir=${2:-.}
# Set go test timeout to fuzz time + 20 minutes to allow for compilation and setup.
# A negative fuzz time (e.g. -1) means run until failure, so disable the timeout.
if (( fuzzTime < 0 )); then
timeout=0
else
timeout=$((fuzzTime + 1200))
fi
EXCLUDE_DIR="graft"
files=$(grep -r --exclude-dir="$EXCLUDE_DIR" --include='**_test.go' --files-with-matches 'func Fuzz' "$fuzzDir")
failed=false
for file in ${files}
do
funcs=$(grep -oP 'func \K(Fuzz\w*)' "$file")
for func in ${funcs}
do
echo "Fuzzing $func in $file"
parentDir=$(dirname "$file")
# If any of the fuzz tests fail, return exit code 1
if ! go test -tags test -timeout="${timeout}s" "$parentDir" -run="$func" -fuzz="$func" -fuzztime="${fuzzTime}"s; then
failed=true
fi
done
done
if $failed; then
exit 1
fi