Commit 17a662f9 authored by Michal Berger's avatar Michal Berger Committed by Tomasz Zawadzki
Browse files

test/json_config: Simplify events check



Consider multiple nvme devices loaded to subsystem prior running
the checks.

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


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarJohn Kariuki <John.K.Kariuki@intel.com>
parent 5247e10a
Loading
Loading
Loading
Loading
+35 −64
Original line number Diff line number Diff line
@@ -38,7 +38,6 @@ function initiator_rpc() {
	$rootdir/scripts/rpc.py -s "${app_socket[initiator]}" "$@"
}

RE_UUID="[[:alnum:]-]+"
last_event_id=0

function tgt_check_notification_types() {
@@ -57,42 +56,38 @@ function tgt_check_notification_types() {
	return $ret
}

function tgt_check_notifications() {
	local event_line event ev_type ev_ctx
	local rc=""

	while read -r event_line; do
		# remove ID
		event="${event_line%:*}"

		ev_type=${event%:*}
		ev_ctx=${event#*:}

		ex_ev_type=${1%%:*}
		ex_ev_ctx=${1#*:}

		last_event_id=${event_line##*:}
get_notifications() {
	local ev_type ev_ctx event_id

		# set rc=false in case of failure so all errors can be printed
		if (($# == 0)); then
			echo "ERROR: got extra event: $event_line"
			rc=false
			continue
		elif ! echo "$ev_type" | grep -E -q "^${ex_ev_type}\$" || ! echo "$ev_ctx" | grep -E -q "^${ex_ev_ctx}\$"; then
			echo "ERROR: expected event '$1' but got '$event' (whole event line: $event_line)"
			rc=false
		fi

		shift
	done < <(tgt_rpc notify_get_notifications -i ${last_event_id} | jq -r '.[] | "\(.type):\(.ctx):\(.id)"')

	$rc
	while IFS=":" read -r ev_type ev_ctx event_id; do
		echo "$ev_type:$ev_ctx"
	done < <(tgt_rpc notify_get_notifications -i "$last_event_id" | jq -r '.[] | "\(.type):\(.ctx):\(.id)"')
}

	if (($# != 0)); then
		echo "ERROR: missing events:"
		echo "$@"
function tgt_check_notifications() {
	local events_to_check
	local recorded_events

	events_to_check=("$@")
	recorded_events=($(get_notifications))

	# These should be in order hence compare entire arrays
	if [[ ${events_to_check[*]} != "${recorded_events[*]}" ]]; then
		cat <<- ERROR
			Expected events did not match.

			Expected:
			$(printf ' %s\n' "${events_to_check[@]}")
			Recorded:
			$(printf ' %s\n' "${recorded_events[@]}")
		ERROR
		return 1
	fi

	cat <<- INFO
		Expected events matched:
		$(printf ' %s\n' "${recorded_events[@]}")
	INFO
}

# $1 - target / initiator
@@ -150,32 +145,12 @@ function create_bdev_subsystem_config() {

	local expected_notifications=()

	local event_line event ev_type ev_ctx
	local rc=""

	# Before testing notifications generated by the operations in this function, we
	# need add existing notification to the expected list first. Otherwise it would fail.
	while read -r event_line; do
		# remove ID
		event="${event_line%:*}"
		ev_type=${event%:*}
		ev_ctx=${event#*:}

		expected_notifications+=(${ev_type}:${ev_ctx})
	done < <(tgt_rpc notify_get_notifications -i ${last_event_id} | jq -r '.[] | "\(.type):\(.ctx):\(.id)"')
	# Consider multiple nvme devices loaded into the subsystem prior running
	# the tests.
	expected_notifications+=($(get_notifications))

	if [[ $SPDK_TEST_BLOCKDEV -eq 1 ]]; then
		local lvol_store_base_bdev=Nvme0n1
		if ! tgt_rpc get_bdevs --name ${lvol_store_base_bdev} > /dev/null; then
			if [[ $(uname -s) = Linux ]]; then
				lvol_store_base_bdev=aio_disk
				echo "WARNING: No NVMe drive found. Using '$lvol_store_base_bdev' instead."
			else
				echo "ERROR: No NVMe drive found and bdev_aio is not supported on $(uname -s)."
				timing_exit "${FUNCNAME[0]}"
				return 1
			fi
		fi

		tgt_rpc bdev_split_create $lvol_store_base_bdev 2
		tgt_rpc bdev_split_create Malloc0 3
@@ -211,16 +186,12 @@ function create_bdev_subsystem_config() {
		# If LVOLs configuration will be reordered (eg moved before splits or AIO/NVMe)
		# it should fail loading JSON config from file.
		tgt_rpc bdev_lvol_create_lvstore -c 1048576 ${lvol_store_base_bdev}p0 lvs_test
		tgt_rpc bdev_lvol_create -l lvs_test lvol0 32
		tgt_rpc bdev_lvol_create -l lvs_test -t lvol1 32
		tgt_rpc bdev_lvol_snapshot lvs_test/lvol0 snapshot0
		tgt_rpc bdev_lvol_clone lvs_test/snapshot0 clone0

		expected_notifications+=(
			"bdev_register:$RE_UUID"
			"bdev_register:$RE_UUID"
			"bdev_register:$RE_UUID"
			"bdev_register:$RE_UUID"
			"bdev_register:$(tgt_rpc bdev_lvol_create -l lvs_test lvol0 32)"
			"bdev_register:$(tgt_rpc bdev_lvol_create -l lvs_test -t lvol1 32)"
			"bdev_register:$(tgt_rpc bdev_lvol_snapshot lvs_test/lvol0 snapshot0)"
			"bdev_register:$(tgt_rpc bdev_lvol_clone lvs_test/snapshot0 clone0)"
		)
	fi