ioengines: libzbc: disable libzbc block backend driver
[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                 if ((conv_pcnt)); then
71                         if ((!conv_supported)); then
72                                 echo "null_blk does not support conventional zones"
73                                 return 2
74                         fi
75                         nr_conv=$((dev_size/zone_size*conv_pcnt/100))
76                         echo "${nr_conv}" > zone_nr_conv
77                 fi
78         fi
79
80         echo 1 > power || return $?
81         return 0
82 }
83
84 show_nullb_config()
85 {
86         if ((conv_pcnt < 100)); then
87                 echo "    $(printf "Zoned Device, %d%% Conventional Zones (%d)" \
88                           ${conv_pcnt} ${nr_conv})"
89                 echo "    $(printf "Zone Size: %d MB" ${zone_size})"
90                 echo "    $(printf "Zone Capacity: %d MB" ${zone_capacity})"
91                 if ((max_open)); then
92                         echo "    $(printf "Max Open: %d Zones" ${max_open})"
93                 else
94                         echo "    Max Open: Unlimited Zones"
95                 fi
96         else
97                 echo "    Non-zoned Device"
98         fi
99 }
100
101 #
102 # Test sections.
103 #
104 # Fully conventional device.
105 section1()
106 {
107         conv_pcnt=100
108         max_open=0
109 }
110
111 # Zoned device with no conventional zones, ZCAP == ZSIZE, unlimited MaxOpen.
112 section2()
113 {
114         conv_pcnt=0
115         zone_size=1
116         zone_capacity=1
117         max_open=0
118 }
119
120 # Zoned device with no conventional zones, ZCAP < ZSIZE, unlimited MaxOpen.
121 section3()
122 {
123         conv_pcnt=0
124         zone_size=4
125         zone_capacity=3
126         max_open=0
127 }
128
129 # Zoned device with mostly sequential zones, ZCAP == ZSIZE, unlimited MaxOpen.
130 section4()
131 {
132         conv_pcnt=10
133         zone_size=1
134         zone_capacity=1
135         max_open=0
136 }
137
138 # Zoned device with mostly sequential zones, ZCAP < ZSIZE, unlimited MaxOpen.
139 section5()
140 {
141         conv_pcnt=10
142         zone_size=4
143         zone_capacity=3
144         max_open=0
145 }
146
147 # Zoned device with mostly conventional zones, ZCAP == ZSIZE, unlimited MaxOpen.
148 section6()
149 {
150         conv_pcnt=66
151         zone_size=1
152         zone_capacity=1
153         max_open=0
154 }
155
156 # Zoned device with mostly conventional zones, ZCAP < ZSIZE, unlimited MaxOpen.
157 section7()
158 {
159         dev_size=2048
160         conv_pcnt=66
161         zone_size=4
162         zone_capacity=3
163         max_open=0
164 }
165
166 # Zoned device with no conventional zones, ZCAP == ZSIZE, limited MaxOpen.
167 section8()
168 {
169         dev_size=1024
170         conv_pcnt=0
171         zone_size=1
172         zone_capacity=1
173         max_open=${set_max_open}
174         zbd_test_opts+=("-o ${max_open}")
175 }
176
177 # Zoned device with no conventional zones, ZCAP < ZSIZE, limited MaxOpen.
178 section9()
179 {
180         conv_pcnt=0
181         zone_size=4
182         zone_capacity=3
183         max_open=${set_max_open}
184         zbd_test_opts+=("-o ${max_open}")
185 }
186
187 # Zoned device with mostly sequential zones, ZCAP == ZSIZE, limited MaxOpen.
188 section10()
189 {
190         conv_pcnt=10
191         zone_size=1
192         zone_capacity=1
193         max_open=${set_max_open}
194         zbd_test_opts+=("-o ${max_open}")
195 }
196
197 # Zoned device with mostly sequential zones, ZCAP < ZSIZE, limited MaxOpen.
198 section11()
199 {
200         conv_pcnt=10
201         zone_size=4
202         zone_capacity=3
203         max_open=${set_max_open}
204         zbd_test_opts+=("-o ${max_open}")
205 }
206
207 # Zoned device with mostly conventional zones, ZCAP == ZSIZE, limited MaxOpen.
208 section12()
209 {
210         conv_pcnt=66
211         zone_size=1
212         zone_capacity=1
213         max_open=${set_max_open}
214         zbd_test_opts+=("-o ${max_open}")
215 }
216
217 # Zoned device with mostly conventional zones, ZCAP < ZSIZE, limited MaxOpen.
218 section13()
219 {
220         dev_size=2048
221         conv_pcnt=66
222         zone_size=4
223         zone_capacity=3
224         max_open=${set_max_open}
225         zbd_test_opts+=("-o ${max_open}")
226 }
227
228 #
229 # Entry point.
230 #
231 SECONDS=0
232 scriptdir="$(cd "$(dirname "$0")" && pwd)"
233 sections=()
234 zcap_supported=1
235 conv_supported=1
236 list_only=0
237 dev_size=1024
238 dev_blocksize=4096
239 set_max_open=8
240 zbd_test_opts=()
241 num_of_runs=1
242 test_case=0
243 quit_on_err=0
244
245 while (($#)); do
246         case "$1" in
247                 -s) sections+=("$2"); shift; shift;;
248                 -o) set_max_open="${2}"; shift; shift;;
249                 -L) list_only=1; shift;;
250                 -r) cleanup_nullb; exit 0;;
251                 -n) num_of_runs="${2}"; shift; shift;;
252                 -t) test_case="${2}"; shift; shift;;
253                 -q) quit_on_err=1; shift;;
254                 -h) usage; break;;
255                 --) shift; break;;
256                  *) usage; exit 1;;
257         esac
258 done
259
260 if [ "${#sections[@]}" = 0 ]; then
261         readarray -t sections < <(declare -F | grep "section[0-9]*" |  tr -c -d "[:digit:]\n" | sort -n)
262 fi
263
264 cleanup_nullb
265
266 #
267 # Test creating null_blk device and check if newer features are supported
268 #
269 if ! eval "create_nullb"; then
270         echo "can't create nullb"
271         exit 1
272 fi
273 if ! cat /sys/kernel/config/nullb/features | grep -q zone_capacity; then
274         zcap_supported=0
275 fi
276 if ! cat /sys/kernel/config/nullb/features | grep -q zone_nr_conv; then
277         conv_supported=0
278 fi
279
280 rc=0
281 test_rc=0
282 intr=0
283 run_nr=1
284 trap 'kill ${zbd_test_pid}; intr=1' SIGINT
285
286 while ((run_nr <= $num_of_runs)); do
287         echo -e "\nRun #$run_nr:"
288         for section_number in "${sections[@]}"; do
289                 cleanup_nullb
290                 echo "---------- Section $(printf "%02d" $section_number) ----------"
291                 if ! eval "create_nullb"; then
292                         echo "error creating nullb"
293                         exit 1
294                 fi
295                 zbd_test_opts=()
296                 if ((test_case)); then
297                         zbd_test_opts+=("-t" "${test_case}")
298                 fi
299                 if ((quit_on_err)); then
300                         zbd_test_opts+=("-q")
301                 fi
302                 section$section_number
303                 configure_nullb
304                 rc=$?
305                 ((rc == 2)) && continue
306                 if ((rc)); then
307                         echo "can't set up nullb for section $(printf "%02d" $section_number)"
308                         exit 1
309                 fi
310                 show_nullb_config
311                 cd "${scriptdir}"
312                 ((intr)) && exit 1
313                 ((list_only)) && continue
314
315                 ./test-zbd-support ${zbd_test_opts[@]} /dev/nullb0 &
316                 zbd_test_pid=$!
317                 if kill -0 "${zbd_test_pid}"; then
318                         wait "${zbd_test_pid}"
319                         test_rc=$?
320                 else
321                         echo "can't run ZBD tests"
322                         exit 1
323                 fi
324                 ((intr)) && exit 1
325                 if (($test_rc)); then
326                         rc=1
327                         ((quit_on_err)) && break
328                 fi
329         done
330
331         ((rc && quit_on_err)) && break
332         run_nr=$((run_nr + 1))
333 done
334
335 if ((!list_only)); then
336         echo "--------------------------------"
337         echo "Total run time: $(TZ=UTC0 printf "%(%H:%M:%S)T\n" $(( SECONDS )) )"
338 fi
339
340 exit $rc