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