aboutsummaryrefslogtreecommitdiff
path: root/infra/base-images
diff options
context:
space:
mode:
authorCatena cyber <35799796+catenacyber@users.noreply.github.com>2021-03-14 16:29:13 +0100
committerGitHub <noreply@github.com>2021-03-14 08:29:13 -0700
commitb000f70a7ad45f492f4ea7b2ee2c11466e51d4db (patch)
tree204ca5d66be9ac777e637bf1d606961cf25009da /infra/base-images
parent2f9dd0753fb1ca4c56bfb55c987eeb6d7a5422d2 (diff)
downloadoss-fuzz-b000f70a7ad45f492f4ea7b2ee2c11466e51d4db.tar.gz
Golang coverage: build binary instead of bash script (#5377)
Diffstat (limited to 'infra/base-images')
-rwxr-xr-xinfra/base-images/base-builder/compile_go_fuzzer6
-rwxr-xr-xinfra/base-images/base-runner/coverage6
2 files changed, 3 insertions, 9 deletions
diff --git a/infra/base-images/base-builder/compile_go_fuzzer b/infra/base-images/base-builder/compile_go_fuzzer
index 80f661a69..5dfb6b5b1 100755
--- a/infra/base-images/base-builder/compile_go_fuzzer
+++ b/infra/base-images/base-builder/compile_go_fuzzer
@@ -42,12 +42,8 @@ if [[ $SANITIZER = *coverage* ]]; then
sed -i -e 's/mypackagebeingfuzzed/'$fuzzed_package'/' ./"${function,,}"_test.go
sed -i -e 's/TestFuzzCorpus/Test'$function'Corpus/' ./"${function,,}"_test.go
- echo "#!/bin/sh" > $OUT/$fuzzer
- echo "cd \$OUT/$abspath" >> $OUT/$fuzzer
- # The fuzzer may be in a subdirectory, but we want the coverage report for the whole repository
fuzzed_repo=`echo $path | cut -d/ -f-3`
- echo "go test -run Test${function}Corpus -v $tags -coverpkg $fuzzed_repo/... -coverprofile \$1 " >> $OUT/$fuzzer
- chmod +x $OUT/$fuzzer
+ go test -run Test${function}Corpus -v $tags -coverpkg $fuzzed_repo/... -c -o $OUT/$fuzzer $path
else
# Compile and instrument all Go files relevant to this fuzz target.
echo "Running go-fuzz $tags -func $function -o $fuzzer.a $path"
diff --git a/infra/base-images/base-runner/coverage b/infra/base-images/base-runner/coverage
index eb0b1b414..f74345f7a 100755
--- a/infra/base-images/base-runner/coverage
+++ b/infra/base-images/base-runner/coverage
@@ -114,13 +114,11 @@ function run_fuzz_target {
function run_go_fuzz_target {
local target=$1
- cd $GOPATH/src
echo "Running go target $target"
export FUZZ_CORPUS_DIR="/corpus/${target}/"
export FUZZ_PROFILE_NAME="$DUMPS_DIR/$target.perf"
- bash $OUT/$target $DUMPS_DIR/$target.profdata &> $LOGS_DIR/$target.log
+ $OUT/$target -test.coverprofile $DUMPS_DIR/$target.profdata &> $LOGS_DIR/$target.log
$SYSGOPATH/bin/gocovsum $DUMPS_DIR/$target.profdata > $FUZZER_STATS_DIR/$target.json
- cd $OUT
}
export SYSGOPATH=$GOPATH
@@ -131,7 +129,7 @@ for fuzz_target in $FUZZ_TARGETS; do
if [[ $FUZZING_LANGUAGE == "go" ]]; then
# Continue if not a fuzz target.
if [[ $FUZZING_ENGINE != "none" ]]; then
- grep "go test -run" $fuzz_target > /dev/null 2>&1 || continue
+ grep "FUZZ_CORPUS_DIR" $fuzz_target > /dev/null 2>&1 || continue
fi
run_go_fuzz_target $fuzz_target &
else