diff --git a/autotest.sh b/autotest.sh index 064cb02ec..bdd8a11ae 100755 --- a/autotest.sh +++ b/autotest.sh @@ -344,13 +344,7 @@ if [ $SPDK_RUN_FUNCTIONAL_TEST -eq 1 ]; then fi if [[ $SPDK_TEST_FUZZER -eq 1 ]]; then - # TODO: Consider re-using test/fuzz directory for all fuzzing tests with proper - # structure, e.g.: test/fuzz/nvmf/*, test/fuzz/vfio/*, etc. - if [[ $SPDK_TEST_VFIOUSER -eq 1 ]]; then - run_test "nvmf_vfio_llvm_fuzz" test/nvmf/target/llvm_vfio_fuzz.sh - else - run_test "nvmf_llvm_fuzz" test/nvmf/target/llvm_nvme_fuzz.sh - fi + run_test "llvm_fuzz" test/fuzz/llvm.sh fi if [[ $SPDK_TEST_RAID5 -eq 1 ]]; then diff --git a/test/common/autotest_common.sh b/test/common/autotest_common.sh index 7765cdf6d..22d497ce1 100755 --- a/test/common/autotest_common.sh +++ b/test/common/autotest_common.sh @@ -171,6 +171,9 @@ export SPDK_TEST_SMA export SPDK_TEST_DAOS : ${SPDK_TEST_XNVME:=0} export SPDK_TEST_XNVME +# Comma-separated list of fuzzer targets matching test/fuzz/llvm/$target +: ${SPDK_TEST_FUZZER_TARGET:=} +export SPDK_TEST_FUZZER_TARGET # always test with SPDK shared objects. export SPDK_LIB_DIR="$rootdir/build/lib" @@ -504,10 +507,42 @@ function get_config_params() { config_params+=' --with-xnvme' fi + if [[ $SPDK_TEST_FUZZER -eq 1 ]]; then + config_params+=" $(get_fuzzer_target_config)" + fi + echo "$config_params" xtrace_restore } +function get_fuzzer_target_config() { + local -A fuzzer_targets_to_config=() + local config target + + fuzzer_targets_to_config["vfio"]="--with-vfio-user" + for target in $(get_fuzzer_targets); do + [[ -n ${fuzzer_targets_to_config["$target"]} ]] || continue + config+=("${fuzzer_targets_to_config["$target"]}") + done + + if ((${#config[@]} > 0)); then + echo "${config[*]}" + fi +} + +function get_fuzzer_targets() { + local fuzzers=() + + if [[ -n $SPDK_TEST_FUZZER_TARGET ]]; then + IFS="," read -ra fuzzers <<< "$SPDK_TEST_FUZZER_TARGET" + else + fuzzers=("$rootdir/test/fuzz/llvm/"*) + fuzzers=("${fuzzers[@]##*/}") + fi + + echo "${fuzzers[*]}" +} + function rpc_cmd() { xtrace_disable local rsp rc=1 diff --git a/test/fuzz/llvm.sh b/test/fuzz/llvm.sh new file mode 100755 index 000000000..d52ce287e --- /dev/null +++ b/test/fuzz/llvm.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +testdir=$(readlink -f "$(dirname "$0")") +rootdir=$(readlink -f "$testdir/../../") + +source "$rootdir/test/common/autotest_common.sh" + +fuzzers=($(get_fuzzer_targets)) + +for fuzzer in "${fuzzers[@]}"; do + case "$fuzzer" in + nvmf) run_test "nvmf_fuzz" "$testdir/llvm/$fuzzer/run.sh" ;; + vfio) run_test "vfio_fuzz" "$testdir/llvm/$fuzzer/run.sh" ;; + esac +done diff --git a/test/nvmf/target/fuzz_json.conf b/test/fuzz/llvm/nvmf/fuzz_json.conf similarity index 100% rename from test/nvmf/target/fuzz_json.conf rename to test/fuzz/llvm/nvmf/fuzz_json.conf diff --git a/test/nvmf/target/llvm_nvme_fuzz.sh b/test/fuzz/llvm/nvmf/run.sh similarity index 97% rename from test/nvmf/target/llvm_nvme_fuzz.sh rename to test/fuzz/llvm/nvmf/run.sh index 959c1c9a7..d03c3cb24 100755 --- a/test/nvmf/target/llvm_nvme_fuzz.sh +++ b/test/fuzz/llvm/nvmf/run.sh @@ -44,7 +44,7 @@ function run_fuzz() { } testdir=$(readlink -f $(dirname $0)) -rootdir=$(readlink -f $testdir/../../..) +rootdir=$(readlink -f $testdir/../../../../) source $rootdir/test/common/autotest_common.sh fuzzfile=$rootdir/test/app/fuzz/llvm_nvme_fuzz/llvm_nvme_fuzz.c diff --git a/test/nvmf/target/fuzz_vfio_json.conf b/test/fuzz/llvm/vfio/fuzz_vfio_json.conf similarity index 100% rename from test/nvmf/target/fuzz_vfio_json.conf rename to test/fuzz/llvm/vfio/fuzz_vfio_json.conf diff --git a/test/nvmf/target/llvm_vfio_fuzz.sh b/test/fuzz/llvm/vfio/run.sh similarity index 97% rename from test/nvmf/target/llvm_vfio_fuzz.sh rename to test/fuzz/llvm/vfio/run.sh index a16351635..8241d32a4 100755 --- a/test/nvmf/target/llvm_vfio_fuzz.sh +++ b/test/fuzz/llvm/vfio/run.sh @@ -48,7 +48,7 @@ function run_fuzz() { } testdir=$(readlink -f $(dirname $0)) -rootdir=$(readlink -f $testdir/../../..) +rootdir=$(readlink -f $testdir/../../../../) source $rootdir/test/common/autotest_common.sh fuzzfile=$rootdir/test/app/fuzz/llvm_vfio_fuzz/llvm_vfio_fuzz.c