xref: /spdk/test/nvme/nvme.sh (revision 14e26b9d0410a98689caffcba7bfacac8d85c74d)
1#!/usr/bin/env bash
2#  SPDX-License-Identifier: BSD-3-Clause
3#  Copyright (C) 2015 Intel Corporation
4#  All rights reserved.
5#
6testdir=$(readlink -f $(dirname $0))
7rootdir=$(readlink -f $testdir/../..)
8source $rootdir/scripts/common.sh
9source $rootdir/test/common/autotest_common.sh
10
11function nvme_identify() {
12	local bdfs=() bdf
13	bdfs=($(get_nvme_bdfs))
14	$SPDK_BIN_DIR/spdk_nvme_identify -i 0
15	for bdf in "${bdfs[@]}"; do
16		$SPDK_BIN_DIR/spdk_nvme_identify -r "trtype:PCIe traddr:${bdf}" -i 0
17	done
18}
19
20function nvme_perf() {
21	# enable no shutdown notification option
22	$SPDK_BIN_DIR/spdk_nvme_perf -q 128 -w read -o 12288 -t 1 -LL -i 0 -N
23	$SPDK_BIN_DIR/spdk_nvme_perf -q 128 -w write -o 12288 -t 1 -LL -i 0
24	if [ -b /dev/ram0 ]; then
25		# Test perf with AIO device
26		$SPDK_BIN_DIR/spdk_nvme_perf /dev/ram0 -q 128 -w read -o 12288 -t 1 -LL -i 0
27	fi
28}
29
30function nvme_fio_test() {
31	PLUGIN_DIR=$rootdir/app/fio/nvme
32	ran_fio=false
33	local bdfs=($(get_nvme_bdfs)) bdf
34	for bdf in "${bdfs[@]}"; do
35		if ! "$SPDK_BIN_DIR/spdk_nvme_identify" -r "trtype:PCIe traddr:${bdf}" | grep -qE "^Namespace ID:[0-9]+"; then
36			continue
37		fi
38		if $SPDK_BIN_DIR/spdk_nvme_identify -r "trtype:PCIe traddr:${bdf}" | grep -q "Extended Data LBA"; then
39			bs=4160
40		else
41			bs=4096
42		fi
43		fio_nvme $PLUGIN_DIR/example_config.fio --filename="trtype=PCIe traddr=${bdf//:/.}" --bs="$bs"
44		ran_fio=true
45	done
46	$ran_fio || (echo "No valid NVMe drive found. Failing test." && false)
47}
48
49function nvme_multi_secondary() {
50	# Primary process exits last
51	$SPDK_BIN_DIR/spdk_nvme_perf -i 0 -q 16 -w read -o 4096 -t 5 -c 0x1 &
52	pid0=$!
53	$SPDK_BIN_DIR/spdk_nvme_perf -i 0 -q 16 -w read -o 4096 -t 3 -c 0x2 &
54	pid1=$!
55	$SPDK_BIN_DIR/spdk_nvme_perf -i 0 -q 16 -w read -o 4096 -t 3 -c 0x4
56	wait $pid0
57	wait $pid1
58
59	# Secondary process exits last
60	$SPDK_BIN_DIR/spdk_nvme_perf -i 0 -q 16 -w read -o 4096 -t 3 -c 0x1 &
61	pid0=$!
62	$SPDK_BIN_DIR/spdk_nvme_perf -i 0 -q 16 -w read -o 4096 -t 3 -c 0x2 &
63	pid1=$!
64	$SPDK_BIN_DIR/spdk_nvme_perf -i 0 -q 16 -w read -o 4096 -t 5 -c 0x4
65	wait $pid0
66	wait $pid1
67}
68
69function nvme_doorbell_aers() {
70	local bdfs=() bdf
71	bdfs=($(get_nvme_bdfs))
72	for bdf in "${bdfs[@]}"; do
73		timeout --preserve-status 10 $testdir/doorbell_aers/doorbell_aers -r "trtype:PCIe traddr:${bdf}"
74	done
75}
76
77"$rootdir/scripts/setup.sh"
78
79if [ $(uname) = Linux ]; then
80	trap "kill_stub -9; exit 1" SIGINT SIGTERM EXIT
81	start_stub "-s 4096 -i 0 -m 0xE"
82fi
83
84run_test "nvme_reset" $testdir/reset/reset -q 64 -w write -o 4096 -t 5
85run_test "nvme_identify" nvme_identify
86run_test "nvme_perf" nvme_perf
87run_test "nvme_hello_world" $SPDK_EXAMPLE_DIR/hello_world -i 0
88run_test "nvme_sgl" $testdir/sgl/sgl
89run_test "nvme_e2edp" $testdir/e2edp/nvme_dp
90run_test "nvme_reserve" $testdir/reserve/reserve
91run_test "nvme_err_injection" $testdir/err_injection/err_injection
92run_test "nvme_overhead" $testdir/overhead/overhead -o 4096 -t 1 -H -i 0
93run_test "nvme_arbitration" $SPDK_EXAMPLE_DIR/arbitration -t 3 -i 0
94run_test "nvme_single_aen" $testdir/aer/aer -T -i 0
95run_test "nvme_doorbell_aers" nvme_doorbell_aers
96
97if [ $(uname) != "FreeBSD" ]; then
98	run_test "nvme_multi_aen" $testdir/aer/aer -m -T -i 0
99	run_test "nvme_startup" $testdir/startup/startup -t 1000000
100	run_test "nvme_multi_secondary" nvme_multi_secondary
101	trap - SIGINT SIGTERM EXIT
102	kill_stub
103fi
104
105run_test "bdev_nvme_reset_stuck_adm_cmd" $rootdir/test/nvme/nvme_reset_stuck_adm_cmd.sh
106
107if [[ $CONFIG_FIO_PLUGIN == y ]]; then
108	run_test "nvme_fio" nvme_fio_test
109fi
110