]> git.ipfire.org Git - thirdparty/mdadm.git/blob - test
DDF: ddf_process_update: Fix updates for SVDs
[thirdparty/mdadm.git] / test
1 #!/bin/bash
2 #
3 # run test suite for mdadm
4 user=`id -un`
5 if [ " $user" != " root" ]
6 then echo >&2 "test: testing can only be done as 'root'."
7 exit 1;
8 fi
9
10 prefix='[0-9][0-9]'
11
12 dir=`pwd`
13 mdadm=$dir/mdadm
14 if [ \! -x $mdadm ]
15 then
16 echo >&2 "test: $mdadm isn't usable."
17 fi
18
19 testdir="tests"
20 logdir="$testdir/logs"
21 logsave=0
22 exitonerror=1
23
24 echo "Testing on linux-$(uname -r) kernel"
25
26 # Check whether to run multipath tests
27 modprobe multipath 2> /dev/null
28 if grep -s 'Personalities : .*multipath' > /dev/null /proc/mdstat ; then
29 MULTIPATH="yes"
30 fi
31 INTEGRITY=yes
32
33 # assume md0, md1, md2 exist in /dev
34 md0=/dev/md0 md1=/dev/md1 md2=/dev/md2
35 mdp0=/dev/md_d0
36 mdp1=/dev/md_d1
37
38 # We test mdadm on loop-back block devices.
39 # dir for storing files should be settable by command line maybe
40 targetdir=/var/tmp
41 size=20000
42 # super0, round down to multiple of 64 and substract 64
43 mdsize0=19904
44 # super00 is nested, subtract 128
45 mdsize00=19840
46 # super1.0 round down to multiple of 2, subtract 8
47 mdsize1=19992
48 mdsize1a=19988
49 mdsize12=19988
50 # super1.2 for linear: round to multiple of 2, subtract 4
51 mdsize1_l=19996
52 mdsize2_l=19996
53 # subtract another 4 for bitmaps
54 mdsize1b=19988
55 mdsize11=19992
56 mdsize11a=19456
57 mdsize12=19988
58
59 # ddf needs bigger devices as 32Meg is reserved!
60 ddfsize=65536
61
62 config=/tmp/mdadm.conf
63
64 cleanup() {
65 udevadm settle
66 $mdadm -Ssq 2> /dev/null
67 for d in 0 1 2 3 4 5 6 7 8 9 10 11 12
68 do
69 losetup -d /dev/loop$d ; # rm -f $targetdir/mdtest$d
70 rm -f /dev/disk/by-path/loop*
71 done
72 }
73
74 ctrl_c() {
75 exitonerror=1
76 }
77
78 do_setup() {
79 trap cleanup 0 1 3 15
80 trap ctrl_c 2
81
82 devlist=
83 for d in 0 1 2 3 4 5 6 7 8 9 10 11 12
84 do
85 sz=$size
86 if [ $d -gt 7 ]; then sz=$ddfsize ; fi
87 [ -f $targetdir/mdtest$d ] || dd if=/dev/zero of=$targetdir/mdtest$d count=$sz bs=1K > /dev/null 2>&1
88 [ -b /dev/loop$d ] || mknod /dev/loop$d b 7 $d
89 if [ $d -eq 7 ]
90 then
91 losetup /dev/loop$d $targetdir/mdtest6 # for multipath use
92 else
93 losetup /dev/loop$d $targetdir/mdtest$d
94 fi
95 eval dev$d=/dev/loop$d
96 eval file$d=$targetdir/mdtest$d
97 eval devlist=\"\$devlist \$dev$d\"
98 eval devlist$d=\"\$devlist\"
99 #" <-- add this quote to un-confuse vim syntax highlighting
100 done
101 path0=$dev6
102 path1=$dev7
103
104 ulimit -c unlimited
105 [ -f /proc/mdstat ] || modprobe md_mod
106 echo 2000 > /proc/sys/dev/raid/speed_limit_max
107 echo 0 > /sys/module/md_mod/parameters/start_ro
108 }
109
110 # mdadm always adds --quiet, and we want to see any unexpected messages
111 mdadm() {
112 rm -f $targetdir/stderr
113 case $* in
114 *-S* ) udevadm settle;;
115 esac
116 case $* in
117 *-C* ) $mdadm 2> $targetdir/stderr --quiet "$@" --auto=yes;;
118 * ) $mdadm 2> $targetdir/stderr --quiet "$@"
119 esac
120 rv=$?
121 case $* in
122 *-S* ) udevadm settle;;
123 esac
124 cat >&2 $targetdir/stderr
125 return $rv
126 }
127
128 # check various things
129 check() {
130 case $1 in
131 spares )
132 spares=`tr '] ' '\012\012' < /proc/mdstat | grep -c '(S)' || exit 0`
133 if [ $spares -ne $2 ]
134 then
135 echo >&2 "ERROR expected $2 spares, found $spares"; exit 1;
136 fi
137 ;;
138 raid* | linear )
139 grep -s "active $1 " /proc/mdstat > /dev/null || {
140 echo >&2 "ERROR active $1 not found" ; cat /proc/mdstat ; exit 1;}
141 ;;
142 algorithm )
143 grep -s " algorithm $2 " /proc/mdstat > /dev/null || {
144 echo >&2 "ERROR algorithm $2 not found"; cat /proc/mdstat; exit 1;}
145 ;;
146 resync | recovery | reshape)
147 sleep 0.5
148 grep -s $1 /proc/mdstat > /dev/null || {
149 echo >&2 ERROR no $1 happening; cat /proc/mdstat; exit 1; }
150 ;;
151
152 nosync )
153 sleep 0.5
154 if grep -s -E '(resync|recovery|reshape) *=' > /dev/null /proc/mdstat ; then
155 echo >&2 "ERROR resync or recovery is happening!"; cat /proc/mdstat ; exit 1;
156 fi
157 ;;
158
159 wait )
160 sleep 0.1
161 while grep -E '(resync|recovery|reshape|check|repair) *=' > /dev/null /proc/mdstat
162 do sleep 2;
163 done
164 ;;
165
166 state )
167 grep -s "blocks.*\[$2\]\$" /proc/mdstat > /dev/null || {
168 echo >&2 "ERROR state $2 not found!"; cat /proc/mdstat ; exit 1; }
169 sleep 0.5
170 ;;
171
172 bitmap )
173 grep -s bitmap > /dev/null /proc/mdstat || {
174 echo >&2 ERROR no bitmap ; cat /proc/mdstat ; exit 1; }
175 ;;
176 nobitmap )
177 if grep -s "bitmap" > /dev/null /proc/mdstat
178 then
179 echo >&2 ERROR bitmap present ; cat /proc/mdstat ; exit 1;
180 fi
181 ;;
182
183 * ) echo >&2 ERROR unknown check $1 ; exit 1;
184 esac
185 }
186
187 no_errors() {
188 if [ -s $targetdir/stderr ]
189 then echo Bad errors from mdadm: ; cat $targetdir/stderr; exit 2;
190 fi
191 }
192 # basic device test
193
194 testdev() {
195 udevadm settle
196 dev=$1
197 cnt=$2
198 dvsize=$3
199 chunk=$4
200 if [ -z "$5" ]; then
201 mkfs -j $dev > /dev/null 2>&1 && fsck -fn $dev >&2
202 fi
203 dsize=$[dvsize/chunk]
204 dsize=$[dsize*chunk]
205 rasize=$[dsize*2*cnt]
206 # rasize is in sectors
207 if [ -n "$DEV_ROUND_K" ]; then
208 rasize=$[rasize/DEV_ROUND_K/2]
209 rasize=$[rasize*DEV_ROUND_K*2]
210 fi
211 if [ `/sbin/blockdev --getsize $dev` -eq 0 ]; then sleep 2 ; fi
212 _sz=`/sbin/blockdev --getsize $dev`
213 if [ $rasize -lt $_sz -o $[rasize*4/5] -gt $_sz ]
214 then
215 echo "ERROR: size is wrong for $dev: $cnt * $dvsize (chunk=$chunk) = $rasize, not $_sz"
216 exit 1
217 fi
218 }
219
220 rotest() {
221 dev=$1
222 fsck -fn $dev >&2
223 }
224
225 do_test() {
226 _script=$1
227 _basename=`basename $_script`
228 if [ -f "$_script" ]
229 then
230 rm -f $targetdir/stderr
231 # stop all arrays, just incase some script left an array active.
232 $mdadm -Ssq 2> /dev/null
233 mdadm --zero $devlist 2> /dev/null
234 mdadm --zero $devlist 2> /dev/null
235 # source script in a subshell, so it has access to our
236 # namespace, but cannot change it.
237 echo -ne "$_script... "
238 if ( set -ex ; . $_script ) &> $targetdir/log
239 then
240 echo "succeeded"
241 _fail=0
242 else
243 log=log
244 cat $targetdir/stderr >> $targetdir/log
245 if [ $exitonerror == 0 ]; then
246 log=log-`basename $_script`
247 mv $targetdir/log $targetdir/$log
248 fi
249 echo "FAILED - see $targetdir/$log for details"
250 _fail=1
251 fi
252 if [ "$savelogs" == "1" ]; then
253 cp $targetdir/log $logdir/$_basename.log
254 fi
255 if [ "$_fail" == "1" -a "$exitonerror" == "1" ]; then
256 exit 1
257 fi
258 fi
259 }
260
261 do_help() {
262 echo "Usage: $0 [options]"
263 echo " Options:"
264 echo " --tests=<test1,test2,..> Comma separated list of tests to run"
265 echo " --disable-multipath Disable any tests involving multipath"
266 echo " --disable-integrity Disable slow tests of RAID[56] consistency"
267 echo " --logdir=<directory> Directory to save logfiles in"
268 echo " --save-logs Save all logs in <logdir>"
269 echo " --keep-going Don't stop on error, ie. run all tests"
270 echo " setup Setup test environment and exit"
271 echo " cleanup Cleanup test environment"
272 echo " <prefix> Run tests with <prefix>"
273 }
274
275 parse_args() {
276 for i in $*
277 do
278 case $i in
279 [0-9]*)
280 prefix=$i
281 ;;
282 setup)
283 echo "mdadm test environment setup"
284 do_setup
285 trap 0; exit 0
286 ;;
287 cleanup)
288 cleanup
289 exit 0
290 ;;
291 --tests=*)
292 TESTLIST=`expr "x$i" : 'x[^=]*=\(.*\)' | sed -e 's/,/ /g'`
293 ;;
294 --logdir=*)
295 logdir=`expr "x$i" : 'x[^=]*=\(.*\)'`
296 ;;
297 --save-logs)
298 savelogs=1
299 if [ ! -d $logdir ] ; then
300 mkdir $logdir
301 if [ $? -ne 0 ] ; then
302 exit 1;
303 fi
304 fi
305 ;;
306 --keep-going | --no-error)
307 exitonerror=0
308 ;;
309 --disable-multipath)
310 unset MULTIPATH
311 ;;
312 --disable-integrity)
313 unset INTEGRITY
314 ;;
315 --help)
316 do_help
317 exit 0;
318 ;;
319 -*)
320 echo " $0: Unknown argument: $i"
321 do_help
322 exit 0;
323 ;;
324 esac
325 done
326 }
327
328 parse_args $@
329
330 do_setup
331
332 if [ "$savelogs" == "1" ]; then
333 echo "Saving logs to $logdir"
334 fi
335
336 if [ "x$TESTLIST" != "x" ]; then
337 for script in $TESTLIST
338 do
339 do_test $testdir/$script
340 done
341 else
342 for script in $testdir/$prefix $testdir/$prefix*[^~]
343 do
344 do_test $script
345 done
346 fi
347 exit 0