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