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