1#!/usr/bin/env bash 2# SPDX-License-Identifier: BSD-3-Clause 3# Copyright (C) 2016 Intel Corporation 4# Copyright (c) 2022, 2023 NVIDIA CORPORATION & AFFILIATES. 5# All rights reserved. 6# 7testdir=$(readlink -f $(dirname $0)) 8rootdir=$(readlink -f $testdir/../..) 9source $rootdir/test/common/autotest_common.sh 10source $testdir/nbd_common.sh 11 12# nullglob will remove unmatched words containing '*', '?', '[' characters during word splitting. 13# This means that empty alias arrays will be removed instead of printing "[]", which breaks 14# consecutive "jq" calls, as the "aliases" key will have no value and the whole JSON will be 15# invalid. Hence do not enable this option for the duration of the tests in this script. 16shopt -s extglob 17 18rpc_py=rpc_cmd 19conf_file="$testdir/bdev.json" 20nonenclosed_conf_file="$testdir/nonenclosed.json" 21nonarray_conf_file="$testdir/nonarray.json" 22 23# Make sure the configuration is clean 24: > "$conf_file" 25 26function cleanup() { 27 rm -f "$SPDK_TEST_STORAGE/aiofile" 28 rm -f "$conf_file" 29 30 if [[ $test_type == rbd ]]; then 31 rbd_cleanup 32 fi 33 34 if [[ $test_type == daos ]]; then 35 daos_cleanup 36 fi 37 38 if [[ "$test_type" = "gpt" ]]; then 39 "$rootdir/scripts/setup.sh" reset 40 if [[ -b $gpt_nvme ]]; then 41 wipefs --all "$gpt_nvme" 42 fi 43 fi 44 if [[ $test_type == xnvme ]]; then 45 "$rootdir/scripts/setup.sh" 46 fi 47} 48 49function start_spdk_tgt() { 50 "$SPDK_BIN_DIR/spdk_tgt" "$env_ctx" "$wait_for_rpc" & 51 spdk_tgt_pid=$! 52 trap 'killprocess "$spdk_tgt_pid"; exit 1' SIGINT SIGTERM EXIT 53 waitforlisten "$spdk_tgt_pid" 54} 55 56function setup_bdev_conf() { 57 "$rpc_py" <<- RPC 58 bdev_split_create Malloc1 2 59 bdev_split_create -s 4 Malloc2 8 60 bdev_malloc_create -b Malloc0 32 512 61 bdev_malloc_create -b Malloc1 32 512 62 bdev_malloc_create -b Malloc2 32 512 63 bdev_malloc_create -b Malloc3 32 512 64 bdev_malloc_create -b Malloc4 32 512 65 bdev_malloc_create -b Malloc5 32 512 66 bdev_malloc_create -b Malloc6 32 512 67 bdev_malloc_create -b Malloc7 32 512 68 bdev_passthru_create -p TestPT -b Malloc3 69 bdev_raid_create -n raid0 -z 64 -r 0 -b "Malloc4 Malloc5" 70 bdev_raid_create -n concat0 -z 64 -r concat -b "Malloc6 Malloc7" 71 bdev_set_qos_limit --rw_mbytes_per_sec 100 Malloc3 72 bdev_set_qos_limit --rw_ios_per_sec 20000 Malloc0 73 RPC 74 if [[ $(uname -s) != "FreeBSD" ]]; then 75 dd if=/dev/zero of="$SPDK_TEST_STORAGE/aiofile" bs=2048 count=5000 76 "$rpc_py" bdev_aio_create "$SPDK_TEST_STORAGE/aiofile" AIO0 2048 77 fi 78} 79 80function setup_nvme_conf() { 81 local json 82 mapfile -t json < <("$rootdir/scripts/gen_nvme.sh") 83 "$rpc_py" load_subsystem_config -j "'${json[*]}'" 84} 85 86function setup_xnvme_conf() { 87 # TODO: Switch to io_uring_cmd when proper CI support is in place 88 local io_mechanism=io_uring 89 local nvme nvmes 90 91 "$rootdir/scripts/setup.sh" reset 92 get_zoned_devs 93 94 for nvme in /dev/nvme*n*; do 95 [[ -b $nvme && -z ${zoned_devs["${nvme##*/}"]} ]] || continue 96 nvmes+=("bdev_xnvme_create $nvme ${nvme##*/} $io_mechanism") 97 done 98 99 ((${#nvmes[@]} > 0)) 100 "$rpc_py" < <(printf '%s\n' "${nvmes[@]}") 101} 102 103function setup_gpt_conf() { 104 $rootdir/scripts/setup.sh reset 105 get_zoned_devs 106 # Get nvme devices by following drivers' links towards nvme class 107 local nvme_devs=(/sys/bus/pci/drivers/nvme/*/nvme/nvme*/nvme*n*) nvme_dev 108 gpt_nvme="" 109 # Pick first device which doesn't have any valid partition table 110 for nvme_dev in "${nvme_devs[@]}"; do 111 [[ -z ${zoned_devs["${nvme_dev##*/}"]} ]] || continue 112 dev=/dev/${nvme_dev##*/} 113 if ! pt=$(parted "$dev" -ms print 2>&1); then 114 [[ $pt == *"$dev: unrecognised disk label"* ]] || continue 115 gpt_nvme=$dev 116 break 117 fi 118 done 119 if [[ -n $gpt_nvme ]]; then 120 # These Unique Partition GUIDs were randomly generated for testing and are distinct 121 # from the Partition Type GUIDs (SPDK_GPT_OLD_GUID and SPDK_GPT_GUID) which have 122 # special meaning to SPDK. See section 5.3.3 of UEFI Spec 2.3 for the distinction 123 # between Unique Partition GUID and Partition Type GUID. 124 typeset -g g_unique_partguid=6f89f330-603b-4116-ac73-2ca8eae53030 125 typeset -g g_unique_partguid_old=abf1734f-66e5-4c0f-aa29-4021d4d307df 126 127 # Create gpt partition table 128 parted -s "$gpt_nvme" mklabel gpt mkpart SPDK_TEST_first '0%' '50%' mkpart SPDK_TEST_second '50%' '100%' 129 # Change the partition type GUIDs to SPDK partition type values 130 SPDK_GPT_OLD_GUID=$(get_spdk_gpt_old) 131 SPDK_GPT_GUID=$(get_spdk_gpt) 132 sgdisk -t "1:$SPDK_GPT_GUID" -u "1:$g_unique_partguid" "$gpt_nvme" 133 sgdisk -t "2:$SPDK_GPT_OLD_GUID" -u "2:$g_unique_partguid_old" "$gpt_nvme" 134 "$rootdir/scripts/setup.sh" 135 "$rpc_py" bdev_get_bdevs 136 setup_nvme_conf 137 else 138 printf 'Did not find any nvme block devices to work with, aborting the test\n' >&2 139 "$rootdir/scripts/setup.sh" 140 return 1 141 fi 142} 143 144function setup_crypto_aesni_conf() { 145 # Malloc0 and Malloc1 use AESNI 146 "$rpc_py" <<- RPC 147 dpdk_cryptodev_scan_accel_module 148 dpdk_cryptodev_set_driver -d crypto_aesni_mb 149 accel_assign_opc -o encrypt -m dpdk_cryptodev 150 accel_assign_opc -o decrypt -m dpdk_cryptodev 151 framework_start_init 152 accel_crypto_key_create -c AES_CBC -k 01234567891234560123456789123456 -n test_dek_aesni_cbc_1 153 accel_crypto_key_create -c AES_CBC -k 12345678912345601234567891234560 -n test_dek_aesni_cbc_2 154 accel_crypto_key_create -c AES_CBC -k 23456789123456012345678912345601 -n test_dek_aesni_cbc_3 155 accel_crypto_key_create -c AES_CBC -k 34567891234560123456789123456012 -n test_dek_aesni_cbc_4 156 bdev_malloc_create -b Malloc0 32 512 157 bdev_malloc_create -b Malloc1 32 512 158 bdev_malloc_create -b Malloc2 32 4096 159 bdev_malloc_create -b Malloc3 32 4096 160 bdev_crypto_create Malloc0 crypto_ram -n test_dek_aesni_cbc_1 161 bdev_crypto_create Malloc1 crypto_ram2 -n test_dek_aesni_cbc_2 162 bdev_crypto_create Malloc2 crypto_ram3 -n test_dek_aesni_cbc_3 163 bdev_crypto_create Malloc3 crypto_ram4 -n test_dek_aesni_cbc_4 164 RPC 165} 166 167function setup_crypto_qat_conf() { 168 # Malloc0 will use QAT AES_CBC 169 # Malloc1 will use QAT AES_XTS 170 "$rpc_py" <<- RPC 171 dpdk_cryptodev_scan_accel_module 172 dpdk_cryptodev_set_driver -d crypto_qat 173 accel_assign_opc -o encrypt -m dpdk_cryptodev 174 accel_assign_opc -o decrypt -m dpdk_cryptodev 175 framework_start_init 176 accel_crypto_key_create -c AES_CBC -k 01234567891234560123456789123456 -n test_dek_qat_cbc 177 accel_crypto_key_create -c AES_XTS -k 00112233445566778899001122334455 -e 12345678912345601234567891234560 -n test_dek_qat_xts 178 accel_crypto_key_create -c AES_CBC -k 23456789123456012345678912345601 -n test_dek_qat_cbc2 179 accel_crypto_key_create -c AES_XTS -k 22334455667788990011223344550011 -e 34567891234560123456789123456012 -n test_dek_qat_xts2 180 bdev_malloc_create -b Malloc0 32 512 181 bdev_malloc_create -b Malloc1 32 512 182 bdev_malloc_create -b Malloc2 32 4096 183 bdev_malloc_create -b Malloc3 32 4096 184 bdev_crypto_create Malloc0 crypto_ram -n test_dek_qat_cbc 185 bdev_crypto_create Malloc1 crypto_ram1 -n test_dek_qat_xts 186 bdev_crypto_create Malloc2 crypto_ram2 -n test_dek_qat_cbc2 187 bdev_crypto_create Malloc3 crypto_ram3 -n test_dek_qat_xts2 188 bdev_get_bdevs -b Malloc1 189 RPC 190} 191 192function setup_crypto_sw_conf() { 193 "$rpc_py" <<- RPC 194 framework_start_init 195 bdev_malloc_create -b Malloc0 16 512 196 bdev_malloc_create -b Malloc1 16 4096 197 accel_crypto_key_create -c AES_XTS -k 00112233445566778899001122334455 -e 11223344556677889900112233445500 -n test_dek_sw 198 accel_crypto_key_create -c AES_XTS -k 22334455667788990011223344550011 -e 33445566778899001122334455001122 -n test_dek_sw2 199 accel_crypto_key_create -c AES_XTS -k 33445566778899001122334455001122 -e 44556677889900112233445500112233 -n test_dek_sw3 200 bdev_crypto_create Malloc0 crypto_ram -n test_dek_sw 201 bdev_crypto_create Malloc1 crypto_ram2 -n test_dek_sw2 202 bdev_crypto_create crypto_ram2 crypto_ram3 -n test_dek_sw3 203 bdev_get_bdevs -b Malloc1 204 RPC 205} 206 207function setup_crypto_accel_mlx5_conf() { 208 "$rpc_py" <<- RPC 209 mlx5_scan_accel_module 210 accel_assign_opc -o encrypt -m mlx5 211 accel_assign_opc -o decrypt -m mlx5 212 framework_start_init 213 bdev_malloc_create -b Malloc0 32 512 214 bdev_malloc_create -b Malloc1 32 512 215 bdev_malloc_create -b Malloc2 32 4096 216 bdev_malloc_create -b Malloc3 32 4096 217 accel_crypto_key_create -c AES_XTS -k 00112233445566778899001122334455 -e 11223344556677889900112233445500 -n test_dek_accel_mlx5_1 218 accel_crypto_key_create -c AES_XTS -k 11223344556677889900112233445500 -e 22334455667788990011223344550011 -n test_dek_accel_mlx5_2 219 accel_crypto_key_create -c AES_XTS -k 22334455667788990011223344550011 -e 33445566778899001122334455002233 -n test_dek_accel_mlx5_3 220 accel_crypto_key_create -c AES_XTS -k 33445566778899001122334455001122 -e 44556677889900112233445500112233 -n test_dek_accel_mlx5_4 221 bdev_crypto_create Malloc0 crypto_ram_1 -n test_dek_accel_mlx5_1 222 bdev_crypto_create Malloc1 crypto_ram_2 -n test_dek_accel_mlx5_2 223 bdev_crypto_create Malloc2 crypto_ram_3 -n test_dek_accel_mlx5_3 224 bdev_crypto_create Malloc3 crypto_ram_4 -n test_dek_accel_mlx5_4 225 bdev_get_bdevs -b Malloc1 226 RPC 227} 228 229function setup_crypto_mlx5_conf() { 230 local key=$1 231 local block_key 232 local tweak_key 233 if [ ${#key} == 96 ]; then 234 # 96 bytes is 64 + 32 - AES_XTS_256 in hexlified format 235 # Copy first 64 chars into the 'key'. This gives 32 in the 236 # binary or 256 bit. 237 block_key=${key:0:64} 238 # Copy the the rest of the key and pass it as the 'key2'. 239 tweak_key=${key:64:32} 240 elif [ ${#key} == 160 ]; then 241 # 160 bytes is 128 + 32 - AES_XTS_512 in hexlified format 242 # Copy first 128 chars into the 'key'. This gives 64 in the 243 # binary or 512 bit. 244 block_key=${key:0:128} 245 # Copy the the rest of the key and pass it as the 'key2'. 246 tweak_key=${key:128:32} 247 else 248 echo "ERROR: Invalid DEK size for MLX5 crypto setup: ${#key}" 249 echo "ERROR: Supported key sizes for MLX5: 96 bytes (AES_XTS_256) and 160 bytes (AES_XTS_512)." 250 return 1 251 fi 252 253 # Malloc0 will use MLX5 AES_XTS 254 "$rootdir/scripts/rpc.py" <<- RPC 255 dpdk_cryptodev_scan_accel_module 256 dpdk_cryptodev_set_driver -d mlx5_pci 257 accel_assign_opc -o encrypt -m dpdk_cryptodev 258 accel_assign_opc -o decrypt -m dpdk_cryptodev 259 framework_start_init 260 bdev_malloc_create -b Malloc0 16 512 261 bdev_crypto_create Malloc0 crypto_ram4 -k $block_key -c AES_XTS -k2 $tweak_key 262 bdev_get_bdevs -b Malloc0 263 RPC 264} 265 266function setup_rbd_conf() { 267 timing_enter rbd_setup 268 rbd_setup 127.0.0.1 269 timing_exit rbd_setup 270 271 "$rpc_py" bdev_rbd_create -b Ceph0 rbd foo 512 272} 273 274function setup_daos_conf() { 275 local pool=testpool 276 local cont=testcont 277 278 timing_enter daos_setup 279 daos_setup $pool $cont 280 timing_exit daos_setup 281 282 "$rpc_py" bdev_daos_create Daos0 $pool $cont 16 4096 283} 284 285function setup_raid5f_conf() { 286 "$rpc_py" <<- RPC 287 bdev_malloc_create -b Malloc0 32 512 288 bdev_malloc_create -b Malloc1 32 512 289 bdev_malloc_create -b Malloc2 32 512 290 bdev_raid_create -n raid5f -z 2 -r 5f -b "Malloc0 Malloc1 Malloc2" 291 RPC 292} 293 294function bdev_bounds() { 295 $testdir/bdevio/bdevio -w -s $PRE_RESERVED_MEM --json "$conf_file" "$env_ctx" & 296 bdevio_pid=$! 297 trap 'cleanup; killprocess $bdevio_pid; exit 1' SIGINT SIGTERM EXIT 298 echo "Process bdevio pid: $bdevio_pid" 299 waitforlisten $bdevio_pid 300 $testdir/bdevio/tests.py perform_tests 301 killprocess $bdevio_pid 302 trap - SIGINT SIGTERM EXIT 303} 304 305function nbd_function_test() { 306 [[ $(uname -s) == Linux ]] || return 0 307 308 local rpc_server=/var/tmp/spdk-nbd.sock 309 local conf=$1 310 local bdev_all=($2) 311 local bdev_num=${#bdev_all[@]} 312 313 # FIXME: Centos7 in the CI is not shipped with a kernel supporting BLK_DEV_NBD 314 # so don't fail here for now. 315 [[ -e /sys/module/nbd ]] || modprobe -q nbd nbds_max=$bdev_num || return 0 316 317 local nbd_all=(/dev/nbd+([0-9])) 318 bdev_num=$((${#nbd_all[@]} < bdev_num ? ${#nbd_all[@]} : bdev_num)) 319 320 local nbd_list=(${nbd_all[@]::bdev_num}) 321 local bdev_list=(${bdev_all[@]::bdev_num}) 322 323 $rootdir/test/app/bdev_svc/bdev_svc -r $rpc_server -i 0 --json "$conf" "$env_ctx" & 324 nbd_pid=$! 325 trap 'cleanup; killprocess $nbd_pid' SIGINT SIGTERM EXIT 326 waitforlisten $nbd_pid $rpc_server 327 328 nbd_rpc_start_stop_verify $rpc_server "${bdev_list[*]}" 329 nbd_rpc_data_verify $rpc_server "${bdev_list[*]}" "${nbd_list[*]}" 330 nbd_with_lvol_verify $rpc_server "${nbd_list[*]}" 331 332 killprocess $nbd_pid 333 trap - SIGINT SIGTERM EXIT 334} 335 336function fio_test_suite() { 337 local env_context 338 339 # Make sure that state files and anything else produced by fio test will 340 # stay at the testdir. 341 pushd $testdir 342 trap 'rm -f ./*.state; popd; exit 1' SIGINT SIGTERM EXIT 343 344 # Generate the fio config file given the list of all unclaimed bdevs 345 env_context=$(echo "$env_ctx" | sed 's/--env-context=//') 346 fio_config_gen $testdir/bdev.fio verify AIO "$env_context" 347 for b in $(echo $bdevs | jq -r '.name'); do 348 echo "[job_$b]" >> $testdir/bdev.fio 349 echo "filename=$b" >> $testdir/bdev.fio 350 done 351 352 local fio_params="--ioengine=spdk_bdev --iodepth=8 --bs=4k --runtime=10 $testdir/bdev.fio \ 353 --verify_state_save=0 --spdk_json_conf=$conf_file" 354 355 run_test "bdev_fio_rw_verify" fio_bdev $fio_params --spdk_mem=$PRE_RESERVED_MEM --aux-path=$output_dir 356 rm -f ./*.state 357 rm -f $testdir/bdev.fio 358 359 # Generate the fio config file given the list of all unclaimed bdevs that support unmap 360 fio_config_gen $testdir/bdev.fio trim "" "$env_context" 361 if [ "$(echo $bdevs | jq -r 'select(.supported_io_types.unmap == true) | .name')" != "" ]; then 362 for b in $(echo $bdevs | jq -r 'select(.supported_io_types.unmap == true) | .name'); do 363 echo "[job_$b]" >> $testdir/bdev.fio 364 echo "filename=$b" >> $testdir/bdev.fio 365 done 366 else 367 rm -f $testdir/bdev.fio 368 popd 369 trap - SIGINT SIGTERM EXIT 370 return 0 371 fi 372 373 run_test "bdev_fio_trim" fio_bdev $fio_params --verify_state_save=0 --aux-path=$output_dir 374 rm -f ./*.state 375 rm -f $testdir/bdev.fio 376 popd 377 trap - SIGINT SIGTERM EXIT 378} 379 380function get_io_result() { 381 local limit_type=$1 382 local qos_dev=$2 383 local iostat_result 384 iostat_result=$($rootdir/scripts/iostat.py -d -i 1 -t $QOS_RUN_TIME | grep $qos_dev | tail -1) 385 if [ $limit_type = IOPS ]; then 386 iostat_result=$(awk '{print $2}' <<< $iostat_result) 387 elif [ $limit_type = BANDWIDTH ]; then 388 iostat_result=$(awk '{print $6}' <<< $iostat_result) 389 fi 390 391 echo ${iostat_result/.*/} 392} 393 394function run_qos_test() { 395 local qos_limit=$1 396 local qos_result=0 397 398 qos_result=$(get_io_result $2 $3) 399 if [ $2 = BANDWIDTH ]; then 400 qos_limit=$((qos_limit * 1024)) 401 fi 402 lower_limit=$((qos_limit * 9 / 10)) 403 upper_limit=$((qos_limit * 11 / 10)) 404 405 # QoS realization is related with bytes transferred. It currently has some variation. 406 if [ $qos_result -lt $lower_limit ] || [ $qos_result -gt $upper_limit ]; then 407 echo "Failed to limit the io read rate of NULL bdev by qos" 408 $rpc_py bdev_malloc_delete $QOS_DEV_1 409 $rpc_py bdev_null_delete $QOS_DEV_2 410 killprocess $QOS_PID 411 exit 1 412 fi 413} 414 415function qos_function_test() { 416 local qos_lower_iops_limit=1000 417 local qos_lower_bw_limit=2 418 local io_result=0 419 local iops_limit=0 420 local bw_limit=0 421 422 io_result=$(get_io_result IOPS $QOS_DEV_1) 423 # Set the IOPS limit as one quarter of the measured performance without QoS 424 iops_limit=$(((io_result / 4) / qos_lower_iops_limit * qos_lower_iops_limit)) 425 if [ $iops_limit -gt $qos_lower_iops_limit ]; then 426 427 # Run bdevperf with IOPS rate limit on bdev 1 428 $rpc_py bdev_set_qos_limit --rw_ios_per_sec $iops_limit $QOS_DEV_1 429 run_test "bdev_qos_iops" run_qos_test $iops_limit IOPS $QOS_DEV_1 430 431 # Run bdevperf with bandwidth rate limit on bdev 2 432 # Set the bandwidth limit as 1/10 of the measure performance without QoS 433 bw_limit=$(get_io_result BANDWIDTH $QOS_DEV_2) 434 bw_limit=$((bw_limit / 1024 / 10)) 435 if [ $bw_limit -lt $qos_lower_bw_limit ]; then 436 bw_limit=$qos_lower_bw_limit 437 fi 438 $rpc_py bdev_set_qos_limit --rw_mbytes_per_sec $bw_limit $QOS_DEV_2 439 run_test "bdev_qos_bw" run_qos_test $bw_limit BANDWIDTH $QOS_DEV_2 440 441 # Run bdevperf with additional read only bandwidth rate limit on bdev 1 442 $rpc_py bdev_set_qos_limit --r_mbytes_per_sec $qos_lower_bw_limit $QOS_DEV_1 443 run_test "bdev_qos_ro_bw" run_qos_test $qos_lower_bw_limit BANDWIDTH $QOS_DEV_1 444 else 445 echo "Actual IOPS without limiting is too low - exit testing" 446 fi 447} 448 449function qos_test_suite() { 450 # Run bdevperf with QoS disabled first 451 "$rootdir/build/examples/bdevperf" -z -m 0x2 -q 256 -o 4096 -w randread -t 60 "$env_ctx" & 452 QOS_PID=$! 453 echo "Process qos testing pid: $QOS_PID" 454 trap 'cleanup; killprocess $QOS_PID; exit 1' SIGINT SIGTERM EXIT 455 waitforlisten $QOS_PID 456 457 $rpc_py bdev_malloc_create -b $QOS_DEV_1 128 512 458 waitforbdev $QOS_DEV_1 459 $rpc_py bdev_null_create $QOS_DEV_2 128 512 460 waitforbdev $QOS_DEV_2 461 462 $rootdir/examples/bdev/bdevperf/bdevperf.py perform_tests & 463 qos_function_test 464 465 $rpc_py bdev_malloc_delete $QOS_DEV_1 466 $rpc_py bdev_null_delete $QOS_DEV_2 467 killprocess $QOS_PID 468 trap - SIGINT SIGTERM EXIT 469} 470 471function error_test_suite() { 472 DEV_1="Dev_1" 473 DEV_2="Dev_2" 474 ERR_DEV="EE_Dev_1" 475 476 # Run bdevperf with 1 normal bdev and 1 error bdev, also continue on error 477 "$rootdir/build/examples/bdevperf" -z -m 0x2 -q 16 -o 4096 -w randread -t 5 -f "$env_ctx" & 478 ERR_PID=$! 479 echo "Process error testing pid: $ERR_PID" 480 waitforlisten $ERR_PID 481 482 $rpc_py bdev_malloc_create -b $DEV_1 128 512 483 waitforbdev $DEV_1 484 $rpc_py bdev_error_create $DEV_1 485 $rpc_py bdev_malloc_create -b $DEV_2 128 512 486 waitforbdev $DEV_2 487 $rpc_py bdev_error_inject_error $ERR_DEV 'all' 'failure' -n 5 488 489 $rootdir/examples/bdev/bdevperf/bdevperf.py -t 1 perform_tests & 490 sleep 1 491 492 # Bdevperf is expected to be there as the continue on error is set 493 if kill -0 $ERR_PID; then 494 echo "Process is existed as continue on error is set. Pid: $ERR_PID" 495 else 496 echo "Process exited unexpectedly. Pid: $ERR_PID" 497 exit 1 498 fi 499 500 # Delete the error devices 501 $rpc_py bdev_error_delete $ERR_DEV 502 $rpc_py bdev_malloc_delete $DEV_1 503 sleep 5 504 # Expected to exit normally 505 killprocess $ERR_PID 506 507 # Run bdevperf with 1 normal bdev and 1 error bdev, and exit on error 508 "$rootdir/build/examples/bdevperf" -z -m 0x2 -q 16 -o 4096 -w randread -t 5 "$env_ctx" & 509 ERR_PID=$! 510 echo "Process error testing pid: $ERR_PID" 511 waitforlisten $ERR_PID 512 513 $rpc_py bdev_malloc_create -b $DEV_1 128 512 514 waitforbdev $DEV_1 515 $rpc_py bdev_error_create $DEV_1 516 $rpc_py bdev_malloc_create -b $DEV_2 128 512 517 waitforbdev $DEV_2 518 $rpc_py bdev_error_inject_error $ERR_DEV 'all' 'failure' -n 5 519 520 $rootdir/examples/bdev/bdevperf/bdevperf.py -t 1 perform_tests & 521 NOT wait $ERR_PID 522} 523 524function qd_sampling_function_test() { 525 local bdev_name=$1 526 local sampling_period=10 527 local iostats 528 529 $rpc_py bdev_set_qd_sampling_period $bdev_name $sampling_period 530 531 iostats=$($rpc_py bdev_get_iostat -b $bdev_name) 532 533 qd_sampling_period=$(jq -r '.bdevs[0].queue_depth_polling_period' <<< "$iostats") 534 535 if [ $qd_sampling_period == null ] || [ $qd_sampling_period -ne $sampling_period ]; then 536 echo "Qeueue depth polling period is not right" 537 $rpc_py bdev_malloc_delete $QD_DEV 538 killprocess $QD_PID 539 exit 1 540 fi 541} 542 543function qd_sampling_test_suite() { 544 QD_DEV="Malloc_QD" 545 546 "$rootdir/build/examples/bdevperf" -z -m 0x3 -q 256 -o 4096 -w randread -t 5 -C "$env_ctx" & 547 QD_PID=$! 548 echo "Process bdev QD sampling period testing pid: $QD_PID" 549 trap 'cleanup; killprocess $QD_PID; exit 1' SIGINT SIGTERM EXIT 550 waitforlisten $QD_PID 551 552 $rpc_py bdev_malloc_create -b $QD_DEV 128 512 553 waitforbdev $QD_DEV 554 555 $rootdir/examples/bdev/bdevperf/bdevperf.py perform_tests & 556 sleep 2 557 qd_sampling_function_test $QD_DEV 558 559 $rpc_py bdev_malloc_delete $QD_DEV 560 killprocess $QD_PID 561 trap - SIGINT SIGTERM EXIT 562} 563 564function stat_function_test() { 565 local bdev_name=$1 566 local iostats 567 local io_count1 568 local io_count2 569 local iostats_per_channel 570 local io_count_per_channel1 571 local io_count_per_channel2 572 local io_count_per_channel_all=0 573 574 iostats=$($rpc_py bdev_get_iostat -b $bdev_name) 575 io_count1=$(jq -r '.bdevs[0].num_read_ops' <<< "$iostats") 576 577 iostats_per_channel=$($rpc_py bdev_get_iostat -b $bdev_name -c) 578 io_count_per_channel1=$(jq -r '.channels[0].num_read_ops' <<< "$iostats_per_channel") 579 io_count_per_channel_all=$((io_count_per_channel_all + io_count_per_channel1)) 580 io_count_per_channel2=$(jq -r '.channels[1].num_read_ops' <<< "$iostats_per_channel") 581 io_count_per_channel_all=$((io_count_per_channel_all + io_count_per_channel2)) 582 583 iostats=$($rpc_py bdev_get_iostat -b $bdev_name) 584 io_count2=$(jq -r '.bdevs[0].num_read_ops' <<< "$iostats") 585 586 # There is little time passed between the three iostats collected. So that 587 # the accumulated statistics from per channel data shall be bigger than the 588 # the first run and smaller than the third run in this short time of period. 589 if [ $io_count_per_channel_all -lt $io_count1 ] || [ $io_count_per_channel_all -gt $io_count2 ]; then 590 echo "Failed to collect the per Core IO statistics" 591 $rpc_py bdev_malloc_delete $STAT_DEV 592 killprocess $STAT_PID 593 exit 1 594 fi 595} 596 597function stat_test_suite() { 598 STAT_DEV="Malloc_STAT" 599 600 # Run bdevperf with 2 cores so as to collect per Core IO statistics 601 "$rootdir/build/examples/bdevperf" -z -m 0x3 -q 256 -o 4096 -w randread -t 10 -C "$env_ctx" & 602 STAT_PID=$! 603 echo "Process Bdev IO statistics testing pid: $STAT_PID" 604 trap 'cleanup; killprocess $STAT_PID; exit 1' SIGINT SIGTERM EXIT 605 waitforlisten $STAT_PID 606 607 $rpc_py bdev_malloc_create -b $STAT_DEV 128 512 608 waitforbdev $STAT_DEV 609 610 $rootdir/examples/bdev/bdevperf/bdevperf.py perform_tests & 611 sleep 2 612 stat_function_test $STAT_DEV 613 614 $rpc_py bdev_malloc_delete $STAT_DEV 615 killprocess $STAT_PID 616 trap - SIGINT SIGTERM EXIT 617} 618 619function bdev_gpt_uuid() { 620 local bdev 621 622 start_spdk_tgt 623 624 "$rpc_py" load_config -j "$conf_file" 625 "$rpc_py" bdev_wait_for_examine 626 627 bdev=$("$rpc_py" bdev_get_bdevs -b "$g_unique_partguid") 628 [[ "$(jq -r 'length' <<< "$bdev")" == "1" ]] 629 [[ "$(jq -r '.[0].aliases[0]' <<< "$bdev")" == "$g_unique_partguid" ]] 630 [[ "$(jq -r '.[0].driver_specific.gpt.unique_partition_guid' <<< "$bdev")" == "$g_unique_partguid" ]] 631 632 bdev=$("$rpc_py" bdev_get_bdevs -b "$g_unique_partguid_old") 633 [[ "$(jq -r 'length' <<< "$bdev")" == "1" ]] 634 [[ "$(jq -r '.[0].aliases[0]' <<< "$bdev")" == "$g_unique_partguid_old" ]] 635 [[ "$(jq -r '.[0].driver_specific.gpt.unique_partition_guid' <<< "$bdev")" == "$g_unique_partguid_old" ]] 636 637 killprocess "$spdk_tgt_pid" 638} 639 640# Initial bdev creation and configuration 641#----------------------------------------------------- 642QOS_DEV_1="Malloc_0" 643QOS_DEV_2="Null_1" 644QOS_RUN_TIME=5 645 646if [ $(uname -s) = Linux ]; then 647 # Test dynamic memory management. All hugepages will be reserved at runtime 648 PRE_RESERVED_MEM=0 649else 650 # Dynamic memory management is not supported on BSD 651 PRE_RESERVED_MEM=2048 652fi 653 654test_type=${1:-bdev} 655crypto_device=$2 656wcs_file=$3 657dek=$4 658env_ctx="" 659wait_for_rpc="" 660if [ -n "$crypto_device" ] && [ -n "$wcs_file" ]; then 661 # We need full path here since fio perf test does 'pushd' to the test dir 662 # and crypto login of fio plugin test can fail. 663 wcs_file=$(readlink -f $wcs_file) 664 if [ -f $wcs_file ]; then 665 env_ctx="--env-context=--allow=$crypto_device,class=crypto,wcs_file=$wcs_file" 666 else 667 echo "ERROR: Credentials file $3 is not found!" 668 exit 1 669 fi 670fi 671if [[ $test_type == crypto_* ]]; then 672 wait_for_rpc="--wait-for-rpc" 673fi 674start_spdk_tgt 675case "$test_type" in 676 bdev) 677 setup_bdev_conf 678 ;; 679 nvme) 680 setup_nvme_conf 681 ;; 682 gpt) 683 setup_gpt_conf 684 ;; 685 crypto_aesni) 686 setup_crypto_aesni_conf 687 ;; 688 crypto_qat) 689 setup_crypto_qat_conf 690 ;; 691 crypto_sw) 692 setup_crypto_sw_conf 693 ;; 694 crypto_mlx5) 695 setup_crypto_mlx5_conf $dek 696 ;; 697 crypto_accel_mlx5) 698 setup_crypto_accel_mlx5_conf 699 ;; 700 rbd) 701 setup_rbd_conf 702 ;; 703 daos) 704 setup_daos_conf 705 ;; 706 raid5f) 707 setup_raid5f_conf 708 ;; 709 xnvme) 710 setup_xnvme_conf 711 ;; 712 *) 713 echo "invalid test name" 714 exit 1 715 ;; 716esac 717 718"$rpc_py" bdev_wait_for_examine 719 720# Generate json config and use it throughout all the tests 721cat <<- CONF > "$conf_file" 722 {"subsystems":[ 723 $("$rpc_py" save_subsystem_config -n accel), 724 $("$rpc_py" save_subsystem_config -n bdev) 725 ]} 726CONF 727 728bdevs=$("$rpc_py" bdev_get_bdevs | jq -r '.[] | select(.claimed == false)') 729bdevs_name=$(echo $bdevs | jq -r '.name') 730bdev_list=($bdevs_name) 731 732hello_world_bdev=${bdev_list[0]} 733trap - SIGINT SIGTERM EXIT 734killprocess "$spdk_tgt_pid" 735# End bdev configuration 736#----------------------------------------------------- 737 738trap "cleanup" SIGINT SIGTERM EXIT 739 740run_test "bdev_hello_world" $SPDK_EXAMPLE_DIR/hello_bdev --json "$conf_file" -b "$hello_world_bdev" "$env_ctx" 741run_test "bdev_bounds" bdev_bounds "$env_ctx" 742run_test "bdev_nbd" nbd_function_test $conf_file "$bdevs_name" "$env_ctx" 743if [[ $CONFIG_FIO_PLUGIN == y ]]; then 744 if [ "$test_type" = "nvme" ] || [ "$test_type" = "gpt" ]; then 745 # TODO: once we get real multi-ns drives, re-enable this test for NVMe. 746 echo "skipping fio tests on NVMe due to multi-ns failures." 747 else 748 run_test "bdev_fio" fio_test_suite "$env_ctx" 749 fi 750else 751 echo "FIO not available" 752 exit 1 753fi 754 755trap "cleanup" SIGINT SIGTERM EXIT 756 757run_test "bdev_verify" $rootdir/build/examples/bdevperf --json "$conf_file" -q 128 -o 4096 -w verify -t 5 -C -m 0x3 "$env_ctx" 758run_test "bdev_verify_big_io" $rootdir/build/examples/bdevperf --json "$conf_file" -q 128 -o 65536 -w verify -t 5 -C -m 0x3 "$env_ctx" 759run_test "bdev_write_zeroes" $rootdir/build/examples/bdevperf --json "$conf_file" -q 128 -o 4096 -w write_zeroes -t 1 "$env_ctx" 760 761# test json config not enclosed with {} 762run_test "bdev_json_nonenclosed" $rootdir/build/examples/bdevperf --json "$nonenclosed_conf_file" -q 128 -o 4096 -w write_zeroes -t 1 "$env_ctx" || true 763 764# test json config "subsystems" not with array 765run_test "bdev_json_nonarray" $rootdir/build/examples/bdevperf --json "$nonarray_conf_file" -q 128 -o 4096 -w write_zeroes -t 1 "$env_ctx" || true 766 767if [[ $test_type == bdev ]]; then 768 run_test "bdev_qos" qos_test_suite "$env_ctx" 769 run_test "bdev_qd_sampling" qd_sampling_test_suite "$env_ctx" 770 run_test "bdev_error" error_test_suite "$env_ctx" 771 run_test "bdev_stat" stat_test_suite "$env_ctx" 772fi 773 774if [[ $test_type == gpt ]]; then 775 run_test "bdev_gpt_uuid" bdev_gpt_uuid 776fi 777 778# Temporarily disabled - infinite loop 779# if [ $RUN_NIGHTLY -eq 1 ]; then 780# run_test "bdev_reset" $rootdir/build/examples/bdevperf --json "$conf_file" -q 16 -w reset -o 4096 -t 60 "$env_ctx" 781# fi 782 783# Bdev and configuration cleanup below this line 784#----------------------------------------------------- 785 786trap - SIGINT SIGTERM EXIT 787cleanup 788