Merge branch 'security-token' of https://github.com/sfc-gh-rnarubin/fio
[fio.git] / t / zbd / run-tests-against-nullb
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."
22         echo -e "\t-t <#test> Only run the test with the given number in every section."
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."
26         echo -e "\t-q Quit t/zbd/test-zbd-support run after any failed test."
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
70
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))
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
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
91                 fi
92         fi
93
94         [[ -w badblocks_once ]] && echo 1 > badblocks_once
95         [[ -w badblocks_partial_io ]] && echo 1 > badblocks_partial_io
96
97         echo 1 > power || return $?
98         return 0
99 }
100
101 show_nullb_config()
102 {
103         if ((conv_pcnt < 100)); then
104                 echo "    $(printf "Zoned Device, %d%% Conventional Zones (%d)" \
105                           ${conv_pcnt} ${nr_conv})"
106                 echo "    $(printf "Zone Size: %d MB" ${zone_size})"
107                 echo "    $(printf "Zone Capacity: %d MB" ${zone_capacity})"
108                 if ((max_open)); then
109                         echo "    $(printf "Max Open: %d Zones" ${max_open})"
110                         if ((max_active)); then
111                                 echo "    $(printf "Max Active: %d Zones" ${max_active})"
112                         else
113                                 echo "    Max Active: Unlimited Zones"
114                         fi
115                 else
116                         echo "    Max Open: Unlimited Zones"
117                 fi
118         else
119                 echo "    Non-zoned Device"
120         fi
121 }
122
123 #
124 # Test sections.
125 #
126 # Fully conventional device.
127 section1()
128 {
129         conv_pcnt=100
130         max_open=0
131 }
132
133 # Zoned device with no conventional zones, ZCAP == ZSIZE, unlimited MaxOpen.
134 section2()
135 {
136         conv_pcnt=0
137         zone_size=1
138         zone_capacity=1
139         max_open=0
140 }
141
142 # Zoned device with no conventional zones, ZCAP < ZSIZE, unlimited MaxOpen.
143 section3()
144 {
145         conv_pcnt=0
146         zone_size=4
147         zone_capacity=3
148         max_open=0
149         max_active=0
150 }
151
152 # Zoned device with mostly sequential zones, ZCAP == ZSIZE, unlimited MaxOpen.
153 section4()
154 {
155         conv_pcnt=10
156         zone_size=1
157         zone_capacity=1
158         max_open=0
159         max_active=0
160 }
161
162 # Zoned device with mostly sequential zones, ZCAP < ZSIZE, unlimited MaxOpen.
163 section5()
164 {
165         conv_pcnt=10
166         zone_size=4
167         zone_capacity=3
168         max_open=0
169         max_active=0
170 }
171
172 # Zoned device with mostly conventional zones, ZCAP == ZSIZE, unlimited MaxOpen.
173 section6()
174 {
175         conv_pcnt=66
176         zone_size=1
177         zone_capacity=1
178         max_open=0
179         max_active=0
180 }
181
182 # Zoned device with mostly conventional zones, ZCAP < ZSIZE, unlimited MaxOpen.
183 section7()
184 {
185         dev_size=2048
186         conv_pcnt=66
187         zone_size=4
188         zone_capacity=3
189         max_open=0
190         max_active=0
191 }
192
193 # Zoned device with no conventional zones, ZCAP == ZSIZE, limited MaxOpen,
194 # unlimited MaxActive.
195 section8()
196 {
197         dev_size=1024
198         conv_pcnt=0
199         zone_size=1
200         zone_capacity=1
201         max_open=${set_max_open}
202         zbd_test_opts+=("-o ${max_open}")
203         max_active=0
204 }
205
206 # Zoned device with no conventional zones, ZCAP < ZSIZE, limited MaxOpen,
207 # unlimited MaxActive.
208 section9()
209 {
210         conv_pcnt=0
211         zone_size=4
212         zone_capacity=3
213         max_open=${set_max_open}
214         zbd_test_opts+=("-o ${max_open}")
215         max_active=0
216 }
217
218 # Zoned device with mostly sequential zones, ZCAP == ZSIZE, limited MaxOpen,
219 # unlimited MaxActive.
220 section10()
221 {
222         conv_pcnt=10
223         zone_size=1
224         zone_capacity=1
225         max_open=${set_max_open}
226         zbd_test_opts+=("-o ${max_open}")
227         max_active=0
228 }
229
230 # Zoned device with mostly sequential zones, ZCAP < ZSIZE, limited MaxOpen,
231 # unlimited MaxActive.
232 section11()
233 {
234         conv_pcnt=10
235         zone_size=4
236         zone_capacity=3
237         max_open=${set_max_open}
238         zbd_test_opts+=("-o ${max_open}")
239         max_active=0
240 }
241
242 # Zoned device with mostly conventional zones, ZCAP == ZSIZE, limited MaxOpen,
243 # unlimited MaxActive.
244 section12()
245 {
246         conv_pcnt=66
247         zone_size=1
248         zone_capacity=1
249         max_open=${set_max_open}
250         zbd_test_opts+=("-o ${max_open}")
251         max_active=0
252 }
253
254 # Zoned device with mostly conventional zones, ZCAP < ZSIZE, limited MaxOpen,
255 # unlimited MaxActive.
256 section13()
257 {
258         dev_size=2048
259         conv_pcnt=66
260         zone_size=4
261         zone_capacity=3
262         max_open=${set_max_open}
263         zbd_test_opts+=("-o ${max_open}")
264         max_active=0
265 }
266
267 # Zoned device with no conventional zones, ZCAP == ZSIZE, limited MaxOpen,
268 # MaxActive == MaxOpen.
269 section14()
270 {
271         dev_size=1024
272         conv_pcnt=0
273         zone_size=1
274         zone_capacity=1
275         max_open=${set_max_open}
276         zbd_test_opts+=("-o ${max_open}")
277         max_active=${set_max_open}
278 }
279
280 # Zoned device with no conventional zones, ZCAP < ZSIZE, limited MaxOpen,
281 # MaxActive == MaxOpen.
282 section15()
283 {
284         conv_pcnt=0
285         zone_size=4
286         zone_capacity=3
287         max_open=${set_max_open}
288         zbd_test_opts+=("-o ${max_open}")
289         max_active=${set_max_open}
290 }
291
292 # Zoned device with mostly sequential zones, ZCAP == ZSIZE, limited MaxOpen,
293 # MaxActive == MaxOpen.
294 section16()
295 {
296         conv_pcnt=10
297         zone_size=1
298         zone_capacity=1
299         max_open=${set_max_open}
300         zbd_test_opts+=("-o ${max_open}")
301         max_active=${set_max_open}
302 }
303
304 # Zoned device with mostly sequential zones, ZCAP < ZSIZE, limited MaxOpen,
305 # MaxActive == MaxOpen.
306 section17()
307 {
308         conv_pcnt=10
309         zone_size=4
310         zone_capacity=3
311         max_open=${set_max_open}
312         zbd_test_opts+=("-o ${max_open}")
313         max_active=${set_max_open}
314 }
315
316 # Zoned device with mostly conventional zones, ZCAP == ZSIZE, limited MaxOpen,
317 # MaxActive == MaxOpen.
318 section18()
319 {
320         conv_pcnt=66
321         zone_size=1
322         zone_capacity=1
323         max_open=${set_max_open}
324         zbd_test_opts+=("-o ${max_open}")
325         max_active=${set_max_open}
326 }
327
328 # Zoned device with mostly conventional zones, ZCAP < ZSIZE, limited MaxOpen,
329 # MaxActive == MaxOpen.
330 section19()
331 {
332         dev_size=2048
333         conv_pcnt=66
334         zone_size=4
335         zone_capacity=3
336         max_open=${set_max_open}
337         zbd_test_opts+=("-o ${max_open}")
338         max_active=${set_max_open}
339 }
340
341 # Zoned device with no conventional zones, ZCAP == ZSIZE, limited MaxOpen,
342 # MaxActive > MaxOpen.
343 section20()
344 {
345         dev_size=1024
346         conv_pcnt=0
347         zone_size=1
348         zone_capacity=1
349         max_open=${set_max_open}
350         zbd_test_opts+=("-o ${max_open}")
351         max_active=$((set_max_open+set_extra_max_active))
352 }
353
354 # Zoned device with no conventional zones, ZCAP < ZSIZE, limited MaxOpen,
355 # MaxActive > MaxOpen.
356 section21()
357 {
358         conv_pcnt=0
359         zone_size=4
360         zone_capacity=3
361         max_open=${set_max_open}
362         zbd_test_opts+=("-o ${max_open}")
363         max_active=$((set_max_open+set_extra_max_active))
364 }
365
366 # Zoned device with mostly sequential zones, ZCAP == ZSIZE, limited MaxOpen,
367 # MaxActive > MaxOpen.
368 section22()
369 {
370         conv_pcnt=10
371         zone_size=1
372         zone_capacity=1
373         max_open=${set_max_open}
374         zbd_test_opts+=("-o ${max_open}")
375         max_active=$((set_max_open+set_extra_max_active))
376 }
377
378 # Zoned device with mostly sequential zones, ZCAP < ZSIZE, limited MaxOpen,
379 # MaxActive > MaxOpen.
380 section23()
381 {
382         conv_pcnt=10
383         zone_size=4
384         zone_capacity=3
385         max_open=${set_max_open}
386         zbd_test_opts+=("-o ${max_open}")
387         max_active=$((set_max_open+set_extra_max_active))
388 }
389
390 # Zoned device with mostly conventional zones, ZCAP == ZSIZE, limited MaxOpen,
391 # MaxActive > MaxOpen.
392 section24()
393 {
394         conv_pcnt=66
395         zone_size=1
396         zone_capacity=1
397         max_open=${set_max_open}
398         zbd_test_opts+=("-o ${max_open}")
399         max_active=$((set_max_open+set_extra_max_active))
400 }
401
402 # Zoned device with mostly conventional zones, ZCAP < ZSIZE, limited MaxOpen,
403 # MaxActive > MaxOpen.
404 section25()
405 {
406         dev_size=2048
407         conv_pcnt=66
408         zone_size=4
409         zone_capacity=3
410         max_open=${set_max_open}
411         zbd_test_opts+=("-o ${max_open}")
412         max_active=$((set_max_open+set_extra_max_active))
413 }
414
415 #
416 # Entry point.
417 #
418 SECONDS=0
419 scriptdir="$(cd "$(dirname "$0")" && pwd)"
420 sections=()
421 zcap_supported=1
422 conv_supported=1
423 max_act_supported=1
424 list_only=0
425 dev_size=1024
426 dev_blocksize=4096
427 set_max_open=8
428 set_extra_max_active=2
429 zbd_test_opts=()
430 num_of_runs=1
431 test_case=0
432 quit_on_err=0
433
434 while (($#)); do
435         case "$1" in
436                 -s) sections+=("$2"); shift; shift;;
437                 -o) set_max_open="${2}"; shift; shift;;
438                 -L) list_only=1; shift;;
439                 -r) cleanup_nullb; exit 0;;
440                 -n) num_of_runs="${2}"; shift; shift;;
441                 -t) test_case="${2}"; shift; shift;;
442                 -q) quit_on_err=1; shift;;
443                 -h) usage; break;;
444                 --) shift; break;;
445                  *) usage; exit 1;;
446         esac
447 done
448
449 if [ "${#sections[@]}" = 0 ]; then
450         readarray -t sections < <(declare -F | grep "section[0-9]*" |  tr -c -d "[:digit:]\n" | sort -n)
451 fi
452
453 cleanup_nullb
454
455 #
456 # Test creating null_blk device and check if newer features are supported
457 #
458 if ! eval "create_nullb"; then
459         echo "can't create nullb"
460         exit 1
461 fi
462 if ! cat /sys/kernel/config/nullb/features | grep -q zone_capacity; then
463         zcap_supported=0
464 fi
465 if ! cat /sys/kernel/config/nullb/features | grep -q zone_nr_conv; then
466         conv_supported=0
467 fi
468 if ! cat /sys/kernel/config/nullb/features | grep -q zone_max_active; then
469         max_act_supported=0
470 fi
471
472 rc=0
473 test_rc=0
474 intr=0
475 run_nr=1
476 trap 'kill ${zbd_test_pid}; intr=1' SIGINT
477
478 while ((run_nr <= $num_of_runs)); do
479         echo -e "\nRun #$run_nr:"
480         for section_number in "${sections[@]}"; do
481                 cleanup_nullb
482                 echo "---------- Section $(printf "%02d" $section_number) ----------"
483                 if ! eval "create_nullb"; then
484                         echo "error creating nullb"
485                         exit 1
486                 fi
487                 zbd_test_opts=()
488                 if ((test_case)); then
489                         zbd_test_opts+=("-t" "${test_case}")
490                 fi
491                 if ((quit_on_err)); then
492                         zbd_test_opts+=("-q")
493                 fi
494                 section$section_number
495                 configure_nullb
496                 rc=$?
497                 ((rc == 2)) && continue
498                 if ((rc)); then
499                         echo "can't set up nullb for section $(printf "%02d" $section_number)"
500                         exit 1
501                 fi
502                 show_nullb_config
503                 cd "${scriptdir}"
504                 ((intr)) && exit 1
505                 ((list_only)) && continue
506
507                 ./test-zbd-support ${zbd_test_opts[@]} /dev/nullb0 &
508                 zbd_test_pid=$!
509                 if kill -0 "${zbd_test_pid}"; then
510                         wait "${zbd_test_pid}"
511                         test_rc=$?
512                 else
513                         echo "can't run ZBD tests"
514                         exit 1
515                 fi
516                 ((intr)) && exit 1
517                 if (($test_rc)); then
518                         rc=1
519                         ((quit_on_err)) && break
520                 fi
521         done
522
523         ((rc && quit_on_err)) && break
524         run_nr=$((run_nr + 1))
525 done
526
527 if ((!list_only)); then
528         echo "--------------------------------"
529         echo "Total run time: $(TZ=UTC0 printf "%(%H:%M:%S)T\n" $(( SECONDS )) )"
530 fi
531
532 exit $rc