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