Correct PPTP server firewall rules chain.
[tomato/davidwu.git] / release / src / router / mdadm / test
bloba83b68e69d181f737f17696a5b79656c76c04403
1 #!/bin/sh
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
10 prefix='[0-9][0-9]'
11 if [ -n "$1" ]
12 then prefix=$1
15 dir=`pwd`
16 mdadm=$dir/mdadm
17 if [ \! -x $mdadm ]
18 then
19 echo >&2 "test: $mdadm isn't usable."
22 # assume md0, md1, md2 exist in /dev
23 md0=/dev/md0 md1=/dev/md1 md2=/dev/md2
25 # We test mdadm on loop-back block devices.
26 # dir for storing files should be settable by command line maybe
27 targetdir=/var/tmp
28 size=20000
29 mdsize0=19904
30 mdsize1=19992
31 mdsize11=19996
32 mdsize12=19992
34 cleanup() {
35 $mdadm -Ss
36 for d in 0 1 2 3 4 5 6 7
38 losetup -d /dev/loop$d ; # rm -f $targetdir/mdtest$d
39 done
42 trap cleanup 0 1 2 3 15
44 devlist=
45 for d in 0 1 2 3 4 5 6 7
47 [ -f $targetdir/mdtest$d ] || dd if=/dev/zero of=$targetdir/mdtest$d count=$size bs=1K > /dev/null 2>&1
48 [ -b /dev/loop$d ] || mknod /dev/loop$d b 7 $d
49 if [ $d -eq 7 ]
50 then
51 losetup /dev/loop$d $targetdir/mdtest6 # for multipath use
52 else
53 losetup /dev/loop$d $targetdir/mdtest$d
55 eval dev$d=/dev/loop$d
56 eval file$d=$targetdir/mdtest$d
57 eval devlist=\"\$devlist \$dev$d\"
58 done
59 path0=$dev6
60 path1=$dev7
62 if [ " $1" = " setup" ]
63 then trap 0 ; exit 0
66 # mdadm always adds --quiet, and we want to see any unexpected messages
67 mdadm() {
68 rm -f $targetdir/stderr
69 case $* in
70 *-C* ) $mdadm 2> $targetdir/stderr --quiet "$@" --auto=yes;;
71 * ) $mdadm 2> $targetdir/stderr --quiet "$@"
72 esac
73 cat >&2 $targetdir/stderr
76 # check various things
77 check() {
78 case $1 in
79 spares )
80 spares=`tr '] ' '\012\012' < /proc/mdstat | grep -c '(S)' || exit 0`
81 if [ $spares -ne $2 ]
82 then
83 echo >&2 "ERROR expected $2 spares, found $spares"; exit 1;
86 raid* | linear )
87 grep -s "active $1 " /proc/mdstat > /dev/null || {
88 echo >&2 "ERROR active $1 not found" ; cat /proc/mdstat ; exit 1;}
90 resync | recovery )
91 sleep 0.5
92 grep -s $1 /proc/mdstat > /dev/null || {
93 echo >&2 ERROR no $1 happening; cat /proc/mdstat; exit 1; }
96 nosync )
97 sleep 0.5
98 if grep -s 're[synccovery]* =' > /dev/null /proc/mdstat ; then
99 echo >&2 "ERROR resync or recovery is happening!"; cat /proc/mdstat ; exit 1;
103 wait )
104 sleep 0.1
105 while grep 're[synccovery]* =' > /dev/null /proc/mdstat
106 do sleep 2;
107 done
110 state )
111 grep -s "blocks.*\[$2\]\$" /proc/mdstat > /dev/null || {
112 echo >&2 "ERROR state $2 not found!"; cat /proc/mdstat ; exit 1; }
113 sleep 0.5
116 bitmap )
117 grep -s bitmap > /dev/null /proc/mdstat || {
118 echo >&2 ERROR no bitmap ; cat /proc/mdstat ; exit 1; }
120 nobitmap )
121 if grep -s "bitmap" > /dev/null /proc/mdstat
122 then
123 echo >&2 ERROR bitmap present ; cat /proc/mdstat ; exit 1;
127 * ) echo >&2 ERROR unknown check $1 ; exit 1;
128 esac
131 no_errors() {
132 if [ -s $targetdir/stderr ]
133 then echo Bad errors from mdadm: ; cat $targetdir/stderr; exit 2;
136 # basic device test
138 testdev() {
139 dev=$1
140 cnt=$2
141 dvsize=$3
142 chunk=$4
143 mkfs -j $dev > /dev/null 2>&1 && fsck -fn $dev >&2
144 dsize=$[dvsize/chunk]
145 dsize=$[dsize*chunk]
146 rasize=$[dsize*2*cnt]
147 if [ $rasize -ne `/sbin/blockdev --getsize $dev` ]
148 then
149 echo "ERROR: size is wrong for $dev: $cnt * $dvsize (chunk=$chunk) = $rasize, not `/sbin/blockdev --getsize $dev`"
150 exit 1
154 rotest() {
155 dev=$1
156 fsck -fn $dev >&2
161 for script in tests/$prefix tests/$prefix*[^~]
163 if [ -f "$script" ]
164 then
165 rm -f $targetdir/stderr
166 # source script in a subshell, so it has access to our
167 # namespace, but cannot change it.
168 if ( set -ex ; . $script ) 2> $targetdir/log
169 then echo "$script succeeded"
170 else cat $targetdir/log ; cat $targetdir/stderr
171 echo "$script failed"
172 exit 1
175 done
176 exit 0