xref: /spdk/test/nvme/nvme.sh (revision e450b8e728dcbba26f855289561f873728aef374)
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
8function nvme_identify() {
9	$SPDK_EXAMPLE_DIR/identify -i 0
10	for bdf in $(get_nvme_bdfs); do
11		$SPDK_EXAMPLE_DIR/identify -r "trtype:PCIe traddr:${bdf}" -i 0
12	done
13	timing_exit identify
14}
15
16function nvme_perf() {
17	# enable no shutdown notification option
18	$SPDK_EXAMPLE_DIR/perf -q 128 -w read -o 12288 -t 1 -LL -i 0 -N
19	$SPDK_EXAMPLE_DIR/perf -q 128 -w write -o 12288 -t 1 -LL -i 0
20	if [ -b /dev/ram0 ]; then
21		# Test perf with AIO device
22		$SPDK_EXAMPLE_DIR/perf /dev/ram0 -q 128 -w read -o 12288 -t 1 -LL -i 0
23	fi
24}
25
26function nvme_fio_test() {
27	PLUGIN_DIR=$rootdir/examples/nvme/fio_plugin
28	ran_fio=false
29	for bdf in $(get_nvme_bdfs); do
30		if ! "$SPDK_EXAMPLE_DIR/identify" -r "trtype:PCIe traddr:${bdf}" | grep -qE "^Namespace ID:[0-9]+"; then
31			continue
32		fi
33		if $SPDK_EXAMPLE_DIR/identify -r "trtype:PCIe traddr:${bdf}" | grep -q "Extended Data LBA"; then
34			bs=4160
35		else
36			bs=4096
37		fi
38		fio_nvme $PLUGIN_DIR/example_config.fio --filename="trtype=PCIe traddr=${bdf//:/.}" --bs="$bs"
39		ran_fio=true
40	done
41	$ran_fio || (echo "No valid NVMe drive found. Failing test." && false)
42}
43
44function nvme_multi_secondary() {
45	# Primary process exits last
46	$SPDK_EXAMPLE_DIR/perf -i 0 -q 16 -w read -o 4096 -t 5 -c 0x1 &
47	pid0=$!
48	$SPDK_EXAMPLE_DIR/perf -i 0 -q 16 -w read -o 4096 -t 3 -c 0x2 &
49	pid1=$!
50	$SPDK_EXAMPLE_DIR/perf -i 0 -q 16 -w read -o 4096 -t 3 -c 0x4
51	wait $pid0
52	wait $pid1
53
54	# Secondary process exits last
55	$SPDK_EXAMPLE_DIR/perf -i 0 -q 16 -w read -o 4096 -t 3 -c 0x1 &
56	pid0=$!
57	$SPDK_EXAMPLE_DIR/perf -i 0 -q 16 -w read -o 4096 -t 3 -c 0x2 &
58	pid1=$!
59	$SPDK_EXAMPLE_DIR/perf -i 0 -q 16 -w read -o 4096 -t 5 -c 0x4
60	wait $pid0
61	wait $pid1
62}
63
64if [ $(uname) = Linux ]; then
65	# check that our setup.sh script does not bind NVMe devices to uio/vfio if they
66	# have an active mountpoint
67	$rootdir/scripts/setup.sh reset
68	blkname=''
69	# first, find an NVMe device that does not have an active mountpoint already;
70	# this covers rare case where someone is running this test script on a system
71	# that has a mounted NVMe filesystem
72	#
73	# note: more work probably needs to be done to properly handle devices with multiple
74	# namespaces
75	for bdf in $(get_nvme_bdfs); do
76		for name in $(get_nvme_name_from_bdf $bdf); do
77			if [ "$name" != "" ]; then
78				mountpoints=$(lsblk /dev/$name --output MOUNTPOINT -n | wc -w)
79				if [ "$mountpoints" = "0" ]; then
80					blkname=$name
81					break 2
82				fi
83			fi
84		done
85	done
86
87	# if we found an NVMe block device without an active mountpoint, create and mount
88	# a filesystem on it for purposes of testing the setup.sh script
89	if [ "$blkname" != "" ]; then
90		parted -s /dev/$blkname mklabel gpt
91		# just create a 100MB partition - this tests our ability to detect mountpoints
92		# on partitions of the device, not just the device itself;  it also is faster
93		# since we don't trim and initialize the whole namespace
94		parted -s /dev/$blkname mkpart SPDK_TEST 1 100
95		sleep 1
96		mkfs.ext4 -F /dev/${blkname}p1
97		mkdir -p /tmp/nvmetest
98		mount /dev/${blkname}p1 /tmp/nvmetest
99		sleep 1
100		$rootdir/scripts/setup.sh
101		driver=$(basename $(readlink /sys/bus/pci/devices/$bdf/driver))
102		# check that the nvme driver is still loaded against the device
103		if [ "$driver" != "nvme" ]; then
104			exit 1
105		fi
106		umount /tmp/nvmetest
107		rmdir /tmp/nvmetest
108		# write zeroes to the device to blow away the partition table and filesystem
109		dd if=/dev/zero of=/dev/$blkname oflag=direct bs=1M count=1
110		$rootdir/scripts/setup.sh
111		driver=$(basename $(readlink /sys/bus/pci/devices/$bdf/driver))
112		# check that the nvme driver is not loaded against the device
113		if [ "$driver" = "nvme" ]; then
114			exit 1
115		fi
116	else
117		$rootdir/scripts/setup.sh
118	fi
119fi
120
121if [ $(uname) = Linux ]; then
122	trap "kill_stub -9; exit 1" SIGINT SIGTERM EXIT
123	start_stub "-s 4096 -i 0 -m 0xE"
124fi
125
126run_test "nvme_reset" $testdir/reset/reset -q 64 -w write -s 4096 -t 5
127run_test "nvme_identify" nvme_identify
128run_test "nvme_perf" nvme_perf
129run_test "nvme_hello_world" $SPDK_EXAMPLE_DIR/hello_world -i 0
130run_test "nvme_deallocated_value" $testdir/deallocated_value/deallocated_value -i 0
131run_test "nvme_sgl" $testdir/sgl/sgl
132run_test "nvme_e2edp" $testdir/e2edp/nvme_dp
133run_test "nvme_reserve" $testdir/reserve/reserve
134run_test "nvme_err_injection" $testdir/err_injection/err_injection
135run_test "nvme_overhead" $testdir/overhead/overhead -s 4096 -t 1 -H -i 0
136run_test "nvme_arbitration" $SPDK_EXAMPLE_DIR/arbitration -t 3 -i 0
137run_test "nvme_single_aen" $testdir/aer/aer -T -i 0 -L log
138
139if [ $(uname) != "FreeBSD" ]; then
140	run_test "nvme_multi_aen" $testdir/aer/aer -m -T -i 0 -L log
141	run_test "nvme_startup" $testdir/startup/startup -t 1000000
142	run_test "nvme_multi_secondary" nvme_multi_secondary
143	trap - SIGINT SIGTERM EXIT
144	kill_stub
145fi
146
147if [[ $CONFIG_FIO_PLUGIN == y ]]; then
148	run_test "nvme_fio" nvme_fio_test
149fi
150