3 # Copyright (C) 2020 Western Digital Corporation or its affiliates.
5 # This file is released under the GPL.
7 # Run t/zbd/test-zbd-support script against a variety of conventional,
8 # zoned and mixed zone configurations.
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]"
18 echo -e "\t-h Show this message."
19 echo -e "\t-L List the device layouts for every section without running"
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."
34 for d in /sys/kernel/config/nullb/*; do [ -d "$d" ] && rmdir "$d"; done
36 modprobe null_blk nr_devices=0 || exit $?
37 for d in /sys/kernel/config/nullb/*; do
38 [ -d "$d" ] && rmdir "$d"
41 [ -e /sys/module/null_blk ] && exit $?
46 modprobe null_blk nr_devices=0 &&
47 cd /sys/kernel/config/nullb &&
49 cd nullb0 || return $?
54 echo 0 > completion_nsec &&
55 echo ${dev_blocksize} > blocksize &&
56 echo ${dev_size} > size &&
57 echo 1 > memory_backed || return $?
59 if ((conv_pcnt < 100)); then
61 echo "${zone_size}" > zone_size || return $?
63 if ((zone_capacity < zone_size)); then
64 if ((!zcap_supported)); then
65 echo "null_blk does not support zone capacity"
68 echo "${zone_capacity}" > zone_capacity
71 if ((conv_pcnt)); then
72 if ((!conv_supported)); then
73 echo "null_blk does not support conventional zones"
76 nr_conv=$((dev_size/zone_size*conv_pcnt/100))
80 echo "${nr_conv}" > zone_nr_conv
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"
89 echo "${max_active}" > zone_max_active
94 [[ -w badblocks_once ]] && echo 1 > badblocks_once
95 [[ -w badblocks_partial_io ]] && echo 1 > badblocks_partial_io
97 echo 1 > power || return $?
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})"
113 echo " Max Active: Unlimited Zones"
116 echo " Max Open: Unlimited Zones"
119 echo " Non-zoned Device"
126 # Fully conventional device.
133 # Zoned device with no conventional zones, ZCAP == ZSIZE, unlimited MaxOpen.
142 # Zoned device with no conventional zones, ZCAP < ZSIZE, unlimited MaxOpen.
152 # Zoned device with mostly sequential zones, ZCAP == ZSIZE, unlimited MaxOpen.
162 # Zoned device with mostly sequential zones, ZCAP < ZSIZE, unlimited MaxOpen.
172 # Zoned device with mostly conventional zones, ZCAP == ZSIZE, unlimited MaxOpen.
182 # Zoned device with mostly conventional zones, ZCAP < ZSIZE, unlimited MaxOpen.
193 # Zoned device with no conventional zones, ZCAP == ZSIZE, limited MaxOpen,
194 # unlimited MaxActive.
201 max_open=${set_max_open}
202 zbd_test_opts+=("-o ${max_open}")
206 # Zoned device with no conventional zones, ZCAP < ZSIZE, limited MaxOpen,
207 # unlimited MaxActive.
213 max_open=${set_max_open}
214 zbd_test_opts+=("-o ${max_open}")
218 # Zoned device with mostly sequential zones, ZCAP == ZSIZE, limited MaxOpen,
219 # unlimited MaxActive.
225 max_open=${set_max_open}
226 zbd_test_opts+=("-o ${max_open}")
230 # Zoned device with mostly sequential zones, ZCAP < ZSIZE, limited MaxOpen,
231 # unlimited MaxActive.
237 max_open=${set_max_open}
238 zbd_test_opts+=("-o ${max_open}")
242 # Zoned device with mostly conventional zones, ZCAP == ZSIZE, limited MaxOpen,
243 # unlimited MaxActive.
249 max_open=${set_max_open}
250 zbd_test_opts+=("-o ${max_open}")
254 # Zoned device with mostly conventional zones, ZCAP < ZSIZE, limited MaxOpen,
255 # unlimited MaxActive.
262 max_open=${set_max_open}
263 zbd_test_opts+=("-o ${max_open}")
267 # Zoned device with no conventional zones, ZCAP == ZSIZE, limited MaxOpen,
268 # MaxActive == MaxOpen.
275 max_open=${set_max_open}
276 zbd_test_opts+=("-o ${max_open}")
277 max_active=${set_max_open}
280 # Zoned device with no conventional zones, ZCAP < ZSIZE, limited MaxOpen,
281 # MaxActive == MaxOpen.
287 max_open=${set_max_open}
288 zbd_test_opts+=("-o ${max_open}")
289 max_active=${set_max_open}
292 # Zoned device with mostly sequential zones, ZCAP == ZSIZE, limited MaxOpen,
293 # MaxActive == MaxOpen.
299 max_open=${set_max_open}
300 zbd_test_opts+=("-o ${max_open}")
301 max_active=${set_max_open}
304 # Zoned device with mostly sequential zones, ZCAP < ZSIZE, limited MaxOpen,
305 # MaxActive == MaxOpen.
311 max_open=${set_max_open}
312 zbd_test_opts+=("-o ${max_open}")
313 max_active=${set_max_open}
316 # Zoned device with mostly conventional zones, ZCAP == ZSIZE, limited MaxOpen,
317 # MaxActive == MaxOpen.
323 max_open=${set_max_open}
324 zbd_test_opts+=("-o ${max_open}")
325 max_active=${set_max_open}
328 # Zoned device with mostly conventional zones, ZCAP < ZSIZE, limited MaxOpen,
329 # MaxActive == MaxOpen.
336 max_open=${set_max_open}
337 zbd_test_opts+=("-o ${max_open}")
338 max_active=${set_max_open}
341 # Zoned device with no conventional zones, ZCAP == ZSIZE, limited MaxOpen,
342 # MaxActive > MaxOpen.
349 max_open=${set_max_open}
350 zbd_test_opts+=("-o ${max_open}")
351 max_active=$((set_max_open+set_extra_max_active))
354 # Zoned device with no conventional zones, ZCAP < ZSIZE, limited MaxOpen,
355 # MaxActive > MaxOpen.
361 max_open=${set_max_open}
362 zbd_test_opts+=("-o ${max_open}")
363 max_active=$((set_max_open+set_extra_max_active))
366 # Zoned device with mostly sequential zones, ZCAP == ZSIZE, limited MaxOpen,
367 # MaxActive > MaxOpen.
373 max_open=${set_max_open}
374 zbd_test_opts+=("-o ${max_open}")
375 max_active=$((set_max_open+set_extra_max_active))
378 # Zoned device with mostly sequential zones, ZCAP < ZSIZE, limited MaxOpen,
379 # MaxActive > MaxOpen.
385 max_open=${set_max_open}
386 zbd_test_opts+=("-o ${max_open}")
387 max_active=$((set_max_open+set_extra_max_active))
390 # Zoned device with mostly conventional zones, ZCAP == ZSIZE, limited MaxOpen,
391 # MaxActive > MaxOpen.
397 max_open=${set_max_open}
398 zbd_test_opts+=("-o ${max_open}")
399 max_active=$((set_max_open+set_extra_max_active))
402 # Zoned device with mostly conventional zones, ZCAP < ZSIZE, limited MaxOpen,
403 # MaxActive > MaxOpen.
410 max_open=${set_max_open}
411 zbd_test_opts+=("-o ${max_open}")
412 max_active=$((set_max_open+set_extra_max_active))
419 scriptdir="$(cd "$(dirname "$0")" && pwd)"
428 set_extra_max_active=2
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;;
449 if [ "${#sections[@]}" = 0 ]; then
450 readarray -t sections < <(declare -F | grep "section[0-9]*" | tr -c -d "[:digit:]\n" | sort -n)
456 # Test creating null_blk device and check if newer features are supported
458 if ! eval "create_nullb"; then
459 echo "can't create nullb"
462 if ! cat /sys/kernel/config/nullb/features | grep -q zone_capacity; then
465 if ! cat /sys/kernel/config/nullb/features | grep -q zone_nr_conv; then
468 if ! cat /sys/kernel/config/nullb/features | grep -q zone_max_active; then
476 trap 'kill ${zbd_test_pid}; intr=1' SIGINT
478 while ((run_nr <= $num_of_runs)); do
479 echo -e "\nRun #$run_nr:"
480 for section_number in "${sections[@]}"; do
482 echo "---------- Section $(printf "%02d" $section_number) ----------"
483 if ! eval "create_nullb"; then
484 echo "error creating nullb"
488 if ((test_case)); then
489 zbd_test_opts+=("-t" "${test_case}")
491 if ((quit_on_err)); then
492 zbd_test_opts+=("-q")
494 section$section_number
497 ((rc == 2)) && continue
499 echo "can't set up nullb for section $(printf "%02d" $section_number)"
505 ((list_only)) && continue
507 ./test-zbd-support ${zbd_test_opts[@]} /dev/nullb0 &
509 if kill -0 "${zbd_test_pid}"; then
510 wait "${zbd_test_pid}"
513 echo "can't run ZBD tests"
517 if (($test_rc)); then
519 ((quit_on_err)) && break
523 ((rc && quit_on_err)) && break
524 run_nr=$((run_nr + 1))
527 if ((!list_only)); then
528 echo "--------------------------------"
529 echo "Total run time: $(TZ=UTC0 printf "%(%H:%M:%S)T\n" $(( SECONDS )) )"