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