Skip to content

Commit 7974615

Browse files
committed
gateway: fix broken coverage build
Signed-off-by: Adam Korczynski <[email protected]>
1 parent b9ac9e6 commit 7974615

File tree

4 files changed

+27
-29
lines changed

4 files changed

+27
-29
lines changed

infra/base-images/base-builder/compile_native_go_fuzzer

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,8 @@ function build_native_go_fuzzer() {
2222
tags="-tags gofuzz"
2323

2424
if [[ $SANITIZER == *coverage* ]]; then
25-
current_dir=$(pwd)
26-
mkdir $OUT/rawfuzzers || true
27-
cd $abs_file_dir
28-
go test $tags -c -run $fuzzer -o $OUT/$fuzzer -cover
29-
cp "${fuzzer_filename}" "${OUT}/rawfuzzers/${fuzzer}"
30-
3125
fuzzed_repo=$(go list $tags -f {{.Module}} "$path")
32-
abspath_repo=`go list -m $tags -f {{.Dir}} $fuzzed_repo || go list $tags -f {{.Dir}} $fuzzed_repo`
33-
# give equivalence to absolute paths in another file, as go test -cover uses golangish pkg.Dir
34-
echo "s=$fuzzed_repo"="$abspath_repo"= > $OUT/$fuzzer.gocovpath
35-
36-
cd $current_dir
26+
go-118-fuzz-build $tags -o $fuzzer -sanitizer=coverage -coverpkg=$fuzzed_repo/... -func $function $abs_file_dir
3727
else
3828
go-118-fuzz-build $tags -o $fuzzer.a -func $function $abs_file_dir
3929
$CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -o $OUT/$fuzzer

infra/base-images/base-runner/coverage

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -137,30 +137,18 @@ function run_go_fuzz_target {
137137
export FUZZ_CORPUS_DIR="$CORPUS_DIR/${target}/"
138138
export FUZZ_PROFILE_NAME="$DUMPS_DIR/$target.perf"
139139

140-
# setup for native go fuzzers
141-
cd $OUT
142-
mkdir -p "testdata/fuzz/${target}"
143-
cp -r "${FUZZ_CORPUS_DIR}" "testdata/fuzz/"
144-
145-
# rewrite libFuzzer corpus to Std Go corpus if native fuzzing
146-
grep "TestFuzzCorpus" $target > /dev/null 2>&1 && $SYSGOPATH/bin/convertcorpus $target "testdata/fuzz/${target}"
147-
cd -
148-
149140
timeout $TIMEOUT $OUT/$target -test.coverprofile $DUMPS_DIR/$target.profdata &> $LOGS_DIR/$target.log
150141
if (( $? != 0 )); then
151142
echo "Error occured while running $target:"
152143
cat $LOGS_DIR/$target.log
153144
fi
154145

155-
# cleanup after native go fuzzers
156-
rm -r "${OUT}/testdata/fuzz/${target}"
157-
158-
# The Go 1.18 fuzzers are renamed to "*_fuzz_.go" during "infra/helper.py build_fuzzers".
159-
# They are are therefore refered to as "*_fuzz_.go" in the profdata files.
160-
# Since the copies named "*_fuzz_.go" do not exist in the file tree during
146+
# The Go 1.18 fuzzers are renamed to "*libFuzzer.go" during "infra/helper.py build_fuzzers".
147+
# They are are therefore refered to as "*_libFuzzer.go" in the profdata files.
148+
# Since the copies named "*_libFuzzer.go" do not exist in the file tree during
161149
# the coverage build, we change the references in the .profdata files
162150
# to the original file names.
163-
#sed -i "s/_test.go_fuzz_.go/_test.go/g" $DUMPS_DIR/$target.profdata
151+
sed -i "s/_libFuzzer.go/_test.go/g" $DUMPS_DIR/$target.profdata
164152
# translate from golangish paths to current absolute paths
165153
cat $OUT/$target.gocovpath | while read i; do sed -i $i $DUMPS_DIR/$target.profdata; done
166154
# cf PATH_EQUIVALENCE_ARGS

projects/gateway/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ RUN wget https://go.dev/dl/go1.24.0.linux-amd64.tar.gz \
2525
&& apt-get update \
2626
&& apt-get install -y btrfs-progs libbtrfs-dev
2727

28+
RUN git clone --depth=1 --branch=november-update https://github.com/AdamKorcz/go-118-fuzz-build
2829
RUN git clone --depth 1 https://github.com/envoyproxy/gateway.git
2930

30-
COPY build.sh $SRC/
31+
COPY build.sh $SRC/

projects/gateway/build.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,23 @@
1515
#
1616
################################################################################
1717

18-
$SRC/gateway/test/fuzz/oss_fuzz_build.sh
18+
cd "$SRC"/go-118-fuzz-build
19+
go build
20+
rm "$GOPATH"/bin/go-118-fuzz-build
21+
mv go-118-fuzz-build "$GOPATH"/bin/
22+
23+
cd "$SRC"/gateway
24+
25+
set -o nounset
26+
set -o pipefail
27+
set -o errexit
28+
set -x
29+
printf "package envoygateway\nimport _ \"github.com/AdamKorcz/go-118-fuzz-build/testing\"\n" > register.go
30+
go mod edit -replace github.com/AdamKorcz/go-118-fuzz-build="$SRC"/go-118-fuzz-build
31+
go mod tidy
32+
33+
# compile native-format fuzzers
34+
compile_native_go_fuzzer github.com/envoyproxy/gateway/test/fuzz FuzzGatewayAPIToXDS FuzzGatewayAPIToXDS
35+
36+
# add seed corpus
37+
zip -j "$OUT"/FuzzGatewayAPIToXDS_seed_corpus.zip "$SRC"/gateway/test/fuzz/testdata/FuzzGatewayAPIToXDS/*

0 commit comments

Comments
 (0)