xref: /spdk/test/vhost/other/negative.sh (revision 32999ab917f67af61872f868585fd3d78ad6fb8a)
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
8function usage() {
9	[[ -n $2 ]] && (
10		echo "$2"
11		echo ""
12	)
13	echo "Shortcut script for running vhost app."
14	echo "Usage: $(basename $1) [-x] [-h|--help] [--clean-build]"
15	echo "-h, --help           print help and exit"
16	echo "-x                   Set -x for script debug"
17
18	exit 0
19}
20
21run_in_background=false
22while getopts 'xh-:' optchar; do
23	case "$optchar" in
24		-)
25			case "$OPTARG" in
26				help) usage $0 ;;
27				conf-dir=*) CONF_DIR="${OPTARG#*=}" ;;
28				*) usage $0 echo "Invalid argument '$OPTARG'" ;;
29			esac
30			;;
31		h) usage $0 ;;
32		x) set -x ;;
33		*) usage $0 "Invalid argument '$optchar'" ;;
34	esac
35done
36
37vhosttestinit
38
39trap error_exit ERR
40
41notice "Testing vhost command line arguments"
42# Printing help will force vhost to exit without error
43"${VHOST_APP[@]}" -c /path/to/non_existing_file/conf -S $testdir -e 0x0 -s 1024 -d -h --silence-noticelog
44
45# Testing vhost create pid file option. Vhost will exit with error as invalid config path is given
46if "${VHOST_APP[@]}" -c /path/to/non_existing_file/conf -f "$VHOST_DIR/vhost/vhost.pid"; then
47	fail "vhost started when specifying invalid config file"
48fi
49rm -f $VHOST_DIR/vhost/vhost.pid
50
51# Expecting vhost to fail if an incorrect argument is given
52if "${VHOST_APP[@]}" -x -h; then
53	fail "vhost started with invalid -x command line option"
54fi
55
56# Passing trace flags if spdk is build without CONFIG_DEBUG=y option make vhost exit with error
57if ! "${VHOST_APP[@]}" -t vhost_scsi -h; then
58	warning "vhost did not started with trace flags enabled but ignoring this as it might not be a debug build"
59fi
60
61# Run with valid config and try some negative rpc calls
62notice "==============="
63notice ""
64notice "running SPDK"
65notice ""
66vhost_run -n 0 -a "-m 0xf"
67notice ""
68rpc_py="$rootdir/scripts/rpc.py -s $(get_vhost_dir 0)/rpc.sock"
69$rpc_py bdev_malloc_create -b Malloc0 128 4096
70$rpc_py bdev_malloc_create -b Malloc1 128 4096
71$rpc_py bdev_malloc_create -b Malloc2 128 4096
72$rpc_py bdev_split_create Malloc2 8
73
74# Try to get nonexistent vhost controller
75if $rpc_py vhost_get_controllers -n nonexistent; then
76	error "vhost returned controller that does not exist"
77fi
78
79notice "Set coalescing for nonexistent controller"
80if $rpc_py vhost_controller_set_coalescing nonexistent 1 100; then
81	error "Set coalescing for nonexistent controller should fail"
82fi
83
84# General commands
85notice "Trying to remove nonexistent controller"
86if $rpc_py vhost_delete_controller unk0 > /dev/null; then
87	error "Removing nonexistent controller succeeded, but it shouldn't"
88fi
89
90# SCSI
91notice "Trying to create scsi controller with incorrect cpumask outside of application cpumask"
92if $rpc_py vhost_create_scsi_controller vhost.invalid.cpumask --cpumask 0xf0; then
93	error "Creating scsi controller with incorrect cpumask succeeded, but it shouldn't"
94fi
95
96notice "Trying to create scsi controller with incorrect cpumask partially outside of application cpumask"
97if $rpc_py vhost_create_scsi_controller vhost.invalid.cpumask --cpumask 0xff; then
98	error "Creating scsi controller with incorrect cpumask succeeded, but it shouldn't"
99fi
100
101notice "Trying to remove device from nonexistent scsi controller"
102if $rpc_py vhost_scsi_controller_remove_target vhost.nonexistent.name 0; then
103	error "Removing device from nonexistent scsi controller succeeded, but it shouldn't"
104fi
105
106notice "Trying to add device to nonexistent scsi controller"
107if $rpc_py vhost_scsi_controller_add_target vhost.nonexistent.name 0 Malloc0; then
108	error "Adding device to nonexistent scsi controller succeeded, but it shouldn't"
109fi
110
111notice "Trying to create scsi controller with incorrect name"
112if $rpc_py vhost_create_scsi_controller .; then
113	error "Creating scsi controller with incorrect name succeeded, but it shouldn't"
114fi
115
116notice "Creating controller naa.0"
117$rpc_py vhost_create_scsi_controller naa.0
118
119notice "Pass invalid parameter for vhost_controller_set_coalescing"
120if $rpc_py vhost_controller_set_coalescing naa.0 -1 100; then
121	error "Set coalescing with invalid parameter should fail"
122fi
123
124notice "Trying to add nonexistent device to scsi controller"
125if $rpc_py vhost_scsi_controller_add_target naa.0 0 nonexistent_bdev; then
126	error "Adding nonexistent device to scsi controller succeeded, but it shouldn't"
127fi
128
129notice "Adding device to naa.0 with slot number exceeding max"
130if $rpc_py vhost_scsi_controller_add_target naa.0 8 Malloc0; then
131	error "Adding device to naa.0 should fail but succeeded"
132fi
133
134for i in $(seq 0 7); do
135	$rpc_py vhost_scsi_controller_add_target naa.0 -1 Malloc2p$i
136done
137notice "All slots are occupied. Try to add one more device to naa.0"
138if $rpc_py vhost_scsi_controller_add_target naa.0 -1 Malloc0; then
139	error "Adding device to naa.0 should fail but succeeded"
140fi
141for i in $(seq 0 7); do
142	$rpc_py vhost_scsi_controller_remove_target naa.0 $i
143done
144
145notice "Adding initial device (0) to naa.0"
146$rpc_py vhost_scsi_controller_add_target naa.0 0 Malloc0
147
148notice "Adding device to naa.0 with slot number 0"
149if $rpc_py vhost_scsi_controller_add_target naa.0 0 Malloc1; then
150	error "Adding device to naa.0 occupied slot should fail but succeeded"
151fi
152
153notice "Trying to remove nonexistent device on existing controller"
154if $rpc_py vhost_scsi_controller_remove_target naa.0 1 > /dev/null; then
155	error "Removing nonexistent device (1) from controller naa.0 succeeded, but it shouldn't"
156fi
157
158notice "Trying to remove existing device from a controller"
159$rpc_py vhost_scsi_controller_remove_target naa.0 0
160
161notice "Trying to remove a just-deleted device from a controller again"
162if $rpc_py vhost_scsi_controller_remove_target naa.0 0 > /dev/null; then
163	error "Removing device 0 from controller naa.0 succeeded, but it shouldn't"
164fi
165
166notice "Trying to remove scsi target with invalid slot number"
167if $rpc_py vhost_scsi_controller_remove_target naa.0 8 > /dev/null; then
168	error "Removing device 8 from controller naa.0 succeeded, but it shouldn't"
169fi
170
171notice "Re-adding device 0 to naa.0"
172$rpc_py vhost_scsi_controller_add_target naa.0 0 Malloc0
173
174# BLK
175notice "Trying to create block controller with incorrect cpumask outside of application cpumask"
176if $rpc_py vhost_create_blk_controller vhost.invalid.cpumask Malloc0 --cpumask 0xf0; then
177	error "Creating block controller with incorrect cpumask succeeded, but it shouldn't"
178fi
179
180notice "Trying to create block controller with incorrect cpumask partially outside of application cpumask"
181if $rpc_py vhost_create_blk_controller vhost.invalid.cpumask Malloc0 --cpumask 0xff; then
182	error "Creating block controller with incorrect cpumask succeeded, but it shouldn't"
183fi
184
185notice "Trying to remove nonexistent block controller"
186if $rpc_py vhost_delete_controller vhost.nonexistent.name; then
187	error "Removing nonexistent block controller succeeded, but it shouldn't"
188fi
189
190notice "Trying to create block controller with incorrect name"
191if $rpc_py vhost_create_blk_controller . Malloc0; then
192	error "Creating block controller with incorrect name succeeded, but it shouldn't"
193fi
194
195notice "Trying to create block controller with nonexistent bdev"
196if $rpc_py vhost_create_blk_controller blk_ctrl Malloc3; then
197	error "Creating block controller with nonexistent bdev succeeded, but shouldn't"
198fi
199
200notice "Trying to create block controller with claimed bdev"
201$rpc_py bdev_lvol_create_lvstore Malloc0 lvs
202if $rpc_py vhost_create_blk_controller blk_ctrl Malloc0; then
203	error "Creating block controller with claimed bdev succeeded, but shouldn't"
204fi
205$rpc_py bdev_lvol_delete_lvstore -l lvs
206
207notice "Testing done -> shutting down"
208notice "killing vhost app"
209vhost_kill 0
210
211notice "EXIT DONE"
212notice "==============="
213
214vhosttestfini
215