]> git.ipfire.org Git - thirdparty/mdadm.git/blob - test
Assemble(): don't dup_super() before we need it.
[thirdparty/mdadm.git] / test
1 #!/bin/sh
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 if [ -n "$1" ]
12 then prefix=$1
13 fi
14
15 dir=`pwd`
16 mdadm=$dir/mdadm
17 if [ \! -x $mdadm ]
18 then
19 echo >&2 "test: $mdadm isn't usable."
20 fi
21
22 # assume md0, md1, md2 exist in /dev
23 md0=/dev/md0 md1=/dev/md1 md2=/dev/md2
24 mdp0=/dev/md_d0
25 mdp1=/dev/md_d1
26
27 # We test mdadm on loop-back block devices.
28 # dir for storing files should be settable by command line maybe
29 targetdir=/var/tmp
30 size=20000
31 # super0, round down to multiple of 64 and substract 64
32 mdsize0=19904
33 # super00 is nested, subtract 128
34 mdsize00=19840
35 # super1.0 round down to multiple of 2, subtract 8
36 mdsize1=19992
37 mdsize1a=19988
38 mdsize12=19988
39 # super1.2 for linear: round to multiple of 2, subtract 4
40 mdsize1_l=18976
41 mdsize2_l=18976
42 # subtract another 4 for bitmaps
43 mdsize1b=19988
44 mdsize11=19992
45 mdsize11a=18944
46 mdsize12=19988
47
48 # ddf needs bigger devices as 32Meg is reserved!
49 ddfsize=65536
50
51 config=/tmp/mdadm.conf
52
53 cleanup() {
54 udevadm settle
55 $mdadm -Ssq 2> /dev/null
56 for d in 0 1 2 3 4 5 6 7 8 9 10 11 12
57 do
58 losetup -d /dev/loop$d ; # rm -f $targetdir/mdtest$d
59 rm -f /dev/disk/by-path/loop*
60 done
61 }
62
63 trap cleanup 0 1 2 3 15
64
65 devlist=
66 for d in 0 1 2 3 4 5 6 7 8 9 10 11 12
67 do
68 sz=$size
69 if [ $d -gt 7 ]; then sz=$ddfsize ; fi
70 [ -f $targetdir/mdtest$d ] || dd if=/dev/zero of=$targetdir/mdtest$d count=$sz bs=1K > /dev/null 2>&1
71 [ -b /dev/loop$d ] || mknod /dev/loop$d b 7 $d
72 if [ $d -eq 7 ]
73 then
74 losetup /dev/loop$d $targetdir/mdtest6 # for multipath use
75 else
76 losetup /dev/loop$d $targetdir/mdtest$d
77 fi
78 eval dev$d=/dev/loop$d
79 eval file$d=$targetdir/mdtest$d
80 eval devlist=\"\$devlist \$dev$d\"
81 #" <-- add this quote to un-confuse vim syntax highlighting
82 done
83 path0=$dev6
84 path1=$dev7
85
86 ulimit -c unlimited
87 [ -f /proc/mdstat ] || modprobe md_mod
88 echo 2000 > /proc/sys/dev/raid/speed_limit_max
89 echo 0 > /sys/module/md_mod/parameters/start_ro
90
91 if [ " $1" = " setup" ]
92 then trap 0 ; exit 0
93 fi
94
95 # mdadm always adds --quiet, and we want to see any unexpected messages
96 mdadm() {
97 rm -f $targetdir/stderr
98 case $* in
99 *-S* ) udevadm settle;;
100 esac
101 case $* in
102 *-C* ) $mdadm 2> $targetdir/stderr --quiet "$@" --auto=yes;;
103 * ) $mdadm 2> $targetdir/stderr --quiet "$@"
104 esac
105 rv=$?
106 case $* in
107 *-S* ) udevadm settle;;
108 esac
109 cat >&2 $targetdir/stderr
110 return $rv
111 }
112
113 # check various things
114 check() {
115 case $1 in
116 spares )
117 spares=`tr '] ' '\012\012' < /proc/mdstat | grep -c '(S)' || exit 0`
118 if [ $spares -ne $2 ]
119 then
120 echo >&2 "ERROR expected $2 spares, found $spares"; exit 1;
121 fi
122 ;;
123 raid* | linear )
124 grep -s "active $1 " /proc/mdstat > /dev/null || {
125 echo >&2 "ERROR active $1 not found" ; cat /proc/mdstat ; exit 1;}
126 ;;
127 resync | recovery | reshape)
128 sleep 0.5
129 grep -s $1 /proc/mdstat > /dev/null || {
130 echo >&2 ERROR no $1 happening; cat /proc/mdstat; exit 1; }
131 ;;
132
133 nosync )
134 sleep 0.5
135 if grep -s -E '(resync|recovery|reshape) *=' > /dev/null /proc/mdstat ; then
136 echo >&2 "ERROR resync or recovery is happening!"; cat /proc/mdstat ; exit 1;
137 fi
138 ;;
139
140 wait )
141 sleep 0.1
142 while grep -E '(resync|recovery|reshape|check|repair) *=' > /dev/null /proc/mdstat
143 do sleep 2;
144 done
145 ;;
146
147 state )
148 grep -s "blocks.*\[$2\]\$" /proc/mdstat > /dev/null || {
149 echo >&2 "ERROR state $2 not found!"; cat /proc/mdstat ; exit 1; }
150 sleep 0.5
151 ;;
152
153 bitmap )
154 grep -s bitmap > /dev/null /proc/mdstat || {
155 echo >&2 ERROR no bitmap ; cat /proc/mdstat ; exit 1; }
156 ;;
157 nobitmap )
158 if grep -s "bitmap" > /dev/null /proc/mdstat
159 then
160 echo >&2 ERROR bitmap present ; cat /proc/mdstat ; exit 1;
161 fi
162 ;;
163
164 * ) echo >&2 ERROR unknown check $1 ; exit 1;
165 esac
166 }
167
168 no_errors() {
169 if [ -s $targetdir/stderr ]
170 then echo Bad errors from mdadm: ; cat $targetdir/stderr; exit 2;
171 fi
172 }
173 # basic device test
174
175 testdev() {
176 udevadm settle
177 dev=$1
178 cnt=$2
179 dvsize=$3
180 chunk=$4
181 if [ -z "$5" ]; then
182 mkfs -j $dev > /dev/null 2>&1 && fsck -fn $dev >&2
183 fi
184 dsize=$[dvsize/chunk]
185 dsize=$[dsize*chunk]
186 rasize=$[dsize*2*cnt]
187 # rasize is in sectors
188 if [ -n "$DEV_ROUND_K" ]; then
189 rasize=$[rasize/DEV_ROUND_K/2]
190 rasize=$[rasize*DEV_ROUND_K*2]
191 fi
192 if [ `/sbin/blockdev --getsize $dev` -eq 0 ]; then sleep 2 ; fi
193 if [ $rasize -ne `/sbin/blockdev --getsize $dev` ]
194 then
195 echo "ERROR: size is wrong for $dev: $cnt * $dvsize (chunk=$chunk) = $rasize, not `/sbin/blockdev --getsize $dev`"
196 exit 1
197 fi
198 }
199
200 rotest() {
201 dev=$1
202 fsck -fn $dev >&2
203 }
204
205 for script in tests/$prefix tests/$prefix*[^~]
206 do
207 if [ -f "$script" ]
208 then
209 rm -f $targetdir/stderr
210 # stop all arrays, just incase some script left an array active.
211 $mdadm -Ssq 2> /dev/null
212 mdadm --zero $devlist 2> /dev/null
213 mdadm --zero $devlist 2> /dev/null
214 # source script in a subshell, so it has access to our
215 # namespace, but cannot change it.
216 echo -ne "$script... "
217 if ( set -ex ; . $script ) 2> $targetdir/log
218 then echo "succeeded"
219 else echo "FAILED - see $targetdir/log for details"
220 exit 1
221 fi
222 fi
223 done
224 exit 0