2018-06-14 22:00:46 +00:00
|
|
|
#!/bin/bash -u
|
|
|
|
# Copyright 2018 Google Inc.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
cd $OUT
|
|
|
|
|
2018-06-18 21:19:48 +00:00
|
|
|
if (( $# > 0 )); then
|
|
|
|
FUZZ_TARGETS="$@"
|
|
|
|
else
|
|
|
|
FUZZ_TARGETS="$(find . -maxdepth 1 -type f -executable)"
|
|
|
|
fi
|
|
|
|
|
2018-06-14 22:00:46 +00:00
|
|
|
LOGS_DIR="$OUT/logs"
|
|
|
|
mkdir -p $LOGS_DIR
|
|
|
|
|
|
|
|
# This will be used by llvm-cov command to generate the actual report.
|
|
|
|
objects=""
|
|
|
|
|
|
|
|
# Number of CPUs available, this is needed for running tests in parallel.
|
|
|
|
NPROC=$(nproc)
|
|
|
|
|
|
|
|
function run_fuzz_target {
|
|
|
|
local target=$1
|
|
|
|
|
|
|
|
# Use 100s timeout instead of 25s as code coverage builds can be very slow.
|
|
|
|
local args="-timeout=100 -runs=0 /corpus/${target}"
|
|
|
|
|
|
|
|
LLVM_PROFILE_FILE="$target.profraw" $target $args &> $LOGS_DIR/$target.log
|
|
|
|
if (( $? != 0)); then
|
|
|
|
echo "Error occured while running $target:"
|
|
|
|
cat $LOGS_DIR/$target.log
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Run each fuzz target, generate raw coverage dumps.
|
2018-06-18 21:19:48 +00:00
|
|
|
for fuzz_target in $FUZZ_TARGETS; do
|
2018-06-26 15:23:56 +00:00
|
|
|
# Continue if not a fuzz target.
|
2018-06-28 14:08:57 +00:00
|
|
|
if [[ $FUZZING_ENGINE != "none" ]]; then
|
|
|
|
grep "LLVMFuzzerTestOneInput" $FUZZER_BINARY > /dev/null 2>&1 || continue
|
|
|
|
fi
|
2018-06-25 23:35:28 +00:00
|
|
|
|
2018-06-14 22:00:46 +00:00
|
|
|
echo "Running $fuzz_target"
|
|
|
|
run_fuzz_target $fuzz_target &
|
|
|
|
objects="$objects -object=$fuzz_target"
|
|
|
|
|
|
|
|
# Do not spawn more processes than the number of CPUs available.
|
|
|
|
n_child_proc=$(jobs -rp | wc -l)
|
|
|
|
while [ "$n_child_proc" -eq "$NPROC" ]; do
|
|
|
|
sleep 4
|
|
|
|
n_child_proc=$(jobs -rp | wc -l)
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
# Wait for background processes to finish.
|
|
|
|
wait
|
|
|
|
|
|
|
|
# Merge all raw dumps.
|
|
|
|
llvm-profdata merge -sparse *.profraw -o merged.profdata
|
|
|
|
|
|
|
|
# Delete unnecessary and (potentially) large .profraw files.
|
|
|
|
rm *.profraw
|
|
|
|
|
|
|
|
# TODO(mmoroz): add script from Chromium for rendering directory view reports.
|
|
|
|
|
|
|
|
# Generate HTML report.
|
|
|
|
llvm-cov show -format=html -output-dir=report -path-equivalence="/,$OUT" \
|
|
|
|
-instr-profile merged.profdata $objects
|
|
|
|
|
|
|
|
# Serve the report locally.
|
2018-06-15 17:44:18 +00:00
|
|
|
echo "Serving the report on http://127.0.0.1:$HTTP_PORT/"
|
2018-06-14 22:00:46 +00:00
|
|
|
cd report
|
2018-06-15 17:44:18 +00:00
|
|
|
python3 -m http.server $HTTP_PORT
|