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