]> git.ipfire.org Git - thirdparty/mdadm.git/blob - test
mdmonitor: use MAILFROM to set sendmail envelope sender address
[thirdparty/mdadm.git] / test
1 #!/bin/bash
2 #
3 # run test suite for mdadm
4 mdadm=`which mdadm`
5 targetdir="/var/tmp"
6 logdir="$targetdir"
7 config=/tmp/mdadm.conf
8 testdir=$PWD/tests
9 system_speed_limit_max=0
10 system_speed_limit_min=0
11 test_speed_limit_min=100
12 test_speed_limit_max=500
13 devlist=
14 # If super1 metadata name doesn't have the same hostname with machine,
15 # it's treated as foreign.
16 # For example, /dev/md0 is created, stops it, then assemble it, the
17 # device node will be /dev/md127 (127 is choosed by mdadm autumatically)
18 is_foreign="no"
19 #disable selinux
20 sys_selinux="Permissive"
21
22 skipping_linear="no"
23 skipping_multipath="no"
24
25 savelogs=0
26 exitonerror=1
27 ctrl_c_error=0
28 skipbroken=0
29 skipbigcase=0
30 skipfile="skiptests"
31 skipcheckfile=$testdir/$skipfile
32 checkscript=""
33 loop=1
34 prefix='[0-9][0-9]'
35
36 # use loop devices by default if doesn't specify --dev
37 DEVTYPE=loop
38 INTEGRITY=yes
39 LVM_VOLGROUP=mdtest
40
41 # assume md0, md1, md2 exist in /dev
42 md0=/dev/md0
43 md1=/dev/md1
44 md2=/dev/md2
45 # if user doesn't specify minor number, mdadm chooses minor number
46 # automatically from 127.
47 md127=/dev/md127
48 md126=/dev/md126
49 md125=/dev/md125
50 mdp0=/dev/md_d0
51 mdp1=/dev/md_d1
52
53 SKIP=3
54
55 die() {
56 echo -e "\n\tERROR: $* \n"
57 save_log fail
58 exit 2
59 }
60
61 skip() {
62 echo -e "\n\tSKIPPING, REASON: $* \n"
63 exit $SKIP
64 }
65
66 ctrl_c() {
67 exitonerror=1
68 ctrl_c_error=1
69 }
70
71 mdadm() {
72 rm -f $targetdir/stderr
73 case $* in
74 *-S* )
75 udevadm settle
76 p=`cat /proc/sys/dev/raid/speed_limit_max`
77 echo 20000 > /proc/sys/dev/raid/speed_limit_max
78 ;;
79 esac
80 case $* in
81 *-C* | *--create* | *-B* | *--build* )
82 # clear superblock every time once creating or
83 # building arrays, because it's always creating
84 # and building array many times in a test case.
85 for args in $*
86 do
87 [[ $args =~ "/dev/" ]] && {
88 [[ $args =~ "md" ]] ||
89 $mdadm --zero $args > /dev/null
90 }
91 done
92 $mdadm 2> $targetdir/stderr "$@"
93 ;;
94 * )
95 $mdadm 2> $targetdir/stderr "$@"
96 ;;
97 esac
98 rv=$?
99 case $* in
100 *-S* )
101 udevadm settle
102 echo $p > /proc/sys/dev/raid/speed_limit_max
103 ;;
104 esac
105 cat >&2 $targetdir/stderr
106 return $rv
107 }
108
109 print_time_elapsed() {
110 local start_sec=$1
111 local end_sec=$(date +%s)
112
113 local execution_time=$((end_sec - start_sec))
114
115 echo -ne "Execution time (seconds): ${execution_time} "
116 }
117
118 do_test() {
119 _script=$1
120 _basename=`basename $_script`
121 _broken=0
122
123 local start_sec=$(date +%s)
124
125 if [ -f "$_script" ]
126 then
127 if [ -f "${_script}.broken" ]; then
128 _broken=1
129 _broken_msg=$(head -n1 "${_script}.broken" | tr -d '\n')
130 if [ "$skipbroken" == "all" ]; then
131 return
132 elif [ "$skipbroken" == "always" ] &&
133 [[ "$_broken_msg" == *always* ]]; then
134 return
135 fi
136 fi
137
138 rm -f $targetdir/stderr
139 do_clean
140 # source script in a subshell, so it has access to our
141 # namespace, but cannot change it.
142 control_system_speed_limit
143 echo -ne "$_script... "
144 if ( set -ex ; . $_script ) &> $targetdir/log
145 then
146 print_time_elapsed $start_sec
147 if [ -f "${_script}.inject_error" ]; then
148 echo "dmesg checking is skipped because test inject error"
149 else
150 dmesg | grep -iq "error\|call trace\|segfault" | grep -v "systemd" &&
151 die "dmesg prints errors when testing $_basename!"
152 fi
153 succeed "succeeded\n"
154 _fail=0
155 else
156 exit_code=$? # Capture the exit code from the script
157 if [ $exit_code -eq $SKIP ]; then
158 warn "skipping"
159 save_log
160 _fail=0
161 else
162 print_time_elapsed $start_sec
163 save_log fail
164 _fail=1
165 if [ "$_broken" == "1" ]; then
166 echo " (KNOWN BROKEN TEST: $_broken_msg)"
167 fi
168 fi
169 fi
170 restore_system_speed_limit
171
172 [ "$savelogs" == "1" ] && mv -f $targetdir/log $logdir/$_basename.log
173
174 [ "$ctrl_c_error" == "1" ] && exit 1
175
176 [ "$_fail" == "1" -a "$exitonerror" == "1" -a "$_broken" == "0" ] && exit 1
177
178 [ "$_fail" == "1" ] && do_test_ret=1
179 fi
180 }
181
182 do_help() {
183 cat <<-EOF
184 Usage: $0 [options]
185 Example for disk mode: ./test --dev=disk --disks=/dev/sda{2..15}
186 Options:
187 --tests=test1,test2,... Comma separated list of tests to run
188 --testdir= Specify testdir as tests|clustermd_tests
189 --raidtype= raid0|linear|raid1|raid456|raid10|ddf|imsm
190 --disable-multipath Disable any tests involving multipath
191 --disable-integrity Disable slow tests of RAID[56] consistency
192 --disable-linear Disable any tests involving linear
193 --logdir=directory Directory to save all logfiles in
194 --save-logs Usually use with --logdir together
195 --keep-going | --no-error Don't stop on error, ie. run all tests
196 --loop=N Run tests N times (0 to run forever)
197 --skip-broken Skip tests that are known to be broken
198 --skip-always-broken Skip tests that are known to always fail
199 --skip-bigcase Skip tests that need time than 200 seconds
200 --dev=loop|lvm|ram|disk Use loop devices (default), LVM, RAM or disk
201 --disks= Provide a bunch of physical devices for test
202 --volgroup=name LVM volume group for LVM test
203 setup Setup test environment and exit
204 cleanup Cleanup test environment
205 prefix Run tests with <prefix>
206 --help | -h Print this usage
207 EOF
208 }
209
210 parse_args() {
211 for i in $*
212 do
213 case $i in
214 --testdir=* )
215 case ${i##*=} in
216 tests )
217 testdir=tests
218 ;;
219 clustermd_tests )
220 testdir=clustermd_tests
221 CLUSTER_CONF="$PWD/$testdir/cluster_conf"
222 ;;
223 * )
224 echo "Unknown argument: $i"
225 do_help
226 exit 1
227 ;;
228 esac
229 ;;
230 esac
231 done
232 [ -z "$testdir" ] && testdir=tests
233 . $testdir/func.sh
234 for i in $*
235 do
236 case $i in
237 [0-9][0-9] )
238 prefix=$i
239 ;;
240 setup )
241 echo "mdadm test environment setup"
242 do_setup
243 trap 0
244 exit 0
245 ;;
246 cleanup )
247 cleanup
248 exit 0
249 ;;
250 --testdir=* )
251 ;;
252 --tests=* )
253 TESTLIST=($(echo ${i##*=} | sed -e 's/,/ /g'))
254 ;;
255 --raidtype=* )
256 case ${i##*=} in
257 raid0 )
258 TESTLIST=($(ls $testdir | grep "[0-9][0-9]r0\|raid0"))
259 ;;
260 linear )
261 TESTLIST=($(ls $testdir | grep "linear"))
262 ;;
263 raid1 )
264 TESTLIST=($(ls $testdir | grep "[0-9][0-9]r1\|raid1" | grep -vi "r10\|raid10"))
265 ;;
266 raid456 )
267 TESTLIST=($(ls $testdir | grep "[0-9][0-9]r[4-6]\|raid[4-6]"))
268 ;;
269 raid10 )
270 TESTLIST=($(ls $testdir | grep "[0-9][0-9]r10\|raid10"))
271 ;;
272 ddf )
273 TESTLIST=($(ls $testdir | grep "[0-9][0-9]ddf"))
274 ;;
275 imsm )
276 TESTLIST=($(ls $testdir | grep "[0-9][0-9]imsm"))
277 ;;
278 * )
279 echo "Unknown argument: $i"
280 do_help
281 exit 1
282 ;;
283 esac
284 ;;
285 --logdir=* )
286 logdir="${i##*=}"
287 ;;
288 --save-logs )
289 savelogs=1
290 ;;
291 --keep-going | --no-error )
292 exitonerror=0
293 ;;
294 --loop=* )
295 loop="${i##*=}"
296 ;;
297 --skip-broken )
298 skipbroken=all
299 ;;
300 --skip-always-broken )
301 skipbroken=always
302 ;;
303 --skip-bigcase )
304 skipbigcase=all
305 ;;
306 --disable-multipath )
307 unset MULTIPATH
308 ;;
309 --disable-integrity )
310 unset INTEGRITY
311 ;;
312 --disable-linear )
313 unset LINEAR
314 ;;
315 --dev=* )
316 case ${i##*=} in
317 loop )
318 DEVTYPE=loop
319 ;;
320 lvm )
321 DEVTYPE=lvm
322 ;;
323 ram )
324 DEVTYPE=ram
325 ;;
326 disk )
327 DEVTYPE=disk
328 ;;
329 * )
330 echo "Unknown argument: $i"
331 do_help
332 exit 1
333 ;;
334 esac
335 ;;
336 --disks=* )
337 disks=(${disks[*]} ${i##*=})
338 ;;
339 --volgroup=* )
340 LVM_VOLGROUP=`expr "x$i" : 'x[^=]*=\(.*\)'`
341 ;;
342 --help | -h )
343 do_help
344 exit 0
345 ;;
346 * )
347 echo " $0: Unknown argument: $i"
348 do_help
349 exit 1
350 ;;
351 esac
352 done
353 }
354
355 print_warning() {
356 warn "Warning! Tests are performed on system level mdadm!\n"
357 echo "If you want to test local build, you need to install it first!"
358 }
359
360 main() {
361 print_warning
362 do_setup
363
364 echo "Testing on linux-$(uname -r) kernel"
365 [ "$savelogs" == "1" ] &&
366 echo "Saving logs to $logdir"
367
368 do_test_ret=0
369
370 while true; do
371 if [ "x$TESTLIST" != "x" ]
372 then
373 for script in ${TESTLIST[@]}
374 do
375 do_test $testdir/$script
376 done
377 else
378 for script in $testdir/$prefix $testdir/$prefix*[^~]
379 do
380 checkscript="${script##*/}"
381 case $script in
382 *.broken)
383 ;;
384 *)
385 if grep -q "$checkscript" "$skipcheckfile"; then
386 if [ "$skipbigcase" == "all" ]; then
387 continue
388 fi
389 fi
390 do_test $script
391 esac
392 done
393 fi
394
395 let loop=$loop-1
396 if [ "$loop" == "0" ]; then
397 break
398 fi
399 done
400
401 restore_selinux
402 exit $do_test_ret
403 }
404
405 parse_args $@
406 main