]> git.proxmox.com Git - ceph.git/blame - ceph/src/spdk/test/vhost/other/negative.sh
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / spdk / test / vhost / other / negative.sh
CommitLineData
11fdf7f2
TL
1#!/usr/bin/env bash
2
9f95a23c
TL
3testdir=$(readlink -f $(dirname $0))
4rootdir=$(readlink -f $testdir/../../..)
5source $rootdir/test/common/autotest_common.sh
6source $rootdir/test/vhost/common.sh
11fdf7f2 7
f67539c2
TL
8function usage() {
9 [[ -n $2 ]] && (
10 echo "$2"
11 echo ""
12 )
11fdf7f2 13 echo "Shortcut script for running vhost app."
9f95a23c 14 echo "Usage: $(basename $1) [-x] [-h|--help] [--clean-build]"
11fdf7f2
TL
15 echo "-h, --help print help and exit"
16 echo "-x Set -x for script debug"
11fdf7f2
TL
17
18 exit 0
19}
20
21run_in_background=false
22while getopts 'xh-:' optchar; do
23 case "$optchar" in
24 -)
f67539c2
TL
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'" ;;
11fdf7f2
TL
34 esac
35done
36
9f95a23c 37vhosttestinit
11fdf7f2
TL
38
39trap error_exit ERR
40
11fdf7f2
TL
41notice "Testing vhost command line arguments"
42# Printing help will force vhost to exit without error
f67539c2 43"${VHOST_APP[@]}" -c /path/to/non_existing_file/conf -S $testdir -e 0x0 -s 1024 -d -h --silence-noticelog
11fdf7f2
TL
44
45# Testing vhost create pid file option. Vhost will exit with error as invalid config path is given
f67539c2 46if "${VHOST_APP[@]}" -c /path/to/non_existing_file/conf -f "$VHOST_DIR/vhost/vhost.pid"; then
9f95a23c
TL
47 fail "vhost started when specifying invalid config file"
48fi
f67539c2 49rm -f $VHOST_DIR/vhost/vhost.pid
9f95a23c
TL
50
51# Testing vhost start with invalid config. Vhost will exit with error as bdev module init failed
f67539c2 52if "${VHOST_APP[@]}" -c $testdir/invalid.config; then
11fdf7f2
TL
53 fail "vhost started when specifying invalid config file"
54fi
55
56# Expecting vhost to fail if an incorrect argument is given
f67539c2 57if "${VHOST_APP[@]}" -x -h; then
11fdf7f2
TL
58 fail "vhost started with invalid -x command line option"
59fi
60
61# Passing trace flags if spdk is build without CONFIG_DEBUG=y option make vhost exit with error
f67539c2 62if ! "${VHOST_APP[@]}" -t vhost_scsi -h; then
11fdf7f2
TL
63 warning "vhost did not started with trace flags enabled but ignoring this as it might not be a debug build"
64fi
65
f67539c2
TL
66# Run with valid config and try some negative rpc calls
67notice "==============="
68notice ""
69notice "running SPDK"
70notice ""
71vhost_run 0
72notice ""
73rpc_py="$rootdir/scripts/rpc.py -s $(get_vhost_dir 0)/rpc.sock"
74$rpc_py bdev_malloc_create -b Malloc0 128 4096
75$rpc_py bdev_malloc_create -b Malloc1 128 4096
76$rpc_py bdev_malloc_create -b Malloc2 128 4096
77$rpc_py bdev_split_create Malloc2 8
78
79# Try to get nonexistent vhost controller
80if $rpc_py vhost_get_controllers -n nonexistent; then
81 error "vhost returned controller that does not exist"
82fi
83
84notice "Set coalescing for nonexistent controller"
85if $rpc_py vhost_controller_set_coalescing nonexistent 1 100; then
86 error "Set coalescing for nonexistent controller should fail"
87fi
88
89# General commands
90notice "Trying to remove nonexistent controller"
91if $rpc_py vhost_delete_controller unk0 > /dev/null; then
92 error "Removing nonexistent controller succeeded, but it shouldn't"
93fi
94
95# SCSI
96notice "Trying to create scsi controller with incorrect cpumask"
97if $rpc_py vhost_create_scsi_controller vhost.invalid.cpumask --cpumask 0x2; 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"
11fdf7f2 127fi
9f95a23c 128
f67539c2
TL
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"
176if $rpc_py vhost_create_blk_controller vhost.invalid.cpumask Malloc0 --cpumask 0x2; then
177 error "Creating block controller with incorrect cpumask succeeded, but it shouldn't"
178fi
179
180notice "Trying to remove nonexistent block controller"
181if $rpc_py vhost_delete_controller vhost.nonexistent.name; then
182 error "Removing nonexistent block controller succeeded, but it shouldn't"
183fi
184
185notice "Trying to create block controller with incorrect name"
186if $rpc_py vhost_create_blk_controller . Malloc0; then
187 error "Creating block controller with incorrect name succeeded, but it shouldn't"
188fi
189
190notice "Trying to create block controller with nonexistent bdev"
191if $rpc_py vhost_create_blk_controller blk_ctrl Malloc3; then
192 error "Creating block controller with nonexistent bdev succeeded, but shouldn't"
193fi
194
195notice "Trying to create block controller with claimed bdev"
196$rpc_py bdev_lvol_create_lvstore Malloc0 lvs
197if $rpc_py vhost_create_blk_controller blk_ctrl Malloc0; then
198 error "Creating block controller with claimed bdev succeeded, but shouldn't"
199fi
200$rpc_py bdev_lvol_delete_lvstore -l lvs
201
202notice "Testing done -> shutting down"
203notice "killing vhost app"
204vhost_kill 0
205
206notice "EXIT DONE"
207notice "==============="
208
9f95a23c 209vhosttestfini