Commit 4641aa53 authored by Michal Berger's avatar Michal Berger Committed by Tomasz Zawadzki
Browse files

test/common: Provide {ext,null}glob by default in autotest suite



This requires adjustments in several test suites due to some bad
practices exposed by explicit use of nullglob.

Change-Id: Idbe7eeec598ffc06e98986898344e4e0d88f4a5d
Signed-off-by: default avatarMichal Berger <michal.berger@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/19551


Reviewed-by: default avatarJim Harris <jim.harris@gmail.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
parent 13479ef5
Loading
Loading
Loading
Loading
+7 −13
Original line number Diff line number Diff line
@@ -9,12 +9,6 @@ rootdir=$(readlink -f $testdir/../..)
source $rootdir/test/common/autotest_common.sh
source $testdir/nbd_common.sh

# nullglob will remove unmatched words containing '*', '?', '[' characters during word splitting.
# This means that empty alias arrays will be removed instead of printing "[]", which breaks
# consecutive "jq" calls, as the "aliases" key will have no value and the whole JSON will be
# invalid. Hence do not enable this option for the duration of the tests in this script.
shopt -s extglob

rpc_py=rpc_cmd
conf_file="$testdir/bdev.json"
nonenclosed_conf_file="$testdir/nonenclosed.json"
@@ -342,7 +336,7 @@ function fio_test_suite() {
	# Generate the fio config file given the list of all unclaimed bdevs
	env_context=$(echo "$env_ctx" | sed 's/--env-context=//')
	fio_config_gen $testdir/bdev.fio verify AIO "$env_context"
	for b in $(echo $bdevs | jq -r '.name'); do
	for b in "${bdevs_name[@]}"; do
		echo "[job_$b]" >> $testdir/bdev.fio
		echo "filename=$b" >> $testdir/bdev.fio
	done
@@ -356,8 +350,8 @@ function fio_test_suite() {

	# Generate the fio config file given the list of all unclaimed bdevs that support unmap
	fio_config_gen $testdir/bdev.fio trim "" "$env_context"
	if [ "$(echo $bdevs | jq -r 'select(.supported_io_types.unmap == true) | .name')" != "" ]; then
		for b in $(echo $bdevs | jq -r 'select(.supported_io_types.unmap == true) | .name'); do
	if [[ -n $(printf '%s\n' "${bdevs[@]}" | jq -r 'select(.supported_io_types.unmap == true) | .name') ]]; then
		for b in $(printf '%s\n' "${bdevs[@]}" | jq -r 'select(.supported_io_types.unmap == true) | .name'); do
			echo "[job_$b]" >> $testdir/bdev.fio
			echo "filename=$b" >> $testdir/bdev.fio
		done
@@ -749,9 +743,9 @@ cat <<- CONF > "$conf_file"
	        ]}
CONF

bdevs=$("$rpc_py" bdev_get_bdevs | jq -r '.[] | select(.claimed == false)')
bdevs_name=$(echo $bdevs | jq -r '.name')
bdev_list=($bdevs_name)
mapfile -t bdevs < <("$rpc_py" bdev_get_bdevs | jq -r '.[] | select(.claimed == false)')
mapfile -t bdevs_name < <(printf '%s\n' "${bdevs[@]}" | jq -r '.name')
bdev_list=("${bdevs_name[@]}")

hello_world_bdev=${bdev_list[0]}
trap - SIGINT SIGTERM EXIT
@@ -763,7 +757,7 @@ trap "cleanup" SIGINT SIGTERM EXIT

run_test "bdev_hello_world" $SPDK_EXAMPLE_DIR/hello_bdev --json "$conf_file" -b "$hello_world_bdev" "$env_ctx"
run_test "bdev_bounds" bdev_bounds "$env_ctx"
run_test "bdev_nbd" nbd_function_test $conf_file "$bdevs_name" "$env_ctx"
run_test "bdev_nbd" nbd_function_test "$conf_file" "${bdevs_name[*]}" "$env_ctx"
if [[ $CONFIG_FIO_PLUGIN == y ]]; then
	if [ "$test_type" = "nvme" ] || [ "$test_type" = "gpt" ]; then
		# TODO: once we get real multi-ns drives, re-enable this test for NVMe.
+15 −14
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ function xtrace_fd() {
}

set -e
shopt -s nullglob
shopt -s extglob

if [[ -e $rootdir/test/common/build_config.sh ]]; then
	source "$rootdir/test/common/build_config.sh"
@@ -747,9 +749,7 @@ function process_core() {

	local coredumps core

	shopt -s nullglob
	coredumps=("$output_dir/coredumps/"*.bt.txt)
	shopt -u nullglob

	((${#coredumps[@]} > 0)) || return 0
	chmod -R a+r "$output_dir/coredumps"
@@ -1366,9 +1366,7 @@ function autotest_cleanup() {
		kill "$udevadm_pid" || :
	fi

	shopt -s nullglob
	local storage_fallback_purge=("${TMPDIR:-/tmp}/spdk."??????)
	shopt -u nullglob

	if ((${#storage_fallback_purge[@]} > 0)); then
		rm -rf "${storage_fallback_purge[@]}"
@@ -1456,29 +1454,32 @@ function get_nvme_ctrlr_from_bdf() {
# Get BDF addresses of all NVMe drives currently attached to
# uio-pci-generic or vfio-pci
function get_nvme_bdfs() {
	xtrace_disable
	bdfs=$(jq -r .config[].params.traddr <<< $($rootdir/scripts/gen_nvme.sh))
	if [[ -z ${bdfs:-} ]]; then
		echo "No devices to test on!"
		exit 1
	local bdfs=()
	bdfs=($("$rootdir/scripts/gen_nvme.sh" | jq -r '.config[].params.traddr'))
	if ((${#bdfs[@]} == 0)); then
		echo "No bdevs found" >&2
		return 1
	fi
	echo "$bdfs"
	xtrace_restore
	printf '%s\n' "${bdfs[@]}"
}

# Same as function above, but just get the first disks BDF address
function get_first_nvme_bdf() {
	head -1 <<< "$(get_nvme_bdfs)"
	local bdfs=()
	bdfs=($(get_nvme_bdfs))

	echo "${bdfs[0]}"
}

function nvme_namespace_revert() {
	$rootdir/scripts/setup.sh
	sleep 1
	bdfs=$(get_nvme_bdfs)
	local bdfs=()
	bdfs=($(get_nvme_bdfs))

	$rootdir/scripts/setup.sh reset

	for bdf in $bdfs; do
	for bdf in "${bdfs[@]}"; do
		nvme_ctrlr=/dev/$(get_nvme_ctrlr_from_bdf ${bdf})
		if [[ -z "${nvme_ctrlr:-}" ]]; then
			continue
+0 −2
Original line number Diff line number Diff line
@@ -8,8 +8,6 @@ testdir=$(readlink -f "$(dirname $0)")
rootdir=$(readlink -f "$testdir/../../")
source "$rootdir/test/common/autotest_common.sh"

shopt -s nullglob

rpc_sock1=/var/tmp/spdk.sock
rpc_sock2=/var/tmp/spdk2.sock

+12 −12
Original line number Diff line number Diff line
@@ -87,7 +87,7 @@ waitfortcp $server_pid $INITIATOR_IP:$ISCSI_PORT

# send message using hello_sock client
message="**MESSAGE:This is a test message from the client**"
response=$(echo $message | $HELLO_SOCK_APP -H $INITIATOR_IP -P $ISCSI_PORT -N "posix")
response=$(echo "$message" | $HELLO_SOCK_APP -H $INITIATOR_IP -P $ISCSI_PORT -N "posix")

if ! echo "$response" | grep -q "$message"; then
	exit 1
@@ -95,7 +95,7 @@ fi

# send message using hello_sock client with zero copy disabled
message="**MESSAGE:This is a test message from the client with zero copy disabled**"
response=$(echo $message | $HELLO_SOCK_APP -H $INITIATOR_IP -P $ISCSI_PORT -N "posix" -z)
response=$(echo "$message" | $HELLO_SOCK_APP -H $INITIATOR_IP -P $ISCSI_PORT -N "posix" -z)

if ! echo "$response" | grep -q "$message"; then
	exit 1
@@ -103,7 +103,7 @@ fi

# send message using hello_sock client with zero copy enabled
message="**MESSAGE:This is a test message from the client with zero copy enabled**"
response=$(echo $message | $HELLO_SOCK_APP -H $INITIATOR_IP -P $ISCSI_PORT -N "posix" -Z)
response=$(echo "$message" | $HELLO_SOCK_APP -H $INITIATOR_IP -P $ISCSI_PORT -N "posix" -Z)

if ! echo "$response" | grep -q "$message"; then
	exit 1
@@ -129,25 +129,25 @@ waitforlisten $server_pid

# send message using hello_sock client
message="**MESSAGE:This is a test message from the hello_sock client with ssl**"
response=$(echo $message | $HELLO_SOCK_APP -H $TARGET_IP -P $ISCSI_PORT $PSK -m 0x2)
response=$(echo "$message" | $HELLO_SOCK_APP -H $TARGET_IP -P $ISCSI_PORT $PSK -m 0x2)
if ! echo "$response" | grep -q "$message"; then
	exit 1
fi

# send message using hello_sock client using TLS 1.3
message="**MESSAGE:This is a test message from the hello_sock client with ssl using TLS 1.3**"
response=$(echo $message | $HELLO_SOCK_APP -H $TARGET_IP -P $ISCSI_PORT $PSK -T 13 -m 0x2)
response=$(echo "$message" | $HELLO_SOCK_APP -H $TARGET_IP -P $ISCSI_PORT $PSK -T 13 -m 0x2)
if ! echo "$response" | grep -q "$message"; then
	exit 1
fi

# send message using hello_sock client using incorrect TLS 7
message="**MESSAGE:This is a test message from the hello_sock client with ssl using incorrect TLS 7**"
echo $message | $HELLO_SOCK_APP -H $TARGET_IP -P $ISCSI_PORT $PSK -T 7 -m 0x2 && exit 1
echo "$message" | $HELLO_SOCK_APP -H $TARGET_IP -P $ISCSI_PORT $PSK -T 7 -m 0x2 && exit 1

# send message using hello_sock client with KTLS disabled
message="**MESSAGE:This is a test message from the hello_sock client with KTLS disabled**"
response=$(echo $message | $HELLO_SOCK_APP -H $TARGET_IP -P $ISCSI_PORT $PSK -k -m 0x2)
response=$(echo "$message" | $HELLO_SOCK_APP -H $TARGET_IP -P $ISCSI_PORT $PSK -k -m 0x2)
if ! echo "$response" | grep -q "$message"; then
	exit 1
fi
@@ -159,12 +159,12 @@ fi
# See GH issue #2687

# message="**MESSAGE:This is a test message from the hello_sock client with KTLS enabled**"
# echo $message | $HELLO_SOCK_APP -H $TARGET_IP -P $ISCSI_PORT $PSK -K
# echo "$message" | $HELLO_SOCK_APP -H $TARGET_IP -P $ISCSI_PORT $PSK -K

# send message using openssl client using TLS 1.3
message="**MESSAGE:This is a test message from the openssl client using TLS 1.3**"
response=$( (
	echo -ne $message
	echo -ne "$message"
	sleep 2
) | $OPENSSL_APP s_client -debug -state -tlsextdebug -tls1_3 -psk_identity psk.spdk.io -psk "1234567890ABCDEF" -connect $TARGET_IP:$ISCSI_PORT)
if ! echo "$response" | grep -q "$message"; then
@@ -173,11 +173,11 @@ fi

# send message using hello_sock client with unmatching PSK KEY, expect a failure
message="**MESSAGE:This is a test message from the hello_sock client with unmatching psk_key**"
echo $message | $HELLO_SOCK_APP -H $TARGET_IP -P $ISCSI_PORT $PSK -E 4321DEADBEEF1234 -m 0x2 && exit 1
echo "$message" | $HELLO_SOCK_APP -H $TARGET_IP -P $ISCSI_PORT $PSK -E 4321DEADBEEF1234 -m 0x2 && exit 1

# send message using hello_sock client with unmatching PSK IDENTITY, expect a failure
message="**MESSAGE:This is a test message from the hello_sock client with unmatching psk_key**"
echo $message | $HELLO_SOCK_APP -H $TARGET_IP -P $ISCSI_PORT $PSK -I WRONG_PSK_ID -m 0x2 && exit 1
echo "$message" | $HELLO_SOCK_APP -H $TARGET_IP -P $ISCSI_PORT $PSK -I WRONG_PSK_ID -m 0x2 && exit 1

trap '-' SIGINT SIGTERM EXIT
# NOTE: socat returns code 143 on SIGINT
@@ -199,7 +199,7 @@ waitforlisten $server_pid

# send message to server using socat
message="**MESSAGE:This is a test message to the server**"
response=$(echo $message | $SOCAT_APP - tcp:$TARGET_IP:$ISCSI_PORT 2> /dev/null)
response=$(echo "$message" | $SOCAT_APP - tcp:$TARGET_IP:$ISCSI_PORT 2> /dev/null)

if [ "$message" != "$response" ]; then
	exit 1
+0 −2
Original line number Diff line number Diff line
@@ -8,8 +8,6 @@ testdir=$(readlink -f "$(dirname "$0")")
rootdir=$(readlink -f "$testdir/../../../")
source "$rootdir/test/common/autotest_common.sh"

shopt -s extglob nullglob

decode_cmb_regs() {
	local cmb=$1
	local cmbs
Loading