2019-10-24 18:11:51 +00:00
|
|
|
#!/usr/bin/env bash
|
2022-11-02 15:49:40 +00:00
|
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
# Copyright (C) 2019 Intel Corporation
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
2019-10-24 18:11:51 +00:00
|
|
|
testdir=$(readlink -f $(dirname $0))
|
2020-06-08 11:42:52 +00:00
|
|
|
rootdir=$(readlink -f $testdir/../../..)
|
2019-10-24 18:11:51 +00:00
|
|
|
source $rootdir/scripts/common.sh
|
|
|
|
source $rootdir/test/common/autotest_common.sh
|
|
|
|
|
2019-11-29 16:27:12 +00:00
|
|
|
rm -Rf $testdir/match_files
|
|
|
|
mkdir $testdir/match_files
|
|
|
|
|
|
|
|
KERNEL_OUT=$testdir/match_files/kernel.out
|
|
|
|
CUSE_OUT=$testdir/match_files/cuse.out
|
|
|
|
|
2019-10-24 18:11:51 +00:00
|
|
|
NVME_CMD=/usr/local/src/nvme-cli/nvme
|
|
|
|
rpc_py=$rootdir/scripts/rpc.py
|
|
|
|
|
2020-03-16 16:32:39 +00:00
|
|
|
bdf=$(get_first_nvme_bdf)
|
2019-11-29 16:27:12 +00:00
|
|
|
|
2020-11-25 20:31:42 +00:00
|
|
|
PCI_ALLOWED="${bdf}" $rootdir/scripts/setup.sh reset
|
2020-06-08 14:48:03 +00:00
|
|
|
nvme_name=$(get_nvme_ctrlr_from_bdf ${bdf})
|
|
|
|
if [[ -z "$nvme_name" ]]; then
|
2019-11-29 16:27:12 +00:00
|
|
|
echo "setup.sh failed bind kernel driver to ${bdf}"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
ctrlr="/dev/${nvme_name}"
|
|
|
|
ns="/dev/${nvme_name}n1"
|
|
|
|
|
2020-06-18 11:20:13 +00:00
|
|
|
waitforblk "${nvme_name}n1"
|
|
|
|
|
2020-05-07 11:27:06 +00:00
|
|
|
oacs=$(${NVME_CMD} id-ctrl $ctrlr | grep oacs | cut -d: -f2)
|
|
|
|
oacs_firmware=$((oacs & 0x4))
|
2020-01-13 09:41:05 +00:00
|
|
|
|
2019-11-29 16:27:12 +00:00
|
|
|
${NVME_CMD} get-ns-id $ns > ${KERNEL_OUT}.1
|
|
|
|
${NVME_CMD} id-ns $ns > ${KERNEL_OUT}.2
|
|
|
|
${NVME_CMD} list-ns $ns > ${KERNEL_OUT}.3
|
|
|
|
|
|
|
|
${NVME_CMD} id-ctrl $ctrlr > ${KERNEL_OUT}.4
|
|
|
|
${NVME_CMD} list-ctrl $ctrlr > ${KERNEL_OUT}.5
|
2020-01-13 09:41:05 +00:00
|
|
|
if [ "$oacs_firmware" -ne "0" ]; then
|
|
|
|
${NVME_CMD} fw-log $ctrlr > ${KERNEL_OUT}.6
|
|
|
|
fi
|
2019-11-29 16:27:12 +00:00
|
|
|
${NVME_CMD} smart-log $ctrlr
|
|
|
|
${NVME_CMD} error-log $ctrlr > ${KERNEL_OUT}.7
|
|
|
|
${NVME_CMD} get-feature $ctrlr -f 1 -s 1 -l 100 > ${KERNEL_OUT}.8
|
|
|
|
${NVME_CMD} get-log $ctrlr -i 1 -l 100 > ${KERNEL_OUT}.9
|
|
|
|
${NVME_CMD} reset $ctrlr > ${KERNEL_OUT}.10
|
2021-12-08 23:40:06 +00:00
|
|
|
# Negative test to make sure status message is the same on failures
|
|
|
|
# FID 2 is power management. It should be constrained to the whole system
|
|
|
|
# Attempting to apply it to a namespace should result in a failure
|
|
|
|
${NVME_CMD} set-feature $ctrlr -n 1 -f 2 -v 0 2> ${KERNEL_OUT}.11 || true
|
2019-11-29 16:27:12 +00:00
|
|
|
|
|
|
|
$rootdir/scripts/setup.sh
|
|
|
|
|
2020-05-11 21:15:03 +00:00
|
|
|
$SPDK_BIN_DIR/spdk_tgt -m 0x3 &
|
2019-10-24 18:11:51 +00:00
|
|
|
spdk_tgt_pid=$!
|
|
|
|
trap 'kill -9 ${spdk_tgt_pid}; exit 1' SIGINT SIGTERM EXIT
|
|
|
|
|
|
|
|
waitforlisten $spdk_tgt_pid
|
|
|
|
|
|
|
|
$rpc_py bdev_nvme_attach_controller -b Nvme0 -t PCIe -a ${bdf}
|
2019-11-15 11:14:19 +00:00
|
|
|
$rpc_py bdev_nvme_cuse_register -n Nvme0
|
2019-10-24 18:11:51 +00:00
|
|
|
|
2020-06-18 16:43:43 +00:00
|
|
|
ctrlr="/dev/spdk/nvme0"
|
|
|
|
ns="${ctrlr}n1"
|
|
|
|
waitforfile "$ns"
|
2019-11-04 17:06:46 +00:00
|
|
|
|
2019-10-24 18:11:51 +00:00
|
|
|
$rpc_py bdev_get_bdevs
|
|
|
|
$rpc_py bdev_nvme_get_controllers
|
|
|
|
|
2019-11-29 16:27:12 +00:00
|
|
|
${NVME_CMD} get-ns-id $ns > ${CUSE_OUT}.1
|
|
|
|
${NVME_CMD} id-ns $ns > ${CUSE_OUT}.2
|
|
|
|
${NVME_CMD} list-ns $ns > ${CUSE_OUT}.3
|
2019-10-24 18:11:51 +00:00
|
|
|
|
2019-11-29 16:27:12 +00:00
|
|
|
${NVME_CMD} id-ctrl $ctrlr > ${CUSE_OUT}.4
|
|
|
|
${NVME_CMD} list-ctrl $ctrlr > ${CUSE_OUT}.5
|
2020-01-13 09:41:05 +00:00
|
|
|
if [ "$oacs_firmware" -ne "0" ]; then
|
|
|
|
${NVME_CMD} fw-log $ctrlr > ${CUSE_OUT}.6
|
|
|
|
fi
|
2019-11-29 16:27:12 +00:00
|
|
|
${NVME_CMD} smart-log $ctrlr
|
|
|
|
${NVME_CMD} error-log $ctrlr > ${CUSE_OUT}.7
|
|
|
|
${NVME_CMD} get-feature $ctrlr -f 1 -s 1 -l 100 > ${CUSE_OUT}.8
|
|
|
|
${NVME_CMD} get-log $ctrlr -i 1 -l 100 > ${CUSE_OUT}.9
|
|
|
|
${NVME_CMD} reset $ctrlr > ${CUSE_OUT}.10
|
2021-12-08 23:40:06 +00:00
|
|
|
${NVME_CMD} set-feature $ctrlr -n 1 -f 2 -v 0 2> ${CUSE_OUT}.11 || true
|
2019-12-20 11:58:08 +00:00
|
|
|
|
2021-12-08 23:40:06 +00:00
|
|
|
for i in {1..11}; do
|
2019-11-29 16:27:12 +00:00
|
|
|
if [ -f "${KERNEL_OUT}.${i}" ] && [ -f "${CUSE_OUT}.${i}" ]; then
|
2020-02-21 11:46:07 +00:00
|
|
|
sed -i "s/${nvme_name}/nvme0/g" ${KERNEL_OUT}.${i}
|
2019-11-29 16:27:12 +00:00
|
|
|
diff --suppress-common-lines ${KERNEL_OUT}.${i} ${CUSE_OUT}.${i}
|
|
|
|
fi
|
2019-10-24 18:11:51 +00:00
|
|
|
done
|
|
|
|
|
2019-11-29 16:27:12 +00:00
|
|
|
rm -Rf $testdir/match_files
|
|
|
|
|
2020-09-02 15:06:07 +00:00
|
|
|
# Verify read/write path
|
|
|
|
tr < /dev/urandom -dc "a-zA-Z0-9" | fold -w 512 | head -n 1 > $testdir/write_file
|
|
|
|
${NVME_CMD} write $ns --data-size=512 --data=$testdir/write_file
|
|
|
|
${NVME_CMD} read $ns --data-size=512 --data=$testdir/read_file
|
|
|
|
diff --ignore-trailing-space $testdir/write_file $testdir/read_file
|
|
|
|
rm -f $testdir/write_file $testdir/read_file
|
|
|
|
|
2020-04-07 18:11:57 +00:00
|
|
|
# Verify admin cmd when no data is transferred,
|
|
|
|
# by creating and deleting completion queue.
|
|
|
|
${NVME_CMD} admin-passthru $ctrlr -o 5 --cdw10=0x3ff0003 --cdw11=0x1 -r
|
|
|
|
${NVME_CMD} admin-passthru $ctrlr -o 4 --cdw10=0x3
|
|
|
|
|
2020-06-18 16:43:43 +00:00
|
|
|
[[ -c "$ctrlr" ]]
|
|
|
|
[[ -c "$ns" ]]
|
|
|
|
|
2019-10-24 18:11:51 +00:00
|
|
|
trap - SIGINT SIGTERM EXIT
|
2019-11-18 16:41:51 +00:00
|
|
|
killprocess $spdk_tgt_pid
|