Commit | Line | Data |
---|---|---|
037b2b50 DF |
1 | #!/bin/bash |
2 | # | |
3 | # Copyright (C) 2020 Western Digital Corporation or its affiliates. | |
4 | # | |
5 | # This file is released under the GPL. | |
6 | # | |
7 | # Run t/zbd/test-zbd-support script against a variety of conventional, | |
8 | # zoned and mixed zone configurations. | |
9 | # | |
10 | ||
11 | usage() | |
12 | { | |
13 | echo "This script runs the tests from t/zbd/test-zbd-support script" | |
14 | echo "against a nullb device in a variety of conventional and zoned" | |
15 | echo "configurations." | |
16 | echo "Usage: ${0} [OPTIONS]" | |
17 | echo "Options:" | |
18 | echo -e "\t-h Show this message." | |
19 | echo -e "\t-L List the device layouts for every section without running" | |
20 | echo -e "\t tests." | |
21 | echo -e "\t-s <#section> Only run the section with the given number." | |
073c6443 | 22 | echo -e "\t-t <#test> Only run the test with the given number in every section." |
037b2b50 DF |
23 | echo -e "\t-o <max_open_zones> Specify MaxOpen value, (${set_max_open} by default)." |
24 | echo -e "\t-n <#number of runs> Set the number of times to run the entire suite " | |
25 | echo -e "\t or an individual section/test." | |
56e87b2f | 26 | echo -e "\t-q Quit t/zbd/test-zbd-support run after any failed test." |
037b2b50 DF |
27 | echo -e "\t-r Remove the /dev/nullb0 device that may still exist after" |
28 | echo -e "\t running this script." | |
29 | exit 1 | |
30 | } | |
31 | ||
32 | cleanup_nullb() | |
33 | { | |
34 | for d in /sys/kernel/config/nullb/*; do [ -d "$d" ] && rmdir "$d"; done | |
35 | modprobe -r null_blk | |
36 | modprobe null_blk nr_devices=0 || exit $? | |
37 | for d in /sys/kernel/config/nullb/*; do | |
38 | [ -d "$d" ] && rmdir "$d" | |
39 | done | |
40 | modprobe -r null_blk | |
41 | [ -e /sys/module/null_blk ] && exit $? | |
42 | } | |
43 | ||
44 | create_nullb() | |
45 | { | |
46 | modprobe null_blk nr_devices=0 && | |
47 | cd /sys/kernel/config/nullb && | |
48 | mkdir nullb0 && | |
49 | cd nullb0 || return $? | |
50 | } | |
51 | ||
52 | configure_nullb() | |
53 | { | |
54 | echo 0 > completion_nsec && | |
55 | echo ${dev_blocksize} > blocksize && | |
56 | echo ${dev_size} > size && | |
57 | echo 1 > memory_backed || return $? | |
58 | ||
59 | if ((conv_pcnt < 100)); then | |
60 | echo 1 > zoned && | |
61 | echo "${zone_size}" > zone_size || return $? | |
62 | ||
63 | if ((zone_capacity < zone_size)); then | |
64 | if ((!zcap_supported)); then | |
65 | echo "null_blk does not support zone capacity" | |
66 | return 2 | |
67 | fi | |
68 | echo "${zone_capacity}" > zone_capacity | |
69 | fi | |
70970620 | 70 | |
037b2b50 DF |
71 | if ((conv_pcnt)); then |
72 | if ((!conv_supported)); then | |
73 | echo "null_blk does not support conventional zones" | |
74 | return 2 | |
75 | fi | |
76 | nr_conv=$((dev_size/zone_size*conv_pcnt/100)) | |
70970620 DF |
77 | else |
78 | nr_conv=0 | |
79 | fi | |
80 | echo "${nr_conv}" > zone_nr_conv | |
81 | ||
82 | if ((max_open)); then | |
83 | echo "${max_open}" > zone_max_open | |
caf7ac7e DF |
84 | if ((max_active)); then |
85 | if ((!max_act_supported)); then | |
86 | echo "null_blk does not support active zone counts" | |
87 | return 2 | |
88 | fi | |
89 | echo "${max_active}" > zone_max_active | |
90 | fi | |
037b2b50 DF |
91 | fi |
92 | fi | |
93 | ||
94 | echo 1 > power || return $? | |
95 | return 0 | |
96 | } | |
97 | ||
98 | show_nullb_config() | |
99 | { | |
100 | if ((conv_pcnt < 100)); then | |
101 | echo " $(printf "Zoned Device, %d%% Conventional Zones (%d)" \ | |
102 | ${conv_pcnt} ${nr_conv})" | |
103 | echo " $(printf "Zone Size: %d MB" ${zone_size})" | |
104 | echo " $(printf "Zone Capacity: %d MB" ${zone_capacity})" | |
105 | if ((max_open)); then | |
106 | echo " $(printf "Max Open: %d Zones" ${max_open})" | |
caf7ac7e DF |
107 | if ((max_active)); then |
108 | echo " $(printf "Max Active: %d Zones" ${max_active})" | |
109 | else | |
110 | echo " Max Active: Unlimited Zones" | |
111 | fi | |
037b2b50 DF |
112 | else |
113 | echo " Max Open: Unlimited Zones" | |
114 | fi | |
115 | else | |
116 | echo " Non-zoned Device" | |
117 | fi | |
118 | } | |
119 | ||
120 | # | |
121 | # Test sections. | |
122 | # | |
123 | # Fully conventional device. | |
124 | section1() | |
125 | { | |
126 | conv_pcnt=100 | |
127 | max_open=0 | |
128 | } | |
129 | ||
130 | # Zoned device with no conventional zones, ZCAP == ZSIZE, unlimited MaxOpen. | |
131 | section2() | |
132 | { | |
133 | conv_pcnt=0 | |
134 | zone_size=1 | |
135 | zone_capacity=1 | |
136 | max_open=0 | |
137 | } | |
138 | ||
139 | # Zoned device with no conventional zones, ZCAP < ZSIZE, unlimited MaxOpen. | |
140 | section3() | |
141 | { | |
142 | conv_pcnt=0 | |
143 | zone_size=4 | |
144 | zone_capacity=3 | |
145 | max_open=0 | |
caf7ac7e | 146 | max_active=0 |
037b2b50 DF |
147 | } |
148 | ||
149 | # Zoned device with mostly sequential zones, ZCAP == ZSIZE, unlimited MaxOpen. | |
150 | section4() | |
151 | { | |
152 | conv_pcnt=10 | |
153 | zone_size=1 | |
154 | zone_capacity=1 | |
155 | max_open=0 | |
caf7ac7e | 156 | max_active=0 |
037b2b50 DF |
157 | } |
158 | ||
159 | # Zoned device with mostly sequential zones, ZCAP < ZSIZE, unlimited MaxOpen. | |
160 | section5() | |
161 | { | |
162 | conv_pcnt=10 | |
163 | zone_size=4 | |
164 | zone_capacity=3 | |
165 | max_open=0 | |
caf7ac7e | 166 | max_active=0 |
037b2b50 DF |
167 | } |
168 | ||
169 | # Zoned device with mostly conventional zones, ZCAP == ZSIZE, unlimited MaxOpen. | |
170 | section6() | |
171 | { | |
172 | conv_pcnt=66 | |
173 | zone_size=1 | |
174 | zone_capacity=1 | |
175 | max_open=0 | |
caf7ac7e | 176 | max_active=0 |
037b2b50 DF |
177 | } |
178 | ||
179 | # Zoned device with mostly conventional zones, ZCAP < ZSIZE, unlimited MaxOpen. | |
180 | section7() | |
181 | { | |
182 | dev_size=2048 | |
183 | conv_pcnt=66 | |
184 | zone_size=4 | |
185 | zone_capacity=3 | |
186 | max_open=0 | |
caf7ac7e | 187 | max_active=0 |
037b2b50 DF |
188 | } |
189 | ||
caf7ac7e DF |
190 | # Zoned device with no conventional zones, ZCAP == ZSIZE, limited MaxOpen, |
191 | # unlimited MaxActive. | |
037b2b50 DF |
192 | section8() |
193 | { | |
194 | dev_size=1024 | |
195 | conv_pcnt=0 | |
196 | zone_size=1 | |
197 | zone_capacity=1 | |
198 | max_open=${set_max_open} | |
199 | zbd_test_opts+=("-o ${max_open}") | |
caf7ac7e | 200 | max_active=0 |
037b2b50 DF |
201 | } |
202 | ||
caf7ac7e DF |
203 | # Zoned device with no conventional zones, ZCAP < ZSIZE, limited MaxOpen, |
204 | # unlimited MaxActive. | |
037b2b50 DF |
205 | section9() |
206 | { | |
207 | conv_pcnt=0 | |
208 | zone_size=4 | |
209 | zone_capacity=3 | |
210 | max_open=${set_max_open} | |
211 | zbd_test_opts+=("-o ${max_open}") | |
caf7ac7e | 212 | max_active=0 |
037b2b50 DF |
213 | } |
214 | ||
caf7ac7e DF |
215 | # Zoned device with mostly sequential zones, ZCAP == ZSIZE, limited MaxOpen, |
216 | # unlimited MaxActive. | |
037b2b50 DF |
217 | section10() |
218 | { | |
219 | conv_pcnt=10 | |
220 | zone_size=1 | |
221 | zone_capacity=1 | |
222 | max_open=${set_max_open} | |
223 | zbd_test_opts+=("-o ${max_open}") | |
caf7ac7e | 224 | max_active=0 |
037b2b50 DF |
225 | } |
226 | ||
caf7ac7e DF |
227 | # Zoned device with mostly sequential zones, ZCAP < ZSIZE, limited MaxOpen, |
228 | # unlimited MaxActive. | |
037b2b50 DF |
229 | section11() |
230 | { | |
231 | conv_pcnt=10 | |
232 | zone_size=4 | |
233 | zone_capacity=3 | |
234 | max_open=${set_max_open} | |
235 | zbd_test_opts+=("-o ${max_open}") | |
caf7ac7e | 236 | max_active=0 |
037b2b50 DF |
237 | } |
238 | ||
caf7ac7e DF |
239 | # Zoned device with mostly conventional zones, ZCAP == ZSIZE, limited MaxOpen, |
240 | # unlimited MaxActive. | |
037b2b50 DF |
241 | section12() |
242 | { | |
243 | conv_pcnt=66 | |
244 | zone_size=1 | |
245 | zone_capacity=1 | |
246 | max_open=${set_max_open} | |
247 | zbd_test_opts+=("-o ${max_open}") | |
caf7ac7e | 248 | max_active=0 |
037b2b50 DF |
249 | } |
250 | ||
caf7ac7e DF |
251 | # Zoned device with mostly conventional zones, ZCAP < ZSIZE, limited MaxOpen, |
252 | # unlimited MaxActive. | |
037b2b50 DF |
253 | section13() |
254 | { | |
255 | dev_size=2048 | |
256 | conv_pcnt=66 | |
257 | zone_size=4 | |
258 | zone_capacity=3 | |
259 | max_open=${set_max_open} | |
260 | zbd_test_opts+=("-o ${max_open}") | |
caf7ac7e DF |
261 | max_active=0 |
262 | } | |
263 | ||
264 | # Zoned device with no conventional zones, ZCAP == ZSIZE, limited MaxOpen, | |
265 | # MaxActive == MaxOpen. | |
266 | section14() | |
267 | { | |
268 | dev_size=1024 | |
269 | conv_pcnt=0 | |
270 | zone_size=1 | |
271 | zone_capacity=1 | |
272 | max_open=${set_max_open} | |
273 | zbd_test_opts+=("-o ${max_open}") | |
274 | max_active=${set_max_open} | |
275 | } | |
276 | ||
277 | # Zoned device with no conventional zones, ZCAP < ZSIZE, limited MaxOpen, | |
278 | # MaxActive == MaxOpen. | |
279 | section15() | |
280 | { | |
281 | conv_pcnt=0 | |
282 | zone_size=4 | |
283 | zone_capacity=3 | |
284 | max_open=${set_max_open} | |
285 | zbd_test_opts+=("-o ${max_open}") | |
286 | max_active=${set_max_open} | |
287 | } | |
288 | ||
289 | # Zoned device with mostly sequential zones, ZCAP == ZSIZE, limited MaxOpen, | |
290 | # MaxActive == MaxOpen. | |
291 | section16() | |
292 | { | |
293 | conv_pcnt=10 | |
294 | zone_size=1 | |
295 | zone_capacity=1 | |
296 | max_open=${set_max_open} | |
297 | zbd_test_opts+=("-o ${max_open}") | |
298 | max_active=${set_max_open} | |
299 | } | |
300 | ||
301 | # Zoned device with mostly sequential zones, ZCAP < ZSIZE, limited MaxOpen, | |
302 | # MaxActive == MaxOpen. | |
303 | section17() | |
304 | { | |
305 | conv_pcnt=10 | |
306 | zone_size=4 | |
307 | zone_capacity=3 | |
308 | max_open=${set_max_open} | |
309 | zbd_test_opts+=("-o ${max_open}") | |
310 | max_active=${set_max_open} | |
311 | } | |
312 | ||
313 | # Zoned device with mostly conventional zones, ZCAP == ZSIZE, limited MaxOpen, | |
314 | # MaxActive == MaxOpen. | |
315 | section18() | |
316 | { | |
317 | conv_pcnt=66 | |
318 | zone_size=1 | |
319 | zone_capacity=1 | |
320 | max_open=${set_max_open} | |
321 | zbd_test_opts+=("-o ${max_open}") | |
322 | max_active=${set_max_open} | |
323 | } | |
324 | ||
325 | # Zoned device with mostly conventional zones, ZCAP < ZSIZE, limited MaxOpen, | |
326 | # MaxActive == MaxOpen. | |
327 | section19() | |
328 | { | |
329 | dev_size=2048 | |
330 | conv_pcnt=66 | |
331 | zone_size=4 | |
332 | zone_capacity=3 | |
333 | max_open=${set_max_open} | |
334 | zbd_test_opts+=("-o ${max_open}") | |
335 | max_active=${set_max_open} | |
336 | } | |
337 | ||
338 | # Zoned device with no conventional zones, ZCAP == ZSIZE, limited MaxOpen, | |
339 | # MaxActive > MaxOpen. | |
340 | section20() | |
341 | { | |
342 | dev_size=1024 | |
343 | conv_pcnt=0 | |
344 | zone_size=1 | |
345 | zone_capacity=1 | |
346 | max_open=${set_max_open} | |
347 | zbd_test_opts+=("-o ${max_open}") | |
348 | max_active=$((set_max_open+set_extra_max_active)) | |
349 | } | |
350 | ||
351 | # Zoned device with no conventional zones, ZCAP < ZSIZE, limited MaxOpen, | |
352 | # MaxActive > MaxOpen. | |
353 | section21() | |
354 | { | |
355 | conv_pcnt=0 | |
356 | zone_size=4 | |
357 | zone_capacity=3 | |
358 | max_open=${set_max_open} | |
359 | zbd_test_opts+=("-o ${max_open}") | |
360 | max_active=$((set_max_open+set_extra_max_active)) | |
361 | } | |
362 | ||
363 | # Zoned device with mostly sequential zones, ZCAP == ZSIZE, limited MaxOpen, | |
364 | # MaxActive > MaxOpen. | |
365 | section22() | |
366 | { | |
367 | conv_pcnt=10 | |
368 | zone_size=1 | |
369 | zone_capacity=1 | |
370 | max_open=${set_max_open} | |
371 | zbd_test_opts+=("-o ${max_open}") | |
372 | max_active=$((set_max_open+set_extra_max_active)) | |
373 | } | |
374 | ||
375 | # Zoned device with mostly sequential zones, ZCAP < ZSIZE, limited MaxOpen, | |
376 | # MaxActive > MaxOpen. | |
377 | section23() | |
378 | { | |
379 | conv_pcnt=10 | |
380 | zone_size=4 | |
381 | zone_capacity=3 | |
382 | max_open=${set_max_open} | |
383 | zbd_test_opts+=("-o ${max_open}") | |
384 | max_active=$((set_max_open+set_extra_max_active)) | |
385 | } | |
386 | ||
387 | # Zoned device with mostly conventional zones, ZCAP == ZSIZE, limited MaxOpen, | |
388 | # MaxActive > MaxOpen. | |
389 | section24() | |
390 | { | |
391 | conv_pcnt=66 | |
392 | zone_size=1 | |
393 | zone_capacity=1 | |
394 | max_open=${set_max_open} | |
395 | zbd_test_opts+=("-o ${max_open}") | |
396 | max_active=$((set_max_open+set_extra_max_active)) | |
397 | } | |
398 | ||
399 | # Zoned device with mostly conventional zones, ZCAP < ZSIZE, limited MaxOpen, | |
400 | # MaxActive > MaxOpen. | |
401 | section25() | |
402 | { | |
403 | dev_size=2048 | |
404 | conv_pcnt=66 | |
405 | zone_size=4 | |
406 | zone_capacity=3 | |
407 | max_open=${set_max_open} | |
408 | zbd_test_opts+=("-o ${max_open}") | |
409 | max_active=$((set_max_open+set_extra_max_active)) | |
037b2b50 DF |
410 | } |
411 | ||
412 | # | |
413 | # Entry point. | |
414 | # | |
415 | SECONDS=0 | |
416 | scriptdir="$(cd "$(dirname "$0")" && pwd)" | |
417 | sections=() | |
418 | zcap_supported=1 | |
419 | conv_supported=1 | |
caf7ac7e | 420 | max_act_supported=1 |
037b2b50 DF |
421 | list_only=0 |
422 | dev_size=1024 | |
423 | dev_blocksize=4096 | |
424 | set_max_open=8 | |
caf7ac7e | 425 | set_extra_max_active=2 |
037b2b50 | 426 | zbd_test_opts=() |
037b2b50 | 427 | num_of_runs=1 |
073c6443 | 428 | test_case=0 |
56e87b2f | 429 | quit_on_err=0 |
037b2b50 DF |
430 | |
431 | while (($#)); do | |
432 | case "$1" in | |
433 | -s) sections+=("$2"); shift; shift;; | |
434 | -o) set_max_open="${2}"; shift; shift;; | |
435 | -L) list_only=1; shift;; | |
436 | -r) cleanup_nullb; exit 0;; | |
037b2b50 | 437 | -n) num_of_runs="${2}"; shift; shift;; |
073c6443 | 438 | -t) test_case="${2}"; shift; shift;; |
56e87b2f | 439 | -q) quit_on_err=1; shift;; |
037b2b50 DF |
440 | -h) usage; break;; |
441 | --) shift; break;; | |
442 | *) usage; exit 1;; | |
443 | esac | |
444 | done | |
445 | ||
446 | if [ "${#sections[@]}" = 0 ]; then | |
447 | readarray -t sections < <(declare -F | grep "section[0-9]*" | tr -c -d "[:digit:]\n" | sort -n) | |
448 | fi | |
449 | ||
450 | cleanup_nullb | |
451 | ||
452 | # | |
453 | # Test creating null_blk device and check if newer features are supported | |
454 | # | |
455 | if ! eval "create_nullb"; then | |
456 | echo "can't create nullb" | |
457 | exit 1 | |
458 | fi | |
459 | if ! cat /sys/kernel/config/nullb/features | grep -q zone_capacity; then | |
460 | zcap_supported=0 | |
461 | fi | |
462 | if ! cat /sys/kernel/config/nullb/features | grep -q zone_nr_conv; then | |
463 | conv_supported=0 | |
464 | fi | |
caf7ac7e DF |
465 | if ! cat /sys/kernel/config/nullb/features | grep -q zone_max_active; then |
466 | max_act_supported=0 | |
467 | fi | |
037b2b50 DF |
468 | |
469 | rc=0 | |
470 | test_rc=0 | |
471 | intr=0 | |
472 | run_nr=1 | |
473 | trap 'kill ${zbd_test_pid}; intr=1' SIGINT | |
474 | ||
475 | while ((run_nr <= $num_of_runs)); do | |
476 | echo -e "\nRun #$run_nr:" | |
477 | for section_number in "${sections[@]}"; do | |
478 | cleanup_nullb | |
479 | echo "---------- Section $(printf "%02d" $section_number) ----------" | |
480 | if ! eval "create_nullb"; then | |
481 | echo "error creating nullb" | |
482 | exit 1 | |
483 | fi | |
484 | zbd_test_opts=() | |
073c6443 SK |
485 | if ((test_case)); then |
486 | zbd_test_opts+=("-t" "${test_case}") | |
487 | fi | |
56e87b2f DF |
488 | if ((quit_on_err)); then |
489 | zbd_test_opts+=("-q") | |
490 | fi | |
037b2b50 DF |
491 | section$section_number |
492 | configure_nullb | |
493 | rc=$? | |
494 | ((rc == 2)) && continue | |
495 | if ((rc)); then | |
496 | echo "can't set up nullb for section $(printf "%02d" $section_number)" | |
497 | exit 1 | |
498 | fi | |
499 | show_nullb_config | |
037b2b50 DF |
500 | cd "${scriptdir}" |
501 | ((intr)) && exit 1 | |
502 | ((list_only)) && continue | |
503 | ||
504 | ./test-zbd-support ${zbd_test_opts[@]} /dev/nullb0 & | |
505 | zbd_test_pid=$! | |
506 | if kill -0 "${zbd_test_pid}"; then | |
507 | wait "${zbd_test_pid}" | |
508 | test_rc=$? | |
509 | else | |
510 | echo "can't run ZBD tests" | |
511 | exit 1 | |
512 | fi | |
513 | ((intr)) && exit 1 | |
56e87b2f DF |
514 | if (($test_rc)); then |
515 | rc=1 | |
516 | ((quit_on_err)) && break | |
517 | fi | |
037b2b50 DF |
518 | done |
519 | ||
56e87b2f | 520 | ((rc && quit_on_err)) && break |
037b2b50 DF |
521 | run_nr=$((run_nr + 1)) |
522 | done | |
523 | ||
524 | if ((!list_only)); then | |
525 | echo "--------------------------------" | |
526 | echo "Total run time: $(TZ=UTC0 printf "%(%H:%M:%S)T\n" $(( SECONDS )) )" | |
527 | fi | |
528 | ||
529 | exit $rc |