Whamcloud - gitweb
703d378164b809783ec41d9c5c94553f59310628
[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
7 ALWAYS_EXCEPT=${ALWAYS_EXCEPT:-"8"}
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 [ "$SANITYLOG" ] && rm -f $SANITYLOG || true
92
93 error () {
94         log "FAIL: $@"
95         if [ "$SANITYLOG" ]; then
96                 echo "FAIL: $TESTNAME $@" >> $SANITYLOG
97         else
98                 exit 1
99         fi
100 }
101
102 pass() {
103         echo PASS
104 }
105
106 export MOUNT1=`mount| awk '/ lustre/ { print $3 }'| head -1`
107 export MOUNT2=`mount| awk '/ lustre/ { print $3 }'| tail -1`
108 [ -z "$MOUNT1" ] && error "NAME=$NAME not mounted once"
109 [ "$MOUNT1" = "$MOUNT2" ] && error "NAME=$NAME not mounted twice"
110 [ `mount| awk '/ lustre/ { print $3 }'| wc -l` -ne 2 ] && \
111         error "NAME=$NAME mounted more than twice"
112
113 export DIR1=${DIR1:-$MOUNT1}
114 export DIR2=${DIR2:-$MOUNT2}
115 [ -z "`echo $DIR1 | grep $MOUNT1`" ] && echo "$DIR1 not in $MOUNT1" && exit 96
116 [ -z "`echo $DIR2 | grep $MOUNT2`" ] && echo "$DIR2 not in $MOUNT2" && exit 95
117
118 rm -rf $DIR1/[df][0-9]* $DIR1/lnk
119
120 test_1a() {
121         touch $DIR1/f1
122         [ -f $DIR2/f1 ] || error
123 }
124 run_test 1a "check create on 2 mtpt's =========================="
125
126 test_1b() {
127         chmod 777 $DIR2/f1
128         $CHECKSTAT -t file -p 0777 $DIR1/f1 || error
129         chmod a-x $DIR2/f1
130 }
131 run_test 1b "check attribute updates on 2 mtpt's ==============="
132
133 test_1c() {
134         $CHECKSTAT -t file -p 0666 $DIR1/f1 || error
135 }
136 run_test 1c "check after remount attribute updates on 2 mtpt's ="
137
138 test_1d() {
139         rm $DIR2/f1
140         $CHECKSTAT -a $DIR1/f1 || error
141 }
142 run_test 1d "unlink on one mountpoint removes file on other ===="
143
144 test_2a() {
145         touch $DIR1/f2a
146         ls -l $DIR2/f2a
147         chmod 777 $DIR2/f2a
148         $CHECKSTAT -t file -p 0777 $DIR1/f2a || error
149 }
150 run_test 2a "check cached attribute updates on 2 mtpt's ========"
151
152 test_2b() {
153         touch $DIR1/f2b
154         ls -l $DIR2/f2b
155         chmod 777 $DIR1/f2b
156         $CHECKSTAT -t file -p 0777 $DIR2/f2b || error
157 }
158 run_test 2b "check cached attribute updates on 2 mtpt's ========"
159
160 # NEED TO SAVE ROOT DIR MODE
161 test_2c() {
162         chmod 777 $DIR1
163         $CHECKSTAT -t dir -p 0777 $DIR2 || error
164 }
165 run_test 2c "check cached attribute updates on 2 mtpt's root ==="
166
167 test_2d() {
168         chmod 755 $DIR1
169         $CHECKSTAT -t dir -p 0755 $DIR2 || error
170 }
171 run_test 2d "check cached attribute updates on 2 mtpt's root ==="
172
173 test_3() {
174         ( cd $DIR1 ; ln -s this/is/good lnk )
175         [ "this/is/good" = "`perl -e 'print readlink("'$DIR2/lnk'");'`" ] || \
176                 error
177 }
178 run_test 3 "symlink on one mtpt, readlink on another ==========="
179
180 test_4() {
181         ./multifstat $DIR1/f4 $DIR2/f4
182 }
183 run_test 4 "fstat validation on multiple mount points =========="
184
185 test_5() {
186         mcreate $DIR1/f5
187         truncate $DIR2/f5 100
188         $CHECKSTAT -t file -s 100 $DIR1/f5 || error
189         rm $DIR1/f5
190 }
191 run_test 5 "create a file on one mount, truncate it on the other"
192
193 test_6() {
194         ./openunlink $DIR1/f6 $DIR2/f6 || error
195 }
196 run_test 6 "remove of open file on other node =================="
197
198 test_7() {
199         ./opendirunlink $DIR1/d7 $DIR2/d7 || error
200 }
201 run_test 7 "remove of open directory on other node ============="
202
203 test_8() {
204         ./opendevunlink $DIR1/dev8 $DIR2/dev8 || error
205 }
206 run_test 8 "remove of open special file on other node =========="
207
208 test_9() {
209         MTPT=1
210         > $DIR2/f9
211         for C in a b c d e f g h i j k l; do
212                 DIR=`eval echo \\$DIR$MTPT`
213                 echo -n $C >> $DIR/f9
214                 [ "$MTPT" -eq 1 ] && MTPT=2 || MTPT=1
215         done
216         [ "`cat $DIR1/f9`" = "abcdefghijkl" ] || \
217                 error "`od -a $DIR1/f10` != abcdefghijkl"
218 }
219 run_test 9 "append of file with sub-page size on multiple mounts"
220
221 test_10a() {
222         MTPT=1
223         OFFSET=0
224         > $DIR2/f10
225         for C in a b c d e f g h i j k l; do
226                 DIR=`eval echo \\$DIR$MTPT`
227                 echo -n $C | dd of=$DIR/f10 bs=1 seek=$OFFSET count=1
228                 [ "$MTPT" -eq 1 ] && MTPT=2 || MTPT=1
229                 OFFSET=`expr $OFFSET + 1`
230         done
231         [ "`cat $DIR1/f10`" = "abcdefghijkl" ] || \
232                 error "`od -a $DIR1/f10` != abcdefghijkl"
233 }
234 run_test 10a "write of file with sub-page size on multiple mounts "
235
236 test_10b() {
237         set -vx
238         yes "R" | dd of=$DIR1/f10b bs=3k count=1 || error "dd $DIR1"
239
240         truncate $DIR1/f10b 4096 || error "truncate 4096"
241
242         dd if=$DIR2/f10b of=$TMP/f10b-lustre bs=4k count=1 || error "dd $DIR2"
243
244         # create a test file locally to compare
245         yes "R" | dd of=$TMP/f10b bs=3k count=1 || error "dd random"
246         truncate $TMP/f10b 4096 || error "truncate 4096"
247         cmp $TMP/f10b $TMP/f10b-lustre || error "file miscompare"
248 }
249 run_test 10b "write of file with sub-page size on multiple mounts "
250
251 test_11() {
252         mkdir $DIR1/d11
253         multiop $DIR1/d11/f O_c &
254         MULTIPID=$!
255         usleep 200
256         cp -p /bin/ls $DIR1/d11/f
257         $DIR2/d11/f
258         RC=$?
259         kill -USR1 $MULTIPID
260         wait $MULTIPID || error
261         [ $RC -eq 0 ] && error || true
262 }
263 run_test 11 "execution of file opened for write should return error ===="
264
265 test_12() {
266        sh lockorder.sh
267 }
268 run_test 12 "test lock ordering (link, stat, unlink) ==========="
269
270 test_13() {     # bug 2451 - directory coherency
271        rm -rf $DIR1/d13
272        mkdir $DIR1/d13 || error
273        cd $DIR1/d13 || error
274        ls
275        ( touch $DIR1/d13/f13 ) # needs to be a separate shell
276        ls
277        rm -f $DIR2/d13/f13 || error
278        ls 2>&1 | grep f13 && error "f13 shouldn't return an error (1)" || true
279        # need to run it twice
280        ( touch $DIR1/d13/f13 ) # needs to be a separate shell
281        ls
282        rm -f $DIR2/d13/f13 || error
283        ls 2>&1 | grep f13 && error "f13 shouldn't return an error (2)" || true
284 }
285 run_test 13 "test directory page revocation ===================="
286
287 log "cleanup: ======================================================"
288 rm -rf $DIR1/[df][0-9]* $DIR1/lnk || true
289 echo '=========================== finished ==============================='
290 [ -f "$SANITYLOG" ] && cat $SANITYLOG && exit 1 || true