-
Notifications
You must be signed in to change notification settings - Fork 741
/
Copy pathbuild_fuzz.sh
executable file
·39 lines (32 loc) · 1.04 KB
/
build_fuzz.sh
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
#!/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:-.}
files=$(grep -r --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 "$parentDir" -run="$func" -fuzz="$func" -fuzztime="${fuzzTime}"s; then
failed=true
fi
done
done
if $failed; then
exit 1
fi