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-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
|
|
|
|
|
|
|
|
VFIOUSER_DIR=/tmp/vfio-user/domain/1
|
2022-08-17 06:05:00 +00:00
|
|
|
VFIOUSER_IO_DIR=/tmp/vfio-user/domain/2
|
2022-07-29 07:58:26 +00:00
|
|
|
mkdir -p $VFIOUSER_DIR
|
2022-08-17 06:05:00 +00:00
|
|
|
mkdir -p $VFIOUSER_IO_DIR
|
2022-07-29 07:58:26 +00:00
|
|
|
|
|
|
|
function start_llvm_fuzz() {
|
|
|
|
local fuzzer_type=$1
|
|
|
|
local corpus_dir
|
2022-10-21 09:48:37 +00:00
|
|
|
|
|
|
|
corpus_dir=$rootdir/../corpus/llvm_vfio_$fuzzer_type
|
2022-07-29 07:58:26 +00:00
|
|
|
mkdir -p $corpus_dir
|
2022-10-21 09:48:37 +00:00
|
|
|
|
|
|
|
$rootdir/test/app/fuzz/llvm_vfio_fuzz/llvm_vfio_fuzz -m 0x1 \
|
|
|
|
-i 0 \
|
|
|
|
-F $VFIOUSER_DIR \
|
|
|
|
-c $testdir/fuzz_vfio_json.conf \
|
|
|
|
-t $TIME \
|
|
|
|
-D $corpus_dir \
|
|
|
|
-Y $VFIOUSER_IO_DIR \
|
|
|
|
-Z $fuzzer_type
|
2022-07-29 07:58:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function run_fuzz() {
|
|
|
|
local startday
|
|
|
|
local today
|
|
|
|
local interval=0
|
|
|
|
local weekloop
|
|
|
|
# Get the date number, format is like '22078'
|
|
|
|
# The purpose is when Jenkins schedule one fuzz in Saturday
|
|
|
|
# We can decide which one fuzz will be run , there are lots of fuzz, but only run one of them in Saturday each time
|
|
|
|
# and make sure all fuzz will be tested, so use this function. Such run fuzz 0 in 03/26, and run fuzz 1 in 04/02, run fuzz 2 in 04/09 ....
|
|
|
|
startday=$(date -d '2022-03-19' '+%y%j')
|
|
|
|
today=$(date '+%y%j')
|
|
|
|
interval=$(((today - startday) / 7))
|
|
|
|
weekloop=$((interval / fuzz_num))
|
|
|
|
if [[ $weekloop -lt 1 ]]; then # The first loop of fuzz
|
|
|
|
fuzzer_type=$interval
|
|
|
|
else
|
|
|
|
fuzzer_type=$((interval % fuzz_num))
|
|
|
|
fi
|
2022-11-09 16:59:57 +00:00
|
|
|
start_llvm_fuzz $fuzzer_type &> $output_dir/llvm/llvm_vfio_$fuzzer_type.txt
|
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
|
|
|
|
|
|
|
|
fuzzfile=$rootdir/test/app/fuzz/llvm_vfio_fuzz/llvm_vfio_fuzz.c
|
|
|
|
fuzz_num=$(($(grep -c "fn =" $fuzzfile) - 1))
|
|
|
|
[[ $fuzz_num -ne 0 ]]
|
|
|
|
|
2022-10-21 09:48:37 +00:00
|
|
|
trap 'process_shm --id 0; rm -rf $VFIOUSER_DIR $VFIOUSER_IO_DIR; exit 1' SIGINT SIGTERM EXIT
|
2022-07-29 07:58:26 +00:00
|
|
|
|
|
|
|
if [[ $SPDK_TEST_FUZZER_SHORT -eq 1 ]]; then
|
|
|
|
for ((i = 0; i < fuzz_num; i++)); do
|
|
|
|
start_llvm_fuzz $i
|
|
|
|
done
|
|
|
|
elif [[ $SPDK_TEST_FUZZER -eq 1 ]]; then
|
|
|
|
run_fuzz
|
|
|
|
else
|
|
|
|
start_llvm_fuzz $1
|
|
|
|
fi
|
|
|
|
|
2022-10-21 09:48:37 +00:00
|
|
|
rm -rf $VFIOUSER_DIR $VFIOUSER_IO_DIR
|
2022-07-29 07:58:26 +00:00
|
|
|
trap - SIGINT SIGTERM EXIT
|