Skip to content

Commit

Permalink
test: add a script to run the fuzzer and compute the coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bboilot-ledger committed Dec 27, 2024
1 parent 4323935 commit f86eb28
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/fuzzing/local_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

# Clean
rm -rf build

# Build the fuzzer
cmake -B build -S . -DCMAKE_C_COMPILER=/usr/bin/clang
cmake --build build

# Create the corpus directory if it doesn't exist
if ! [ -d ./corpus ]; then
mkdir corpus
fi

# Run the fuzzer on half CPU cores
ncpus=$(nproc)
jobs=$(($ncpus/2))
echo "The fuzzer will start very soon, press Ctrl-C when you want to stop it and compute the coverage"
./build/fuzzer -max_len=8192 -jobs="$jobs" ./corpus


read -p "Would you like to compute coverage (y/n)? " -n 1 -r
echo
if [[ $REPLY =~ ^[Nn]$ ]]
then
exit 0
fi

# Remove previous artifcats
rm default.profdata default.profraw

# Run profiling on the corpus
./build/fuzzer -max_len=8192 -runs=0 ./corpus

# Compute coverage
llvm-profdata merge -sparse *.profraw -o default.profdata
llvm-cov show build/fuzzer -instr-profile=default.profdata -format=html -ignore-filename-regex='ethereum-plugin-sdk\/|secure-sdk\/' > report.html
llvm-cov report build/fuzzer -instr-profile=default.profdata -ignore-filename-regex='ethereum-plugin-sdk\/|secure-sdk\/'

0 comments on commit f86eb28

Please sign in to comment.