xref: /spdk/test/bdev/blockdev.sh (revision 28d7251a2dda924d4fdee8dc6cd1fc97983fbff4)
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
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}
78
79function setup_nvme_conf() {
80	local json
81	mapfile -t json < <("$rootdir/scripts/gen_nvme.sh")
82	"$rpc_py" load_subsystem_config -j "'${json[*]}'"
83}
84
85function setup_xnvme_conf() {
86	# TODO: Switch to io_uring_cmd when proper CI support is in place
87	local io_mechanism=io_uring
88	local nvme nvmes
89
90	"$rootdir/scripts/setup.sh" reset
91	get_zoned_devs
92
93	for nvme in /dev/nvme*n*; do
94		[[ -b $nvme && -z ${zoned_devs["${nvme##*/}"]} ]] || continue
95		nvmes+=("bdev_xnvme_create $nvme ${nvme##*/} $io_mechanism")
96	done
97
98	((${#nvmes[@]} > 0))
99	"$rpc_py" < <(printf '%s\n' "${nvmes[@]}")
100}
101
102function setup_gpt_conf() {
103	$rootdir/scripts/setup.sh reset
104	get_zoned_devs
105	# Get nvme devices by following drivers' links towards nvme class
106	local nvme_devs=(/sys/bus/pci/drivers/nvme/*/nvme/nvme*/nvme*n*) 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[*]}"
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 $(echo $bdevs | jq -r '.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 [ "$(echo $bdevs | jq -r 'select(.supported_io_types.unmap == true) | .name')" != "" ]; then
355		for b in $(echo $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 "Qeueue 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
633# Initial bdev creation and configuration
634#-----------------------------------------------------
635QOS_DEV_1="Malloc_0"
636QOS_DEV_2="Null_1"
637QOS_RUN_TIME=5
638
639if [ $(uname -s) = Linux ]; then
640	# Test dynamic memory management. All hugepages will be reserved at runtime
641	PRE_RESERVED_MEM=0
642else
643	# Dynamic memory management is not supported on BSD
644	PRE_RESERVED_MEM=2048
645fi
646
647test_type=${1:-bdev}
648crypto_device=$2
649dek=$3
650env_ctx=""
651wait_for_rpc=""
652if [ -n "$crypto_device" ]; then
653	env_ctx="--env-context=--allow=$crypto_device,class=crypto"
654fi
655if [[ $test_type == crypto_* ]]; then
656	wait_for_rpc="--wait-for-rpc"
657fi
658start_spdk_tgt
659case "$test_type" in
660	bdev)
661		setup_bdev_conf
662		;;
663	nvme)
664		setup_nvme_conf
665		;;
666	gpt)
667		setup_gpt_conf
668		;;
669	crypto_aesni)
670		setup_crypto_aesni_conf
671		;;
672	crypto_qat)
673		setup_crypto_qat_conf
674		;;
675	crypto_sw)
676		setup_crypto_sw_conf
677		;;
678	crypto_mlx5)
679		setup_crypto_mlx5_conf $dek
680		;;
681	crypto_accel_mlx5)
682		setup_crypto_accel_mlx5_conf
683		;;
684	rbd)
685		setup_rbd_conf
686		;;
687	daos)
688		setup_daos_conf
689		;;
690	raid5f)
691		setup_raid5f_conf
692		;;
693	xnvme)
694		setup_xnvme_conf
695		;;
696	*)
697		echo "invalid test name"
698		exit 1
699		;;
700esac
701
702"$rpc_py" bdev_wait_for_examine
703
704# Generate json config and use it throughout all the tests
705cat <<- CONF > "$conf_file"
706	        {"subsystems":[
707	        $("$rpc_py" save_subsystem_config -n accel),
708	        $("$rpc_py" save_subsystem_config -n bdev)
709	        ]}
710CONF
711
712bdevs=$("$rpc_py" bdev_get_bdevs | jq -r '.[] | select(.claimed == false)')
713bdevs_name=$(echo $bdevs | jq -r '.name')
714bdev_list=($bdevs_name)
715
716hello_world_bdev=${bdev_list[0]}
717trap - SIGINT SIGTERM EXIT
718killprocess "$spdk_tgt_pid"
719# End bdev configuration
720#-----------------------------------------------------
721
722trap "cleanup" SIGINT SIGTERM EXIT
723
724run_test "bdev_hello_world" $SPDK_EXAMPLE_DIR/hello_bdev --json "$conf_file" -b "$hello_world_bdev" "$env_ctx"
725run_test "bdev_bounds" bdev_bounds "$env_ctx"
726run_test "bdev_nbd" nbd_function_test $conf_file "$bdevs_name" "$env_ctx"
727if [[ $CONFIG_FIO_PLUGIN == y ]]; then
728	if [ "$test_type" = "nvme" ] || [ "$test_type" = "gpt" ]; then
729		# TODO: once we get real multi-ns drives, re-enable this test for NVMe.
730		echo "skipping fio tests on NVMe due to multi-ns failures."
731	else
732		run_test "bdev_fio" fio_test_suite "$env_ctx"
733	fi
734else
735	echo "FIO not available"
736	exit 1
737fi
738
739trap "cleanup" SIGINT SIGTERM EXIT
740
741run_test "bdev_verify" $rootdir/build/examples/bdevperf --json "$conf_file" -q 128 -o 4096 -w verify -t 5 -C -m 0x3 "$env_ctx"
742run_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"
743run_test "bdev_write_zeroes" $rootdir/build/examples/bdevperf --json "$conf_file" -q 128 -o 4096 -w write_zeroes -t 1 "$env_ctx"
744
745# test json config not enclosed with {}
746run_test "bdev_json_nonenclosed" $rootdir/build/examples/bdevperf --json "$nonenclosed_conf_file" -q 128 -o 4096 -w write_zeroes -t 1 "$env_ctx" || true
747
748# test json config "subsystems" not with array
749run_test "bdev_json_nonarray" $rootdir/build/examples/bdevperf --json "$nonarray_conf_file" -q 128 -o 4096 -w write_zeroes -t 1 "$env_ctx" || true
750
751if [[ $test_type == bdev ]]; then
752	run_test "bdev_qos" qos_test_suite "$env_ctx"
753	run_test "bdev_qd_sampling" qd_sampling_test_suite "$env_ctx"
754	run_test "bdev_error" error_test_suite "$env_ctx"
755	run_test "bdev_stat" stat_test_suite "$env_ctx"
756fi
757
758if [[ $test_type == gpt ]]; then
759	run_test "bdev_gpt_uuid" bdev_gpt_uuid
760fi
761
762# Temporarily disabled - infinite loop
763# if [ $RUN_NIGHTLY -eq 1 ]; then
764# run_test "bdev_reset" $rootdir/build/examples/bdevperf --json "$conf_file" -q 16 -w reset -o 4096 -t 60 "$env_ctx"
765# fi
766
767# Bdev and configuration cleanup below this line
768#-----------------------------------------------------
769
770trap - SIGINT SIGTERM EXIT
771cleanup
772