]> git.proxmox.com Git - ceph.git/blame - ceph/src/spdk/test/nvme/nvme.sh
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / spdk / test / nvme / nvme.sh
CommitLineData
11fdf7f2
TL
1#!/usr/bin/env bash
2
11fdf7f2
TL
3testdir=$(readlink -f $(dirname $0))
4rootdir=$(readlink -f $testdir/../..)
5source $rootdir/scripts/common.sh
6source $rootdir/test/common/autotest_common.sh
7
f67539c2
TL
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
11fdf7f2 23 fi
f67539c2
TL
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 -E "^Number of Namespaces" - | grep -q "0" -; then
31 continue
11fdf7f2 32 fi
f67539c2
TL
33 fio_nvme $PLUGIN_DIR/example_config.fio --filename="trtype=PCIe traddr=${bdf//:/.}"
34 ran_fio=true
11fdf7f2 35 done
f67539c2 36 $ran_fio || (echo "No valid NVMe drive found. Failing test." && false)
11fdf7f2
TL
37}
38
f67539c2
TL
39function nvme_multi_secondary() {
40 $SPDK_EXAMPLE_DIR/perf -i 0 -q 16 -w read -o 4096 -t 3 -c 0x1 &
41 pid0=$!
42 $SPDK_EXAMPLE_DIR/perf -i 0 -q 16 -w read -o 4096 -t 3 -c 0x2 &
43 pid1=$!
44 $SPDK_EXAMPLE_DIR/perf -i 0 -q 16 -w read -o 4096 -t 3 -c 0x4
45 wait $pid0
46 wait $pid1
47}
11fdf7f2 48
f67539c2 49if [ $(uname) = Linux ]; then
11fdf7f2
TL
50 # check that our setup.sh script does not bind NVMe devices to uio/vfio if they
51 # have an active mountpoint
52 $rootdir/scripts/setup.sh reset
53 # give kernel nvme driver some time to create the block devices before we start looking for them
54 sleep 1
55 blkname=''
56 # first, find an NVMe device that does not have an active mountpoint already;
57 # this covers rare case where someone is running this test script on a system
58 # that has a mounted NVMe filesystem
59 #
60 # note: more work probably needs to be done to properly handle devices with multiple
61 # namespaces
f67539c2
TL
62 for bdf in $(get_nvme_bdfs); do
63 for name in $(get_nvme_name_from_bdf $bdf); do
64 if [ "$name" != "" ]; then
65 mountpoints=$(lsblk /dev/$name --output MOUNTPOINT -n | wc -w)
66 if [ "$mountpoints" = "0" ]; then
67 blkname=$name
68 break 2
69 fi
11fdf7f2 70 fi
f67539c2 71 done
11fdf7f2
TL
72 done
73
74 # if we found an NVMe block device without an active mountpoint, create and mount
75 # a filesystem on it for purposes of testing the setup.sh script
76 if [ "$blkname" != "" ]; then
77 parted -s /dev/$blkname mklabel gpt
78 # just create a 100MB partition - this tests our ability to detect mountpoints
79 # on partitions of the device, not just the device itself; it also is faster
80 # since we don't trim and initialize the whole namespace
81 parted -s /dev/$blkname mkpart primary 1 100
82 sleep 1
83 mkfs.ext4 -F /dev/${blkname}p1
84 mkdir -p /tmp/nvmetest
85 mount /dev/${blkname}p1 /tmp/nvmetest
9f95a23c 86 sleep 1
11fdf7f2
TL
87 $rootdir/scripts/setup.sh
88 driver=$(basename $(readlink /sys/bus/pci/devices/$bdf/driver))
89 # check that the nvme driver is still loaded against the device
90 if [ "$driver" != "nvme" ]; then
91 exit 1
92 fi
93 umount /tmp/nvmetest
94 rmdir /tmp/nvmetest
95 # write zeroes to the device to blow away the partition table and filesystem
96 dd if=/dev/zero of=/dev/$blkname oflag=direct bs=1M count=1
97 $rootdir/scripts/setup.sh
98 driver=$(basename $(readlink /sys/bus/pci/devices/$bdf/driver))
99 # check that the nvme driver is not loaded against the device
100 if [ "$driver" = "nvme" ]; then
101 exit 1
102 fi
103 else
104 $rootdir/scripts/setup.sh
105 fi
106fi
107
f67539c2 108if [ $(uname) = Linux ]; then
9f95a23c 109 trap "kill_stub -9; exit 1" SIGINT SIGTERM EXIT
f67539c2 110 start_stub "-s 4096 -i 0 -m 0xE"
11fdf7f2
TL
111fi
112
f67539c2
TL
113run_test "nvme_reset" $testdir/reset/reset -q 64 -w write -s 4096 -t 5
114run_test "nvme_identify" nvme_identify
115run_test "nvme_perf" nvme_perf
116run_test "nvme_hello_world" $SPDK_EXAMPLE_DIR/hello_world
117run_test "nvme_deallocated_value" $testdir/deallocated_value/deallocated_value
118run_test "nvme_sgl" $testdir/sgl/sgl
119run_test "nvme_e2edp" $testdir/e2edp/nvme_dp
120run_test "nvme_reserve" $testdir/reserve/reserve
121run_test "nvme_err_injection" $testdir/err_injection/err_injection
122run_test "nvme_overhead" $testdir/overhead/overhead -s 4096 -t 1 -H
123run_test "nvme_arbitration" $SPDK_EXAMPLE_DIR/arbitration -t 3 -i 0
124
125if [ $(uname) != "FreeBSD" ]; then
126 run_test "nvme_startup" $testdir/startup/startup -t 1000000
127 run_test "nvme_multi_secondary" nvme_multi_secondary
11fdf7f2
TL
128 trap - SIGINT SIGTERM EXIT
129 kill_stub
130fi
11fdf7f2 131
f67539c2
TL
132if [[ $CONFIG_FIO_PLUGIN == y ]]; then
133 run_test "nvme_fio" nvme_fio_test
11fdf7f2 134fi