xref: /spdk/test/fuzz/llvm/vfio/run.sh (revision 14e26b9d0410a98689caffcba7bfacac8d85c74d)
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
31	# set LSAN_OPTIONS to "report_objects=1" to let the LLVM fuzzer report an address
32	# of leaked memory object
33	local LSAN_OPTIONS=report_objects=1
34
35	mkdir -p $fuzzer_dir $vfiouser_dir $vfiouser_io_dir $corpus_dir
36
37	# Adjust paths to allow multiply instance of fuzzer
38	sed -e "s%/tmp/vfio-user/domain/1%$vfiouser_dir%;
39		s%/tmp/vfio-user/domain/2%$vfiouser_io_dir%" $testdir/fuzz_vfio_json.conf > $vfiouser_cfg
40
41	$rootdir/test/app/fuzz/llvm_vfio_fuzz/llvm_vfio_fuzz \
42		-m $core \
43		-s $mem_size \
44		-P $output_dir/llvm/ \
45		-F $vfiouser_dir \
46		-c $vfiouser_cfg \
47		-t $timen \
48		-D $corpus_dir \
49		-Y $vfiouser_io_dir \
50		-r $fuzzer_dir/spdk$fuzzer_type.sock \
51		-Z $fuzzer_type
52
53	rm -rf $fuzzer_dir
54}
55
56testdir=$(readlink -f $(dirname $0))
57rootdir=$(readlink -f $testdir/../../../../)
58source $rootdir/test/common/autotest_common.sh
59source $rootdir/test/setup/common.sh
60source $testdir/../common.sh
61
62fuzzfile=$rootdir/test/app/fuzz/llvm_vfio_fuzz/llvm_vfio_fuzz.c
63fuzz_num=$(($(grep -c "\.fn =" $fuzzfile) - 1))
64((fuzz_num != 0))
65
66trap 'cleanup /tmp/vfio-user-*; exit 1' SIGINT SIGTERM EXIT
67
68# vfiouser transport is unable to connect if memory is restricted
69mem_size=0
70if [[ $SPDK_TEST_FUZZER_SHORT -eq 1 ]]; then
71	start_llvm_fuzz_short $fuzz_num $TIME
72elif [[ $SPDK_TEST_FUZZER -eq 1 ]]; then
73	get_testn $fuzz_num 2048
74	start_llvm_fuzz_all $TESTN $fuzz_num $TIME
75else
76	start_llvm_fuzz $1 $TIME 0x1
77fi
78
79trap - SIGINT SIGTERM EXIT
80