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
·41 lines (33 loc) · 1.1 KB
/
Copy pathbuild_fuzz.sh
File metadata and controls
executable file
·41 lines (33 loc) · 1.1 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
#!/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:-.}
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 "$parentDir" -run="$func" -fuzz="$func" -fuzztime="${fuzzTime}"s; then
failed=true
fi
done
done
if $failed; then
exit 1
fi