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