Whamcloud - gitweb
Add bug 2366 to ALWAYS_EXCEPT until it is fixed.
[fs/lustre-release.git] / lustre / tests / sanityN.sh
1 #!/bin/bash
2
3 set -e
4
5 ONLY=${ONLY:-"$*"}
6 # bug number for skipped test: 1557 2366
7 ALWAYS_EXCEPT=${ALWAYS_EXCEPT:-"8   10   "}
8 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
9
10 [ "$ALWAYS_EXCEPT$EXCEPT" ] && echo "Skipping tests: $ALWAYS_EXCEPT $EXCEPT"
11
12 SRCDIR=`dirname $0`
13 PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
14
15 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
16 CREATETEST=${CREATETEST:-createtest}
17 LFIND=${LFIND:-lfind}
18 LSTRIPE=${LSTRIPE:-lstripe}
19 LCTL=${LCTL:-lctl}
20 MCREATE=${MCREATE:-mcreate}
21 OPENFILE=${OPENFILE:-openfile}
22 OPENUNLINK=${OPENUNLINK:-openunlink}
23 TOEXCL=${TOEXCL:-toexcl}
24 TRUNCATE=${TRUNCATE:-truncate}
25
26 if [ $UID -ne 0 ]; then
27         RUNAS_ID="$UID"
28         RUNAS=""
29 else
30         RUNAS_ID=${RUNAS_ID:-500}
31         RUNAS=${RUNAS:-"runas -u $RUNAS_ID"}
32 fi
33
34 export NAME=${NAME:-mount2}
35
36 SAVE_PWD=$PWD
37
38 clean() {
39         echo -n "cln.."
40         sh llmountcleanup.sh > /dev/null || exit 20
41 }
42 CLEAN=${CLEAN:-clean}
43
44 start() {
45         echo -n "mnt.."
46         sh llrmount.sh > /dev/null || exit 10
47         echo "done"
48 }
49 START=${START:-start}
50
51 log() {
52         echo "$*"
53         lctl mark "$*" 2> /dev/null || true
54 }
55
56 run_one() {
57         if ! mount | grep -q $DIR1; then
58                 $START
59         fi
60         log "== test $1: $2"
61         export TESTNAME=test_$1
62         test_$1 || error "test_$1: exit with rc=$?"
63         unset TESTNAME
64         pass
65         cd $SAVE_PWD
66         $CLEAN
67 }
68
69 run_test() {
70         for O in $ONLY; do
71                 if [ "`echo $1 | grep '\<'$O'[a-z]*\>'`" ]; then
72                         echo ""
73                         run_one $1 "$2"
74                         return $?
75                 else
76                         echo -n "."
77                 fi
78         done
79         for X in $EXCEPT $ALWAYS_EXCEPT; do
80                 if [ "`echo $1 | grep '\<'$X'[a-z]*\>'`" ]; then
81                         echo "skipping excluded test $1"
82                         return 0
83                 fi
84         done
85         if [ -z "$ONLY" ]; then
86                 run_one $1 "$2"
87                 return $?
88         fi
89 }
90
91 error () {
92         log "FAIL: $TESTNAME $@"
93         exit 1
94 }
95
96 pass() {
97         echo PASS
98 }
99
100 export MOUNT1=`mount| awk '/ lustre/ { print $3 }'| head -1`
101 export MOUNT2=`mount| awk '/ lustre/ { print $3 }'| tail -1`
102 [ -z "$MOUNT1" ] && error "NAME=$NAME not mounted once"
103 [ "$MOUNT1" = "$MOUNT2" ] && error "NAME=$NAME not mounted twice"
104 [ `mount| awk '/ lustre/ { print $3 }'| wc -l` -ne 2 ] && \
105         error "NAME=$NAME mounted more than twice"
106
107 export DIR1=${DIR1:-$MOUNT1}
108 export DIR2=${DIR2:-$MOUNT2}
109 [ -z "`echo $DIR1 | grep $MOUNT1`" ] && echo "$DIR1 not in $MOUNT1" && exit 96
110 [ -z "`echo $DIR2 | grep $MOUNT2`" ] && echo "$DIR2 not in $MOUNT2" && exit 95
111
112 rm -rf $DIR1/[df][0-9]* $DIR1/lnk
113
114 test_1a() {
115         touch $DIR1/f1
116         [ -f $DIR2/f1 ] || error
117 }
118 run_test 1a "check create on 2 mtpt's =========================="
119
120 test_1b() {
121         chmod 777 $DIR2/f1
122         $CHECKSTAT -t file -p 0777 $DIR1/f1 || error
123         chmod a-x $DIR2/f1
124 }
125 run_test 1b "check attribute updates on 2 mtpt's ==============="
126
127 test_1c() {
128         $CHECKSTAT -t file -p 0666 $DIR1/f1 || error
129 }
130 run_test 1c "check after remount attribute updates on 2 mtpt's ="
131
132 test_1d() {
133         rm $DIR2/f1
134         $CHECKSTAT -a $DIR1/f1 || error
135 }
136 run_test 1d "unlink on one mountpoint removes file on other ===="
137
138 test_2a() {
139         touch $DIR1/f2a
140         ls -l $DIR2/f2a
141         chmod 777 $DIR2/f2a
142         $CHECKSTAT -t file -p 0777 $DIR1/f2a || error
143 }
144 run_test 2a "check cached attribute updates on 2 mtpt's ========"
145
146 test_2b() {
147         touch $DIR1/f2b
148         ls -l $DIR2/f2b
149         chmod 777 $DIR1/f2b
150         $CHECKSTAT -t file -p 0777 $DIR2/f2b || error
151 }
152 run_test 2b "check cached attribute updates on 2 mtpt's ========"
153
154 # NEED TO SAVE ROOT DIR MODE
155 test_2c() {
156         chmod 777 $DIR1
157         $CHECKSTAT -t dir -p 0777 $DIR2 || error
158 }
159 run_test 2c "check cached attribute updates on 2 mtpt's root ==="
160
161 test_2d() {
162         chmod 755 $DIR1
163         $CHECKSTAT -t dir -p 0755 $DIR2 || error
164 }
165 run_test 2c "check cached attribute updates on 2 mtpt's root ==="
166
167 test_3() {
168         ( cd $DIR1 ; ln -s this/is/good lnk )
169         [ "this/is/good" = "`perl -e 'print readlink("'$DIR2/lnk'");'`" ] || \
170                 error
171 }
172 run_test 3 "symlink on one mtpt, readlink on another ==========="
173
174 test_4() {
175         ./multifstat $DIR1/f4 $DIR2/f4
176 }
177 run_test 4 "fstat validation on multiple mount points =========="
178
179 test_5() {
180         mcreate $DIR1/f5
181         truncate $DIR2/f5 100
182         $CHECKSTAT -t file -s 100 $DIR1/f5 || error
183         rm $DIR1/f5
184 }
185 run_test 5 "create a file on one mount, truncate it on the other"
186
187 test_6() {
188         ./openunlink $DIR1/f6 $DIR2/f6 || error
189 }
190 run_test 6 "remove of open file on other node =================="
191
192 test_7() {
193         ./opendirunlink $DIR1/d7 $DIR2/d7 || error
194 }
195 run_test 7 "remove of open directory on other node ============="
196
197 test_8() {
198         ./opendevunlink $DIR1/dev8 $DIR2/dev8 || error
199 }
200 run_test 8 "remove of open special file on other node =========="
201
202 test_9() {
203         MTPT=1
204         > $DIR2/f9
205         for C in a b c d e f g h i j k l; do
206                 DIR=`eval echo \\$DIR$MTPT`
207                 echo -n $C >> $DIR/f9
208                 [ "$MTPT" -eq 1 ] && MTPT=2 || MTPT=1
209         done
210         [ "`cat $DIR1/f9`" = "abcdefghijkl" ] || \
211                 error "`od -a $DIR1/f10` != abcdefghijkl"
212 }
213 run_test 9 "append of file with sub-page size on multiple mounts"
214
215 test_10() {
216         MTPT=1
217         OFFSET=0
218         > $DIR2/f10
219         for C in a b c d e f g h i j k l; do
220                 DIR=`eval echo \\$DIR$MTPT`
221                 echo -n $C | dd of=$DIR/f10 bs=1 seek=$OFFSET count=1
222                 [ "$MTPT" -eq 1 ] && MTPT=2 || MTPT=1
223                 OFFSET=`expr $OFFSET + 1`
224         done
225         [ "`cat $DIR1/f10`" = "abcdefghijkl" ] || \
226                 error "`od -a $DIR1/f10` != abcdefghijkl"
227 }
228 run_test 10 "write of file with sub-page size on multiple mounts "
229
230 test_11() {
231         mkdir $DIR1/d11
232         multiop $DIR1/d11/f O_c &
233         MULTIPID=$!
234         cp -p /bin/ls $DIR1/d11/f
235         $DIR2/d11/f
236         RC=$?
237         kill -USR1 $MULTIPID
238         wait $MULTIPID || error
239         [ $RC -eq 0 ] && error || true
240 }
241 run_test 11 "execution of file opened for write should return error ===="
242
243 test_12() {
244        sh lockorder.sh
245 }
246 run_test 12 "test lock ordering (link, stat, unlink) ==========="
247
248 test_13() {     # bug 2451 - directory coherency
249        rm -rf $DIR1/d13
250        mkdir $DIR1/d13 || error
251        cd $DIR1/d13 || error
252        ls
253        ( touch $DIR1/d13/f13 ) # needs to be a separate shell
254        ls
255        rm -f $DIR2/d13/f13 || error
256        ls 2>&1 | grep f13 && error "f13 shouldn't return an error (1)" || true
257        # need to run it twice
258        ( touch $DIR1/d13/f13 ) # needs to be a separate shell
259        ls
260        rm -f $DIR2/d13/f13 || error
261        ls 2>&1 | grep f13 && error "f13 shouldn't return an error (2)" || true
262 }
263 run_test 13 "test directory page revocation ===================="
264
265 log "cleanup: ======================================================"
266 rm -rf $DIR1/[df][0-9]* $DIR1/lnk || true
267 echo '=========================== finished ==============================='