diff --git a/test/json_config/json_config.sh b/test/json_config/json_config.sh index 7244d8638..965f74382 100755 --- a/test/json_config/json_config.sh +++ b/test/json_config/json_config.sh @@ -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 } +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() { - local event_line event ev_type ev_ctx - local rc="" + local events_to_check + local recorded_events - while read -r event_line; do - # remove ID - event="${event_line%:*}" + events_to_check=("$@") + recorded_events=($(get_notifications)) - ev_type=${event%:*} - ev_ctx=${event#*:} + # These should be in order hence compare entire arrays + if [[ ${events_to_check[*]} != "${recorded_events[*]}" ]]; then + cat <<- ERROR + Expected events did not match. - ex_ev_type=${1%%:*} - ex_ev_ctx=${1#*:} - - last_event_id=${event_line##*:} - - # 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 "$@" + 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