Commit 6ce6e400 authored by trinity-1686a's avatar trinity-1686a
Browse files

add script for coverage on fuzzing

parent 74e3f26b
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -2,6 +2,8 @@
/coverage_meta/
/target/
/crates/*/target/
/crates/*/target-coverage/
/crates/*/fuzz/coverage/
/crates/*/fuzz/target/
/crates/*/fuzz/Cargo.lock
/crates/*/fuzz-*.log
@@ -13,3 +15,4 @@
/arti-windows.exe
/arti-macos
/chutney
/osxcross
+43 −0
Original line number Diff line number Diff line
#!/bin/bash

set -e

if [ -z "$LLVM_PROFILE_FILE" ]; then
    echo "This script is meant to be run inside with_coverage" >&2
    exit 1
fi

coverage_dir=$(dirname "$LLVM_PROFILE_FILE")

TOPDIR=$(realpath "$(dirname "$0")/..")
cd "$TOPDIR"

# for some reason, compiling with coverage is very slow, especially for curve25519-dalek,
# and mixing normal runs and coverage runs trash the cache. Here we set an alternative
# target directory so it's possible to reuse cached artifacts between coverage runs.
export CARGO_TARGET_DIR="target-coverage"

# remove comments starting with #@ to run in parallel. This makes output very messy, uses a lot more
# ram and make the load average go crazy, but it's also way faster both to compile (due to 
# curve25519-dalek compilation being so slow, and it using a single core), and to run because it's
# essentially monothreaded too.
for d in ./crates/*/fuzz; do
    #@{
        pushd "$(dirname "$d")"
        crate=$(basename "$(dirname "$d")")
        mkdir -p "$TOPDIR/target/debug/$crate"
        mkdir -p "$coverage_dir/$crate"
        for fuzzer in $(cargo fuzz list); do
            cargo +nightly fuzz coverage "$fuzzer"

            # we copy binary and coverage data where with_coverage expect it to be
            cp "target-coverage/x86_64-unknown-linux-gnu/release/$fuzzer" "$TOPDIR/target/debug/$crate/$fuzzer"
            mv "fuzz/coverage/$fuzzer/raw" "$coverage_dir/$crate/$fuzzer"
        done
        popd
    #@}&
done

#@for d in ./crates/*/fuzz; do
#@    wait
#@done
+3 −3
Original line number Diff line number Diff line
@@ -21,10 +21,10 @@ while true; do
	pushd "$(dirname "$d")"
	for fuzzer in $(cargo fuzz list); do
	    cargo +nightly fuzz run "$fuzzer" -- \
		-jobs=${JOBS:-0} \
		-workers=${JOBS:-0} \
		-jobs="${JOBS:-0}" \
		-workers="${JOBS:-0}" \
		-max_total_time=$((DURATION * 60)) \
		-seed=${SEED:-0}
		-seed="${SEED:-0}"
	done
	popd
    done
+1 −0
Original line number Diff line number Diff line
@@ -134,6 +134,7 @@ grcov "$COVERAGE_BASEDIR/coverage_meta" \
	--excl-stop '^}' \
	--ignore="*/tests/*" \
	--ignore="*/examples/*" \
	--ignore="*/fuzz/*" \
	--ignore="crates/arti-bench/*" \
	--ignore="*/github.com-1ecc6299db9ec823/*"