Whamcloud - gitweb
LU-1770 ptlrpc: introducing OBD_CONNECT_FLOCK_OWNER flag
[fs/lustre-release.git] / lustre / tests / runtests
1 #!/bin/bash
2 #
3 # Script which does some basic tests to ensure we haven't regressed.
4 # Probably a good idea to run this before doing any checkins.
5 # In the future this can become more fancy, but it's OK for now.
6
7 LUSTRE=${LUSTRE:-`dirname $0`/..}
8 SRCDIR="`dirname $0`"
9 export PATH=/sbin:/usr/sbin:$SRCDIR:$SRCDIR/../utils:$PATH
10
11 export NAME=${NAME:-local}
12
13 . $LUSTRE/tests/test-framework.sh
14 init_test_env $@
15 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
16 init_logging
17
18 RUNTESTS_SRC=${RUNTESTS_SRC:-"/etc /bin"}
19 [ "$COUNT" ] || COUNT=10000
20 [ "$SLOW" = "no" ] && COUNT=1000
21
22 [ "$MCREATE" ] || MCREATE=mcreate
23
24 [ "$MKDIRMANY" ] || MKDIRMANY="createmany -d"
25
26 check_and_setup_lustre
27
28 OSCTMP=`echo $MOUNT | tr "/" "."`
29 USED=`df | awk "/$OSCTMP/ { print \\$3 }" | tail -n 1`
30 USED=`expr $USED + 16`  # Some space for the status file
31
32 # let's start slowly here...
33 START=`date +%s`
34 log "touching $MOUNT at `date`"
35 touch $MOUNT || error "can't touch $MOUNT" 2
36 HOSTS=$MOUNT/hosts.$$
37 TRUNCSIZE=123
38
39 if [ $COUNT -gt 10 -o $COUNT -eq 0 ]; then
40         # this will cause the following cp to trigger bug #620096
41         log "create an empty file $HOSTS"
42         mcreate $HOSTS
43         log "copying /etc/hosts to $HOSTS"
44         cp /etc/hosts $HOSTS || error "can't cp /etc/hosts to $HOSTS" 3
45         log "comparing /etc/hosts and $HOSTS"
46         diff -u /etc/hosts $HOSTS || error "$HOSTS different" 4
47         log "renaming $HOSTS to $HOSTS.ren"
48         mv $HOSTS $HOSTS.ren || error "can't rename $HOSTS to $HOSTS.ren" 5
49         log "copying /etc/hosts to $HOSTS again"
50         cp /etc/hosts $HOSTS || error "can't cp /etc/hosts to $HOSTS again" 6
51         log "truncating $HOSTS"
52         > $HOSTS || error "can't truncate $HOSTS" 8
53         log "removing $HOSTS"
54         rm $HOSTS || error "can't remove $HOSTS" 9
55         cp /etc/hosts $HOSTS.2 || error "can't cp /etc/hosts to $HOSTS.2" 7
56         log "truncating $HOSTS.2 to $TRUNCSIZE bytes"
57         $TRUNCATE $HOSTS.2 $TRUNCSIZE
58 fi
59
60 DST=$MOUNT/runtest.$$
61 # let's start slowly here...
62 log "creating $DST"
63 mkdir $DST || error "can't mkdir $DST" 10
64
65 # ok, that hopefully worked, so let's do a little more, with files that
66 # haven't changed in the last day (hopefully they don't change during test)
67 FILES=$TMP/runtests.files
68 # use "NUL" instead of newline as filename terminator, bug 19702 
69 find $RUNTESTS_SRC -type f -mtime +1 | head -n $COUNT | tr '\n' '\0' > $FILES
70 [ -s "$FILES" ] ||
71         error "$RUNTESTS_SRC contains only files modifed less than 2 days ago"
72 COUNT=$(xargs -0 -n 1 echo < $FILES | wc -l)
73
74 log "copying $COUNT files from $RUNTESTS_SRC to $DST$RUNTESTS_SRC at `date`"
75 tar cf - --null --files-from $FILES | tar xvf - -C $DST > /dev/null ||
76         error "copying $RUNTESTS_SRC" 11
77
78 log "comparing $COUNT newly copied files at `date`"
79
80 cat $FILES | tr "\0" "\n" | ( rc=0; while read f; do
81         [ $V ] && log "verifying $DST/$f"
82         diff -q "$f" "$DST/$f" || rc=11
83 done
84 [ "$rc" = 0 ] || error_exit "old and new files are different: rc=$rc" ) 
85
86 log "finished at `date` ($(($(date +%s) - START)))"
87
88 stopall || exit 19
89 setupall || exit 20
90
91 log "comparing $COUNT previously copied files"
92 cat $FILES | tr "\0" "\n" | ( rc=0; while read f; do
93         [ $V ] && log "verifying $DST/$f"
94         diff -q "$f" "$DST/$f" || rc=22
95 done
96 [ "$rc" = 0 ] || error_exit "old and new files are different: rc=$rc" )
97
98 stopall || exit 21
99 setupall || exit 22
100
101 log "removing $DST"
102 rm -r $V $DST || error "can't remove $DST" 37
103
104 if [ $COUNT -gt 10 -o $COUNT -eq 0 ]; then
105         log "renaming $HOSTS.ren to $HOSTS"
106         mv $HOSTS.ren $HOSTS || error "can't rename $HOSTS.ren to $HOSTS" 32
107         log "truncating $HOSTS"
108         > $HOSTS || error "can't truncate $HOSTS" 34
109         log "removing $HOSTS"
110         rm $HOSTS || error "can't remove $HOSTS again" 36
111         log "verifying $HOSTS.2 is $TRUNCSIZE bytes"
112         checkstat -s $TRUNCSIZE $HOSTS.2 || \
113                 error "$HOSTS.2 isn't $TRUNCSIZE bytes" 37
114         rm $HOSTS.2 || error "can't remove $HOSTS.2" 38
115 fi
116
117 # mkdirmany test (bug 589)
118 log "running $MKDIRMANY $MOUNT/base$$ 100"
119 $MKDIRMANY $MOUNT/base$$ 100 || error "mkdirmany failed"
120 log "removing $MKDIRMANY directories"
121 rmdir $MOUNT/base$$* || error "mkdirmany cleanup failed"
122
123 log "done"
124
125 NOWUSED=`df | awk "/$OSCTMP/ { print \\$3 }" | tail -n 1`
126 if [ `expr $NOWUSED - $USED` -gt 1024 ]; then
127         echo "Space not all freed: now ${NOWUSED}kB, was ${USED}kB." 1>&2
128 fi
129
130 complete $SECONDS
131 rm -f $FILES
132 check_and_cleanup_lustre
133 exit_status