Commit c2f7b597 authored by eta's avatar eta
Browse files

Merge branch 'fuzz' into 'main'

add script for coverage of fuzzing

Closes #137

See merge request !339
parents 0ebab3df 9a95bac1
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -2,8 +2,11 @@
/coverage_meta/
/target/
/crates/*/target/
/crates/*/target-coverage/
/crates/*/fuzz/coverage/
/crates/*/fuzz/target/
/crates/*/fuzz/Cargo.lock
/crates/*/fuzz-*.log
*~
.#*
\#*\#
@@ -12,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=${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 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
+15 −23
Original line number Diff line number Diff line
@@ -2,44 +2,36 @@

set -e

trap 'kill $(jobs -p)' EXIT
echo "Using toolchain +${RUST_FUZZ_TOOLCHAIN:=nightly}. (Override with \$RUST_FUZZ_TOOLCHAIN)"

# Validate that "+${RUST_FUZZ_TOOLCHAIN}" is installed.  This will log a message to stderr
# if it itsn't.
cargo "+${RUST_FUZZ_TOOLCHAIN}" -h >/dev/null

for d in ./crates/*/fuzz; do
    pushd "$(dirname "$d")"
    for fuzzer in $(cargo +nightly fuzz list); do
    for fuzzer in $(cargo fuzz list); do
	echo "$fuzzer"
	cargo +nightly fuzz build "$fuzzer"
	cargo "+${RUST_FUZZ_TOOLCHAIN}" fuzz build "$fuzzer"
    done
    popd
done


#JOBS=4
#SEED=0
DURATION=20

while true; do
    for d in ./crates/*/fuzz; do
	pushd "$(dirname "$d")"
	for fuzzer in $(cargo +nightly fuzz list); do
	    set +e
	    timeout 20m cargo +nightly fuzz run "$fuzzer"
	    status="$?"
	    set -e
	    case "$status" in
		0)
  		    # Successful exit?
		    ;;
		124)
		    # This is a timeout
		    ;;
		*)
		    exit 1
		    ;;
	    esac
	for fuzzer in $(cargo fuzz list); do
	    cargo "+${RUST_FUZZ_TOOLCHAIN}" fuzz run "$fuzzer" -- \
		-jobs="${JOBS:-0}" \
		-workers="${JOBS:-0}" \
		-max_total_time=$((DURATION * 60)) \
		-seed="${SEED:-0}"
	done
	popd
    done
done


# wait -n
+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/*"