]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | #!/usr/bin/env bash |
2 | ||
9f95a23c TL |
3 | testdir=$(readlink -f $(dirname $0)) |
4 | rootdir=$(readlink -f $testdir/../../..) | |
5 | source $rootdir/test/common/autotest_common.sh | |
6 | source $rootdir/test/vhost/common.sh | |
11fdf7f2 | 7 | |
f67539c2 TL |
8 | function 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 | ||
21 | run_in_background=false | |
22 | while 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 |
35 | done | |
36 | ||
9f95a23c | 37 | vhosttestinit |
11fdf7f2 TL |
38 | |
39 | trap error_exit ERR | |
40 | ||
11fdf7f2 TL |
41 | notice "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 | 46 | if "${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" |
48 | fi | |
f67539c2 | 49 | rm -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 | 52 | if "${VHOST_APP[@]}" -c $testdir/invalid.config; then |
11fdf7f2 TL |
53 | fail "vhost started when specifying invalid config file" |
54 | fi | |
55 | ||
56 | # Expecting vhost to fail if an incorrect argument is given | |
f67539c2 | 57 | if "${VHOST_APP[@]}" -x -h; then |
11fdf7f2 TL |
58 | fail "vhost started with invalid -x command line option" |
59 | fi | |
60 | ||
61 | # Passing trace flags if spdk is build without CONFIG_DEBUG=y option make vhost exit with error | |
f67539c2 | 62 | if ! "${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" |
64 | fi | |
65 | ||
f67539c2 TL |
66 | # Run with valid config and try some negative rpc calls |
67 | notice "===============" | |
68 | notice "" | |
69 | notice "running SPDK" | |
70 | notice "" | |
71 | vhost_run 0 | |
72 | notice "" | |
73 | rpc_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 | |
80 | if $rpc_py vhost_get_controllers -n nonexistent; then | |
81 | error "vhost returned controller that does not exist" | |
82 | fi | |
83 | ||
84 | notice "Set coalescing for nonexistent controller" | |
85 | if $rpc_py vhost_controller_set_coalescing nonexistent 1 100; then | |
86 | error "Set coalescing for nonexistent controller should fail" | |
87 | fi | |
88 | ||
89 | # General commands | |
90 | notice "Trying to remove nonexistent controller" | |
91 | if $rpc_py vhost_delete_controller unk0 > /dev/null; then | |
92 | error "Removing nonexistent controller succeeded, but it shouldn't" | |
93 | fi | |
94 | ||
95 | # SCSI | |
96 | notice "Trying to create scsi controller with incorrect cpumask" | |
97 | if $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" | |
99 | fi | |
100 | ||
101 | notice "Trying to remove device from nonexistent scsi controller" | |
102 | if $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" | |
104 | fi | |
105 | ||
106 | notice "Trying to add device to nonexistent scsi controller" | |
107 | if $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" | |
109 | fi | |
110 | ||
111 | notice "Trying to create scsi controller with incorrect name" | |
112 | if $rpc_py vhost_create_scsi_controller .; then | |
113 | error "Creating scsi controller with incorrect name succeeded, but it shouldn't" | |
114 | fi | |
115 | ||
116 | notice "Creating controller naa.0" | |
117 | $rpc_py vhost_create_scsi_controller naa.0 | |
118 | ||
119 | notice "Pass invalid parameter for vhost_controller_set_coalescing" | |
120 | if $rpc_py vhost_controller_set_coalescing naa.0 -1 100; then | |
121 | error "Set coalescing with invalid parameter should fail" | |
122 | fi | |
123 | ||
124 | notice "Trying to add nonexistent device to scsi controller" | |
125 | if $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 | 127 | fi |
9f95a23c | 128 | |
f67539c2 TL |
129 | notice "Adding device to naa.0 with slot number exceeding max" |
130 | if $rpc_py vhost_scsi_controller_add_target naa.0 8 Malloc0; then | |
131 | error "Adding device to naa.0 should fail but succeeded" | |
132 | fi | |
133 | ||
134 | for i in $(seq 0 7); do | |
135 | $rpc_py vhost_scsi_controller_add_target naa.0 -1 Malloc2p$i | |
136 | done | |
137 | notice "All slots are occupied. Try to add one more device to naa.0" | |
138 | if $rpc_py vhost_scsi_controller_add_target naa.0 -1 Malloc0; then | |
139 | error "Adding device to naa.0 should fail but succeeded" | |
140 | fi | |
141 | for i in $(seq 0 7); do | |
142 | $rpc_py vhost_scsi_controller_remove_target naa.0 $i | |
143 | done | |
144 | ||
145 | notice "Adding initial device (0) to naa.0" | |
146 | $rpc_py vhost_scsi_controller_add_target naa.0 0 Malloc0 | |
147 | ||
148 | notice "Adding device to naa.0 with slot number 0" | |
149 | if $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" | |
151 | fi | |
152 | ||
153 | notice "Trying to remove nonexistent device on existing controller" | |
154 | if $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" | |
156 | fi | |
157 | ||
158 | notice "Trying to remove existing device from a controller" | |
159 | $rpc_py vhost_scsi_controller_remove_target naa.0 0 | |
160 | ||
161 | notice "Trying to remove a just-deleted device from a controller again" | |
162 | if $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" | |
164 | fi | |
165 | ||
166 | notice "Trying to remove scsi target with invalid slot number" | |
167 | if $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" | |
169 | fi | |
170 | ||
171 | notice "Re-adding device 0 to naa.0" | |
172 | $rpc_py vhost_scsi_controller_add_target naa.0 0 Malloc0 | |
173 | ||
174 | # BLK | |
175 | notice "Trying to create block controller with incorrect cpumask" | |
176 | if $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" | |
178 | fi | |
179 | ||
180 | notice "Trying to remove nonexistent block controller" | |
181 | if $rpc_py vhost_delete_controller vhost.nonexistent.name; then | |
182 | error "Removing nonexistent block controller succeeded, but it shouldn't" | |
183 | fi | |
184 | ||
185 | notice "Trying to create block controller with incorrect name" | |
186 | if $rpc_py vhost_create_blk_controller . Malloc0; then | |
187 | error "Creating block controller with incorrect name succeeded, but it shouldn't" | |
188 | fi | |
189 | ||
190 | notice "Trying to create block controller with nonexistent bdev" | |
191 | if $rpc_py vhost_create_blk_controller blk_ctrl Malloc3; then | |
192 | error "Creating block controller with nonexistent bdev succeeded, but shouldn't" | |
193 | fi | |
194 | ||
195 | notice "Trying to create block controller with claimed bdev" | |
196 | $rpc_py bdev_lvol_create_lvstore Malloc0 lvs | |
197 | if $rpc_py vhost_create_blk_controller blk_ctrl Malloc0; then | |
198 | error "Creating block controller with claimed bdev succeeded, but shouldn't" | |
199 | fi | |
200 | $rpc_py bdev_lvol_delete_lvstore -l lvs | |
201 | ||
202 | notice "Testing done -> shutting down" | |
203 | notice "killing vhost app" | |
204 | vhost_kill 0 | |
205 | ||
206 | notice "EXIT DONE" | |
207 | notice "===============" | |
208 | ||
9f95a23c | 209 | vhosttestfini |