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