1#!/usr/bin/env bash 2# SPDX-License-Identifier: BSD-3-Clause 3# Copyright (C) 2022 Intel Corporation 4# All rights reserved. 5# 6FUZZER=vfio 7if [[ $SPDK_TEST_FUZZER_SHORT -eq 0 ]]; then 8 TIME=60000 9else 10 TIME=1 11fi 12 13for i in "$@"; do 14 case "$i" in 15 --time=*) 16 TIME="${i#*=}" 17 ;; 18 esac 19done 20 21function start_llvm_fuzz() { 22 local fuzzer_type=$1 23 local timen=$2 24 local core=$3 25 local corpus_dir=$rootdir/../corpus/llvm_vfio_$fuzzer_type 26 local fuzzer_dir=/tmp/vfio-user-$fuzzer_type 27 local vfiouser_dir=$fuzzer_dir/domain/1 28 local vfiouser_io_dir=$fuzzer_dir/domain/2 29 local vfiouser_cfg=$fuzzer_dir/fuzz_vfio_json.conf 30 local suppress_file="/var/tmp/suppress_vfio_fuzz" 31 32 # set LSAN_OPTIONS to "report_objects=1" to let the LLVM fuzzer report an address 33 # of leaked memory object 34 local LSAN_OPTIONS=report_objects=1:suppressions="$suppress_file":print_suppressions=0 35 36 mkdir -p $fuzzer_dir $vfiouser_dir $vfiouser_io_dir $corpus_dir 37 38 # Adjust paths to allow multiply instance of fuzzer 39 sed -e "s%/tmp/vfio-user/domain/1%$vfiouser_dir%; 40 s%/tmp/vfio-user/domain/2%$vfiouser_io_dir%" $testdir/fuzz_vfio_json.conf > $vfiouser_cfg 41 42 # Suppress false memory leaks reported by LSan 43 echo "leak:spdk_nvmf_qpair_disconnect" > "$suppress_file" 44 echo "leak:nvmf_ctrlr_create" >> "$suppress_file" 45 46 $rootdir/test/app/fuzz/llvm_vfio_fuzz/llvm_vfio_fuzz \ 47 -m $core \ 48 -s $mem_size \ 49 -P $output_dir/llvm/ \ 50 -F $vfiouser_dir \ 51 -c $vfiouser_cfg \ 52 -t $timen \ 53 -D $corpus_dir \ 54 -Y $vfiouser_io_dir \ 55 -r $fuzzer_dir/spdk$fuzzer_type.sock \ 56 -Z $fuzzer_type 57 58 rm -rf $fuzzer_dir $suppress_file 59} 60 61testdir=$(readlink -f $(dirname $0)) 62rootdir=$(readlink -f $testdir/../../../../) 63source $rootdir/test/common/autotest_common.sh 64source $rootdir/test/setup/common.sh 65source $testdir/../common.sh 66 67fuzzfile=$rootdir/test/app/fuzz/llvm_vfio_fuzz/llvm_vfio_fuzz.c 68fuzz_num=$(($(grep -c "\.fn =" $fuzzfile) - 1)) 69((fuzz_num != 0)) 70 71trap 'cleanup /tmp/vfio-user-* /var/tmp/suppress_vfio_fuzz; exit 1' SIGINT SIGTERM EXIT 72 73# vfiouser transport is unable to connect if memory is restricted 74mem_size=0 75if [[ $SPDK_TEST_FUZZER_SHORT -eq 1 ]]; then 76 start_llvm_fuzz_short $fuzz_num $TIME 77elif [[ $SPDK_TEST_FUZZER -eq 1 ]]; then 78 get_testn $fuzz_num 2048 79 start_llvm_fuzz_all $TESTN $fuzz_num $TIME 80else 81 start_llvm_fuzz $1 $TIME 0x1 82fi 83 84trap - SIGINT SIGTERM EXIT 85