test/json_config: Simplify events check
Consider multiple nvme devices loaded to subsystem prior running the checks. Signed-off-by: Michal Berger <michalx.berger@intel.com> Change-Id: Ie4ce8be6ec22c26c1d46ded42ded468b92d6cc57 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7868 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: John Kariuki <John.K.Kariuki@intel.com>
This commit is contained in:
parent
5247e10a06
commit
17a662f9fe
@ -38,7 +38,6 @@ function initiator_rpc() {
|
|||||||
$rootdir/scripts/rpc.py -s "${app_socket[initiator]}" "$@"
|
$rootdir/scripts/rpc.py -s "${app_socket[initiator]}" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
RE_UUID="[[:alnum:]-]+"
|
|
||||||
last_event_id=0
|
last_event_id=0
|
||||||
|
|
||||||
function tgt_check_notification_types() {
|
function tgt_check_notification_types() {
|
||||||
@ -57,42 +56,38 @@ function tgt_check_notification_types() {
|
|||||||
return $ret
|
return $ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get_notifications() {
|
||||||
|
local ev_type ev_ctx event_id
|
||||||
|
|
||||||
|
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)"')
|
||||||
|
}
|
||||||
|
|
||||||
function tgt_check_notifications() {
|
function tgt_check_notifications() {
|
||||||
local event_line event ev_type ev_ctx
|
local events_to_check
|
||||||
local rc=""
|
local recorded_events
|
||||||
|
|
||||||
while read -r event_line; do
|
events_to_check=("$@")
|
||||||
# remove ID
|
recorded_events=($(get_notifications))
|
||||||
event="${event_line%:*}"
|
|
||||||
|
|
||||||
ev_type=${event%:*}
|
# These should be in order hence compare entire arrays
|
||||||
ev_ctx=${event#*:}
|
if [[ ${events_to_check[*]} != "${recorded_events[*]}" ]]; then
|
||||||
|
cat <<- ERROR
|
||||||
|
Expected events did not match.
|
||||||
|
|
||||||
ex_ev_type=${1%%:*}
|
Expected:
|
||||||
ex_ev_ctx=${1#*:}
|
$(printf ' %s\n' "${events_to_check[@]}")
|
||||||
|
Recorded:
|
||||||
last_event_id=${event_line##*:}
|
$(printf ' %s\n' "${recorded_events[@]}")
|
||||||
|
ERROR
|
||||||
# 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
|
|
||||||
|
|
||||||
if (($# != 0)); then
|
|
||||||
echo "ERROR: missing events:"
|
|
||||||
echo "$@"
|
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
cat <<- INFO
|
||||||
|
Expected events matched:
|
||||||
|
$(printf ' %s\n' "${recorded_events[@]}")
|
||||||
|
INFO
|
||||||
}
|
}
|
||||||
|
|
||||||
# $1 - target / initiator
|
# $1 - target / initiator
|
||||||
@ -150,32 +145,12 @@ function create_bdev_subsystem_config() {
|
|||||||
|
|
||||||
local expected_notifications=()
|
local expected_notifications=()
|
||||||
|
|
||||||
local event_line event ev_type ev_ctx
|
# Consider multiple nvme devices loaded into the subsystem prior running
|
||||||
local rc=""
|
# the tests.
|
||||||
|
expected_notifications+=($(get_notifications))
|
||||||
# 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)"')
|
|
||||||
|
|
||||||
if [[ $SPDK_TEST_BLOCKDEV -eq 1 ]]; then
|
if [[ $SPDK_TEST_BLOCKDEV -eq 1 ]]; then
|
||||||
local lvol_store_base_bdev=Nvme0n1
|
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 $lvol_store_base_bdev 2
|
||||||
tgt_rpc bdev_split_create Malloc0 3
|
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)
|
# If LVOLs configuration will be reordered (eg moved before splits or AIO/NVMe)
|
||||||
# it should fail loading JSON config from file.
|
# 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_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+=(
|
expected_notifications+=(
|
||||||
"bdev_register:$RE_UUID"
|
"bdev_register:$(tgt_rpc bdev_lvol_create -l lvs_test lvol0 32)"
|
||||||
"bdev_register:$RE_UUID"
|
"bdev_register:$(tgt_rpc bdev_lvol_create -l lvs_test -t lvol1 32)"
|
||||||
"bdev_register:$RE_UUID"
|
"bdev_register:$(tgt_rpc bdev_lvol_snapshot lvs_test/lvol0 snapshot0)"
|
||||||
"bdev_register:$RE_UUID"
|
"bdev_register:$(tgt_rpc bdev_lvol_clone lvs_test/snapshot0 clone0)"
|
||||||
)
|
)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user