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-l Use libzbc ioengine to run the tests."
23 echo -e "\t-t <#test> Only run the test with the given number in every section."
24 echo -e "\t-o <max_open_zones> Specify MaxOpen value, (${set_max_open} by default)."
25 echo -e "\t-n <#number of runs> Set the number of times to run the entire suite "
26 echo -e "\t or an individual section/test."
27 echo -e "\t-q Quit t/zbd/test-zbd-support run after any failed test."
28 echo -e "\t-r Remove the /dev/nullb0 device that may still exist after"
29 echo -e "\t running this script."
35 for d in /sys/kernel/config/nullb/*; do [ -d "$d" ] && rmdir "$d"; done
37 modprobe null_blk nr_devices=0 || exit $?
38 for d in /sys/kernel/config/nullb/*; do
39 [ -d "$d" ] && rmdir "$d"
42 [ -e /sys/module/null_blk ] && exit $?
47 modprobe null_blk nr_devices=0 &&
48 cd /sys/kernel/config/nullb &&
50 cd nullb0 || return $?
55 echo 0 > completion_nsec &&
56 echo ${dev_blocksize} > blocksize &&
57 echo ${dev_size} > size &&
58 echo 1 > memory_backed || return $?
60 if ((conv_pcnt < 100)); then
62 echo "${zone_size}" > zone_size || return $?
64 if ((zone_capacity < zone_size)); then
65 if ((!zcap_supported)); then
66 echo "null_blk does not support zone capacity"
69 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))
77 echo "${nr_conv}" > zone_nr_conv
81 echo 1 > power || return $?
87 if ((conv_pcnt < 100)); then
88 echo " $(printf "Zoned Device, %d%% Conventional Zones (%d)" \
89 ${conv_pcnt} ${nr_conv})"
90 echo " $(printf "Zone Size: %d MB" ${zone_size})"
91 echo " $(printf "Zone Capacity: %d MB" ${zone_capacity})"
93 echo " $(printf "Max Open: %d Zones" ${max_open})"
95 echo " Max Open: Unlimited Zones"
98 echo " Non-zoned Device"
105 # Fully conventional device.
112 # Zoned device with no conventional zones, ZCAP == ZSIZE, unlimited MaxOpen.
121 # Zoned device with no conventional zones, ZCAP < ZSIZE, unlimited MaxOpen.
130 # Zoned device with mostly sequential zones, ZCAP == ZSIZE, unlimited MaxOpen.
139 # Zoned device with mostly sequential zones, ZCAP < ZSIZE, unlimited MaxOpen.
148 # Zoned device with mostly conventional zones, ZCAP == ZSIZE, unlimited MaxOpen.
157 # Zoned device with mostly conventional zones, ZCAP < ZSIZE, unlimited MaxOpen.
167 # Zoned device with no conventional zones, ZCAP == ZSIZE, limited MaxOpen.
174 max_open=${set_max_open}
175 zbd_test_opts+=("-o ${max_open}")
178 # Zoned device with no conventional zones, ZCAP < ZSIZE, limited MaxOpen.
184 max_open=${set_max_open}
185 zbd_test_opts+=("-o ${max_open}")
188 # Zoned device with mostly sequential zones, ZCAP == ZSIZE, limited MaxOpen.
194 max_open=${set_max_open}
195 zbd_test_opts+=("-o ${max_open}")
198 # Zoned device with mostly sequential zones, ZCAP < ZSIZE, limited MaxOpen.
204 max_open=${set_max_open}
205 zbd_test_opts+=("-o ${max_open}")
208 # Zoned device with mostly conventional zones, ZCAP == ZSIZE, limited MaxOpen.
214 max_open=${set_max_open}
215 zbd_test_opts+=("-o ${max_open}")
218 # Zoned device with mostly conventional zones, ZCAP < ZSIZE, limited MaxOpen.
225 max_open=${set_max_open}
226 zbd_test_opts+=("-o ${max_open}")
233 scriptdir="$(cd "$(dirname "$0")" && pwd)"
249 -s) sections+=("$2"); shift; shift;;
250 -o) set_max_open="${2}"; shift; shift;;
251 -L) list_only=1; shift;;
252 -r) cleanup_nullb; exit 0;;
253 -l) libzbc=1; shift;;
254 -n) num_of_runs="${2}"; shift; shift;;
255 -t) test_case="${2}"; shift; shift;;
256 -q) quit_on_err=1; shift;;
263 if [ "${#sections[@]}" = 0 ]; then
264 readarray -t sections < <(declare -F | grep "section[0-9]*" | tr -c -d "[:digit:]\n" | sort -n)
270 # Test creating null_blk device and check if newer features are supported
272 if ! eval "create_nullb"; then
273 echo "can't create nullb"
276 if ! cat /sys/kernel/config/nullb/features | grep -q zone_capacity; then
279 if ! cat /sys/kernel/config/nullb/features | grep -q zone_nr_conv; then
287 trap 'kill ${zbd_test_pid}; intr=1' SIGINT
289 while ((run_nr <= $num_of_runs)); do
290 echo -e "\nRun #$run_nr:"
291 for section_number in "${sections[@]}"; do
293 echo "---------- Section $(printf "%02d" $section_number) ----------"
294 if ! eval "create_nullb"; then
295 echo "error creating nullb"
299 if ((test_case)); then
300 zbd_test_opts+=("-t" "${test_case}")
302 if ((quit_on_err)); then
303 zbd_test_opts+=("-q")
305 section$section_number
308 ((rc == 2)) && continue
310 echo "can't set up nullb for section $(printf "%02d" $section_number)"
315 if ((zone_capacity < zone_size)); then
316 echo "libzbc doesn't support zone capacity, skipping section $(printf "%02d" $section_number)"
319 if ((conv_pcnt == 100)); then
320 echo "libzbc only supports zoned devices, skipping section $(printf "%02d" $section_number)"
323 zbd_test_opts+=("-l")
327 ((list_only)) && continue
329 ./test-zbd-support ${zbd_test_opts[@]} /dev/nullb0 &
331 if kill -0 "${zbd_test_pid}"; then
332 wait "${zbd_test_pid}"
335 echo "can't run ZBD tests"
339 if (($test_rc)); then
341 ((quit_on_err)) && break
345 ((rc && quit_on_err)) && break
346 run_nr=$((run_nr + 1))
349 if ((!list_only)); then
350 echo "--------------------------------"
351 echo "Total run time: $(TZ=UTC0 printf "%(%H:%M:%S)T\n" $(( SECONDS )) )"