test/nvmf: Add llvm-nvmf-fuzz test

Add flag "SPDK_TEST_FUZZER" to control building of llvm lib using
CC=clang-$clang_complier
CXX=clang++-$clang_complier

config_params with --with-fuzzer=/usr/lib64/clang/$clangV/lib/linux/libclang_rt.fuzzer_no_main-x86_64.a

Signed-off-by: Jun Wen <junx.wen@intel.com>
Change-Id: Icf3dfe13989d083d22be69b964a54830324a657e
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11153
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Reviewed-by: Dong Yi <dongx.yi@intel.com>
Reviewed-by: <qun.wan@intel.com>
Reviewed-by: Karol Latecki <karol.latecki@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
This commit is contained in:
Jun Wen 2022-01-19 21:35:39 +08:00 committed by Tomasz Zawadzki
parent e7db96cd37
commit 59a0d2c60d
5 changed files with 79 additions and 8 deletions

View File

@ -52,6 +52,22 @@ function ocf_precompile() {
./configure $config_params
}
function llvm_precompile() {
# llvm need clang compiler
local clangV
local clang_complier
clangV=$(clang --version | grep version | cut -d" " -f3)
clang_complier=$(echo "$clangV" | cut -d"." -f1)
export CC=clang-$clang_complier
export CXX=clang++-$clang_complier
# Set config to use precompiled library
config_params="$config_params --with-fuzzer=/usr/lib64/clang/$clangV/lib/linux/libclang_rt.fuzzer_no_main-x86_64.a"
# need to reconfigure to avoid clearing llvm related files on future make clean.
./configure $config_params
}
function build_native_dpdk() {
local external_dpdk_dir
local external_dpdk_base_dir
@ -360,6 +376,10 @@ if [[ $SPDK_TEST_OCF -eq 1 ]]; then
run_test "autobuild_ocf_precompile" ocf_precompile
fi
if [[ $SPDK_TEST_FUZZER -eq 1 ]]; then
run_test "autobuild_llvm_precompile" llvm_precompile
fi
if [[ $SPDK_TEST_AUTOBUILD -eq 1 ]]; then
run_test "autobuild" autobuild_test_suite $1
elif [[ $SPDK_TEST_UNITTEST -eq 1 ]]; then
@ -367,7 +387,12 @@ elif [[ $SPDK_TEST_UNITTEST -eq 1 ]]; then
elif [[ $SPDK_TEST_SCANBUILD -eq 1 ]]; then
run_test "scanbuild_make" scanbuild_make
else
# if we aren't testing the unittests, build with shared objects.
./configure $config_params --with-shared
if [[ $SPDK_TEST_FUZZER -eq 1 ]]; then
# if we are testing nvmf fuzz with llvm lib, --with-shared will cause lib link fail
./configure $config_params
else
# if we aren't testing the unittests, build with shared objects.
./configure $config_params --with-shared
fi
run_test "make" $MAKE $MAKEFLAGS
fi

View File

@ -103,6 +103,8 @@ export SPDK_TEST_NVMF
export SPDK_TEST_VFIOUSER
: ${SPDK_TEST_VFIOUSER_QEMU=0}
export SPDK_TEST_VFIOUSER_QEMU
: ${SPDK_TEST_FUZZER=0}
export SPDK_TEST_FUZZER
: ${SPDK_TEST_NVMF_TRANSPORT="rdma"}
export SPDK_TEST_NVMF_TRANSPORT
: ${SPDK_TEST_RBD=0}

View File

@ -48,6 +48,9 @@ vmd_hello_world
vmd_identify
vmd_perf
# nvmf llvm fuzz build configuration
autobuild_llvm_precompile
# nightly tests
bdev_fio_rw_verify_ext
bdev_fio_trim_ext
@ -66,6 +69,7 @@ iscsi_tgt_fuzz
nvmf_fuzz
nvmf_multiconnection
nvmf_initiator_timeout
nvmf_llvm_fuzz
vhost_blk_cores_2ctrl
vhost_blk_fs_integrity
vhost_blk_integrity

View File

@ -48,6 +48,9 @@ if [ $RUN_NIGHTLY -eq 1 ]; then
run_test "nvmf_fuzz" test/nvmf/target/fabrics_fuzz.sh "${TEST_ARGS[@]}"
run_test "nvmf_multiconnection" test/nvmf/target/multiconnection.sh "${TEST_ARGS[@]}"
run_test "nvmf_initiator_timeout" test/nvmf/target/initiator_timeout.sh "${TEST_ARGS[@]}"
if [ $SPDK_TEST_FUZZER -eq 1 ]; then
run_test "nvmf_llvm_fuzz" test/nvmf/target/llvm_nvme_fuzz.sh "${TEST_ARGS[@]}" "--time=60000" "--all"
fi
fi
run_test "nvmf_nmic" test/nvmf/target/nmic.sh "${TEST_ARGS[@]}"

View File

@ -1,27 +1,64 @@
#!/usr/bin/env bash
TIME=10
FUZZER=0
RUN_ALL=0
for i in "$@"; do
case "$i" in
--time=*)
TIME="${i#*=}"
;;
--fuzzer=*)
FUZZER="${i#*=}"
--all)
RUN_ALL=1
;;
esac
done
function start_llvm_fuzz() {
local fuzzer_type=$1
local corpus_dir
corpus_dir=/tmp/llvm_fuzz$fuzzer_type
mkdir -p $corpus_dir
$rootdir/test/app/fuzz/llvm_nvme_fuzz/llvm_nvme_fuzz -m 0x1 -i 0 -F "$trid" -c $testdir/fuzz_json.conf -t $TIME -D $corpus_dir -Z $fuzzer_type
}
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
start_llvm_fuzz $fuzzer_type
}
testdir=$(readlink -f $(dirname $0))
rootdir=$(readlink -f $testdir/../../..)
source $rootdir/test/common/autotest_common.sh
trap 'process_shm --id 0; exit 1' SIGINT SIGTERM EXIT
fuzzfile=$rootdir/test/app/fuzz/llvm_nvme_fuzz/llvm_nvme_fuzz.c
fuzz_num=$(($(grep -c "fn =" $fuzzfile) - 1))
[[ $fuzz_num -ne 0 ]]
trap 'process_shm --id 0; rm -rf /tmp/llvm_fuzz*; exit 1' SIGINT SIGTERM EXIT
mkdir -p /tmp/corpus$FUZZER
trid="trtype:tcp adrfam:IPv4 subnqn:nqn.2016-06.io.spdk:cnode1 traddr:127.0.0.1 trsvcid:4420"
$rootdir/test/app/fuzz/llvm_nvme_fuzz/llvm_nvme_fuzz -m 0x1 -i 0 -F "$trid" -c $testdir/fuzz_json.conf -t $TIME -D /tmp/corpus$FUZZER -Z $FUZZER
if [[ $RUN_ALL -eq 1 ]]; then
run_fuzz
else
start_llvm_fuzz $1
fi
rm -rf /tmp/llvm_fuzz*
trap - SIGINT SIGTERM EXIT