xref: /spdk/test/vmd/vmd.sh (revision 86e4665b4e7382b1ad6ab9fe98c3454253406fc8)
1#!/usr/bin/env bash
2#  SPDX-License-Identifier: BSD-3-Clause
3#  Copyright (C) 2019 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
11rpc_py=$rootdir/scripts/rpc.py
12VMD_ALLOWED=()
13
14function vmd_identify() {
15	for bdf in $pci_devs; do
16		$SPDK_BIN_DIR/spdk_nvme_identify -i 0 -V -r "trtype:PCIe traddr:$bdf"
17	done
18}
19
20function vmd_perf() {
21	for bdf in $pci_devs; do
22		$SPDK_BIN_DIR/spdk_nvme_perf -q 128 -w read -o 12288 -t 1 -LL -i 0 -V -r "trtype:PCIe traddr:$bdf"
23	done
24}
25
26function vmd_fio() {
27	for bdf in $pci_devs; do
28		fio_nvme $testdir/config/config.fio --filename="trtype=PCIe traddr=${bdf//:/.} ns=1"
29	done
30}
31
32function vmd_bdev_svc() {
33	$rootdir/test/app/bdev_svc/bdev_svc --wait-for-rpc &
34	svcpid=$!
35	trap 'killprocess $svcpid; exit 1' SIGINT SIGTERM EXIT
36
37	# Wait until bdev_svc starts
38	waitforlisten $svcpid
39
40	$rpc_py vmd_enable
41	$rpc_py framework_start_init
42
43	for bdf in $pci_devs; do
44		$rpc_py bdev_nvme_attach_controller -b NVMe_$bdf -t PCIe -a $bdf
45	done
46
47	trap - SIGINT SIGTERM EXIT
48	killprocess $svcpid
49}
50
51# Re-run setup.sh script and only attach VMD devices to uio/vfio.
52$rootdir/scripts/setup.sh reset
53
54vmd_id=$(grep "PCI_DEVICE_ID_INTEL_VMD" $rootdir/include/spdk/pci_ids.h | awk -F"x" '{print $2}')
55
56for bdf in $(iter_pci_dev_id 8086 $vmd_id); do
57	if pci_can_use $bdf; then
58		VMD_ALLOWED+=("$bdf")
59	fi
60done
61PCI_ALLOWED="${VMD_ALLOWED[*]}" $rootdir/scripts/setup.sh
62
63pci_devs=$($SPDK_BIN_DIR/spdk_lspci | grep "NVMe disk behind VMD" | awk '{print $1}')
64
65if [[ -z "$pci_devs" ]]; then
66	echo "Couldn't find any NVMe device behind a VMD."
67	exit 1
68fi
69
70run_test "vmd_identify" vmd_identify
71run_test "vmd_hello_world" $SPDK_EXAMPLE_DIR/hello_world -V
72run_test "vmd_perf" vmd_perf
73if [[ $CONFIG_FIO_PLUGIN == y ]]; then
74	run_test "vmd_fio" vmd_fio
75fi
76
77run_test "vmd_bdev_svc" vmd_bdev_svc
78
79# Re-run setup.sh again so that other tests may continue
80$rootdir/scripts/setup.sh reset
81$rootdir/scripts/setup.sh
82