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