1#!/usr/bin/env bash 2# SPDX-License-Identifier: BSD-3-Clause 3# Copyright (C) 2022 Intel Corporation 4# All rights reserved. 5# 6testdir=$(readlink -f "$(dirname "$0")") 7rootdir=$(readlink -f "$testdir/../../") 8 9source "$rootdir/test/common/autotest_common.sh" 10 11fuzzers=($(get_fuzzer_targets)) 12 13llvm_out=$output_dir/llvm 14 15mkdir -p $rootdir/../corpus/ $llvm_out 16 17function lcov_start() { 18 local out=$llvm_out 19 local src=$rootdir 20 21 if hash lcov; then 22 export LCOV_OPTS=" 23 --rc lcov_branch_coverage=1 24 --rc lcov_function_coverage=1 25 --rc genhtml_branch_coverage=1 26 --rc genhtml_function_coverage=1 27 --rc genhtml_legend=1 28 --rc geninfo_all_blocks=1 29 --gcov-tool $rootdir/test/fuzz/llvm/llvm-gcov.sh 30 " 31 export LCOV="lcov $LCOV_OPTS --no-external" 32 33 # Print lcov version to log 34 $LCOV -v 35 # zero out coverage data 36 $LCOV -q -c -i -t "Baseline" -d $src -o $out/cov_base.info 37 fi 38} 39 40function lcov_stop() { 41 local out=$llvm_out 42 local src=$rootdir 43 44 if hash lcov; then 45 # generate coverage data and combine with baseline 46 $LCOV -q -c -d $src -t "$(hostname)" -o $out/cov_test.info 47 $LCOV -q -a $out/cov_base.info -a $out/cov_test.info -o $out/cov_total.info 48 $LCOV -q -r $out/cov_total.info '*/dpdk/*' -o $out/cov_total.info 49 $LCOV -q -r $out/cov_total.info '/usr/*' -o $out/cov_total.info 50 owner=$(stat -c "%U" .) 51 sudo -u $owner git clean -f "*.gcda" 52 rm -f cov_base.info cov_test.info OLD_STDOUT OLD_STDERR 53 fi 54} 55 56# Collect coverage data when run fuzzers for longer period of time 57# this allow to check coverage progression between runs, and grow of corpus files 58if [[ $SPDK_TEST_FUZZER_SHORT -eq 0 ]]; then 59 lcov_start 60fi 61 62for fuzzer in "${fuzzers[@]}"; do 63 case "$fuzzer" in 64 nvmf) run_test "nvmf_fuzz" "$testdir/llvm/$fuzzer/run.sh" ;; 65 vfio) run_test "vfio_fuzz" "$testdir/llvm/$fuzzer/run.sh" ;; 66 esac 67done 68 69if [[ $SPDK_TEST_FUZZER_SHORT -eq 0 ]]; then 70 lcov_stop 71 genhtml $llvm_out/cov_total.info --output-directory $llvm_out 72fi 73