1#!/usr/bin/env bash 2# SPDX-License-Identifier: BSD-3-Clause 3# Copyright (C) 2023 Intel Corporation 4# All rights reserved. 5 6testdir=$(readlink -f $(dirname $0)) 7rootdir=$(readlink -f $testdir/../../..) 8source "$testdir/common.sh" 9 10# Give the devices back to the kernel at the end 11trap 'killprocess $spdk_tgt_pid; "$rootdir/scripts/setup.sh" reset' EXIT 12 13nvme() { 14 # Apply some custom filters to align output between the plugin's listing and base nvme-cli's 15 /usr/local/src/nvme-cli-plugin/nvme "$@" \ 16 | sed \ 17 -e 's#nqn.\+ ##g' \ 18 -e 's#"SubsystemNQN.*##g' \ 19 -e 's#NQN=.*##g' \ 20 -e 's#/dev\(/spdk\)\?/##g' \ 21 -e 's#ng#nvme##g' \ 22 -e 's#-subsys##g' \ 23 -e 's#PCIE#pcie#g' \ 24 -e 's#(null)#live#g' 25 ((PIPESTATUS[0] == 0)) 26} 27 28kernel_out=() 29cuse_out=() 30 31rpc_py=$rootdir/scripts/rpc.py 32 33# We need to make sure these tests don't discriminate against the PCI_BLOCKED devices 34# since nvme-cli doesn't really care - to make sure all outputs are aligned, we need to 35# include all the devices that we can find. 36export PCI_BLOCKED="" 37 38"$rootdir/scripts/setup.sh" reset 39scan_nvme_ctrls 40 41kernel_out[0]=$(nvme list) 42kernel_out[1]=$(nvme list -v) 43kernel_out[2]=$(nvme list -v -o json) 44kernel_out[3]=$(nvme list-subsys) 45 46$rootdir/scripts/setup.sh 47 48$SPDK_BIN_DIR/spdk_tgt & 49spdk_tgt_pid=$! 50 51waitforlisten $spdk_tgt_pid 52 53# Keep ctrls in order as cuse will always start registering with id 0 regardless of the ctrl's name 54for ctrl in "${ordered_ctrls[@]}"; do 55 $rpc_py bdev_nvme_attach_controller -b "$ctrl" -t PCIe -a "${bdfs["$ctrl"]}" 56 $rpc_py bdev_nvme_cuse_register -n "$ctrl" 57 58done 59 60$rpc_py bdev_get_bdevs 61$rpc_py bdev_nvme_get_controllers 62 63cuse_out[0]=$(nvme spdk list) 64cuse_out[1]=$(nvme spdk list -v) 65cuse_out[2]=$(nvme spdk list -v -o json) 66cuse_out[3]=$(nvme spdk list-subsys) 67 68# plugin does not support json output for the list-subsys 69[[ $(nvme spdk list-subsys -v -o json 2>&1 || true) == "Json output format is not supported." ]] 70 71diff -ub \ 72 <(printf '%s\n' "${kernel_out[@]}") \ 73 <(printf '%s\n' "${cuse_out[@]}") 74