1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-03-24 06:50:08 +03:00

fuzz: Add utility scripts

Add scripts to minimize a corpus and generate HTML coverage reports.
This commit is contained in:
Nick Wellnhofer 2024-12-18 12:49:24 +01:00
parent 63dfcca670
commit e649c97246
2 changed files with 60 additions and 0 deletions

39
fuzz/scripts/coverage_report.sh Executable file
View File

@ -0,0 +1,39 @@
#!/bin/sh
set -e
fuzzer="$1"
if [ -z "$fuzzer" ]; then
echo usage: $0 fuzzer
exit 1
fi
# Rebuild the project with coverage enabled
make distclean
export CC=clang
export CXX=clang++
export CFLAGS=" \
-O1 -gline-tables-only \
-fsanitize=fuzzer-no-link \
-fprofile-instr-generate -fcoverage-mapping \
-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION"
sh autogen.sh --without-python
make -j5
rm default.profraw
# Process corpus once
cd fuzz
make $fuzzer
./$fuzzer -runs=1 corpus/$fuzzer
# Generate HTML report
llvm-profdata merge default.profraw -o default.profdata
llvm-cov show -format=html -output-dir=report \
-instr-profile default.profdata \
../.libs/libxml2.so
rm default.profraw default.profdata

21
fuzz/scripts/minimize_corpus.sh Executable file
View File

@ -0,0 +1,21 @@
#!/bin/sh
set -e
fuzzer="$1"
if [ -z "$fuzzer" ]; then
echo usage: $0 fuzzer
exit 1
fi
cd fuzz
make $fuzzer
if [ ! -e corpus/${fuzzer}_ ]; then
mv corpus/$fuzzer corpus/${fuzzer}_
fi
mkdir -p corpus/$fuzzer
./$fuzzer -merge=1 -use_value_profile=1 corpus/$fuzzer corpus/${fuzzer}_
rm -rf corpus/${fuzzer}_