xref: /spdk/test/vhost/integrity/integrity_start.sh (revision 7366e569fbc7dff6dcc6709ffb52a890284de67e)
1#!/usr/bin/env bash
2
3testdir=$(readlink -f $(dirname $0))
4rootdir=$(readlink -f $testdir/../../..)
5source $rootdir/test/common/autotest_common.sh
6source $rootdir/test/vhost/common.sh
7
8ctrl_type="spdk_vhost_scsi"
9vm_fs="ext4"
10
11function usage() {
12	[[ -n $2 ]] && (
13		echo "$2"
14		echo ""
15	)
16	echo "Shortcut script for doing automated test"
17	echo "Usage: $(basename $1) [OPTIONS]"
18	echo
19	echo "-h, --help                Print help and exit"
20	echo "    --ctrl-type=TYPE      Controller type to use for test:"
21	echo "                          spdk_vhost_scsi - use spdk vhost scsi"
22	echo "    --fs=FS_LIST          Filesystems to use for test in VM:"
23	echo "                          Example: --fs=\"ext4 ntfs ext2\""
24	echo "                          Default: ext4"
25	echo "                          spdk_vhost_blk - use spdk vhost block"
26	echo "-x                        set -x for script debug"
27	exit 0
28}
29
30function clean_lvol_cfg() {
31	notice "Removing lvol bdev and lvol store"
32	$rpc_py bdev_lvol_delete lvol_store/lvol_bdev
33	$rpc_py bdev_lvol_delete_lvstore -l lvol_store
34}
35
36while getopts 'xh-:' optchar; do
37	case "$optchar" in
38		-)
39			case "$OPTARG" in
40				help) usage $0 ;;
41				ctrl-type=*) ctrl_type="${OPTARG#*=}" ;;
42				fs=*) vm_fs="${OPTARG#*=}" ;;
43				*) usage $0 "Invalid argument '$OPTARG'" ;;
44			esac
45			;;
46		h) usage $0 ;;
47		x)
48			set -x
49			x="-x"
50			;;
51		*) usage $0 "Invalid argument '$OPTARG'" ;;
52	esac
53done
54
55vhosttestinit
56
57. $(readlink -e "$(dirname $0)/../common.sh") || exit 1
58rpc_py="$rootdir/scripts/rpc.py -s $(get_vhost_dir 0)/rpc.sock"
59
60trap 'error_exit "${FUNCNAME}" "${LINENO}"' SIGTERM SIGABRT ERR
61
62# Try to kill if any VM remains from previous runs
63vm_kill_all
64
65notice "Starting SPDK vhost"
66vhost_run -n 0
67notice "..."
68
69# Set up lvols and vhost controllers
70trap 'clean_lvol_cfg; error_exit "${FUNCNAME}" "${LINENO}"' SIGTERM SIGABRT ERR
71notice "Creating lvol store and lvol bdev on top of Nvme0n1"
72lvs_uuid=$($rpc_py bdev_lvol_create_lvstore Nvme0n1 lvol_store)
73$rpc_py bdev_lvol_create lvol_bdev 10000 -l lvol_store
74
75if [[ "$ctrl_type" == "spdk_vhost_scsi" ]]; then
76	$rpc_py vhost_create_scsi_controller naa.Nvme0n1.0
77	$rpc_py vhost_scsi_controller_add_target naa.Nvme0n1.0 0 lvol_store/lvol_bdev
78elif [[ "$ctrl_type" == "spdk_vhost_blk" ]]; then
79	$rpc_py vhost_create_blk_controller naa.Nvme0n1.0 lvol_store/lvol_bdev
80fi
81
82# Set up and run VM
83setup_cmd="vm_setup --disk-type=$ctrl_type --force=0"
84setup_cmd+=" --os=$VM_IMAGE"
85setup_cmd+=" --disks=Nvme0n1"
86$setup_cmd
87
88# Run VM
89vm_run 0
90vm_wait_for_boot 300 0
91
92# Run tests on VM
93vm_scp 0 $testdir/integrity_vm.sh root@127.0.0.1:/root/integrity_vm.sh
94vm_exec 0 "/root/integrity_vm.sh $ctrl_type \"$vm_fs\""
95
96notice "Shutting down virtual machine..."
97vm_shutdown_all
98
99clean_lvol_cfg
100
101$rpc_py bdev_nvme_detach_controller Nvme0
102
103notice "Shutting down SPDK vhost app..."
104vhost_kill 0
105
106vhosttestfini
107