1#!/usr/bin/env bash 2 3rootdir=$(readlink -f $(dirname $0)) 4 5# In autotest_common.sh all tests are disabled by default. 6# If the configuration of tests is not provided, no tests will be carried out. 7if [[ ! -f $1 ]]; then 8 echo "ERROR: SPDK test configuration not specified" 9 exit 1 10fi 11 12# always test with SPDK shared objects. 13export SPDK_LIB_DIR="$rootdir/build/lib" 14 15# Autotest.sh, as part of autorun.sh, runs in a different 16# shell process than autobuild.sh. Use helper file to pass 17# over env variable containing libraries paths. 18if [[ -e /tmp/spdk-ld-path ]]; then 19 source /tmp/spdk-ld-path 20fi 21 22source "$1" 23source "$rootdir/test/common/autotest_common.sh" 24source "$rootdir/test/nvmf/common.sh" 25 26if [ $EUID -ne 0 ]; then 27 echo "$0 must be run as root" 28 exit 1 29fi 30 31if [ $(uname -s) = Linux ]; then 32 old_core_pattern=$(< /proc/sys/kernel/core_pattern) 33 # set core_pattern to a known value to avoid ABRT, systemd-coredump, etc. 34 echo "core" > /proc/sys/kernel/core_pattern 35 36 # Make sure that the hugepage state for our VM is fresh so we don't fail 37 # hugepage allocation. Allow time for this action to complete. 38 echo 1 > /proc/sys/vm/drop_caches 39 sleep 3 40 41 # make sure nbd (network block device) driver is loaded if it is available 42 # this ensures that when tests need to use nbd, it will be fully initialized 43 modprobe nbd || true 44 45 if udevadm=$(type -P udevadm); then 46 "$udevadm" monitor --property &> "$output_dir/udev.log" & 47 udevadm_pid=$! 48 fi 49fi 50 51trap "process_core; autotest_cleanup; exit 1" SIGINT SIGTERM EXIT 52 53timing_enter autotest 54 55create_test_list 56 57src=$(readlink -f $(dirname $0)) 58out=$output_dir 59cd $src 60 61./scripts/setup.sh status 62 63freebsd_update_contigmem_mod 64 65if hash lcov; then 66 # setup output dir for unittest.sh 67 export UT_COVERAGE=$out/ut_coverage 68 export LCOV_OPTS=" 69 --rc lcov_branch_coverage=1 70 --rc lcov_function_coverage=1 71 --rc genhtml_branch_coverage=1 72 --rc genhtml_function_coverage=1 73 --rc genhtml_legend=1 74 --rc geninfo_all_blocks=1 75 " 76 export LCOV="lcov $LCOV_OPTS --no-external" 77 # Print lcov version to log 78 $LCOV -v 79 # zero out coverage data 80 $LCOV -q -c -i -t "Baseline" -d $src -o $out/cov_base.info 81fi 82 83# Make sure the disks are clean (no leftover partition tables) 84timing_enter cleanup 85# Remove old domain socket pathname just in case 86rm -f /var/tmp/spdk*.sock 87 88# Load the kernel driver 89./scripts/setup.sh reset 90 91if [ $(uname -s) = Linux ]; then 92 # OCSSD devices drivers don't support IO issues by kernel so 93 # detect OCSSD devices and blacklist them (unbind from any driver). 94 # If test scripts want to use this device it needs to do this explicitly. 95 # 96 # If some OCSSD device is bound to other driver than nvme we won't be able to 97 # discover if it is OCSSD or not so load the kernel driver first. 98 99 while IFS= read -r -d '' dev; do 100 # Send Open Channel 2.0 Geometry opcode "0xe2" - not supported by NVMe device. 101 if nvme admin-passthru $dev --namespace-id=1 --data-len=4096 --opcode=0xe2 --read > /dev/null; then 102 bdf="$(basename $(readlink -e /sys/class/nvme/${dev#/dev/}/device))" 103 echo "INFO: blacklisting OCSSD device: $dev ($bdf)" 104 PCI_BLACKLIST+=" $bdf" 105 OCSSD_PCI_DEVICES+=" $bdf" 106 fi 107 done < <(find /dev -maxdepth 1 -regex '/dev/nvme[0-9]+' -print0) 108 109 export OCSSD_PCI_DEVICES 110 111 # Now, bind blacklisted devices to pci-stub module. This will prevent 112 # automatic grabbing these devices when we add device/vendor ID to 113 # proper driver. 114 if [[ -n "$PCI_BLACKLIST" ]]; then 115 # shellcheck disable=SC2097,SC2098 116 PCI_WHITELIST="$PCI_BLACKLIST" \ 117 PCI_BLACKLIST="" \ 118 DRIVER_OVERRIDE="pci-stub" \ 119 ./scripts/setup.sh 120 121 # Export our blacklist so it will take effect during next setup.sh 122 export PCI_BLACKLIST 123 fi 124fi 125 126if [[ $(uname -s) == Linux ]]; then 127 # Revert NVMe namespaces to default state 128 nvme_namespace_revert 129fi 130 131# Delete all leftover lvols and gpt partitions 132# Matches both /dev/nvmeXnY on Linux and /dev/nvmeXnsY on BSD 133# Filter out nvme with partitions - the "p*" suffix 134for dev in $(ls /dev/nvme*n* | grep -v p || true); do 135 dd if=/dev/zero of="$dev" bs=1M count=1 136done 137 138sync 139 140timing_exit cleanup 141 142# set up huge pages 143timing_enter afterboot 144./scripts/setup.sh 145timing_exit afterboot 146 147timing_enter nvmf_setup 148rdma_device_init 149timing_exit nvmf_setup 150 151if [[ $SPDK_TEST_CRYPTO -eq 1 || $SPDK_TEST_REDUCE -eq 1 ]]; then 152 if grep -q '#define SPDK_CONFIG_IGB_UIO_DRIVER 1' $rootdir/include/spdk/config.h; then 153 ./scripts/qat_setup.sh igb_uio 154 else 155 ./scripts/qat_setup.sh 156 fi 157fi 158 159# Revert existing OPAL to factory settings that may have been left from earlier failed tests. 160# This ensures we won't hit any unexpected failures due to NVMe SSDs being locked. 161opal_revert_cleanup 162 163##################### 164# Unit Tests 165##################### 166 167if [ $SPDK_TEST_UNITTEST -eq 1 ]; then 168 run_test "unittest" ./test/unit/unittest.sh 169 run_test "env" test/env/env.sh 170fi 171 172if [ $SPDK_RUN_FUNCTIONAL_TEST -eq 1 ]; then 173 timing_enter lib 174 175 run_test "rpc" test/rpc/rpc.sh 176 run_test "rpc_client" test/rpc_client/rpc_client.sh 177 run_test "json_config" ./test/json_config/json_config.sh 178 run_test "alias_rpc" test/json_config/alias_rpc/alias_rpc.sh 179 run_test "spdkcli_tcp" test/spdkcli/tcp.sh 180 run_test "dpdk_mem_utility" test/dpdk_memory_utility/test_dpdk_mem_info.sh 181 run_test "event" test/event/event.sh 182 183 if [ $SPDK_TEST_BLOCKDEV -eq 1 ]; then 184 run_test "blockdev_general" test/bdev/blockdev.sh 185 run_test "bdev_raid" test/bdev/bdev_raid.sh 186 run_test "bdevperf_config" test/bdev/bdevperf/test_config.sh 187 if [[ $(uname -s) == Linux ]]; then 188 run_test "spdk_dd" test/dd/dd.sh 189 fi 190 fi 191 192 if [ $SPDK_TEST_JSON -eq 1 ]; then 193 run_test "test_converter" test/config_converter/test_converter.sh 194 fi 195 196 if [ $SPDK_TEST_NVME -eq 1 ]; then 197 run_test "blockdev_nvme" test/bdev/blockdev.sh "nvme" 198 run_test "blockdev_nvme_gpt" test/bdev/blockdev.sh "gpt" 199 run_test "nvme" test/nvme/nvme.sh 200 if [[ $SPDK_TEST_NVME_CLI -eq 1 ]]; then 201 run_test "nvme_cli" test/nvme/spdk_nvme_cli.sh 202 fi 203 if [[ $SPDK_TEST_NVME_CUSE -eq 1 ]]; then 204 run_test "nvme_cuse" test/nvme/cuse/nvme_cuse.sh 205 fi 206 run_test "nvme_rpc" test/nvme/nvme_rpc.sh 207 # Only test hotplug without ASAN enabled. Since if it is 208 # enabled, it catches SEGV earlier than our handler which 209 # breaks the hotplug logic. 210 if [ $SPDK_RUN_ASAN -eq 0 ]; then 211 run_test "nvme_hotplug" test/nvme/hotplug.sh root 212 fi 213 fi 214 215 if [ $SPDK_TEST_IOAT -eq 1 ]; then 216 run_test "ioat" test/ioat/ioat.sh 217 fi 218 219 timing_exit lib 220 221 if [ $SPDK_TEST_ISCSI -eq 1 ]; then 222 run_test "iscsi_tgt" ./test/iscsi_tgt/iscsi_tgt.sh 223 run_test "spdkcli_iscsi" ./test/spdkcli/iscsi.sh 224 225 # Run raid spdkcli test under iSCSI since blockdev tests run on systems that can't run spdkcli yet 226 run_test "spdkcli_raid" test/spdkcli/raid.sh 227 fi 228 229 if [ $SPDK_TEST_BLOBFS -eq 1 ]; then 230 run_test "rocksdb" ./test/blobfs/rocksdb/rocksdb.sh 231 run_test "blobstore" ./test/blobstore/blobstore.sh 232 run_test "blobfs" ./test/blobfs/blobfs.sh 233 run_test "hello_blob" $SPDK_EXAMPLE_DIR/hello_blob \ 234 examples/blob/hello_world/hello_blob.json 235 fi 236 237 if [ $SPDK_TEST_NVMF -eq 1 ]; then 238 # The NVMe-oF run test cases are split out like this so that the parser that compiles the 239 # list of all tests can properly differentiate them. Please do not merge them into one line. 240 if [ "$SPDK_TEST_NVMF_TRANSPORT" = "rdma" ]; then 241 run_test "nvmf_rdma" ./test/nvmf/nvmf.sh --transport=$SPDK_TEST_NVMF_TRANSPORT 242 run_test "spdkcli_nvmf_rdma" ./test/spdkcli/nvmf.sh 243 elif [ "$SPDK_TEST_NVMF_TRANSPORT" = "tcp" ]; then 244 run_test "nvmf_tcp" ./test/nvmf/nvmf.sh --transport=$SPDK_TEST_NVMF_TRANSPORT 245 run_test "spdkcli_nvmf_tcp" ./test/spdkcli/nvmf.sh 246 run_test "nvmf_identify_passthru" test/nvmf/target/identify_passthru.sh --transport=$SPDK_TEST_NVMF_TRANSPORT 247 elif [ "$SPDK_TEST_NVMF_TRANSPORT" = "fc" ]; then 248 run_test "nvmf_fc" ./test/nvmf/nvmf.sh --transport=$SPDK_TEST_NVMF_TRANSPORT 249 run_test "spdkcli_nvmf_fc" ./test/spdkcli/nvmf.sh 250 else 251 echo "unknown NVMe transport, please specify rdma, tcp, or fc." 252 exit 1 253 fi 254 fi 255 256 if [ $SPDK_TEST_VHOST -eq 1 ]; then 257 run_test "vhost" ./test/vhost/vhost.sh 258 fi 259 260 if [ $SPDK_TEST_LVOL -eq 1 ]; then 261 run_test "lvol" ./test/lvol/lvol.sh 262 run_test "blob_io_wait" ./test/blobstore/blob_io_wait/blob_io_wait.sh 263 fi 264 265 if [ $SPDK_TEST_VHOST_INIT -eq 1 ]; then 266 timing_enter vhost_initiator 267 run_test "vhost_blockdev" ./test/vhost/initiator/blockdev.sh 268 run_test "spdkcli_virtio" ./test/spdkcli/virtio.sh 269 run_test "vhost_shared" ./test/vhost/shared/shared.sh 270 run_test "vhost_fuzz" ./test/vhost/fuzz/fuzz.sh 271 timing_exit vhost_initiator 272 fi 273 274 if [ $SPDK_TEST_PMDK -eq 1 ]; then 275 run_test "blockdev_pmem" ./test/bdev/blockdev.sh "pmem" 276 run_test "pmem" ./test/pmem/pmem.sh -x 277 run_test "spdkcli_pmem" ./test/spdkcli/pmem.sh 278 fi 279 280 if [ $SPDK_TEST_RBD -eq 1 ]; then 281 run_test "blockdev_rbd" ./test/bdev/blockdev.sh "rbd" 282 run_test "spdkcli_rbd" ./test/spdkcli/rbd.sh 283 fi 284 285 if [ $SPDK_TEST_OCF -eq 1 ]; then 286 run_test "ocf" ./test/ocf/ocf.sh 287 fi 288 289 if [ $SPDK_TEST_FTL -eq 1 ]; then 290 run_test "ftl" ./test/ftl/ftl.sh 291 fi 292 293 if [ $SPDK_TEST_VMD -eq 1 ]; then 294 run_test "vmd" ./test/vmd/vmd.sh 295 fi 296 297 if [ $SPDK_TEST_REDUCE -eq 1 ]; then 298 run_test "compress_qat" ./test/compress/compress.sh "qat" 299 run_test "compress_isal" ./test/compress/compress.sh "isal" 300 fi 301 302 if [ $SPDK_TEST_OPAL -eq 1 ]; then 303 run_test "nvme_opal" ./test/nvme/nvme_opal.sh 304 fi 305 306 if [ $SPDK_TEST_CRYPTO -eq 1 ]; then 307 run_test "blockdev_crypto_aesni" ./test/bdev/blockdev.sh "crypto_aesni" 308 # Proceed with the test only if QAT devices are in place 309 if [[ $(lspci -d:37c8) ]]; then 310 run_test "blockdev_crypto_qat" ./test/bdev/blockdev.sh "crypto_qat" 311 fi 312 fi 313fi 314 315timing_enter cleanup 316autotest_cleanup 317timing_exit cleanup 318 319timing_exit autotest 320chmod a+r $output_dir/timing.txt 321 322trap - SIGINT SIGTERM EXIT 323 324# catch any stray core files 325process_core 326 327if hash lcov; then 328 # generate coverage data and combine with baseline 329 $LCOV -q -c -d $src -t "$(hostname)" -o $out/cov_test.info 330 $LCOV -q -a $out/cov_base.info -a $out/cov_test.info -o $out/cov_total.info 331 $LCOV -q -r $out/cov_total.info '*/dpdk/*' -o $out/cov_total.info 332 $LCOV -q -r $out/cov_total.info '/usr/*' -o $out/cov_total.info 333 git clean -f "*.gcda" 334 rm -f cov_base.info cov_test.info OLD_STDOUT OLD_STDERR 335fi 336