]>
Commit | Line | Data |
---|---|---|
23b7d3b9 | 1 | #!/bin/bash |
5e7519fa NB |
2 | # |
3 | # run test suite for mdadm | |
20d10b4b | 4 | dir=$(pwd) |
5e7519fa | 5 | mdadm=$dir/mdadm |
60381555 | 6 | testdir="tests" |
20d10b4b ZL |
7 | targetdir="/var/tmp" |
8 | logdir="$targetdir" | |
9 | config=/tmp/mdadm.conf | |
60381555 | 10 | |
20d10b4b ZL |
11 | savelogs=0 |
12 | exitonerror=1 | |
13 | prefix='[0-9][0-9]' | |
98a92cff | 14 | |
20d10b4b | 15 | # use loop devices by default if doesn't specify --dev |
7d8a70bf | 16 | DEVTYPE=loop |
20d10b4b | 17 | INTEGRITY=yes |
7d8a70bf | 18 | LVM_VOLGROUP=mdtest |
04c1ca5f | 19 | |
9540cc24 N |
20 | # make sure to test local mdmon, not system one |
21 | export MDADM_NO_SYSTEMCTL=1 | |
22 | ||
5e7519fa | 23 | # assume md0, md1, md2 exist in /dev |
662c349a ZL |
24 | md0=/dev/md0 |
25 | md1=/dev/md1 | |
26 | md2=/dev/md2 | |
1f48664b NB |
27 | mdp0=/dev/md_d0 |
28 | mdp1=/dev/md_d1 | |
5e7519fa NB |
29 | |
30 | # We test mdadm on loop-back block devices. | |
31 | # dir for storing files should be settable by command line maybe | |
5e7519fa | 32 | size=20000 |
69646c14 | 33 | # super0, round down to multiple of 64 and substract 64 |
5e7519fa | 34 | mdsize0=19904 |
1c203a4b NB |
35 | # super00 is nested, subtract 128 |
36 | mdsize00=19840 | |
69646c14 | 37 | # super1.0 round down to multiple of 2, subtract 8 |
1bf4e2d9 | 38 | mdsize1=19992 |
ebe6ea0c N |
39 | mdsize1a=19988 |
40 | mdsize12=19988 | |
41 | # super1.2 for linear: round to multiple of 2, subtract 4 | |
3c8b2739 N |
42 | mdsize1_l=19996 |
43 | mdsize2_l=19996 | |
69646c14 NB |
44 | # subtract another 4 for bitmaps |
45 | mdsize1b=19988 | |
46 | mdsize11=19992 | |
3c8b2739 | 47 | mdsize11a=19456 |
69646c14 | 48 | mdsize12=19988 |
5e7519fa | 49 | |
d50683f9 N |
50 | # ddf needs bigger devices as 32Meg is reserved! |
51 | ddfsize=65536 | |
52 | ||
20d10b4b ZL |
53 | # $1 is optional parameter, it shows why to save log |
54 | save_log() { | |
55 | status=$1 | |
56 | logfile="$status""$_basename".log | |
57 | ||
58 | cat $targetdir/stderr >> $targetdir/log | |
59 | cp $targetdir/log $logdir/$_basename.log | |
60 | echo "## $HOSTNAME: saving dmesg." >> $logdir/$logfile | |
61 | dmesg -c >> $logdir/$logfile | |
62 | $mdadm -As 2> /dev/null | |
63 | echo "## $HOSTNAME: saving proc mdstat." >> $logdir/$logfile | |
64 | cat /proc/mdstat >> $logdir/$logfile | |
65 | array=($(mdadm -Ds | cut -d' ' -f2)) | |
66 | echo "## $HOSTNAME: mdadm -D ${array[@]}" >> $logdir/$logfile | |
67 | $mdadm -D ${array[@]} >> $logdir/$logfile | |
68 | [ "$1" == "fail" ] && | |
69 | echo "FAILED - see $logdir/$_basename.log and $logdir/$logfile for details" | |
70 | # ignore saving external(external file, imsm...) bitmap | |
71 | cat /proc/mdstat | grep -q "linear\|external" && return 0 | |
72 | if [ $DEVTYPE == 'lvm' ] | |
73 | then | |
74 | # not supported lvm type yet | |
75 | echo | |
25357919 | 76 | elif [ "$DEVTYPE" == 'loop' -o "$DEVTYPE" == 'disk' ] |
20d10b4b ZL |
77 | then |
78 | if [ ! -z ${array[@]} -a ${#array[@]} -ge 1 ] | |
79 | then | |
25357919 | 80 | md_disks=($($mdadm -D -Y ${array[@]} | grep "/dev/" | cut -d'=' -f2)) |
20d10b4b ZL |
81 | cat /proc/mdstat | grep -q "bitmap" |
82 | if [ $? -eq 0 ] | |
83 | then | |
84 | echo "## $HOSTNAME: mdadm -X ${md_disks[@]}" >> $logdir/$logfile | |
85 | $mdadm -X ${md_disks[@]} >> $logdir/$logfile | |
86 | fi | |
87 | else | |
88 | echo "## $HOSTNAME: no array assembled!" >> $logdir/$logfile | |
89 | fi | |
90 | fi | |
91 | } | |
92 | ||
93 | die() { | |
94 | echo -e "\n\tERROR: $* \n" | |
95 | save_log fail | |
96 | exit 2 | |
97 | } | |
ed02d9cc | 98 | |
5e7519fa | 99 | cleanup() { |
2952742d | 100 | udevadm settle |
4f8a3e5b | 101 | $mdadm -Ssq 2> /dev/null |
662c349a | 102 | case $DEVTYPE in |
20d10b4b | 103 | loop ) |
662c349a ZL |
104 | for d in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 |
105 | do | |
20d10b4b | 106 | losetup -d /dev/loop$d |
662c349a | 107 | rm -f /dev/disk/by-path/loop* |
20d10b4b | 108 | rm -f /var/tmp/mdtest$d |
662c349a ZL |
109 | done |
110 | ;; | |
20d10b4b | 111 | lvm ) |
662c349a ZL |
112 | for d in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 |
113 | do | |
114 | eval "lvremove --quiet -f \$dev$d" | |
115 | done | |
116 | ;; | |
25357919 ZL |
117 | disk ) |
118 | $mdadm --zero ${disks[@]} &> /dev/null | |
119 | ;; | |
662c349a | 120 | esac |
5e7519fa NB |
121 | } |
122 | ||
d5a221a5 | 123 | ctrl_c() { |
4d5995c4 GE |
124 | exitonerror=1 |
125 | } | |
126 | ||
572d7091 | 127 | do_setup() { |
662c349a ZL |
128 | trap cleanup 0 1 3 15 |
129 | trap ctrl_c 2 | |
5e7519fa | 130 | |
20d10b4b ZL |
131 | [ -d $logdir ] || mkdir -p $logdir |
132 | dmesg -c > /dev/null | |
133 | ||
25357919 | 134 | devlist= |
20d10b4b ZL |
135 | if [ "$DEVTYPE" == "loop" ] |
136 | then | |
137 | # make sure there are no loop devices remaining. | |
138 | # udev started things can sometimes prevent them being stopped | |
139 | # immediately | |
140 | while grep loop /proc/partitions > /dev/null 2>&1 | |
141 | do | |
142 | $mdadm -Ssq | |
143 | losetup -d /dev/loop[0-9]* 2> /dev/null | |
144 | sleep 0.2 | |
145 | done | |
25357919 ZL |
146 | elif [ "$DEVTYPE" == "disk" ] |
147 | then | |
148 | if [ ! -z "$disks" ] | |
149 | then | |
150 | for d in $(seq 0 ${#disks[@]}) | |
151 | do | |
152 | eval "dev$d=${disks[$d]}" | |
153 | eval devlist=\"\$devlist \$dev$d\" | |
154 | eval devlist$d=\"\$devlist\" | |
155 | done | |
156 | $mdadm --zero ${disks[@]} &> /dev/null | |
157 | else | |
158 | echo "Forget to provide physical devices for disk mode." | |
159 | exit 1 | |
160 | fi | |
20d10b4b | 161 | fi |
662c349a ZL |
162 | for d in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 |
163 | do | |
164 | sz=$size | |
20d10b4b | 165 | [ $d -gt 7 ] && sz=$ddfsize |
662c349a ZL |
166 | case $DEVTYPE in |
167 | loop) | |
168 | [ -f $targetdir/mdtest$d ] || | |
169 | dd if=/dev/zero of=$targetdir/mdtest$d count=$sz bs=1K > /dev/null 2>&1 | |
170 | # make sure udev doesn't touch | |
171 | mdadm --zero $targetdir/mdtest$d 2> /dev/null | |
172 | [ -b /dev/loop$d ] || mknod /dev/loop$d b 7 $d | |
173 | if [ $d -eq 7 ] | |
174 | then | |
175 | losetup /dev/loop$d $targetdir/mdtest6 # for multipath use | |
176 | else | |
177 | losetup /dev/loop$d $targetdir/mdtest$d | |
178 | fi | |
179 | eval dev$d=/dev/loop$d | |
180 | eval file$d=$targetdir/mdtest$d | |
181 | ;; | |
182 | lvm) | |
183 | unset MULTIPATH | |
184 | eval dev$d=/dev/mapper/${LVM_VOLGROUP}-mdtest$d | |
185 | if ! lvcreate --quiet -L ${sz}K -n mdtest$d $LVM_VOLGROUP | |
186 | then | |
187 | trap '' 0 # make sure lvremove is not called | |
188 | eval echo error creating \$dev$d | |
189 | exit 129 | |
190 | fi | |
191 | ;; | |
192 | ram) | |
193 | unset MULTIPATH | |
194 | eval dev$d=/dev/ram$d | |
195 | ;; | |
196 | esac | |
197 | eval devlist=\"\$devlist \$dev$d\" | |
198 | eval devlist$d=\"\$devlist\" | |
199 | #" <-- add this quote to un-confuse vim syntax highlighting | |
200 | done | |
201 | path0=$dev6 | |
202 | path1=$dev7 | |
203 | ulimit -c unlimited | |
204 | [ -f /proc/mdstat ] || modprobe md_mod | |
205 | echo 2000 > /proc/sys/dev/raid/speed_limit_max | |
206 | echo 0 > /sys/module/md_mod/parameters/start_ro | |
572d7091 | 207 | } |
0aa389dc | 208 | |
dab6685f NB |
209 | # mdadm always adds --quiet, and we want to see any unexpected messages |
210 | mdadm() { | |
662c349a ZL |
211 | rm -f $targetdir/stderr |
212 | case $* in | |
213 | *-S* ) | |
214 | udevadm settle | |
215 | p=`cat /proc/sys/dev/raid/speed_limit_max` | |
216 | echo 20000 > /proc/sys/dev/raid/speed_limit_max | |
217 | ;; | |
218 | esac | |
219 | case $* in | |
20d10b4b ZL |
220 | *-C* | *--create* | *-B* | *--build* ) |
221 | # clear superblock every time once creating or | |
222 | # building arrays, because it's always creating | |
223 | # and building array many times in a test case. | |
224 | for args in $* | |
225 | do | |
226 | [[ $args =~ "/dev/" ]] && { | |
227 | [[ $args =~ "md" ]] || | |
228 | $mdadm --zero $args > /dev/null | |
229 | } | |
230 | done | |
662c349a ZL |
231 | $mdadm 2> $targetdir/stderr --quiet "$@" --auto=yes |
232 | ;; | |
233 | * ) | |
234 | $mdadm 2> $targetdir/stderr --quiet "$@" | |
235 | ;; | |
236 | esac | |
237 | rv=$? | |
238 | case $* in | |
239 | *-S* ) | |
240 | udevadm settle | |
241 | echo $p > /proc/sys/dev/raid/speed_limit_max | |
242 | ;; | |
243 | esac | |
244 | cat >&2 $targetdir/stderr | |
245 | return $rv | |
dab6685f NB |
246 | } |
247 | ||
248 | # check various things | |
249 | check() { | |
662c349a ZL |
250 | case $1 in |
251 | spares ) | |
20d10b4b ZL |
252 | spares=$(tr '] ' '\012\012' < /proc/mdstat | grep -c '(S)' || exit 0) |
253 | [ $spares -ne $2 ] && | |
254 | die "expected $2 spares, found $spares" | |
662c349a ZL |
255 | ;; |
256 | raid* | linear ) | |
20d10b4b ZL |
257 | grep -sq "active $1 " /proc/mdstat || |
258 | die "active $1 not found" | |
662c349a ZL |
259 | ;; |
260 | algorithm ) | |
20d10b4b ZL |
261 | grep -sq " algorithm $2 " /proc/mdstat || |
262 | die "algorithm $2 not found" | |
662c349a ZL |
263 | ;; |
264 | resync | recovery | reshape ) | |
265 | cnt=5 | |
20d10b4b | 266 | while ! grep -sq $1 /proc/mdstat |
662c349a ZL |
267 | do |
268 | if [ $cnt -gt 0 ] && grep -v idle /sys/block/md*/md/sync_action > /dev/null | |
269 | then # Something isn't idle - wait a bit | |
270 | sleep 0.5 | |
271 | cnt=$[cnt-1] | |
272 | else | |
20d10b4b | 273 | die "no $1 happening" |
662c349a ZL |
274 | fi |
275 | done | |
276 | ;; | |
277 | nosync ) | |
a76b3a34 | 278 | sleep 0.5 |
662c349a ZL |
279 | # Since 4.2 we delay the close of recovery until there has been a chance for |
280 | # spares to be activated. That means that a recovery that finds nothing | |
281 | # to do can still take a little longer than expected. | |
282 | # add an extra check: is sync_completed shows the end is reached, assume | |
283 | # there is no recovery. | |
20d10b4b | 284 | if grep -sq -E '(resync|recovery|reshape) *=' /proc/mdstat |
662c349a ZL |
285 | then |
286 | incomplete=`grep / /sys/block/md*/md/sync_completed 2> /dev/null | sed '/^ *\([0-9]*\) \/ \1/d'` | |
20d10b4b ZL |
287 | [ -n "$incomplete" ] && |
288 | die "resync or recovery is happening!" | |
662c349a ZL |
289 | fi |
290 | ;; | |
291 | wait ) | |
292 | p=`cat /proc/sys/dev/raid/speed_limit_max` | |
293 | echo 2000000 > /proc/sys/dev/raid/speed_limit_max | |
294 | sleep 0.1 | |
20d10b4b | 295 | while grep -Eq '(resync|recovery|reshape|check|repair) *=' /proc/mdstat || |
662c349a ZL |
296 | grep -v idle > /dev/null /sys/block/md*/md/sync_action |
297 | do | |
298 | sleep 0.5 | |
299 | done | |
300 | echo $p > /proc/sys/dev/raid/speed_limit_max | |
301 | ;; | |
302 | state ) | |
20d10b4b ZL |
303 | grep -sq "blocks.*\[$2\]\$" /proc/mdstat || |
304 | die "state $2 not found!" | |
662c349a ZL |
305 | sleep 0.5 |
306 | ;; | |
307 | bitmap ) | |
20d10b4b ZL |
308 | grep -sq bitmap /proc/mdstat || |
309 | die "no bitmap" | |
662c349a ZL |
310 | ;; |
311 | nobitmap ) | |
20d10b4b ZL |
312 | grep -sq "bitmap" /proc/mdstat && |
313 | die "bitmap present" | |
662c349a ZL |
314 | ;; |
315 | readonly ) | |
20d10b4b ZL |
316 | grep -sq "read-only" /proc/mdstat || |
317 | die "array is not read-only!" | |
662c349a ZL |
318 | ;; |
319 | inactive ) | |
20d10b4b ZL |
320 | grep -sq "inactive" /proc/mdstat || |
321 | die "array is not inactive!" | |
662c349a ZL |
322 | ;; |
323 | * ) | |
20d10b4b | 324 | die "unknown check $1" |
662c349a ZL |
325 | ;; |
326 | esac | |
dab6685f NB |
327 | } |
328 | ||
bf4fb153 | 329 | no_errors() { |
662c349a ZL |
330 | if [ -s $targetdir/stderr ] |
331 | then | |
332 | echo Bad errors from mdadm: | |
333 | cat $targetdir/stderr | |
334 | exit 2 | |
335 | fi | |
bf4fb153 | 336 | } |
dab6685f | 337 | |
662c349a | 338 | # basic device test |
dab6685f | 339 | testdev() { |
20d10b4b | 340 | [ -b $1 ] || die "$1 isn't a block device." |
25357919 | 341 | [ "$DEVTYPE" == "disk" ] && return 0 |
662c349a ZL |
342 | udevadm settle |
343 | dev=$1 | |
344 | cnt=$2 | |
345 | dvsize=$3 | |
346 | chunk=$4 | |
347 | if [ -z "$5" ] | |
348 | then | |
349 | mkfs.ext3 -F -j $dev > /dev/null 2>&1 && fsck -fn $dev >&2 | |
350 | fi | |
351 | dsize=$[dvsize/chunk] | |
352 | dsize=$[dsize*chunk] | |
353 | rasize=$[dsize*2*cnt] | |
354 | # rasize is in sectors | |
355 | if [ -n "$DEV_ROUND_K" ] | |
356 | then | |
357 | rasize=$[rasize/DEV_ROUND_K/2] | |
358 | rasize=$[rasize*DEV_ROUND_K*2] | |
359 | fi | |
20d10b4b | 360 | [ `/sbin/blockdev --getsize $dev` -eq 0 ] && sleep 2 |
662c349a | 361 | _sz=`/sbin/blockdev --getsize $dev` |
20d10b4b ZL |
362 | [ $rasize -lt $_sz -o $[rasize*4/5] -gt $_sz ] && |
363 | die "size is wrong for $dev: $cnt * $dvsize (chunk=$chunk) = $rasize, not $_sz" | |
364 | return 0 | |
6fd2a36f N |
365 | } |
366 | ||
c13c45e9 | 367 | rotest() { |
662c349a ZL |
368 | dev=$1 |
369 | fsck -fn $dev >&2 | |
c13c45e9 NB |
370 | } |
371 | ||
4e5ce543 | 372 | do_test() { |
662c349a ZL |
373 | _script=$1 |
374 | _basename=`basename $_script` | |
375 | if [ -f "$_script" ] | |
376 | then | |
377 | rm -f $targetdir/stderr | |
378 | # stop all arrays, just incase some script left an array active. | |
379 | $mdadm -Ssq 2> /dev/null | |
380 | mdadm --zero $devlist 2> /dev/null | |
662c349a ZL |
381 | # this might have been reset: restore the default. |
382 | echo 2000 > /proc/sys/dev/raid/speed_limit_max | |
383 | # source script in a subshell, so it has access to our | |
384 | # namespace, but cannot change it. | |
385 | echo -ne "$_script... " | |
386 | if ( set -ex ; . $_script ) &> $targetdir/log | |
387 | then | |
20d10b4b ZL |
388 | dmesg | grep -iq "error\|call trace\|segfault" && |
389 | die "dmesg prints errors when testing $_basename!" | |
662c349a ZL |
390 | echo "succeeded" |
391 | _fail=0 | |
392 | else | |
20d10b4b | 393 | save_log fail |
662c349a ZL |
394 | _fail=1 |
395 | fi | |
20d10b4b ZL |
396 | [ "$savelogs" == "1" ] && |
397 | mv -f $targetdir/log $logdir/$_basename.log | |
398 | [ "$_fail" == "1" -a "$exitonerror" == "1" ] && exit 1 | |
662c349a | 399 | fi |
4e5ce543 JS |
400 | } |
401 | ||
402 | do_help() { | |
20d10b4b ZL |
403 | cat <<-EOF |
404 | Usage: $0 [options] | |
25357919 | 405 | Example for disk mode: ./test --dev=disk --disks=/dev/sda{2..15} |
20d10b4b ZL |
406 | Options: |
407 | --tests=test1,test2,... Comma separated list of tests to run | |
8403b202 | 408 | --raidtype= raid0|linear|raid1|raid456|raid10|ddf|imsm |
20d10b4b ZL |
409 | --disable-multipath Disable any tests involving multipath |
410 | --disable-integrity Disable slow tests of RAID[56] consistency | |
411 | --logdir=directory Directory to save all logfiles in | |
412 | --save-logs Usually use with --logdir together | |
413 | --keep-going | --no-error Don't stop on error, ie. run all tests | |
25357919 ZL |
414 | --dev=loop|lvm|ram|disk Use loop devices (default), LVM, RAM or disk |
415 | --disks= Provide a bunch of physical devices for test | |
20d10b4b ZL |
416 | --volgroup=name LVM volume group for LVM test |
417 | setup Setup test environment and exit | |
418 | cleanup Cleanup test environment | |
419 | prefix Run tests with <prefix> | |
420 | --help | -h Print this usage | |
421 | EOF | |
4e5ce543 JS |
422 | } |
423 | ||
424 | parse_args() { | |
662c349a ZL |
425 | for i in $* |
426 | do | |
427 | case $i in | |
20d10b4b | 428 | [0-9][0-9] ) |
662c349a ZL |
429 | prefix=$i |
430 | ;; | |
431 | setup ) | |
432 | echo "mdadm test environment setup" | |
433 | do_setup | |
434 | trap 0 | |
435 | exit 0 | |
436 | ;; | |
437 | cleanup ) | |
438 | cleanup | |
439 | exit 0 | |
440 | ;; | |
441 | --tests=* ) | |
20d10b4b | 442 | TESTLIST=($(echo ${i##*=} | sed -e 's/,/ /g')) |
662c349a | 443 | ;; |
8403b202 ZL |
444 | --raidtype=* ) |
445 | case ${i##*=} in | |
446 | raid0 ) | |
447 | TESTLIST=($(ls $testdir | grep "[0-9][0-9]r0\|raid0")) | |
448 | ;; | |
449 | linear ) | |
450 | TESTLIST=($(ls $testdir | grep "linear")) | |
451 | ;; | |
452 | raid1 ) | |
453 | TESTLIST=($(ls $testdir | grep "[0-9][0-9]r1\|raid1" | grep -vi raid10)) | |
454 | ;; | |
455 | raid456 ) | |
456 | TESTLIST=($(ls $testdir | grep "[0-9][0-9]r[4-6]\|raid[4-6]")) | |
457 | ;; | |
458 | raid10 ) | |
459 | TESTLIST=($(ls $testdir | grep "[0-9][0-9]r10\|raid10")) | |
460 | ;; | |
461 | ddf ) | |
462 | TESTLIST=($(ls $testdir | grep "[0-9][0-9]ddf")) | |
463 | ;; | |
464 | imsm ) | |
465 | TESTLIST=($(ls $testdir | grep "[0-9][0-9]imsm")) | |
466 | ;; | |
467 | * ) | |
468 | echo "Unknown argument: $i" | |
469 | do_help | |
470 | exit 1 | |
471 | ;; | |
472 | esac | |
473 | ;; | |
662c349a | 474 | --logdir=* ) |
20d10b4b | 475 | logdir="${i##*=}" |
662c349a ZL |
476 | ;; |
477 | --save-logs ) | |
478 | savelogs=1 | |
479 | ;; | |
480 | --keep-going | --no-error ) | |
481 | exitonerror=0 | |
482 | ;; | |
483 | --disable-multipath ) | |
484 | unset MULTIPATH | |
485 | ;; | |
486 | --disable-integrity ) | |
487 | unset INTEGRITY | |
488 | ;; | |
20d10b4b ZL |
489 | --dev=* ) |
490 | case ${i##*=} in | |
491 | loop ) | |
492 | DEVTYPE=loop | |
493 | ;; | |
494 | lvm ) | |
495 | DEVTYPE=lvm | |
496 | ;; | |
497 | ram ) | |
498 | DEVTYPE=ram | |
499 | ;; | |
25357919 ZL |
500 | disk ) |
501 | DEVTYPE=disk | |
502 | ;; | |
20d10b4b ZL |
503 | * ) |
504 | echo "Unknown argument: $i" | |
505 | do_help | |
506 | exit 1 | |
507 | ;; | |
508 | esac | |
662c349a | 509 | ;; |
25357919 ZL |
510 | --disks=* ) |
511 | disks=(${disks[*]} ${i##*=}) | |
512 | ;; | |
662c349a ZL |
513 | --volgroup=* ) |
514 | LVM_VOLGROUP=`expr "x$i" : 'x[^=]*=\(.*\)'` | |
515 | ;; | |
20d10b4b | 516 | --help | -h ) |
662c349a ZL |
517 | do_help |
518 | exit 0 | |
519 | ;; | |
20d10b4b | 520 | * ) |
662c349a ZL |
521 | echo " $0: Unknown argument: $i" |
522 | do_help | |
20d10b4b | 523 | exit 1 |
662c349a ZL |
524 | ;; |
525 | esac | |
526 | done | |
4e5ce543 JS |
527 | } |
528 | ||
20d10b4b ZL |
529 | check_env() { |
530 | user=$(id -un) | |
531 | [ "X$user" != "Xroot" ] && { | |
532 | echo "test: testing can only be done as 'root'." | |
533 | exit 1 | |
534 | } | |
535 | [ -x "raid6check" -a -x $mdadm ] || { | |
536 | echo "test: please run 'make everything' before perform testing." | |
537 | exit 1 | |
538 | } | |
25357919 | 539 | cmds=(mdadm lsblk df udevadm losetup mkfs.ext3 fsck seq) |
20d10b4b ZL |
540 | for cmd in ${cmds[@]} |
541 | do | |
542 | which $cmd > /dev/null || { | |
543 | echo "$cmd command not found!" | |
544 | exit 1 | |
545 | } | |
546 | done | |
547 | mdadm_src_ver="$($mdadm -V 2>&1)" | |
548 | mdadm_sbin_ver="$($(which mdadm) -V 2>&1)" | |
549 | if [ "$mdadm_src_ver" != "$mdadm_sbin_ver" ] | |
550 | then | |
551 | # it's nessesary to 'make install' mdadm to /SBIN/DIR, | |
552 | # such as systemd/mdadm-grow-continue@.service, would | |
553 | # run as an instance by systemd when reshape happens, | |
554 | # thus ensure that the correct mdadm is in testing. | |
555 | echo "test: please run 'make install' before testing." | |
556 | exit 1 | |
557 | fi | |
558 | if ! $(df -T . | grep -iq ext) | |
559 | then | |
560 | # 'external file' bitmap only supports with ext[2-4] file system | |
561 | echo "test: please run test suite with ext[2-4] file system." | |
562 | exit 1 | |
563 | fi | |
564 | if $(lsblk -a | grep -iq raid) | |
565 | then | |
566 | # donot run mdadm -Ss directly if there are RAIDs working. | |
567 | echo "test: please run test suite without running RAIDs environment." | |
568 | exit 1 | |
569 | fi | |
570 | # Check whether to run multipath tests | |
571 | modprobe multipath 2> /dev/null | |
572 | grep -sq 'Personalities : .*multipath' /proc/mdstat && | |
573 | MULTIPATH="yes" | |
574 | } | |
4e5ce543 | 575 | |
20d10b4b ZL |
576 | main() { |
577 | check_env | |
578 | do_setup | |
572d7091 | 579 | |
20d10b4b ZL |
580 | echo "Testing on linux-$(uname -r) kernel" |
581 | [ "$savelogs" == "1" ] && | |
582 | echo "Saving logs to $logdir" | |
583 | if [ "x$TESTLIST" != "x" ] | |
584 | then | |
585 | for script in ${TESTLIST[@]} | |
586 | do | |
587 | do_test $testdir/$script | |
588 | done | |
589 | else | |
590 | for script in $testdir/$prefix $testdir/$prefix*[^~] | |
591 | do | |
592 | do_test $script | |
593 | done | |
594 | fi | |
60381555 | 595 | |
20d10b4b ZL |
596 | exit 0 |
597 | } | |
598 | ||
599 | parse_args $@ | |
600 | main |