xref: /spdk/test/nvme/cuse/spdk_nvme_cli_cuse.sh (revision 16d862d0380886f6fc765f68a87e240bb4295595)
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	exit 1
25fi
26
27sel_cmd=()
28# sel depends on ONCS.4 so make sure it's set
29if (($(get_oncs "$nvme_name") & 1 << 4)); then
30	sel_cmd=(-s 1) # return default attribute value
31fi
32
33ctrlr="/dev/${nvme_name}"
34ns="/dev/${nvme_name}n1"
35bdf=${bdfs["$nvme_name"]}
36
37waitforblk "${nvme_name}n1"
38
39oacs=$(${NVME_CMD} id-ctrl $ctrlr | grep oacs | cut -d: -f2)
40oacs_firmware=$((oacs & 0x4))
41
42${NVME_CMD} get-ns-id $ns > ${KERNEL_OUT}.1
43${NVME_CMD} id-ns $ns > ${KERNEL_OUT}.2
44${NVME_CMD} list-ns $ns > ${KERNEL_OUT}.3
45
46${NVME_CMD} id-ctrl $ctrlr > ${KERNEL_OUT}.4
47${NVME_CMD} list-ctrl $ctrlr > ${KERNEL_OUT}.5
48if [ "$oacs_firmware" -ne "0" ]; then
49	${NVME_CMD} fw-log $ctrlr > ${KERNEL_OUT}.6
50fi
51${NVME_CMD} smart-log $ctrlr
52${NVME_CMD} error-log $ctrlr > ${KERNEL_OUT}.7
53${NVME_CMD} get-feature $ctrlr -f 1 "${sel_cmd[@]}" -l 100 > ${KERNEL_OUT}.8
54${NVME_CMD} get-log $ctrlr -i 1 -l 100 > ${KERNEL_OUT}.9
55${NVME_CMD} reset $ctrlr > ${KERNEL_OUT}.10
56# Negative test to make sure status message is the same on failures
57# FID 2 is power management. It should be constrained to the whole system
58# Attempting to apply it to a namespace should result in a failure
59${NVME_CMD} set-feature $ctrlr -n 1 -f 2 -v 0 2> ${KERNEL_OUT}.11 || true
60
61$rootdir/scripts/setup.sh
62
63$SPDK_BIN_DIR/spdk_tgt -m 0x3 &
64spdk_tgt_pid=$!
65trap 'kill -9 ${spdk_tgt_pid}; exit 1' SIGINT SIGTERM EXIT
66
67waitforlisten $spdk_tgt_pid
68
69$rpc_py bdev_nvme_attach_controller -b Nvme0 -t PCIe -a ${bdf}
70$rpc_py bdev_nvme_cuse_register -n Nvme0
71
72ctrlr="/dev/spdk/nvme0"
73ns="${ctrlr}n1"
74waitforfile "$ns"
75
76$rpc_py bdev_get_bdevs
77$rpc_py bdev_nvme_get_controllers
78
79${NVME_CMD} get-ns-id $ns > ${CUSE_OUT}.1
80${NVME_CMD} id-ns $ns > ${CUSE_OUT}.2
81${NVME_CMD} list-ns $ns > ${CUSE_OUT}.3
82
83${NVME_CMD} id-ctrl $ctrlr > ${CUSE_OUT}.4
84${NVME_CMD} list-ctrl $ctrlr > ${CUSE_OUT}.5
85if [ "$oacs_firmware" -ne "0" ]; then
86	${NVME_CMD} fw-log $ctrlr > ${CUSE_OUT}.6
87fi
88${NVME_CMD} smart-log $ctrlr
89${NVME_CMD} error-log $ctrlr > ${CUSE_OUT}.7
90${NVME_CMD} get-feature $ctrlr -f 1 "${sel_cmd[@]}" -l 100 > ${CUSE_OUT}.8
91${NVME_CMD} get-log $ctrlr -i 1 -l 100 > ${CUSE_OUT}.9
92${NVME_CMD} reset $ctrlr > ${CUSE_OUT}.10
93${NVME_CMD} set-feature $ctrlr -n 1 -f 2 -v 0 2> ${CUSE_OUT}.11 || true
94
95for i in {1..11}; do
96	if [ -f "${KERNEL_OUT}.${i}" ] && [ -f "${CUSE_OUT}.${i}" ]; then
97		sed -i "s/${nvme_name}/nvme0/g" ${KERNEL_OUT}.${i}
98		diff --suppress-common-lines ${KERNEL_OUT}.${i} ${CUSE_OUT}.${i}
99	fi
100done
101
102rm -Rf $testdir/match_files
103
104# Verify read/write path
105bs=$($rpc_py bdev_get_bdevs | jq '.[].block_size')
106head -c"$bs" /dev/urandom > "$testdir/write_file"
107${NVME_CMD} write $ns --data-size="$bs" --data=$testdir/write_file
108${NVME_CMD} read $ns --data-size="$bs" --data=$testdir/read_file
109cmp "$testdir/write_file" "$testdir/read_file"
110rm -f $testdir/write_file $testdir/read_file
111
112# Verify admin cmd when no data is transferred,
113# by creating and deleting completion queue.
114${NVME_CMD} admin-passthru $ctrlr -o 5 --cdw10=0x3ff0003 --cdw11=0x1 -r
115${NVME_CMD} admin-passthru $ctrlr -o 4 --cdw10=0x3
116
117[[ -c "$ctrlr" ]]
118[[ -c "$ns" ]]
119
120trap - SIGINT SIGTERM EXIT
121killprocess $spdk_tgt_pid
122