2022-07-29 07:58:26 +00:00
|
|
|
#!/usr/bin/env bash
|
2022-11-02 15:49:40 +00:00
|
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
# Copyright (C) 2022 Intel Corporation
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
2022-11-09 21:41:02 +00:00
|
|
|
FUZZER=vfio
|
2022-07-29 07:58:26 +00:00
|
|
|
if [[ $SPDK_TEST_FUZZER_SHORT -eq 0 ]]; then
|
|
|
|
TIME=60000
|
|
|
|
else
|
|
|
|
TIME=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
for i in "$@"; do
|
|
|
|
case "$i" in
|
|
|
|
--time=*)
|
|
|
|
TIME="${i#*=}"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
function start_llvm_fuzz() {
|
|
|
|
local fuzzer_type=$1
|
2022-11-09 21:41:02 +00:00
|
|
|
local timen=$2
|
|
|
|
local core=$3
|
|
|
|
local corpus_dir=$rootdir/../corpus/llvm_vfio_$fuzzer_type
|
|
|
|
local fuzzer_dir=/tmp/vfio-user-$fuzzer_type
|
|
|
|
local vfiouser_dir=$fuzzer_dir/domain/1
|
|
|
|
local vfiouser_io_dir=$fuzzer_dir/domain/2
|
|
|
|
local vfiouser_cfg=$fuzzer_dir/fuzz_vfio_json.conf
|
|
|
|
|
|
|
|
mkdir -p $fuzzer_dir $vfiouser_dir $vfiouser_io_dir $corpus_dir
|
2022-10-21 09:48:37 +00:00
|
|
|
|
2022-11-09 21:41:02 +00:00
|
|
|
# Adjust paths to allow multiply instance of fuzzer
|
|
|
|
sed -e "s%/tmp/vfio-user/domain/1%$vfiouser_dir%;
|
|
|
|
s%/tmp/vfio-user/domain/2%$vfiouser_io_dir%" $testdir/fuzz_vfio_json.conf > $vfiouser_cfg
|
2022-10-21 09:48:37 +00:00
|
|
|
|
2022-11-09 21:41:02 +00:00
|
|
|
$rootdir/test/app/fuzz/llvm_vfio_fuzz/llvm_vfio_fuzz \
|
|
|
|
-m $core \
|
|
|
|
-s $mem_size \
|
2022-12-08 17:37:07 +00:00
|
|
|
-P $output_dir/llvm/ \
|
2022-11-09 21:41:02 +00:00
|
|
|
-F $vfiouser_dir \
|
|
|
|
-c $vfiouser_cfg \
|
|
|
|
-t $timen \
|
2022-10-21 09:48:37 +00:00
|
|
|
-D $corpus_dir \
|
2022-11-09 21:41:02 +00:00
|
|
|
-Y $vfiouser_io_dir \
|
|
|
|
-r $fuzzer_dir/spdk$fuzzer_type.sock \
|
2022-10-21 09:48:37 +00:00
|
|
|
-Z $fuzzer_type
|
2022-07-29 07:58:26 +00:00
|
|
|
|
2022-11-09 21:41:02 +00:00
|
|
|
rm -rf $fuzzer_dir
|
2022-07-29 07:58:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
testdir=$(readlink -f $(dirname $0))
|
2022-09-19 11:13:40 +00:00
|
|
|
rootdir=$(readlink -f $testdir/../../../../)
|
2022-07-29 07:58:26 +00:00
|
|
|
source $rootdir/test/common/autotest_common.sh
|
2022-11-09 21:41:02 +00:00
|
|
|
source $rootdir/test/setup/common.sh
|
|
|
|
source $testdir/../common.sh
|
2022-07-29 07:58:26 +00:00
|
|
|
|
|
|
|
fuzzfile=$rootdir/test/app/fuzz/llvm_vfio_fuzz/llvm_vfio_fuzz.c
|
2022-11-09 21:41:02 +00:00
|
|
|
fuzz_num=$(($(grep -c "\.fn =" $fuzzfile) - 1))
|
|
|
|
((fuzz_num != 0))
|
2022-07-29 07:58:26 +00:00
|
|
|
|
2022-11-09 21:41:02 +00:00
|
|
|
trap 'cleanup /tmp/vfio-user-*; exit 1' SIGINT SIGTERM EXIT
|
2022-07-29 07:58:26 +00:00
|
|
|
|
2022-11-09 21:41:02 +00:00
|
|
|
# vfiouser transport is unable to connect if memory is restricted
|
|
|
|
mem_size=0
|
2022-07-29 07:58:26 +00:00
|
|
|
if [[ $SPDK_TEST_FUZZER_SHORT -eq 1 ]]; then
|
2022-11-09 21:41:02 +00:00
|
|
|
start_llvm_fuzz_short $fuzz_num $TIME
|
2022-07-29 07:58:26 +00:00
|
|
|
elif [[ $SPDK_TEST_FUZZER -eq 1 ]]; then
|
2022-11-09 21:41:02 +00:00
|
|
|
get_testn $fuzz_num 1024
|
|
|
|
start_llvm_fuzz_all $TESTN $fuzz_num $TIME
|
2022-07-29 07:58:26 +00:00
|
|
|
else
|
2022-11-09 21:41:02 +00:00
|
|
|
start_llvm_fuzz $1 $TIME 0x1
|
2022-07-29 07:58:26 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
trap - SIGINT SIGTERM EXIT
|