]> git.ipfire.org Git - thirdparty/mdadm.git/blob - test
Assorted fixes
[thirdparty/mdadm.git] / test
1 #!/bin/sh
2 #
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
9
10 prefix='[0-9][0-9]'
11 if [ -n "$1" ]
12 then prefix=$1
13 fi
14
15 dir=`pwd`
16 mdadm=$dir/mdadm
17 if [ \! -x $mdadm ]
18 then
19 echo >&2 "test: $mdadm isn't usable."
20 fi
21
22 # assume md0, md1, md2 exist in /dev
23 md0=/dev/md0 md1=/dev/md1 md2=/dev/md2
24
25 # We test mdadm on loop-back block devices.
26 # dir for storing files should be settable by command line maybe
27 targetdir=/tmp
28 size=20000
29 mdsize0=19904
30 mdsize1=19992
31
32 cleanup() {
33 $mdadm -Ss
34 for d in 0 1 2 3 4 5 6 7
35 do losetup -d /dev/loop$d ; # rm -f $targetdir/mdtest$d
36 done
37 }
38
39 trap cleanup 0 1 2 3 15
40
41 devlist=
42 for d in 0 1 2 3 4 5 6 7
43 do
44 [ -f $targetdir/mdtest$d ] || dd if=/dev/zero of=$targetdir/mdtest$d count=$size bs=1K > /dev/null 2>&1
45 losetup /dev/loop$d $targetdir/mdtest$d
46 eval dev$d=/dev/loop$d
47 eval file$d=$targetdir/mdtest$d
48 eval devlist=\"\$devlist \$dev$d\"
49 done
50
51 # mdadm always adds --quiet, and we want to see any unexpected messages
52 mdadm() {
53 $mdadm 2>&1 --quiet "$@"
54 }
55
56 # check various things
57 check() {
58 case $1 in
59 raid* | linear )
60 grep -s "active $1 " /proc/mdstat > /dev/null || {
61 echo >&2 "ERROR active $1 not found" ; cat /proc/mdstat ; exit 1;}
62 ;;
63 resync | recovery )
64 sleep 0.1
65 grep -s $1 /proc/mdstat > /dev/null || {
66 echo >&2 ERROR no $1 happening; cat /proc/mdstat; exit 1; }
67 ;;
68
69 nosync )
70 sleep 0.5
71 if grep -s 're[synccovery]* =' > /dev/null /proc/mdstat ; then
72 echo >&2 "ERROR resync or recovery is happening!"; cat /proc/mdstat ; exit 1;
73 fi
74 ;;
75
76 wait )
77 sleep 0.1
78 while grep 're[synccovery]* =' > /dev/null /proc/mdstat
79 do sleep 2;
80 done
81 ;;
82
83 state )
84 grep -s "blocks.*\[$2\]\$" /proc/mdstat > /dev/null || {
85 echo >&2 "ERROR state $2 not found!"; cat /proc/mdstat ; exit 1; }
86 sleep 0.5
87 ;;
88
89 bitmap )
90 grep -s bitmap > /dev/null /proc/mdstat || {
91 echo >&2 ERROR no bitmap ; cat /proc/mdstat ; exist 1; }
92 ;;
93 nobitmap )
94 if grep -s "bitmap" > /dev/null /proc/mdstat
95 then
96 echo >&2 ERROR bitmap present ; cat /proc/mdstat ; exit 1;
97 fi
98 ;;
99
100 * ) echo >&2 ERROR unknown check $1 ; exit 1;
101 esac
102 }
103
104 # basic device test
105
106 testdev() {
107 dev=$1
108 cnt=$2
109 dvsize=$3
110 chunk=$4
111 mkfs -j $dev > /dev/null 2>&1 && fsck -fn $dev >&2
112 dsize=$[dvsize/chunk]
113 dsize=$[dsize*chunk]
114 rasize=$[dsize*1024*cnt]
115 if [ $rasize -ne `/sbin/blockdev --getsize64 $dev` ]
116 then
117 echo "ERROR: size is wrong for $dev: $cnt * $dvsize (chunk=$chunk) = $rasize, not `/sbin/blockdev --getsize64 $dev`"
118 exit 1
119 fi
120 }
121
122
123
124 for script in tests/$prefix*[^~]
125 do
126 # source script in a subshell, so it has access to our
127 # namespace, but cannot change it.
128 if ( set -ex ; . $script ) 2> $targetdir/log
129 then echo "$script succeeded"
130 else cat $targetdir/log
131 echo "$script failed"
132 exit 1
133 fi
134 done
135 exit 0