1#!/usr/bin/env bash 2# SPDX-License-Identifier: BSD-3-Clause 3# Copyright (C) 2019 Intel Corporation 4# All rights reserved. 5# 6testdir=$(readlink -f $(dirname $0)) 7rootdir=$(readlink -f $testdir/../../..) 8source "$testdir/common.sh" 9 10rm -Rf $testdir/match_files 11mkdir $testdir/match_files 12 13KERNEL_OUT=$testdir/match_files/kernel.out 14CUSE_OUT=$testdir/match_files/cuse.out 15 16NVME_CMD=/usr/local/src/nvme-cli/nvme 17rpc_py=$rootdir/scripts/rpc.py 18 19"$rootdir/scripts/setup.sh" reset 20scan_nvme_ctrls 21 22if ! nvme_name=$(get_nvme_with_ns_management); then 23 echo "Failed to find suitable nvme for the test" >&2 24 return 1 25fi 26 27ctrlr="/dev/${nvme_name}" 28ns="/dev/${nvme_name}n1" 29bdf=${bdfs["$nvme_name"]} 30 31waitforblk "${nvme_name}n1" 32 33oacs=$(${NVME_CMD} id-ctrl $ctrlr | grep oacs | cut -d: -f2) 34oacs_firmware=$((oacs & 0x4)) 35 36${NVME_CMD} get-ns-id $ns > ${KERNEL_OUT}.1 37${NVME_CMD} id-ns $ns > ${KERNEL_OUT}.2 38${NVME_CMD} list-ns $ns > ${KERNEL_OUT}.3 39 40${NVME_CMD} id-ctrl $ctrlr > ${KERNEL_OUT}.4 41${NVME_CMD} list-ctrl $ctrlr > ${KERNEL_OUT}.5 42if [ "$oacs_firmware" -ne "0" ]; then 43 ${NVME_CMD} fw-log $ctrlr > ${KERNEL_OUT}.6 44fi 45${NVME_CMD} smart-log $ctrlr 46${NVME_CMD} error-log $ctrlr > ${KERNEL_OUT}.7 47${NVME_CMD} get-feature $ctrlr -f 1 -s 1 -l 100 > ${KERNEL_OUT}.8 48${NVME_CMD} get-log $ctrlr -i 1 -l 100 > ${KERNEL_OUT}.9 49${NVME_CMD} reset $ctrlr > ${KERNEL_OUT}.10 50# Negative test to make sure status message is the same on failures 51# FID 2 is power management. It should be constrained to the whole system 52# Attempting to apply it to a namespace should result in a failure 53${NVME_CMD} set-feature $ctrlr -n 1 -f 2 -v 0 2> ${KERNEL_OUT}.11 || true 54 55$rootdir/scripts/setup.sh 56 57$SPDK_BIN_DIR/spdk_tgt -m 0x3 & 58spdk_tgt_pid=$! 59trap 'kill -9 ${spdk_tgt_pid}; exit 1' SIGINT SIGTERM EXIT 60 61waitforlisten $spdk_tgt_pid 62 63$rpc_py bdev_nvme_attach_controller -b Nvme0 -t PCIe -a ${bdf} 64$rpc_py bdev_nvme_cuse_register -n Nvme0 65 66ctrlr="/dev/spdk/nvme0" 67ns="${ctrlr}n1" 68waitforfile "$ns" 69 70$rpc_py bdev_get_bdevs 71$rpc_py bdev_nvme_get_controllers 72 73${NVME_CMD} get-ns-id $ns > ${CUSE_OUT}.1 74${NVME_CMD} id-ns $ns > ${CUSE_OUT}.2 75${NVME_CMD} list-ns $ns > ${CUSE_OUT}.3 76 77${NVME_CMD} id-ctrl $ctrlr > ${CUSE_OUT}.4 78${NVME_CMD} list-ctrl $ctrlr > ${CUSE_OUT}.5 79if [ "$oacs_firmware" -ne "0" ]; then 80 ${NVME_CMD} fw-log $ctrlr > ${CUSE_OUT}.6 81fi 82${NVME_CMD} smart-log $ctrlr 83${NVME_CMD} error-log $ctrlr > ${CUSE_OUT}.7 84${NVME_CMD} get-feature $ctrlr -f 1 -s 1 -l 100 > ${CUSE_OUT}.8 85${NVME_CMD} get-log $ctrlr -i 1 -l 100 > ${CUSE_OUT}.9 86${NVME_CMD} reset $ctrlr > ${CUSE_OUT}.10 87${NVME_CMD} set-feature $ctrlr -n 1 -f 2 -v 0 2> ${CUSE_OUT}.11 || true 88 89for i in {1..11}; do 90 if [ -f "${KERNEL_OUT}.${i}" ] && [ -f "${CUSE_OUT}.${i}" ]; then 91 sed -i "s/${nvme_name}/nvme0/g" ${KERNEL_OUT}.${i} 92 diff --suppress-common-lines ${KERNEL_OUT}.${i} ${CUSE_OUT}.${i} 93 fi 94done 95 96rm -Rf $testdir/match_files 97 98# Verify read/write path 99tr < /dev/urandom -dc "a-zA-Z0-9" | fold -w 512 | head -n 1 > $testdir/write_file 100${NVME_CMD} write $ns --data-size=512 --data=$testdir/write_file 101${NVME_CMD} read $ns --data-size=512 --data=$testdir/read_file 102diff --ignore-trailing-space $testdir/write_file $testdir/read_file 103rm -f $testdir/write_file $testdir/read_file 104 105# Verify admin cmd when no data is transferred, 106# by creating and deleting completion queue. 107${NVME_CMD} admin-passthru $ctrlr -o 5 --cdw10=0x3ff0003 --cdw11=0x1 -r 108${NVME_CMD} admin-passthru $ctrlr -o 4 --cdw10=0x3 109 110[[ -c "$ctrlr" ]] 111[[ -c "$ns" ]] 112 113trap - SIGINT SIGTERM EXIT 114killprocess $spdk_tgt_pid 115