]>
Commit | Line | Data |
---|---|---|
23b7d3b9 | 1 | #!/bin/bash |
5e7519fa NB |
2 | # |
3 | # run test suite for mdadm | |
cbb8d34a | 4 | mdadm=$PWD/mdadm |
20d10b4b ZL |
5 | targetdir="/var/tmp" |
6 | logdir="$targetdir" | |
7 | config=/tmp/mdadm.conf | |
59416da7 | 8 | testdir=$PWD/tests |
6c33d34d | 9 | devlist= |
60381555 | 10 | |
20d10b4b ZL |
11 | savelogs=0 |
12 | exitonerror=1 | |
28520bf1 LG |
13 | ctrl_c_error=0 |
14 | skipbroken=0 | |
a7bfcc71 | 15 | loop=1 |
20d10b4b | 16 | prefix='[0-9][0-9]' |
98a92cff | 17 | |
20d10b4b | 18 | # use loop devices by default if doesn't specify --dev |
7d8a70bf | 19 | DEVTYPE=loop |
20d10b4b | 20 | INTEGRITY=yes |
7d8a70bf | 21 | LVM_VOLGROUP=mdtest |
04c1ca5f | 22 | |
9540cc24 N |
23 | # make sure to test local mdmon, not system one |
24 | export MDADM_NO_SYSTEMCTL=1 | |
25 | ||
5e7519fa | 26 | # assume md0, md1, md2 exist in /dev |
662c349a ZL |
27 | md0=/dev/md0 |
28 | md1=/dev/md1 | |
29 | md2=/dev/md2 | |
1f48664b NB |
30 | mdp0=/dev/md_d0 |
31 | mdp1=/dev/md_d1 | |
5e7519fa | 32 | |
20d10b4b ZL |
33 | die() { |
34 | echo -e "\n\tERROR: $* \n" | |
35 | save_log fail | |
36 | exit 2 | |
37 | } | |
ed02d9cc | 38 | |
d5a221a5 | 39 | ctrl_c() { |
4d5995c4 | 40 | exitonerror=1 |
28520bf1 | 41 | ctrl_c_error=1 |
4d5995c4 GE |
42 | } |
43 | ||
dab6685f NB |
44 | # mdadm always adds --quiet, and we want to see any unexpected messages |
45 | mdadm() { | |
662c349a ZL |
46 | rm -f $targetdir/stderr |
47 | case $* in | |
48 | *-S* ) | |
49 | udevadm settle | |
50 | p=`cat /proc/sys/dev/raid/speed_limit_max` | |
51 | echo 20000 > /proc/sys/dev/raid/speed_limit_max | |
52 | ;; | |
53 | esac | |
54 | case $* in | |
20d10b4b ZL |
55 | *-C* | *--create* | *-B* | *--build* ) |
56 | # clear superblock every time once creating or | |
57 | # building arrays, because it's always creating | |
58 | # and building array many times in a test case. | |
59 | for args in $* | |
60 | do | |
61 | [[ $args =~ "/dev/" ]] && { | |
62 | [[ $args =~ "md" ]] || | |
63 | $mdadm --zero $args > /dev/null | |
64 | } | |
65 | done | |
662c349a ZL |
66 | $mdadm 2> $targetdir/stderr --quiet "$@" --auto=yes |
67 | ;; | |
68 | * ) | |
69 | $mdadm 2> $targetdir/stderr --quiet "$@" | |
70 | ;; | |
71 | esac | |
72 | rv=$? | |
73 | case $* in | |
74 | *-S* ) | |
75 | udevadm settle | |
76 | echo $p > /proc/sys/dev/raid/speed_limit_max | |
77 | ;; | |
78 | esac | |
79 | cat >&2 $targetdir/stderr | |
80 | return $rv | |
dab6685f NB |
81 | } |
82 | ||
4e5ce543 | 83 | do_test() { |
662c349a ZL |
84 | _script=$1 |
85 | _basename=`basename $_script` | |
28520bf1 LG |
86 | _broken=0 |
87 | ||
662c349a ZL |
88 | if [ -f "$_script" ] |
89 | then | |
28520bf1 LG |
90 | if [ -f "${_script}.broken" ]; then |
91 | _broken=1 | |
92 | _broken_msg=$(head -n1 "${_script}.broken" | tr -d '\n') | |
93 | if [ "$skipbroken" == "all" ]; then | |
94 | return | |
95 | elif [ "$skipbroken" == "always" ] && | |
96 | [[ "$_broken_msg" == *always* ]]; then | |
97 | return | |
98 | fi | |
99 | fi | |
100 | ||
662c349a | 101 | rm -f $targetdir/stderr |
662c349a ZL |
102 | # this might have been reset: restore the default. |
103 | echo 2000 > /proc/sys/dev/raid/speed_limit_max | |
064bd3f5 | 104 | do_clean |
662c349a ZL |
105 | # source script in a subshell, so it has access to our |
106 | # namespace, but cannot change it. | |
107 | echo -ne "$_script... " | |
108 | if ( set -ex ; . $_script ) &> $targetdir/log | |
109 | then | |
0ef9465f YK |
110 | if [ -f "${_script}.inject_error" ]; then |
111 | echo "dmesg checking is skipped because test inject error" | |
112 | else | |
113 | dmesg | grep -iq "error\|call trace\|segfault" && | |
114 | die "dmesg prints errors when testing $_basename!" | |
115 | fi | |
662c349a ZL |
116 | echo "succeeded" |
117 | _fail=0 | |
118 | else | |
20d10b4b | 119 | save_log fail |
662c349a | 120 | _fail=1 |
28520bf1 LG |
121 | if [ "$_broken" == "1" ]; then |
122 | echo " (KNOWN BROKEN TEST: $_broken_msg)" | |
123 | fi | |
662c349a | 124 | fi |
20d10b4b ZL |
125 | [ "$savelogs" == "1" ] && |
126 | mv -f $targetdir/log $logdir/$_basename.log | |
28520bf1 LG |
127 | [ "$ctrl_c_error" == "1" ] && exit 1 |
128 | [ "$_fail" == "1" -a "$exitonerror" == "1" \ | |
129 | -a "$_broken" == "0" ] && exit 1 | |
662c349a | 130 | fi |
4e5ce543 JS |
131 | } |
132 | ||
133 | do_help() { | |
20d10b4b ZL |
134 | cat <<-EOF |
135 | Usage: $0 [options] | |
25357919 | 136 | Example for disk mode: ./test --dev=disk --disks=/dev/sda{2..15} |
20d10b4b ZL |
137 | Options: |
138 | --tests=test1,test2,... Comma separated list of tests to run | |
6c33d34d | 139 | --testdir= Specify testdir as tests|clustermd_tests |
8403b202 | 140 | --raidtype= raid0|linear|raid1|raid456|raid10|ddf|imsm |
20d10b4b ZL |
141 | --disable-multipath Disable any tests involving multipath |
142 | --disable-integrity Disable slow tests of RAID[56] consistency | |
64a4fcb4 | 143 | --disable-linear Disable any tests involving linear |
20d10b4b ZL |
144 | --logdir=directory Directory to save all logfiles in |
145 | --save-logs Usually use with --logdir together | |
146 | --keep-going | --no-error Don't stop on error, ie. run all tests | |
a7bfcc71 | 147 | --loop=N Run tests N times (0 to run forever) |
28520bf1 LG |
148 | --skip-broken Skip tests that are known to be broken |
149 | --skip-always-broken Skip tests that are known to always fail | |
25357919 ZL |
150 | --dev=loop|lvm|ram|disk Use loop devices (default), LVM, RAM or disk |
151 | --disks= Provide a bunch of physical devices for test | |
20d10b4b ZL |
152 | --volgroup=name LVM volume group for LVM test |
153 | setup Setup test environment and exit | |
154 | cleanup Cleanup test environment | |
155 | prefix Run tests with <prefix> | |
156 | --help | -h Print this usage | |
157 | EOF | |
4e5ce543 JS |
158 | } |
159 | ||
160 | parse_args() { | |
6c33d34d ZL |
161 | for i in $* |
162 | do | |
163 | case $i in | |
164 | --testdir=* ) | |
165 | case ${i##*=} in | |
166 | tests ) | |
167 | testdir=tests | |
168 | ;; | |
169 | clustermd_tests ) | |
170 | testdir=clustermd_tests | |
171 | CLUSTER_CONF="$PWD/$testdir/cluster_conf" | |
172 | ;; | |
173 | * ) | |
174 | echo "Unknown argument: $i" | |
175 | do_help | |
176 | exit 1 | |
177 | ;; | |
178 | esac | |
179 | ;; | |
180 | esac | |
181 | done | |
182 | [ -z "$testdir" ] && testdir=tests | |
183 | . $testdir/func.sh | |
662c349a ZL |
184 | for i in $* |
185 | do | |
186 | case $i in | |
20d10b4b | 187 | [0-9][0-9] ) |
662c349a ZL |
188 | prefix=$i |
189 | ;; | |
190 | setup ) | |
191 | echo "mdadm test environment setup" | |
192 | do_setup | |
193 | trap 0 | |
194 | exit 0 | |
195 | ;; | |
196 | cleanup ) | |
197 | cleanup | |
198 | exit 0 | |
199 | ;; | |
6c33d34d ZL |
200 | --testdir=* ) |
201 | ;; | |
662c349a | 202 | --tests=* ) |
20d10b4b | 203 | TESTLIST=($(echo ${i##*=} | sed -e 's/,/ /g')) |
662c349a | 204 | ;; |
8403b202 ZL |
205 | --raidtype=* ) |
206 | case ${i##*=} in | |
207 | raid0 ) | |
208 | TESTLIST=($(ls $testdir | grep "[0-9][0-9]r0\|raid0")) | |
209 | ;; | |
210 | linear ) | |
211 | TESTLIST=($(ls $testdir | grep "linear")) | |
212 | ;; | |
213 | raid1 ) | |
05e0e58f | 214 | TESTLIST=($(ls $testdir | grep "[0-9][0-9]r1\|raid1" | grep -vi "r10\|raid10")) |
8403b202 ZL |
215 | ;; |
216 | raid456 ) | |
217 | TESTLIST=($(ls $testdir | grep "[0-9][0-9]r[4-6]\|raid[4-6]")) | |
218 | ;; | |
219 | raid10 ) | |
220 | TESTLIST=($(ls $testdir | grep "[0-9][0-9]r10\|raid10")) | |
221 | ;; | |
222 | ddf ) | |
223 | TESTLIST=($(ls $testdir | grep "[0-9][0-9]ddf")) | |
224 | ;; | |
225 | imsm ) | |
226 | TESTLIST=($(ls $testdir | grep "[0-9][0-9]imsm")) | |
227 | ;; | |
228 | * ) | |
229 | echo "Unknown argument: $i" | |
230 | do_help | |
231 | exit 1 | |
232 | ;; | |
233 | esac | |
234 | ;; | |
662c349a | 235 | --logdir=* ) |
20d10b4b | 236 | logdir="${i##*=}" |
662c349a ZL |
237 | ;; |
238 | --save-logs ) | |
239 | savelogs=1 | |
240 | ;; | |
241 | --keep-going | --no-error ) | |
242 | exitonerror=0 | |
243 | ;; | |
a7bfcc71 LG |
244 | --loop=* ) |
245 | loop="${i##*=}" | |
246 | ;; | |
28520bf1 LG |
247 | --skip-broken ) |
248 | skipbroken=all | |
249 | ;; | |
250 | --skip-always-broken ) | |
251 | skipbroken=always | |
252 | ;; | |
662c349a ZL |
253 | --disable-multipath ) |
254 | unset MULTIPATH | |
255 | ;; | |
256 | --disable-integrity ) | |
257 | unset INTEGRITY | |
258 | ;; | |
64a4fcb4 SL |
259 | --disable-linear ) |
260 | unset LINEAR | |
261 | ;; | |
20d10b4b ZL |
262 | --dev=* ) |
263 | case ${i##*=} in | |
264 | loop ) | |
265 | DEVTYPE=loop | |
266 | ;; | |
267 | lvm ) | |
268 | DEVTYPE=lvm | |
269 | ;; | |
270 | ram ) | |
271 | DEVTYPE=ram | |
272 | ;; | |
25357919 ZL |
273 | disk ) |
274 | DEVTYPE=disk | |
275 | ;; | |
20d10b4b ZL |
276 | * ) |
277 | echo "Unknown argument: $i" | |
278 | do_help | |
279 | exit 1 | |
280 | ;; | |
281 | esac | |
662c349a | 282 | ;; |
25357919 ZL |
283 | --disks=* ) |
284 | disks=(${disks[*]} ${i##*=}) | |
285 | ;; | |
662c349a ZL |
286 | --volgroup=* ) |
287 | LVM_VOLGROUP=`expr "x$i" : 'x[^=]*=\(.*\)'` | |
288 | ;; | |
20d10b4b | 289 | --help | -h ) |
662c349a ZL |
290 | do_help |
291 | exit 0 | |
292 | ;; | |
20d10b4b | 293 | * ) |
662c349a ZL |
294 | echo " $0: Unknown argument: $i" |
295 | do_help | |
20d10b4b | 296 | exit 1 |
662c349a ZL |
297 | ;; |
298 | esac | |
299 | done | |
4e5ce543 JS |
300 | } |
301 | ||
20d10b4b | 302 | main() { |
20d10b4b | 303 | do_setup |
572d7091 | 304 | |
20d10b4b ZL |
305 | echo "Testing on linux-$(uname -r) kernel" |
306 | [ "$savelogs" == "1" ] && | |
307 | echo "Saving logs to $logdir" | |
60381555 | 308 | |
a7bfcc71 LG |
309 | while true; do |
310 | if [ "x$TESTLIST" != "x" ] | |
311 | then | |
312 | for script in ${TESTLIST[@]} | |
313 | do | |
314 | do_test $testdir/$script | |
315 | done | |
316 | else | |
317 | for script in $testdir/$prefix $testdir/$prefix*[^~] | |
318 | do | |
28520bf1 LG |
319 | case $script in |
320 | *.broken) ;; | |
321 | *) | |
322 | do_test $script | |
323 | esac | |
a7bfcc71 LG |
324 | done |
325 | fi | |
326 | ||
327 | let loop=$loop-1 | |
328 | if [ "$loop" == "0" ]; then | |
329 | break | |
330 | fi | |
331 | done | |
20d10b4b ZL |
332 | exit 0 |
333 | } | |
334 | ||
335 | parse_args $@ | |
336 | main |