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