xref: /spdk/test/bdev/blockdev.sh (revision 971ec01268cdf972b0fd02014ffe2998b80931e9)
1f9d5ed28SSeth Howell#!/usr/bin/env bash
2eb53c232Spaul luse#  SPDX-License-Identifier: BSD-3-Clause
3eb53c232Spaul luse#  Copyright (C) 2016 Intel Corporation
4677907dbSAlexey Marchuk#  Copyright (c) 2022, 2023 NVIDIA CORPORATION & AFFILIATES.
5eb53c232Spaul luse#  All rights reserved.
6eb53c232Spaul luse#
7f9d5ed28SSeth Howelltestdir=$(readlink -f $(dirname $0))
8f9d5ed28SSeth Howellrootdir=$(readlink -f $testdir/../..)
9887aff4dSDarek Stojaczyksource $rootdir/test/common/autotest_common.sh
10887aff4dSDarek Stojaczyksource $testdir/nbd_common.sh
11887aff4dSDarek Stojaczyk
1231f8d52dSMichal Bergerrpc_py=rpc_cmd
13b3b45f16SMichal Bergerconf_file="$testdir/bdev.json"
14bb432b4eStongkunkunnonenclosed_conf_file="$testdir/nonenclosed.json"
15bb432b4eStongkunkunnonarray_conf_file="$testdir/nonarray.json"
16bb432b4eStongkunkun
171c656889SMichal Bergerexport RPC_PIPE_TIMEOUT=30
181c656889SMichal Berger
19970601afSPawel Kaminski# Make sure the configuration is clean
20970601afSPawel Kaminski: > "$conf_file"
21970601afSPawel Kaminski
22a940721aSMichal Bergerfunction cleanup() {
23fe711156SMichal Berger	rm -f "$SPDK_TEST_STORAGE/aiofile"
24a940721aSMichal Berger	rm -f "$conf_file"
25a940721aSMichal Berger
2685cda93bSMichal Berger	if [[ $test_type == rbd ]]; then
27a940721aSMichal Berger		rbd_cleanup
2885cda93bSMichal Berger	fi
298419c294SMichal Berger
302e283fcbS0xe0f	if [[ $test_type == daos ]]; then
312e283fcbS0xe0f		daos_cleanup
322e283fcbS0xe0f	fi
332e283fcbS0xe0f
348419c294SMichal Berger	if [[ "$test_type" = "gpt" ]]; then
358419c294SMichal Berger		"$rootdir/scripts/setup.sh" reset
368419c294SMichal Berger		if [[ -b $gpt_nvme ]]; then
378419c294SMichal Berger			wipefs --all "$gpt_nvme"
388419c294SMichal Berger		fi
398419c294SMichal Berger	fi
40008139c8SMichal Berger	if [[ $test_type == xnvme ]]; then
41008139c8SMichal Berger		"$rootdir/scripts/setup.sh"
42008139c8SMichal Berger	fi
43a940721aSMichal Berger}
44a940721aSMichal Berger
45970601afSPawel Kaminskifunction start_spdk_tgt() {
4613f97e67SAlexey Marchuk	"$SPDK_BIN_DIR/spdk_tgt" "$env_ctx" "$wait_for_rpc" &
47970601afSPawel Kaminski	spdk_tgt_pid=$!
48970601afSPawel Kaminski	trap 'killprocess "$spdk_tgt_pid"; exit 1' SIGINT SIGTERM EXIT
49970601afSPawel Kaminski	waitforlisten "$spdk_tgt_pid"
50970601afSPawel Kaminski}
518d945f52SSeth Howell
528d945f52SSeth Howellfunction setup_bdev_conf() {
53ae2d8097SMichal Berger	"$rpc_py" <<- RPC
54bc1bd85eSArtur Paszkiewicz		iobuf_set_options --small-pool-count 10000 --large-pool-count 1100
55bc1bd85eSArtur Paszkiewicz		framework_start_init
56ae2d8097SMichal Berger		bdev_split_create Malloc1 2
57ae2d8097SMichal Berger		bdev_split_create -s 4 Malloc2 8
58ae2d8097SMichal Berger		bdev_malloc_create -b Malloc0 32 512
59ae2d8097SMichal Berger		bdev_malloc_create -b Malloc1 32 512
60ae2d8097SMichal Berger		bdev_malloc_create -b Malloc2 32 512
61ae2d8097SMichal Berger		bdev_malloc_create -b Malloc3 32 512
62ae2d8097SMichal Berger		bdev_malloc_create -b Malloc4 32 512
63ae2d8097SMichal Berger		bdev_malloc_create -b Malloc5 32 512
6464eebbd1Syupeng		bdev_malloc_create -b Malloc6 32 512
6564eebbd1Syupeng		bdev_malloc_create -b Malloc7 32 512
66bc1bd85eSArtur Paszkiewicz		bdev_malloc_create -b Malloc8 32 512
67bc1bd85eSArtur Paszkiewicz		bdev_malloc_create -b Malloc9 32 512
68ae2d8097SMichal Berger		bdev_passthru_create -p TestPT -b Malloc3
69ae2d8097SMichal Berger		bdev_raid_create -n raid0 -z 64 -r 0 -b "Malloc4 Malloc5"
7064eebbd1Syupeng		bdev_raid_create -n concat0 -z 64 -r concat -b "Malloc6 Malloc7"
71bc1bd85eSArtur Paszkiewicz		bdev_raid_create -n raid1 -r 1 -b "Malloc8 Malloc9"
7231f8d52dSMichal Berger		bdev_set_qos_limit --rw_mbytes_per_sec 100 Malloc3
7331f8d52dSMichal Berger		bdev_set_qos_limit --rw_ios_per_sec 20000 Malloc0
74ae2d8097SMichal Berger	RPC
759e06b192SFedor Uporov
76fe711156SMichal Berger	dd if=/dev/zero of="$SPDK_TEST_STORAGE/aiofile" bs=2048 count=5000
77fe711156SMichal Berger	"$rpc_py" bdev_aio_create "$SPDK_TEST_STORAGE/aiofile" AIO0 2048
788d945f52SSeth Howell}
79f9d5ed28SSeth Howell
80e4eee617SSeth Howellfunction setup_nvme_conf() {
8131f8d52dSMichal Berger	local json
8231f8d52dSMichal Berger	mapfile -t json < <("$rootdir/scripts/gen_nvme.sh")
8331f8d52dSMichal Berger	"$rpc_py" load_subsystem_config -j "'${json[*]}'"
84e4eee617SSeth Howell}
85e4eee617SSeth Howell
86008139c8SMichal Bergerfunction setup_xnvme_conf() {
87008139c8SMichal Berger	# TODO: Switch to io_uring_cmd when proper CI support is in place
88008139c8SMichal Berger	local io_mechanism=io_uring
89008139c8SMichal Berger	local nvme nvmes
90008139c8SMichal Berger
91008139c8SMichal Berger	"$rootdir/scripts/setup.sh" reset
92008139c8SMichal Berger	get_zoned_devs
93008139c8SMichal Berger
94008139c8SMichal Berger	for nvme in /dev/nvme*n*; do
95008139c8SMichal Berger		[[ -b $nvme && -z ${zoned_devs["${nvme##*/}"]} ]] || continue
96a25b1619SMichal Berger		nvmes+=("bdev_xnvme_create $nvme ${nvme##*/} $io_mechanism -c")
97008139c8SMichal Berger	done
98008139c8SMichal Berger
99008139c8SMichal Berger	((${#nvmes[@]} > 0))
100008139c8SMichal Berger	"$rpc_py" < <(printf '%s\n' "${nvmes[@]}")
101008139c8SMichal Berger}
102008139c8SMichal Berger
103e4eee617SSeth Howellfunction setup_gpt_conf() {
1049fd5bcccSMichal Berger	$rootdir/scripts/setup.sh reset
1050231fdc7SMichal Berger	get_zoned_devs
106e8a22bccSMichal Berger	local nvme_devs=(/sys/block/nvme!(*c*)) nvme_dev
1079fd5bcccSMichal Berger	gpt_nvme=""
1089fd5bcccSMichal Berger	# Pick first device which doesn't have any valid partition table
1099fd5bcccSMichal Berger	for nvme_dev in "${nvme_devs[@]}"; do
1100231fdc7SMichal Berger		[[ -z ${zoned_devs["${nvme_dev##*/}"]} ]] || continue
1119fd5bcccSMichal Berger		dev=/dev/${nvme_dev##*/}
1129fd5bcccSMichal Berger		if ! pt=$(parted "$dev" -ms print 2>&1); then
1139fd5bcccSMichal Berger			[[ $pt == *"$dev: unrecognised disk label"* ]] || continue
114844c8ec3SMichal Berger			gpt_nvme=$dev
115844c8ec3SMichal Berger			break
116970601afSPawel Kaminski		fi
1179fd5bcccSMichal Berger	done
1189fd5bcccSMichal Berger	if [[ -n $gpt_nvme ]]; then
119ff12a5edSMike Gerdts		# These Unique Partition GUIDs were randomly generated for testing and are distinct
120ff12a5edSMike Gerdts		# from the Partition Type GUIDs (SPDK_GPT_OLD_GUID and SPDK_GPT_GUID) which have
121ff12a5edSMike Gerdts		# special meaning to SPDK. See section 5.3.3 of UEFI Spec 2.3 for the distinction
122ff12a5edSMike Gerdts		# between Unique Partition GUID and Partition Type GUID.
123ff12a5edSMike Gerdts		typeset -g g_unique_partguid=6f89f330-603b-4116-ac73-2ca8eae53030
124ff12a5edSMike Gerdts		typeset -g g_unique_partguid_old=abf1734f-66e5-4c0f-aa29-4021d4d307df
125ff12a5edSMike Gerdts
1269fd5bcccSMichal Berger		# Create gpt partition table
127c733cd68STomasz Zawadzki		parted -s "$gpt_nvme" mklabel gpt mkpart SPDK_TEST_first '0%' '50%' mkpart SPDK_TEST_second '50%' '100%'
12862c399ffSJim Harris		# Change the partition type GUIDs to SPDK partition type values
1293a39d90bSJim Harris		SPDK_GPT_OLD_GUID=$(get_spdk_gpt_old)
130b7947268SMichal Berger		SPDK_GPT_GUID=$(get_spdk_gpt)
131ff12a5edSMike Gerdts		sgdisk -t "1:$SPDK_GPT_GUID" -u "1:$g_unique_partguid" "$gpt_nvme"
132ff12a5edSMike Gerdts		sgdisk -t "2:$SPDK_GPT_OLD_GUID" -u "2:$g_unique_partguid_old" "$gpt_nvme"
1339fd5bcccSMichal Berger		"$rootdir/scripts/setup.sh"
1349fd5bcccSMichal Berger		"$rpc_py" bdev_get_bdevs
1359fd5bcccSMichal Berger		setup_nvme_conf
136de303275SSeth Howell	else
1379fd5bcccSMichal Berger		printf 'Did not find any nvme block devices to work with, aborting the test\n' >&2
1389fd5bcccSMichal Berger		"$rootdir/scripts/setup.sh"
139de303275SSeth Howell		return 1
140e4eee617SSeth Howell	fi
141e4eee617SSeth Howell}
142e4eee617SSeth Howell
143102731bdSMichal Bergerfunction setup_crypto_aesni_conf() {
144102731bdSMichal Berger	# Malloc0 and Malloc1 use AESNI
145102731bdSMichal Berger	"$rpc_py" <<- RPC
14613f97e67SAlexey Marchuk		dpdk_cryptodev_scan_accel_module
14713f97e67SAlexey Marchuk		dpdk_cryptodev_set_driver -d crypto_aesni_mb
14813f97e67SAlexey Marchuk		accel_assign_opc -o encrypt -m dpdk_cryptodev
14913f97e67SAlexey Marchuk		accel_assign_opc -o decrypt -m dpdk_cryptodev
15013f97e67SAlexey Marchuk		framework_start_init
15113f97e67SAlexey Marchuk		accel_crypto_key_create -c AES_CBC -k 01234567891234560123456789123456 -n test_dek_aesni_cbc_1
15213f97e67SAlexey Marchuk		accel_crypto_key_create -c AES_CBC -k 12345678912345601234567891234560 -n test_dek_aesni_cbc_2
15313f97e67SAlexey Marchuk		accel_crypto_key_create -c AES_CBC -k 23456789123456012345678912345601 -n test_dek_aesni_cbc_3
15413f97e67SAlexey Marchuk		accel_crypto_key_create -c AES_CBC -k 34567891234560123456789123456012 -n test_dek_aesni_cbc_4
15513f97e67SAlexey Marchuk		bdev_malloc_create -b Malloc0 32 512
15613f97e67SAlexey Marchuk		bdev_malloc_create -b Malloc1 32 512
15713f97e67SAlexey Marchuk		bdev_malloc_create -b Malloc2 32 4096
15813f97e67SAlexey Marchuk		bdev_malloc_create -b Malloc3 32 4096
15913f97e67SAlexey Marchuk		bdev_crypto_create Malloc0 crypto_ram -n test_dek_aesni_cbc_1
16013f97e67SAlexey Marchuk		bdev_crypto_create Malloc1 crypto_ram2 -n test_dek_aesni_cbc_2
16113f97e67SAlexey Marchuk		bdev_crypto_create Malloc2 crypto_ram3 -n test_dek_aesni_cbc_3
16213f97e67SAlexey Marchuk		bdev_crypto_create Malloc3 crypto_ram4 -n test_dek_aesni_cbc_4
163102731bdSMichal Berger	RPC
164102731bdSMichal Berger}
165102731bdSMichal Berger
166102731bdSMichal Bergerfunction setup_crypto_qat_conf() {
167102731bdSMichal Berger	# Malloc0 will use QAT AES_CBC
168102731bdSMichal Berger	# Malloc1 will use QAT AES_XTS
169102731bdSMichal Berger	"$rpc_py" <<- RPC
17013f97e67SAlexey Marchuk		dpdk_cryptodev_scan_accel_module
17113f97e67SAlexey Marchuk		dpdk_cryptodev_set_driver -d crypto_qat
17213f97e67SAlexey Marchuk		accel_assign_opc -o encrypt -m dpdk_cryptodev
17313f97e67SAlexey Marchuk		accel_assign_opc -o decrypt -m dpdk_cryptodev
17413f97e67SAlexey Marchuk		framework_start_init
17513f97e67SAlexey Marchuk		accel_crypto_key_create -c AES_CBC -k 01234567891234560123456789123456 -n test_dek_qat_cbc
17613f97e67SAlexey Marchuk		accel_crypto_key_create -c AES_XTS -k 00112233445566778899001122334455 -e 12345678912345601234567891234560 -n test_dek_qat_xts
17713f97e67SAlexey Marchuk		accel_crypto_key_create -c AES_CBC -k 23456789123456012345678912345601 -n test_dek_qat_cbc2
17813f97e67SAlexey Marchuk		accel_crypto_key_create -c AES_XTS -k 22334455667788990011223344550011 -e 34567891234560123456789123456012 -n test_dek_qat_xts2
17913f97e67SAlexey Marchuk		bdev_malloc_create -b Malloc0 32 512
18013f97e67SAlexey Marchuk		bdev_malloc_create -b Malloc1 32 512
18113f97e67SAlexey Marchuk		bdev_malloc_create -b Malloc2 32 4096
18213f97e67SAlexey Marchuk		bdev_malloc_create -b Malloc3 32 4096
18313f97e67SAlexey Marchuk		bdev_crypto_create Malloc0 crypto_ram -n test_dek_qat_cbc
18413f97e67SAlexey Marchuk		bdev_crypto_create Malloc1 crypto_ram1 -n test_dek_qat_xts
18513f97e67SAlexey Marchuk		bdev_crypto_create Malloc2 crypto_ram2 -n test_dek_qat_cbc2
18613f97e67SAlexey Marchuk		bdev_crypto_create Malloc3 crypto_ram3 -n test_dek_qat_xts2
18713f97e67SAlexey Marchuk		bdev_get_bdevs -b Malloc1
18813f97e67SAlexey Marchuk	RPC
18913f97e67SAlexey Marchuk}
19013f97e67SAlexey Marchuk
19113f97e67SAlexey Marchukfunction setup_crypto_sw_conf() {
19213f97e67SAlexey Marchuk	"$rpc_py" <<- RPC
19313f97e67SAlexey Marchuk		framework_start_init
194102731bdSMichal Berger		bdev_malloc_create -b Malloc0 16 512
19513f97e67SAlexey Marchuk		bdev_malloc_create -b Malloc1 16 4096
19613f97e67SAlexey Marchuk		accel_crypto_key_create -c AES_XTS -k 00112233445566778899001122334455 -e 11223344556677889900112233445500 -n test_dek_sw
19713f97e67SAlexey Marchuk		accel_crypto_key_create -c AES_XTS -k 22334455667788990011223344550011 -e 33445566778899001122334455001122 -n test_dek_sw2
19838220006SKonrad Sztyber		accel_crypto_key_create -c AES_XTS -k 33445566778899001122334455001122 -e 44556677889900112233445500112233 -n test_dek_sw3
19913f97e67SAlexey Marchuk		bdev_crypto_create Malloc0 crypto_ram -n test_dek_sw
20013f97e67SAlexey Marchuk		bdev_crypto_create Malloc1 crypto_ram2 -n test_dek_sw2
20138220006SKonrad Sztyber		bdev_crypto_create crypto_ram2 crypto_ram3 -n test_dek_sw3
20231f8d52dSMichal Berger		bdev_get_bdevs -b Malloc1
203102731bdSMichal Berger	RPC
204e4eee617SSeth Howell}
205e4eee617SSeth Howell
206969b5632SAlexey Marchukfunction setup_crypto_accel_mlx5_conf() {
207969b5632SAlexey Marchuk	"$rpc_py" <<- RPC
208969b5632SAlexey Marchuk		mlx5_scan_accel_module
209969b5632SAlexey Marchuk		accel_assign_opc -o encrypt -m mlx5
210969b5632SAlexey Marchuk		accel_assign_opc -o decrypt -m mlx5
211969b5632SAlexey Marchuk		framework_start_init
212969b5632SAlexey Marchuk		bdev_malloc_create -b Malloc0 32 512
213969b5632SAlexey Marchuk		bdev_malloc_create -b Malloc1 32 512
214969b5632SAlexey Marchuk		bdev_malloc_create -b Malloc2 32 4096
215969b5632SAlexey Marchuk		bdev_malloc_create -b Malloc3 32 4096
216969b5632SAlexey Marchuk		accel_crypto_key_create -c AES_XTS -k 00112233445566778899001122334455 -e 11223344556677889900112233445500 -n test_dek_accel_mlx5_1
217969b5632SAlexey Marchuk		accel_crypto_key_create -c AES_XTS -k 11223344556677889900112233445500 -e 22334455667788990011223344550011 -n test_dek_accel_mlx5_2
218969b5632SAlexey Marchuk		accel_crypto_key_create -c AES_XTS -k 22334455667788990011223344550011 -e 33445566778899001122334455002233 -n test_dek_accel_mlx5_3
219969b5632SAlexey Marchuk		accel_crypto_key_create -c AES_XTS -k 33445566778899001122334455001122 -e 44556677889900112233445500112233 -n test_dek_accel_mlx5_4
220969b5632SAlexey Marchuk		bdev_crypto_create Malloc0 crypto_ram_1 -n test_dek_accel_mlx5_1
221969b5632SAlexey Marchuk		bdev_crypto_create Malloc1 crypto_ram_2 -n test_dek_accel_mlx5_2
222969b5632SAlexey Marchuk		bdev_crypto_create Malloc2 crypto_ram_3 -n test_dek_accel_mlx5_3
223969b5632SAlexey Marchuk		bdev_crypto_create Malloc3 crypto_ram_4 -n test_dek_accel_mlx5_4
224969b5632SAlexey Marchuk		bdev_get_bdevs -b Malloc1
225969b5632SAlexey Marchuk	RPC
226969b5632SAlexey Marchuk}
227969b5632SAlexey Marchuk
228872e0e46SYuriy Umanetsfunction setup_crypto_mlx5_conf() {
229872e0e46SYuriy Umanets	local key=$1
230872e0e46SYuriy Umanets	local block_key
231872e0e46SYuriy Umanets	local tweak_key
232d20ae7ffSAlexey Marchuk	if [ ${#key} == 64 ]; then
233d20ae7ffSAlexey Marchuk		# 64 bytes is 32 + 32 - AES_XTS_128 in hexlified format
234d20ae7ffSAlexey Marchuk		block_key=${key:0:32}
235d20ae7ffSAlexey Marchuk		tweak_key=${key:32:32}
236d20ae7ffSAlexey Marchuk	elif [ ${#key} == 128 ]; then
237d20ae7ffSAlexey Marchuk		# 128 bytes is 64 + 64 - AES_XTS_256 in hexlified format
238872e0e46SYuriy Umanets		block_key=${key:0:64}
239d20ae7ffSAlexey Marchuk		tweak_key=${key:64:64}
240872e0e46SYuriy Umanets	else
241872e0e46SYuriy Umanets		echo "ERROR: Invalid DEK size for MLX5 crypto setup: ${#key}"
242d20ae7ffSAlexey Marchuk		echo "ERROR: Supported key sizes for MLX5: 64 bytes (AES_XTS_128) and 128 bytes (AES_XTS_256)."
243872e0e46SYuriy Umanets		return 1
244872e0e46SYuriy Umanets	fi
245872e0e46SYuriy Umanets
246872e0e46SYuriy Umanets	# Malloc0 will use MLX5 AES_XTS
247a6545ae3SAlexey Marchuk	"$rootdir/scripts/rpc.py" <<- RPC
24813f97e67SAlexey Marchuk		dpdk_cryptodev_scan_accel_module
24913f97e67SAlexey Marchuk		dpdk_cryptodev_set_driver -d mlx5_pci
25013f97e67SAlexey Marchuk		accel_assign_opc -o encrypt -m dpdk_cryptodev
25113f97e67SAlexey Marchuk		accel_assign_opc -o decrypt -m dpdk_cryptodev
25213f97e67SAlexey Marchuk		framework_start_init
253872e0e46SYuriy Umanets		bdev_malloc_create -b Malloc0 16 512
25413f97e67SAlexey Marchuk		bdev_crypto_create Malloc0 crypto_ram4 -k $block_key -c AES_XTS -k2 $tweak_key
255872e0e46SYuriy Umanets		bdev_get_bdevs -b Malloc0
256872e0e46SYuriy Umanets	RPC
257872e0e46SYuriy Umanets}
258872e0e46SYuriy Umanets
259e4eee617SSeth Howellfunction setup_rbd_conf() {
260e4eee617SSeth Howell	timing_enter rbd_setup
261e4eee617SSeth Howell	rbd_setup 127.0.0.1
262e4eee617SSeth Howell	timing_exit rbd_setup
263e4eee617SSeth Howell
2646b8f9a0fSMichal Berger	"$rpc_py" bdev_rbd_create -b Ceph0 rbd foo 512
265e4eee617SSeth Howell}
266e4eee617SSeth Howell
2672e283fcbS0xe0ffunction setup_daos_conf() {
2682e283fcbS0xe0f	local pool=testpool
2692e283fcbS0xe0f	local cont=testcont
2702e283fcbS0xe0f
2712e283fcbS0xe0f	timing_enter daos_setup
2722e283fcbS0xe0f	daos_setup $pool $cont
2732e283fcbS0xe0f	timing_exit daos_setup
2742e283fcbS0xe0f
2752e283fcbS0xe0f	"$rpc_py" bdev_daos_create Daos0 $pool $cont 16 4096
2762e283fcbS0xe0f}
2772e283fcbS0xe0f
278030951b4SArtur Paszkiewiczfunction setup_raid5f_conf() {
279030951b4SArtur Paszkiewicz	"$rpc_py" <<- RPC
280030951b4SArtur Paszkiewicz		bdev_malloc_create -b Malloc0 32 512
281030951b4SArtur Paszkiewicz		bdev_malloc_create -b Malloc1 32 512
282030951b4SArtur Paszkiewicz		bdev_malloc_create -b Malloc2 32 512
283030951b4SArtur Paszkiewicz		bdev_raid_create -n raid5f -z 2 -r 5f -b "Malloc0 Malloc1 Malloc2"
284030951b4SArtur Paszkiewicz	RPC
285030951b4SArtur Paszkiewicz}
286030951b4SArtur Paszkiewicz
2878295a2b0SSeth Howellfunction bdev_bounds() {
288872e0e46SYuriy Umanets	$testdir/bdevio/bdevio -w -s $PRE_RESERVED_MEM --json "$conf_file" "$env_ctx" &
2898295a2b0SSeth Howell	bdevio_pid=$!
2908419c294SMichal Berger	trap 'cleanup; killprocess $bdevio_pid; exit 1' SIGINT SIGTERM EXIT
2918295a2b0SSeth Howell	echo "Process bdevio pid: $bdevio_pid"
2928295a2b0SSeth Howell	waitforlisten $bdevio_pid
2938295a2b0SSeth Howell	$testdir/bdevio/tests.py perform_tests
2948295a2b0SSeth Howell	killprocess $bdevio_pid
2958295a2b0SSeth Howell	trap - SIGINT SIGTERM EXIT
2968295a2b0SSeth Howell}
2978295a2b0SSeth Howell
298f9d5ed28SSeth Howellfunction nbd_function_test() {
299367fc7a9SMichal Berger	[[ $(uname -s) == Linux ]] || return 0
300367fc7a9SMichal Berger
301f9d5ed28SSeth Howell	local rpc_server=/var/tmp/spdk-nbd.sock
302f9d5ed28SSeth Howell	local conf=$1
303367fc7a9SMichal Berger	local bdev_all=($2)
304367fc7a9SMichal Berger	local bdev_num=${#bdev_all[@]}
305f9d5ed28SSeth Howell
306367fc7a9SMichal Berger	# FIXME: Centos7 in the CI is not shipped with a kernel supporting BLK_DEV_NBD
307367fc7a9SMichal Berger	# so don't fail here for now.
308367fc7a9SMichal Berger	[[ -e /sys/module/nbd ]] || modprobe -q nbd nbds_max=$bdev_num || return 0
309f9d5ed28SSeth Howell
310367fc7a9SMichal Berger	local nbd_all=(/dev/nbd+([0-9]))
311367fc7a9SMichal Berger	bdev_num=$((${#nbd_all[@]} < bdev_num ? ${#nbd_all[@]} : bdev_num))
312367fc7a9SMichal Berger
313367fc7a9SMichal Berger	local nbd_list=(${nbd_all[@]::bdev_num})
314367fc7a9SMichal Berger	local bdev_list=(${bdev_all[@]::bdev_num})
315367fc7a9SMichal Berger
316872e0e46SYuriy Umanets	$rootdir/test/app/bdev_svc/bdev_svc -r $rpc_server -i 0 --json "$conf" "$env_ctx" &
317f9d5ed28SSeth Howell	nbd_pid=$!
318367fc7a9SMichal Berger	trap 'cleanup; killprocess $nbd_pid' SIGINT SIGTERM EXIT
319f9d5ed28SSeth Howell	waitforlisten $nbd_pid $rpc_server
320f9d5ed28SSeth Howell
321efdd6edbSXiaodong Liu	nbd_rpc_start_stop_verify $rpc_server "${bdev_list[*]}"
322f9d5ed28SSeth Howell	nbd_rpc_data_verify $rpc_server "${bdev_list[*]}" "${nbd_list[*]}"
32387a2b42bSMichal Berger	nbd_with_lvol_verify $rpc_server "${nbd_list[0]}"
324f9d5ed28SSeth Howell
325f9d5ed28SSeth Howell	killprocess $nbd_pid
3261599301bSTomasz Zawadzki	trap - SIGINT SIGTERM EXIT
327f9d5ed28SSeth Howell}
328f9d5ed28SSeth Howell
329c4d4abcfSSeth Howellfunction fio_test_suite() {
330872e0e46SYuriy Umanets	local env_context
331872e0e46SYuriy Umanets
332872e0e46SYuriy Umanets	# Make sure that state files and anything else produced by fio test will
333872e0e46SYuriy Umanets	# stay at the testdir.
334872e0e46SYuriy Umanets	pushd $testdir
335872e0e46SYuriy Umanets	trap 'rm -f ./*.state; popd; exit 1' SIGINT SIGTERM EXIT
336872e0e46SYuriy Umanets
337c4d4abcfSSeth Howell	# Generate the fio config file given the list of all unclaimed bdevs
338872e0e46SYuriy Umanets	env_context=$(echo "$env_ctx" | sed 's/--env-context=//')
339872e0e46SYuriy Umanets	fio_config_gen $testdir/bdev.fio verify AIO "$env_context"
3404641aa53SMichal Berger	for b in "${bdevs_name[@]}"; do
3417098c653SDarek Stojaczyk		echo "[job_$b]" >> $testdir/bdev.fio
3427098c653SDarek Stojaczyk		echo "filename=$b" >> $testdir/bdev.fio
343c4d4abcfSSeth Howell	done
344c4d4abcfSSeth Howell
34514c0f94cSKamil Godzwon	local fio_params="--ioengine=spdk_bdev --iodepth=8 --bs=4k --runtime=10 $testdir/bdev.fio \
34614c0f94cSKamil Godzwon			--verify_state_save=0 --spdk_json_conf=$conf_file"
347e0f90388SSeth Howell
34814c0f94cSKamil Godzwon	run_test "bdev_fio_rw_verify" fio_bdev $fio_params --spdk_mem=$PRE_RESERVED_MEM --aux-path=$output_dir
349c4d4abcfSSeth Howell	rm -f ./*.state
350c4d4abcfSSeth Howell	rm -f $testdir/bdev.fio
351c4d4abcfSSeth Howell
352c4d4abcfSSeth Howell	# Generate the fio config file given the list of all unclaimed bdevs that support unmap
353872e0e46SYuriy Umanets	fio_config_gen $testdir/bdev.fio trim "" "$env_context"
3544641aa53SMichal Berger	if [[ -n $(printf '%s\n' "${bdevs[@]}" | jq -r 'select(.supported_io_types.unmap == true) | .name') ]]; then
3554641aa53SMichal Berger		for b in $(printf '%s\n' "${bdevs[@]}" | jq -r 'select(.supported_io_types.unmap == true) | .name'); do
3567098c653SDarek Stojaczyk			echo "[job_$b]" >> $testdir/bdev.fio
3577098c653SDarek Stojaczyk			echo "filename=$b" >> $testdir/bdev.fio
358c4d4abcfSSeth Howell		done
3596ac949c0SSeth Howell	else
3606ac949c0SSeth Howell		rm -f $testdir/bdev.fio
361872e0e46SYuriy Umanets		popd
362872e0e46SYuriy Umanets		trap - SIGINT SIGTERM EXIT
3636ac949c0SSeth Howell		return 0
3646ac949c0SSeth Howell	fi
365c4d4abcfSSeth Howell
36614c0f94cSKamil Godzwon	run_test "bdev_fio_trim" fio_bdev $fio_params --verify_state_save=0 --aux-path=$output_dir
367c4d4abcfSSeth Howell	rm -f ./*.state
368c4d4abcfSSeth Howell	rm -f $testdir/bdev.fio
369872e0e46SYuriy Umanets	popd
370872e0e46SYuriy Umanets	trap - SIGINT SIGTERM EXIT
371c4d4abcfSSeth Howell}
372c4d4abcfSSeth Howell
373a31ae23fSGangCaofunction get_io_result() {
374a31ae23fSGangCao	local limit_type=$1
375863bb94bSGangCao	local qos_dev=$2
376f1687a1bSjiaqizho	local iostat_result
377f1687a1bSjiaqizho	iostat_result=$($rootdir/scripts/iostat.py -d -i 1 -t $QOS_RUN_TIME | grep $qos_dev | tail -1)
378a31ae23fSGangCao	if [ $limit_type = IOPS ]; then
379f1687a1bSjiaqizho		iostat_result=$(awk '{print $2}' <<< $iostat_result)
380f1687a1bSjiaqizho	elif [ $limit_type = BANDWIDTH ]; then
381f1687a1bSjiaqizho		iostat_result=$(awk '{print $6}' <<< $iostat_result)
382a31ae23fSGangCao	fi
383a31ae23fSGangCao
384844c8ec3SMichal Berger	echo ${iostat_result/.*/}
385a31ae23fSGangCao}
386a31ae23fSGangCao
387a31ae23fSGangCaofunction run_qos_test() {
388a31ae23fSGangCao	local qos_limit=$1
389a31ae23fSGangCao	local qos_result=0
390a31ae23fSGangCao
391863bb94bSGangCao	qos_result=$(get_io_result $2 $3)
392a31ae23fSGangCao	if [ $2 = BANDWIDTH ]; then
3939b47757bSGangCao		qos_limit=$((qos_limit * 1024))
394a31ae23fSGangCao	fi
3959b47757bSGangCao	lower_limit=$((qos_limit * 9 / 10))
3969b47757bSGangCao	upper_limit=$((qos_limit * 11 / 10))
397a31ae23fSGangCao
398c9c7c281SJosh Soref	# QoS realization is related with bytes transferred. It currently has some variation.
399a31ae23fSGangCao	if [ $qos_result -lt $lower_limit ] || [ $qos_result -gt $upper_limit ]; then
400a31ae23fSGangCao		echo "Failed to limit the io read rate of NULL bdev by qos"
40126328b7bSGangCao		$rpc_py bdev_malloc_delete $QOS_DEV_1
402863bb94bSGangCao		$rpc_py bdev_null_delete $QOS_DEV_2
403a31ae23fSGangCao		killprocess $QOS_PID
404a31ae23fSGangCao		exit 1
405a31ae23fSGangCao	fi
406a31ae23fSGangCao}
407a31ae23fSGangCao
408a31ae23fSGangCaofunction qos_function_test() {
409a31ae23fSGangCao	local qos_lower_iops_limit=1000
410863bb94bSGangCao	local qos_lower_bw_limit=2
411a31ae23fSGangCao	local io_result=0
412863bb94bSGangCao	local iops_limit=0
413863bb94bSGangCao	local bw_limit=0
414a31ae23fSGangCao
415863bb94bSGangCao	io_result=$(get_io_result IOPS $QOS_DEV_1)
416a31ae23fSGangCao	# Set the IOPS limit as one quarter of the measured performance without QoS
417863bb94bSGangCao	iops_limit=$(((io_result / 4) / qos_lower_iops_limit * qos_lower_iops_limit))
418a31ae23fSGangCao	if [ $iops_limit -gt $qos_lower_iops_limit ]; then
419a31ae23fSGangCao
420863bb94bSGangCao		# Run bdevperf with IOPS rate limit on bdev 1
421863bb94bSGangCao		$rpc_py bdev_set_qos_limit --rw_ios_per_sec $iops_limit $QOS_DEV_1
422cb90136cSSeth Howell		run_test "bdev_qos_iops" run_qos_test $iops_limit IOPS $QOS_DEV_1
423a31ae23fSGangCao
424863bb94bSGangCao		# Run bdevperf with bandwidth rate limit on bdev 2
425863bb94bSGangCao		# Set the bandwidth limit as 1/10 of the measure performance without QoS
426863bb94bSGangCao		bw_limit=$(get_io_result BANDWIDTH $QOS_DEV_2)
427863bb94bSGangCao		bw_limit=$((bw_limit / 1024 / 10))
428863bb94bSGangCao		if [ $bw_limit -lt $qos_lower_bw_limit ]; then
429863bb94bSGangCao			bw_limit=$qos_lower_bw_limit
430863bb94bSGangCao		fi
431863bb94bSGangCao		$rpc_py bdev_set_qos_limit --rw_mbytes_per_sec $bw_limit $QOS_DEV_2
432cb90136cSSeth Howell		run_test "bdev_qos_bw" run_qos_test $bw_limit BANDWIDTH $QOS_DEV_2
433a31ae23fSGangCao
434863bb94bSGangCao		# Run bdevperf with additional read only bandwidth rate limit on bdev 1
435863bb94bSGangCao		$rpc_py bdev_set_qos_limit --r_mbytes_per_sec $qos_lower_bw_limit $QOS_DEV_1
436cb90136cSSeth Howell		run_test "bdev_qos_ro_bw" run_qos_test $qos_lower_bw_limit BANDWIDTH $QOS_DEV_1
437a31ae23fSGangCao	else
438a31ae23fSGangCao		echo "Actual IOPS without limiting is too low - exit testing"
439a31ae23fSGangCao	fi
440a31ae23fSGangCao}
441a31ae23fSGangCao
442d6379a88SSeth Howellfunction qos_test_suite() {
443d6379a88SSeth Howell	# Run bdevperf with QoS disabled first
44429784f35SKrzysztof Karas	"$rootdir/build/examples/bdevperf" -z -m 0x2 -q 256 -o 4096 -w randread -t 60 "$env_ctx" &
445d6379a88SSeth Howell	QOS_PID=$!
446d6379a88SSeth Howell	echo "Process qos testing pid: $QOS_PID"
4478419c294SMichal Berger	trap 'cleanup; killprocess $QOS_PID; exit 1' SIGINT SIGTERM EXIT
448d6379a88SSeth Howell	waitforlisten $QOS_PID
449d6379a88SSeth Howell
45026328b7bSGangCao	$rpc_py bdev_malloc_create -b $QOS_DEV_1 128 512
451d6379a88SSeth Howell	waitforbdev $QOS_DEV_1
452d6379a88SSeth Howell	$rpc_py bdev_null_create $QOS_DEV_2 128 512
453d6379a88SSeth Howell	waitforbdev $QOS_DEV_2
454d6379a88SSeth Howell
45529784f35SKrzysztof Karas	$rootdir/examples/bdev/bdevperf/bdevperf.py perform_tests &
456d6379a88SSeth Howell	qos_function_test
457d6379a88SSeth Howell
45826328b7bSGangCao	$rpc_py bdev_malloc_delete $QOS_DEV_1
459d6379a88SSeth Howell	$rpc_py bdev_null_delete $QOS_DEV_2
460d6379a88SSeth Howell	killprocess $QOS_PID
461d6379a88SSeth Howell	trap - SIGINT SIGTERM EXIT
462d6379a88SSeth Howell}
463d6379a88SSeth Howell
4648f2ca281SGangCaofunction error_test_suite() {
4658f2ca281SGangCao	DEV_1="Dev_1"
4668f2ca281SGangCao	DEV_2="Dev_2"
4678f2ca281SGangCao	ERR_DEV="EE_Dev_1"
4688f2ca281SGangCao
4698f2ca281SGangCao	# Run bdevperf with 1 normal bdev and 1 error bdev, also continue on error
47029784f35SKrzysztof Karas	"$rootdir/build/examples/bdevperf" -z -m 0x2 -q 16 -o 4096 -w randread -t 5 -f "$env_ctx" &
4718f2ca281SGangCao	ERR_PID=$!
4728f2ca281SGangCao	echo "Process error testing pid: $ERR_PID"
4738f2ca281SGangCao	waitforlisten $ERR_PID
4748f2ca281SGangCao
4758f2ca281SGangCao	$rpc_py bdev_malloc_create -b $DEV_1 128 512
4768f2ca281SGangCao	waitforbdev $DEV_1
4778f2ca281SGangCao	$rpc_py bdev_error_create $DEV_1
4788f2ca281SGangCao	$rpc_py bdev_malloc_create -b $DEV_2 128 512
4798f2ca281SGangCao	waitforbdev $DEV_2
4808f2ca281SGangCao	$rpc_py bdev_error_inject_error $ERR_DEV 'all' 'failure' -n 5
4818f2ca281SGangCao
48229784f35SKrzysztof Karas	$rootdir/examples/bdev/bdevperf/bdevperf.py -t 1 perform_tests &
4838f2ca281SGangCao	sleep 1
4848f2ca281SGangCao
4858f2ca281SGangCao	# Bdevperf is expected to be there as the continue on error is set
4868f2ca281SGangCao	if kill -0 $ERR_PID; then
4878f2ca281SGangCao		echo "Process is existed as continue on error is set. Pid: $ERR_PID"
4888f2ca281SGangCao	else
4898f2ca281SGangCao		echo "Process exited unexpectedly. Pid: $ERR_PID"
4908f2ca281SGangCao		exit 1
4918f2ca281SGangCao	fi
4928f2ca281SGangCao
4938f2ca281SGangCao	# Delete the error devices
4948f2ca281SGangCao	$rpc_py bdev_error_delete $ERR_DEV
4958f2ca281SGangCao	$rpc_py bdev_malloc_delete $DEV_1
4968f2ca281SGangCao	sleep 5
4978f2ca281SGangCao	# Expected to exit normally
4988f2ca281SGangCao	killprocess $ERR_PID
4998f2ca281SGangCao
5008f2ca281SGangCao	# Run bdevperf with 1 normal bdev and 1 error bdev, and exit on error
50129784f35SKrzysztof Karas	"$rootdir/build/examples/bdevperf" -z -m 0x2 -q 16 -o 4096 -w randread -t 5 "$env_ctx" &
5028f2ca281SGangCao	ERR_PID=$!
5038f2ca281SGangCao	echo "Process error testing pid: $ERR_PID"
5048f2ca281SGangCao	waitforlisten $ERR_PID
5058f2ca281SGangCao
5068f2ca281SGangCao	$rpc_py bdev_malloc_create -b $DEV_1 128 512
5078f2ca281SGangCao	waitforbdev $DEV_1
5088f2ca281SGangCao	$rpc_py bdev_error_create $DEV_1
5098f2ca281SGangCao	$rpc_py bdev_malloc_create -b $DEV_2 128 512
5108f2ca281SGangCao	waitforbdev $DEV_2
5118f2ca281SGangCao	$rpc_py bdev_error_inject_error $ERR_DEV 'all' 'failure' -n 5
5128f2ca281SGangCao
51329784f35SKrzysztof Karas	$rootdir/examples/bdev/bdevperf/bdevperf.py -t 1 perform_tests &
5146db3ac3aSGangCao	NOT wait $ERR_PID
5158f2ca281SGangCao}
5168f2ca281SGangCao
51748ce2c97SGangCaofunction qd_sampling_function_test() {
51848ce2c97SGangCao	local bdev_name=$1
51948ce2c97SGangCao	local sampling_period=10
52048ce2c97SGangCao	local iostats
52148ce2c97SGangCao
52248ce2c97SGangCao	$rpc_py bdev_set_qd_sampling_period $bdev_name $sampling_period
52348ce2c97SGangCao
52448ce2c97SGangCao	iostats=$($rpc_py bdev_get_iostat -b $bdev_name)
52548ce2c97SGangCao
52648ce2c97SGangCao	qd_sampling_period=$(jq -r '.bdevs[0].queue_depth_polling_period' <<< "$iostats")
52748ce2c97SGangCao
52848ce2c97SGangCao	if [ $qd_sampling_period == null ] || [ $qd_sampling_period -ne $sampling_period ]; then
52934edd9f1SKamil Godzwon		echo "Queue depth polling period is not right"
53048ce2c97SGangCao		$rpc_py bdev_malloc_delete $QD_DEV
53148ce2c97SGangCao		killprocess $QD_PID
53248ce2c97SGangCao		exit 1
53348ce2c97SGangCao	fi
53448ce2c97SGangCao}
53548ce2c97SGangCao
53648ce2c97SGangCaofunction qd_sampling_test_suite() {
53748ce2c97SGangCao	QD_DEV="Malloc_QD"
53848ce2c97SGangCao
53929784f35SKrzysztof Karas	"$rootdir/build/examples/bdevperf" -z -m 0x3 -q 256 -o 4096 -w randread -t 5 -C "$env_ctx" &
54048ce2c97SGangCao	QD_PID=$!
54148ce2c97SGangCao	echo "Process bdev QD sampling period testing pid: $QD_PID"
54248ce2c97SGangCao	trap 'cleanup; killprocess $QD_PID; exit 1' SIGINT SIGTERM EXIT
54348ce2c97SGangCao	waitforlisten $QD_PID
54448ce2c97SGangCao
54548ce2c97SGangCao	$rpc_py bdev_malloc_create -b $QD_DEV 128 512
54648ce2c97SGangCao	waitforbdev $QD_DEV
54748ce2c97SGangCao
54829784f35SKrzysztof Karas	$rootdir/examples/bdev/bdevperf/bdevperf.py perform_tests &
54948ce2c97SGangCao	sleep 2
55048ce2c97SGangCao	qd_sampling_function_test $QD_DEV
55148ce2c97SGangCao
55248ce2c97SGangCao	$rpc_py bdev_malloc_delete $QD_DEV
55348ce2c97SGangCao	killprocess $QD_PID
55448ce2c97SGangCao	trap - SIGINT SIGTERM EXIT
55548ce2c97SGangCao}
55648ce2c97SGangCao
557e28e2479SGangCaofunction stat_function_test() {
558e28e2479SGangCao	local bdev_name=$1
559e28e2479SGangCao	local iostats
560e28e2479SGangCao	local io_count1
561e28e2479SGangCao	local io_count2
562e28e2479SGangCao	local iostats_per_channel
563e28e2479SGangCao	local io_count_per_channel1
564e28e2479SGangCao	local io_count_per_channel2
565e28e2479SGangCao	local io_count_per_channel_all=0
566e28e2479SGangCao
567e28e2479SGangCao	iostats=$($rpc_py bdev_get_iostat -b $bdev_name)
568e28e2479SGangCao	io_count1=$(jq -r '.bdevs[0].num_read_ops' <<< "$iostats")
569e28e2479SGangCao
570e28e2479SGangCao	iostats_per_channel=$($rpc_py bdev_get_iostat -b $bdev_name -c)
571e28e2479SGangCao	io_count_per_channel1=$(jq -r '.channels[0].num_read_ops' <<< "$iostats_per_channel")
572e28e2479SGangCao	io_count_per_channel_all=$((io_count_per_channel_all + io_count_per_channel1))
573e28e2479SGangCao	io_count_per_channel2=$(jq -r '.channels[1].num_read_ops' <<< "$iostats_per_channel")
574e28e2479SGangCao	io_count_per_channel_all=$((io_count_per_channel_all + io_count_per_channel2))
575e28e2479SGangCao
576e28e2479SGangCao	iostats=$($rpc_py bdev_get_iostat -b $bdev_name)
577e28e2479SGangCao	io_count2=$(jq -r '.bdevs[0].num_read_ops' <<< "$iostats")
578e28e2479SGangCao
579e28e2479SGangCao	# There is little time passed between the three iostats collected. So that
580e28e2479SGangCao	# the accumulated statistics from per channel data shall be bigger than the
581e28e2479SGangCao	# the first run and smaller than the third run in this short time of period.
582e28e2479SGangCao	if [ $io_count_per_channel_all -lt $io_count1 ] || [ $io_count_per_channel_all -gt $io_count2 ]; then
583e28e2479SGangCao		echo "Failed to collect the per Core IO statistics"
584e28e2479SGangCao		$rpc_py bdev_malloc_delete $STAT_DEV
585e28e2479SGangCao		killprocess $STAT_PID
586e28e2479SGangCao		exit 1
587e28e2479SGangCao	fi
588e28e2479SGangCao}
589e28e2479SGangCao
590e28e2479SGangCaofunction stat_test_suite() {
591e28e2479SGangCao	STAT_DEV="Malloc_STAT"
592e28e2479SGangCao
593e28e2479SGangCao	# Run bdevperf with 2 cores so as to collect per Core IO statistics
59429784f35SKrzysztof Karas	"$rootdir/build/examples/bdevperf" -z -m 0x3 -q 256 -o 4096 -w randread -t 10 -C "$env_ctx" &
595e28e2479SGangCao	STAT_PID=$!
596e28e2479SGangCao	echo "Process Bdev IO statistics testing pid: $STAT_PID"
597e28e2479SGangCao	trap 'cleanup; killprocess $STAT_PID; exit 1' SIGINT SIGTERM EXIT
598e28e2479SGangCao	waitforlisten $STAT_PID
599e28e2479SGangCao
600e28e2479SGangCao	$rpc_py bdev_malloc_create -b $STAT_DEV 128 512
601e28e2479SGangCao	waitforbdev $STAT_DEV
602e28e2479SGangCao
60329784f35SKrzysztof Karas	$rootdir/examples/bdev/bdevperf/bdevperf.py perform_tests &
604e28e2479SGangCao	sleep 2
605e28e2479SGangCao	stat_function_test $STAT_DEV
606e28e2479SGangCao
607e28e2479SGangCao	$rpc_py bdev_malloc_delete $STAT_DEV
608e28e2479SGangCao	killprocess $STAT_PID
609e28e2479SGangCao	trap - SIGINT SIGTERM EXIT
610e28e2479SGangCao}
611e28e2479SGangCao
612*971ec012SShuhei Matsumoto# Create three types of DIF configuration, 512 + 8, 512 + 16 (DIF is first 8bytes), and
613*971ec012SShuhei Matsumoto# 512 + 16 (DIF is last 8 bytes)
614*971ec012SShuhei Matsumotofunction dif_insert_strip_test_suite() {
615*971ec012SShuhei Matsumoto	DIF_DEV_1="Malloc_DIF_1"
616*971ec012SShuhei Matsumoto	DIF_DEV_2="Malloc_DIF_2"
617*971ec012SShuhei Matsumoto	DIF_DEV_3="Malloc_DIF_3"
618*971ec012SShuhei Matsumoto
619*971ec012SShuhei Matsumoto	"$rootdir/build/examples/bdevperf" -z -m 0xf -q 32 -o 4096 -w randrw -M 50 -t 5 -C -N "$env_ctx" &
620*971ec012SShuhei Matsumoto	DIF_PID=$!
621*971ec012SShuhei Matsumoto	echo "Process bdev DIF insert/strip testing pid: $DIF_PID"
622*971ec012SShuhei Matsumoto	trap 'cleanup; killprocess $DIF_PID; exit 1' SIGINT SIGTERM EXIT
623*971ec012SShuhei Matsumoto	waitforlisten $DIF_PID
624*971ec012SShuhei Matsumoto
625*971ec012SShuhei Matsumoto	$rpc_py bdev_malloc_create -b $DIF_DEV_1 1 512 -m 8 -t 1 -f 0 -i
626*971ec012SShuhei Matsumoto	waitforbdev $DIF_DEV_1
627*971ec012SShuhei Matsumoto	$rpc_py bdev_malloc_create -b $DIF_DEV_2 1 512 -m 16 -t 1 -f 0 -i
628*971ec012SShuhei Matsumoto	waitforbdev $DIF_DEV_2
629*971ec012SShuhei Matsumoto	$rpc_py bdev_malloc_create -b $DIF_DEV_3 1 512 -m 16 -t 1 -f 0 -i -d
630*971ec012SShuhei Matsumoto	waitforbdev $DIF_DEV_3
631*971ec012SShuhei Matsumoto
632*971ec012SShuhei Matsumoto	$rootdir/examples/bdev/bdevperf/bdevperf.py perform_tests &
633*971ec012SShuhei Matsumoto	sleep 10
634*971ec012SShuhei Matsumoto
635*971ec012SShuhei Matsumoto	# Bdevperf is expected to be there because DIF error should not happen.
636*971ec012SShuhei Matsumoto	if kill -0 $DIF_PID; then
637*971ec012SShuhei Matsumoto		echo "Process is existed. Pid: $DIF_PID"
638*971ec012SShuhei Matsumoto	else
639*971ec012SShuhei Matsumoto		echo "Process exited unexpectedly. Pid: $DIF_PID"
640*971ec012SShuhei Matsumoto		exit 1
641*971ec012SShuhei Matsumoto	fi
642*971ec012SShuhei Matsumoto
643*971ec012SShuhei Matsumoto	$rpc_py bdev_malloc_delete $DIF_DEV_1
644*971ec012SShuhei Matsumoto	$rpc_py bdev_malloc_delete $DIF_DEV_2
645*971ec012SShuhei Matsumoto	$rpc_py bdev_malloc_delete $DIF_DEV_3
646*971ec012SShuhei Matsumoto	killprocess $DIF_PID
647*971ec012SShuhei Matsumoto	trap - SIGINT SIGTERM EXIT
648*971ec012SShuhei Matsumoto}
649*971ec012SShuhei Matsumoto
650ff12a5edSMike Gerdtsfunction bdev_gpt_uuid() {
651ff12a5edSMike Gerdts	local bdev
652ff12a5edSMike Gerdts
653ff12a5edSMike Gerdts	start_spdk_tgt
654ff12a5edSMike Gerdts
655ff12a5edSMike Gerdts	"$rpc_py" load_config -j "$conf_file"
656ff12a5edSMike Gerdts	"$rpc_py" bdev_wait_for_examine
657ff12a5edSMike Gerdts
658ff12a5edSMike Gerdts	bdev=$("$rpc_py" bdev_get_bdevs -b "$g_unique_partguid")
659ff12a5edSMike Gerdts	[[ "$(jq -r 'length' <<< "$bdev")" == "1" ]]
660ff12a5edSMike Gerdts	[[ "$(jq -r '.[0].aliases[0]' <<< "$bdev")" == "$g_unique_partguid" ]]
661ff12a5edSMike Gerdts	[[ "$(jq -r '.[0].driver_specific.gpt.unique_partition_guid' <<< "$bdev")" == "$g_unique_partguid" ]]
662ff12a5edSMike Gerdts
663ff12a5edSMike Gerdts	bdev=$("$rpc_py" bdev_get_bdevs -b "$g_unique_partguid_old")
664ff12a5edSMike Gerdts	[[ "$(jq -r 'length' <<< "$bdev")" == "1" ]]
665ff12a5edSMike Gerdts	[[ "$(jq -r '.[0].aliases[0]' <<< "$bdev")" == "$g_unique_partguid_old" ]]
666ff12a5edSMike Gerdts	[[ "$(jq -r '.[0].driver_specific.gpt.unique_partition_guid' <<< "$bdev")" == "$g_unique_partguid_old" ]]
667ff12a5edSMike Gerdts
668ff12a5edSMike Gerdts	killprocess "$spdk_tgt_pid"
669ff12a5edSMike Gerdts}
670ff12a5edSMike Gerdts
671ee47846aSArtur Paszkiewiczfunction bdev_crypto_enomem() {
672ee47846aSArtur Paszkiewicz	local base_dev="base0"
673ee47846aSArtur Paszkiewicz	local test_dev="crypt0"
674ee47846aSArtur Paszkiewicz	local err_dev="EE_$base_dev"
675ee47846aSArtur Paszkiewicz	local qd=32
676ee47846aSArtur Paszkiewicz
677ee47846aSArtur Paszkiewicz	"$rootdir/build/examples/bdevperf" -z -m 0x2 -q $qd -o 4096 -w randwrite -t 5 -f "$env_ctx" &
678ee47846aSArtur Paszkiewicz	ERR_PID=$!
679ee47846aSArtur Paszkiewicz	trap 'cleanup; killprocess $ERR_PID; exit 1' SIGINT SIGTERM EXIT
680ee47846aSArtur Paszkiewicz	waitforlisten $ERR_PID
681ee47846aSArtur Paszkiewicz
682ee47846aSArtur Paszkiewicz	$rpc_py <<- RPC
683ee47846aSArtur Paszkiewicz		accel_crypto_key_create -c AES_XTS -k 00112233445566778899001122334455 -e 11223344556677889900112233445500 -n test_dek_sw
684ee47846aSArtur Paszkiewicz		bdev_null_create $base_dev 1024 512
685ee47846aSArtur Paszkiewicz		bdev_error_create $base_dev
686ee47846aSArtur Paszkiewicz		bdev_crypto_create $err_dev $test_dev -n test_dek_sw
687ee47846aSArtur Paszkiewicz	RPC
688ee47846aSArtur Paszkiewicz
689ee47846aSArtur Paszkiewicz	waitforbdev $test_dev
690ee47846aSArtur Paszkiewicz
691ee47846aSArtur Paszkiewicz	$rootdir/examples/bdev/bdevperf/bdevperf.py perform_tests &
692ee47846aSArtur Paszkiewicz	rpcpid=$!
693ee47846aSArtur Paszkiewicz
694ee47846aSArtur Paszkiewicz	sleep 1
695ee47846aSArtur Paszkiewicz	$rpc_py bdev_error_inject_error $err_dev -n 5 -q $((qd - 1)) write nomem
696ee47846aSArtur Paszkiewicz
697ee47846aSArtur Paszkiewicz	wait $rpcpid
698ee47846aSArtur Paszkiewicz
699ee47846aSArtur Paszkiewicz	$rpc_py bdev_crypto_delete $test_dev
700ee47846aSArtur Paszkiewicz
701ee47846aSArtur Paszkiewicz	killprocess $ERR_PID
702ee47846aSArtur Paszkiewicz	trap - SIGINT SIGTERM EXIT
703ee47846aSArtur Paszkiewicz}
704ee47846aSArtur Paszkiewicz
7053f912cf0SMichal Berger# Initial bdev creation and configuration
7065170ac8dSSeth Howell#-----------------------------------------------------
70726328b7bSGangCaoQOS_DEV_1="Malloc_0"
7085170ac8dSSeth HowellQOS_DEV_2="Null_1"
7095170ac8dSSeth HowellQOS_RUN_TIME=5
7105170ac8dSSeth Howell
7115170ac8dSSeth Howellif [ $(uname -s) = Linux ]; then
7125170ac8dSSeth Howell	# Test dynamic memory management. All hugepages will be reserved at runtime
7135170ac8dSSeth Howell	PRE_RESERVED_MEM=0
7145170ac8dSSeth Howellelse
7155170ac8dSSeth Howell	# Dynamic memory management is not supported on BSD
7165170ac8dSSeth Howell	PRE_RESERVED_MEM=2048
7175170ac8dSSeth Howellfi
7185170ac8dSSeth Howell
71954e71303SMichal Bergertest_type=${1:-bdev}
720872e0e46SYuriy Umanetscrypto_device=$2
721d20ae7ffSAlexey Marchukdek=$3
722872e0e46SYuriy Umanetsenv_ctx=""
72313f97e67SAlexey Marchukwait_for_rpc=""
724d20ae7ffSAlexey Marchukif [ -n "$crypto_device" ]; then
725d20ae7ffSAlexey Marchuk	env_ctx="--env-context=--allow=$crypto_device,class=crypto"
726872e0e46SYuriy Umanetsfi
727bc1bd85eSArtur Paszkiewiczif [[ $test_type == bdev || $test_type == crypto_* ]]; then
72813f97e67SAlexey Marchuk	wait_for_rpc="--wait-for-rpc"
72913f97e67SAlexey Marchukfi
730b3b45f16SMichal Bergerstart_spdk_tgt
731de303275SSeth Howellcase "$test_type" in
732ae2d8097SMichal Berger	bdev)
733844c8ec3SMichal Berger		setup_bdev_conf
734844c8ec3SMichal Berger		;;
735de303275SSeth Howell	nvme)
736844c8ec3SMichal Berger		setup_nvme_conf
737844c8ec3SMichal Berger		;;
738de303275SSeth Howell	gpt)
739844c8ec3SMichal Berger		setup_gpt_conf
740844c8ec3SMichal Berger		;;
741102731bdSMichal Berger	crypto_aesni)
742844c8ec3SMichal Berger		setup_crypto_aesni_conf
743844c8ec3SMichal Berger		;;
744102731bdSMichal Berger	crypto_qat)
745844c8ec3SMichal Berger		setup_crypto_qat_conf
746844c8ec3SMichal Berger		;;
74713f97e67SAlexey Marchuk	crypto_sw)
74813f97e67SAlexey Marchuk		setup_crypto_sw_conf
74913f97e67SAlexey Marchuk		;;
750872e0e46SYuriy Umanets	crypto_mlx5)
751872e0e46SYuriy Umanets		setup_crypto_mlx5_conf $dek
752872e0e46SYuriy Umanets		;;
753969b5632SAlexey Marchuk	crypto_accel_mlx5)
754969b5632SAlexey Marchuk		setup_crypto_accel_mlx5_conf
755969b5632SAlexey Marchuk		;;
756de303275SSeth Howell	rbd)
757844c8ec3SMichal Berger		setup_rbd_conf
758844c8ec3SMichal Berger		;;
7592e283fcbS0xe0f	daos)
7602e283fcbS0xe0f		setup_daos_conf
7612e283fcbS0xe0f		;;
762030951b4SArtur Paszkiewicz	raid5f)
763030951b4SArtur Paszkiewicz		setup_raid5f_conf
764030951b4SArtur Paszkiewicz		;;
765008139c8SMichal Berger	xnvme)
766008139c8SMichal Berger		setup_xnvme_conf
767008139c8SMichal Berger		;;
768de303275SSeth Howell	*)
769de303275SSeth Howell		echo "invalid test name"
770de303275SSeth Howell		exit 1
771de303275SSeth Howell		;;
772de303275SSeth Howellesac
773f9d5ed28SSeth Howell
77477b6f4bcSTomasz Zawadzki"$rpc_py" bdev_wait_for_examine
77577b6f4bcSTomasz Zawadzki
776b3b45f16SMichal Berger# Generate json config and use it throughout all the tests
777970601afSPawel Kaminskicat <<- CONF > "$conf_file"
778970601afSPawel Kaminski	        {"subsystems":[
77913f97e67SAlexey Marchuk	        $("$rpc_py" save_subsystem_config -n accel),
780bc1bd85eSArtur Paszkiewicz	        $("$rpc_py" save_subsystem_config -n bdev),
781bc1bd85eSArtur Paszkiewicz	        $("$rpc_py" save_subsystem_config -n iobuf)
782970601afSPawel Kaminski	        ]}
783970601afSPawel KaminskiCONF
784970601afSPawel Kaminski
7854641aa53SMichal Bergermapfile -t bdevs < <("$rpc_py" bdev_get_bdevs | jq -r '.[] | select(.claimed == false)')
7864641aa53SMichal Bergermapfile -t bdevs_name < <(printf '%s\n' "${bdevs[@]}" | jq -r '.name')
7874641aa53SMichal Bergerbdev_list=("${bdevs_name[@]}")
788a1c7ae2dSKrzysztof Karas
789b2235c1fSSeth Howellhello_world_bdev=${bdev_list[0]}
790970601afSPawel Kaminskitrap - SIGINT SIGTERM EXIT
791970601afSPawel Kaminskikillprocess "$spdk_tgt_pid"
7925170ac8dSSeth Howell# End bdev configuration
7935170ac8dSSeth Howell#-----------------------------------------------------
7945170ac8dSSeth Howell
7958419c294SMichal Bergertrap "cleanup" SIGINT SIGTERM EXIT
7968419c294SMichal Berger
797872e0e46SYuriy Umanetsrun_test "bdev_hello_world" $SPDK_EXAMPLE_DIR/hello_bdev --json "$conf_file" -b "$hello_world_bdev" "$env_ctx"
798872e0e46SYuriy Umanetsrun_test "bdev_bounds" bdev_bounds "$env_ctx"
7994641aa53SMichal Bergerrun_test "bdev_nbd" nbd_function_test "$conf_file" "${bdevs_name[*]}" "$env_ctx"
800053c15b3SMichal Bergerif [[ $CONFIG_FIO_PLUGIN == y ]]; then
801de303275SSeth Howell	if [ "$test_type" = "nvme" ] || [ "$test_type" = "gpt" ]; then
802de303275SSeth Howell		# TODO: once we get real multi-ns drives, re-enable this test for NVMe.
803de303275SSeth Howell		echo "skipping fio tests on NVMe due to multi-ns failures."
804de303275SSeth Howell	else
805872e0e46SYuriy Umanets		run_test "bdev_fio" fio_test_suite "$env_ctx"
806de303275SSeth Howell	fi
807bef870c6STomasz Zawadzkielse
808bef870c6STomasz Zawadzki	echo "FIO not available"
809bef870c6STomasz Zawadzki	exit 1
810f9d5ed28SSeth Howellfi
811f9d5ed28SSeth Howell
8128419c294SMichal Bergertrap "cleanup" SIGINT SIGTERM EXIT
8138419c294SMichal Berger
81429784f35SKrzysztof Karasrun_test "bdev_verify" $rootdir/build/examples/bdevperf --json "$conf_file" -q 128 -o 4096 -w verify -t 5 -C -m 0x3 "$env_ctx"
815677907dbSAlexey Marchukrun_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"
81629784f35SKrzysztof Karasrun_test "bdev_write_zeroes" $rootdir/build/examples/bdevperf --json "$conf_file" -q 128 -o 4096 -w write_zeroes -t 1 "$env_ctx"
817de303275SSeth Howell
818bb432b4eStongkunkun# test json config not enclosed with {}
81929784f35SKrzysztof Karasrun_test "bdev_json_nonenclosed" $rootdir/build/examples/bdevperf --json "$nonenclosed_conf_file" -q 128 -o 4096 -w write_zeroes -t 1 "$env_ctx" || true
820bb432b4eStongkunkun
821bb432b4eStongkunkun# test json config "subsystems" not with array
82229784f35SKrzysztof Karasrun_test "bdev_json_nonarray" $rootdir/build/examples/bdevperf --json "$nonarray_conf_file" -q 128 -o 4096 -w write_zeroes -t 1 "$env_ctx" || true
823bb432b4eStongkunkun
82454e71303SMichal Bergerif [[ $test_type == bdev ]]; then
825872e0e46SYuriy Umanets	run_test "bdev_qos" qos_test_suite "$env_ctx"
82648ce2c97SGangCao	run_test "bdev_qd_sampling" qd_sampling_test_suite "$env_ctx"
8278f2ca281SGangCao	run_test "bdev_error" error_test_suite "$env_ctx"
828e28e2479SGangCao	run_test "bdev_stat" stat_test_suite "$env_ctx"
829*971ec012SShuhei Matsumoto	run_test "bdev_dif_insert_strip" dif_insert_strip_test_suite "$env_ctx"
830de303275SSeth Howellfi
831f9d5ed28SSeth Howell
832ff12a5edSMike Gerdtsif [[ $test_type == gpt ]]; then
833ff12a5edSMike Gerdts	run_test "bdev_gpt_uuid" bdev_gpt_uuid
834ff12a5edSMike Gerdtsfi
835ff12a5edSMike Gerdts
836ee47846aSArtur Paszkiewiczif [[ $test_type == crypto_sw ]]; then
837ee47846aSArtur Paszkiewicz	run_test "bdev_crypto_enomem" bdev_crypto_enomem
838ee47846aSArtur Paszkiewiczfi
839ee47846aSArtur Paszkiewicz
840f9d5ed28SSeth Howell# Temporarily disabled - infinite loop
8418295a2b0SSeth Howell# if [ $RUN_NIGHTLY -eq 1 ]; then
84229784f35SKrzysztof Karas# run_test "bdev_reset" $rootdir/build/examples/bdevperf --json "$conf_file" -q 16 -w reset -o 4096 -t 60 "$env_ctx"
8438295a2b0SSeth Howell# fi
844f9d5ed28SSeth Howell
845c4d4abcfSSeth Howell# Bdev and configuration cleanup below this line
846c4d4abcfSSeth Howell#-----------------------------------------------------
847f9d5ed28SSeth Howell
8488419c294SMichal Bergertrap - SIGINT SIGTERM EXIT
849a940721aSMichal Bergercleanup
850