]> git.ipfire.org Git - thirdparty/mdadm.git/blame - test
Assorted fixes
[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
27targetdir=/tmp
5e7519fa
NB
28size=20000
29mdsize0=19904
30mdsize1=19992
5e7519fa
NB
31
32cleanup() {
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
39trap cleanup 0 1 2 3 15
40
41devlist=
42for d in 0 1 2 3 4 5 6 7
43do
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
dab6685f 46 eval dev$d=/dev/loop$d
fe80f49b 47 eval file$d=$targetdir/mdtest$d
5e7519fa
NB
48 eval devlist=\"\$devlist \$dev$d\"
49done
dab6685f
NB
50
51# mdadm always adds --quiet, and we want to see any unexpected messages
52mdadm() {
53 $mdadm 2>&1 --quiet "$@"
54}
55
56# check various things
57check() {
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 ;;
fe80f49b
NB
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 ;;
dab6685f
NB
99
100 * ) echo >&2 ERROR unknown check $1 ; exit 1;
101 esac
102}
103
104# basic device test
105
106testdev() {
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
5e7519fa
NB
122
123
124for script in tests/$prefix*[^~]
125do
dab6685f
NB
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"
5e7519fa
NB
130 else cat $targetdir/log
131 echo "$script failed"
132 exit 1
133 fi
134done
135exit 0