xref: /spdk/test/fuzz/llvm/nvmf/run.sh (revision c6c1234de9e0015e670dd0b51bf6ce39ee0e07bd)
1#!/usr/bin/env bash
2#  SPDX-License-Identifier: BSD-3-Clause
3#  Copyright (C) 2021 Intel Corporation
4#  All rights reserved.
5#
6
7FUZZER=nvmf
8if [[ $SPDK_TEST_FUZZER_SHORT -eq 0 ]]; then
9	TIME=60000
10else
11	TIME=1
12fi
13
14for i in "$@"; do
15	case "$i" in
16		--time=*)
17			TIME="${i#*=}"
18			;;
19	esac
20done
21
22function start_llvm_fuzz() {
23	local fuzzer_type=$1
24	local timen=$2
25	local core=$3
26	local corpus_dir=$rootdir/../corpus/llvm_nvmf_$fuzzer_type
27	local nvmf_cfg=/tmp/fuzz_json_$fuzzer_type.conf
28	local suppress_file="/var/tmp/suppress_nvmf_fuzz"
29
30	# set LSAN_OPTIONS to "report_objects=1" to let the LLVM fuzzer report an address of
31	# leaked memory object
32	local LSAN_OPTIONS=report_objects=1:suppressions="$suppress_file":print_suppressions=0
33
34	port="44$(printf "%02d" $fuzzer_type)"
35	mkdir -p $corpus_dir
36
37	trid="trtype:tcp adrfam:IPv4 subnqn:nqn.2016-06.io.spdk:cnode1 traddr:127.0.0.1 trsvcid:$port"
38	sed -e "s/\"trsvcid\": \"4420\"/\"trsvcid\": \"$port\"/" $testdir/fuzz_json.conf > $nvmf_cfg
39
40	# Suppress false memory leaks reported by LSan
41	echo "leak:spdk_nvmf_qpair_disconnect" > "$suppress_file"
42	echo "leak:nvmf_ctrlr_create" >> "$suppress_file"
43
44	$rootdir/test/app/fuzz/llvm_nvme_fuzz/llvm_nvme_fuzz \
45		-m $core \
46		-s $mem_size \
47		-P $output_dir/llvm/ \
48		-F "$trid" \
49		-c $nvmf_cfg \
50		-t $timen \
51		-D $corpus_dir \
52		-Z $fuzzer_type
53
54	rm -rf $nvmf_cfg $suppress_file
55}
56
57testdir=$(readlink -f $(dirname $0))
58rootdir=$(readlink -f $testdir/../../../../)
59source $rootdir/test/common/autotest_common.sh
60source $rootdir/test/setup/common.sh
61source $testdir/../common.sh
62
63fuzzfile=$rootdir/test/app/fuzz/llvm_nvme_fuzz/llvm_nvme_fuzz.c
64fuzz_num=$(($(grep -c "\.fn =" $fuzzfile) - 1))
65((fuzz_num != 0))
66
67trap 'cleanup /tmp/llvm_fuzz* /var/tmp/suppress_nvmf_fuzz; exit 1' SIGINT SIGTERM EXIT
68
69mem_size=512
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 $mem_size
74	start_llvm_fuzz_all $TESTN $fuzz_num $TIME
75else
76	start_llvm_fuzz $1 $TIME 0x1
77fi
78
79trap - SIGINT SIGTERM EXIT
80