diff --git a/test/fuzz/autofuzz.sh b/test/fuzz/autofuzz.sh new file mode 100755 index 000000000..27559d162 --- /dev/null +++ b/test/fuzz/autofuzz.sh @@ -0,0 +1,65 @@ +#!/usr/bin/env bash + +testdir=$(readlink -f $(dirname $0)) +rootdir=$(readlink -f $testdir/../..) + +source "$rootdir/test/common/autotest_common.sh" + +# The term transport is used a bit loosely for vhost tests. +allowed_nvme_transports=("rdma" "tcp") +allowed_vhost_transports=("scsi" "blk" "all") +bad_transport=true +config_params="--enable-asan --enable-ubsan --enable-debug --without-isal" + +# This argument is used in addition to the test arguments in autotest_common.sh +for i in "$@"; do + case "$i" in + --module=*) + TEST_MODULE="${i#*=}" + ;; + esac +done + +timing_enter autofuzz +if [ "$TEST_MODULE" == "nvmf" ]; then + allowed_transports=( "${allowed_nvme_transports[@]}" ) + if [ $TEST_TRANSPORT == "rdma" ]; then + config_params="$config_params --with-rdma" + fi +elif [ "$TEST_MODULE" == "vhost" ]; then + allowed_transports=( "${allowed_vhost_transports[@]}" ) + config_params="$config_params --with-vhost --with-virtio" +else + echo "Invalid module specified. Please specify either nvmf or vhost." + exit 1 +fi + +for transport in ${allowed_transports[@]}; do + if [ $transport == "$TEST_TRANSPORT" ]; then + bad_transport=false + fi +done + +if $bad_transport; then + echo "invalid transport. Please supply one of the following for module: $TEST_MODULE." + echo "${allowed_transports[@]}" + exit 1 +fi + +timing_enter make +cd $rootdir +./configure $config_params +$MAKE $MAKEFLAGS +timing_exit make + +# supply --iso to each test module so that it can run setup.sh. +timing_enter fuzz_module +if [ "$TEST_MODULE" == "nvmf" ]; then + sudo $testdir/autofuzz_nvmf.sh --iso --transport=$TEST_TRANSPORT +fi + +if [ "$TEST_MODULE" == "vhost" ]; then + sudo $testdir/autofuzz_vhost.sh --iso --transport=$TEST_TRANSPORT +fi +timing_exit fuzz_module +timing_exit autofuzz diff --git a/test/fuzz/autofuzz_nvmf.sh b/test/fuzz/autofuzz_nvmf.sh new file mode 100755 index 000000000..246f2a87d --- /dev/null +++ b/test/fuzz/autofuzz_nvmf.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +testdir=$(readlink -f $(dirname $0)) +rootdir=$(readlink -f $testdir/../..) +source $rootdir/test/common/autotest_common.sh +source $rootdir/test/nvmf/common.sh + +rpc_py="$rootdir/scripts/rpc.py" + +nvmftestinit + +timing_enter nvmf_fuzz_test + +echo "[Nvme]" > $testdir/nvmf_fuzz.conf +echo " TransportID \"trtype:$TEST_TRANSPORT adrfam:IPv4 subnqn:nqn.2016-06.io.spdk:cnode1 traddr:$NVMF_FIRST_TARGET_IP trsvcid:$NVMF_PORT\" Nvme0" >> $testdir/nvmf_fuzz.conf + +$NVMF_APP -m 0xF &>$output_dir/nvmf_autofuzz_tgt_output.txt & +nvmfpid=$! + +trap "process_shm --id $NVMF_APP_SHM_ID; rm -f $testdir/nvmf_fuzz.conf; killprocess $nvmfpid; nvmftestfini $1; exit 1" SIGINT SIGTERM EXIT + +waitforlisten $nvmfpid +$rpc_py nvmf_create_transport -t $TEST_TRANSPORT -u 8192 + +$rpc_py construct_malloc_bdev -b Malloc0 64 512 + +$rpc_py nvmf_subsystem_create nqn.2016-06.io.spdk:cnode1 -a -s SPDK00000000000001 +$rpc_py nvmf_subsystem_add_ns nqn.2016-06.io.spdk:cnode1 Malloc0 +$rpc_py nvmf_subsystem_add_listener nqn.2016-06.io.spdk:cnode1 -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_PORT + +# Note that we chose a consistent seed to ensure that this test is consistent in nightly builds. +$rootdir/test/app/fuzz/nvme_fuzz/nvme_fuzz -m 0xF0 -r "/var/tmp/nvme_fuzz" -t 12 -C $testdir/nvmf_fuzz.conf -N -a 2>$output_dir/nvmf_autofuzz_logs.txt + +rm -f $testdir/nvmf_fuzz.conf +$rpc_py delete_nvmf_subsystem nqn.2016-06.io.spdk:cnode1 + +trap - SIGINT SIGTERM EXIT + +nvmfcleanup +killprocess $nvmfpid + +nvmftestfini +timing_exit nvmf_fuzz_test diff --git a/test/fuzz/autofuzz_vhost.sh b/test/fuzz/autofuzz_vhost.sh new file mode 100755 index 000000000..715071554 --- /dev/null +++ b/test/fuzz/autofuzz_vhost.sh @@ -0,0 +1,66 @@ +#!/usr/bin/env bash + +rootdir=$(readlink -f $(dirname $0))/../.. +source $rootdir/test/common/autotest_common.sh +source "$rootdir/scripts/common.sh" + +VHOST_APP="$rootdir/app/vhost/vhost -p 0" +FUZZ_RPC_SOCK="/var/tmp/spdk_fuzz.sock" +FUZZ_APP="$rootdir/test/app/fuzz/vhost_fuzz/vhost_fuzz -r $FUZZ_RPC_SOCK --wait-for-rpc" + +vhost_rpc_py="$rootdir/scripts/rpc.py" +fuzz_generic_rpc_py="$rootdir/scripts/rpc.py -s $FUZZ_RPC_SOCK" +fuzz_specific_rpc_py="$rootdir/test/app/fuzz/common/fuzz_rpc.py -s $FUZZ_RPC_SOCK" + +timing_enter vhost_fuzz_test + +#todo refactor this to use the vhosttestinit function when it becomes available. +timing_enter setup +$rootdir/scripts/setup.sh +timing_exit setup + +$VHOST_APP &>$output_dir/vhost_fuzz_tgt_output.txt & +vhostpid=$! +waitforlisten $vhostpid + +trap "killprocess $vhostpid; exit 1" SIGINT SIGTERM exit + +$FUZZ_APP -t 1200 2>$output_dir/vhost_autofuzz_output1.txt & +fuzzpid=$! +waitforlisten $fuzzpid $FUZZ_RPC_SOCK + +trap "killprocess $vhostpid; killprocess $fuzzpid; exit 1" SIGINT SIGTERM exit + +if [ "$TEST_TRANSPORT" == "bdev" ] || [ "$TEST_TRANSPORT" == "all" ]; then + $vhost_rpc_py construct_malloc_bdev -b Malloc0 64 512 + $vhost_rpc_py construct_vhost_blk_controller Vhost.1 Malloc0 + + # test the vhost blk controller with valid data buffers. + $fuzz_specific_rpc_py fuzz_vhost_create_dev -s $(pwd)/Vhost.1 -b -v +fi + +if [ "$TEST_TRANSPORT" == "scsi" ] || [ "$TEST_TRANSPORT" == "all" ]; then + $vhost_rpc_py construct_malloc_bdev -b Malloc1 64 512 + $vhost_rpc_py construct_vhost_scsi_controller naa.VhostScsi0.1 + $vhost_rpc_py add_vhost_scsi_lun naa.VhostScsi0.1 0 Malloc1 + + $vhost_rpc_py construct_malloc_bdev -b Malloc2 64 512 + $vhost_rpc_py construct_vhost_scsi_controller naa.VhostScsi0.2 + $vhost_rpc_py add_vhost_scsi_lun naa.VhostScsi0.2 0 Malloc2 + + # test the vhost scsi I/O queue with valid data buffers on a valid lun. + $fuzz_specific_rpc_py fuzz_vhost_create_dev -s $(pwd)/naa.VhostScsi0.1 -l -v + # test the vhost scsi management queue with valid data buffers. + $fuzz_specific_rpc_py fuzz_vhost_create_dev -s $(pwd)/naa.VhostScsi0.2 -v -m +fi + +# The test won't actually begin until this option is passed in. +$fuzz_generic_rpc_py start_subsystem_init + +wait $fuzzpid + +trap - SIGINT SIGTERM exit + +killprocess $vhostpid +killprocess $fuzzpid +timing_exit vhost_fuzz_test