Whamcloud - gitweb
mdd: little cleanup.
[fs/lustre-release.git] / lustre / tests / runtests
1 #!/bin/sh
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 . $LUSTRE/tests/test-framework.sh
12 init_test_env $@
13 . ${CONFIG:=$LUSTRE/tests/cfg/local.sh}
14
15 SETUP=${SETUP:-setupall}
16 FORMAT=${FORMAT:-formatall}
17 CLEANUP=${CLEANUP:-stopall}
18
19 fail() { 
20         echo "ERROR: $1" 1>&2
21         [ $2 ] && RC=$2 || RC=1
22         exit $RC
23 }
24
25 log() {
26         echo "$*"
27         lctl mark "$*"
28 }
29
30
31 ERROR=
32 SRC=/etc
33 [ "$COUNT" ] || COUNT=1000
34
35 [ "$MCREATE" ] || MCREATE=mcreate
36
37 [ "$MKDIRMANY" ] || MKDIRMANY="createmany -d"
38
39 while [ "$1" ]; do
40         case $1 in
41         *.xml) export NAME=`echo $1 | sed "s/.xml//"` ;;
42         *) OPTS="$OPTS $1" ;;
43         esac
44         shift
45 done
46
47 EXISTING_MOUNT=`awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts`
48 if [ -z "$EXISTING_MOUNT" ]; then
49         $FORMAT
50         $SETUP
51         EXISTING_MOUNT=`awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts`
52         [ -z "$EXISTING_MOUNT" ] && fail "no lustre filesystem mounted" 1
53         I_MOUNTED="yes"
54 fi
55 MOUNT=$EXISTING_MOUNT
56
57 OSCTMP=`echo $MOUNT | tr "/" "."`
58 USED=`df | awk "/$OSCTMP/ { print \\$3 }" | tail -n 1`
59 USED=`expr $USED + 16`  # Some space for the status file
60
61 # let's start slowly here...
62 START=`date +%s`
63 log "touching $MOUNT at `date`"
64 touch $MOUNT || fail "can't touch $MOUNT" 2
65 HOSTS=$MOUNT/hosts.$$
66
67 if [ $COUNT -gt 10 -o $COUNT -eq 0 ]; then
68         # this will cause the following cp to trigger bug #620096
69         log "create an empty file $HOSTS"
70         mcreate $HOSTS
71         log "copying /etc/hosts to $HOSTS"
72         cp /etc/hosts $HOSTS || fail "can't cp /etc/hosts to $HOSTS" 3
73         log "comparing /etc/hosts and $HOSTS"
74         diff -u /etc/hosts $HOSTS || fail "$HOSTS different" 4
75         log "renaming $HOSTS to $HOSTS.ren"
76         mv $HOSTS $HOSTS.ren || fail "can't rename $HOSTS to $HOSTS.ren" 5
77         log "copying /etc/hosts to $HOSTS again"
78         cp /etc/hosts $HOSTS || fail "can't cp /etc/hosts to $HOSTS again" 6
79         log "truncating $HOSTS"
80         > $HOSTS || fail "can't truncate $HOSTS" 8
81         log "removing $HOSTS"
82         rm $HOSTS || fail "can't remove $HOSTS" 9
83 fi
84
85 DST=$MOUNT/runtest.$$
86 # let's start slowly here...
87 log "creating $DST"
88 mkdir $DST || fail "can't mkdir $DST" 10
89
90 # ok, that hopefully worked, so let's do a little more, with files that
91 # haven't changed in the last day (hopefully they don't change during test)
92 FILES=`find $SRC -type f -mtime +1 -ctime +1 | head -n $COUNT`
93 log "copying files from $SRC to $DST$SRC at `date`"
94 tar cf - $FILES | tar xvf - -C $DST > /dev/null || fail "copying $SRC" 11
95
96 log "comparing newly copied files at `date`"
97 for f in $FILES; do
98         [ $V ] && log "verifying $DST/$f"
99         diff -q $f $DST/$f || ERROR=11
100 done
101
102 [ "$ERROR" ] && fail "old and new files are different" $ERROR
103 log "finished at `date` ($(($(date +%s) - START)))"
104
105 $CLEANUP || exit 19
106 $SETUP || exit 20
107
108 log "comparing previously copied files"
109 for f in $FILES; do
110         [ $V ] && log "verifying $DST/$f"
111         diff -q $f $DST/$f || ERROR=22
112 done
113
114 [ "$ERROR" ] && fail "old and new files are different on second diff" $ERROR
115
116 $CLEANUP || exit 19
117 $SETUP || exit 20
118
119 log "removing $DST"
120 rm -r $V $DST || fail "can't remove $DST" 37
121
122 if [ $COUNT -gt 10 -o $COUNT -eq 0 ]; then
123         log "renaming $HOSTS.ren to $HOSTS"
124         mv $HOSTS.ren $HOSTS || fail "can't rename $HOSTS.ren to $HOSTS" 32
125         log "truncating $HOSTS"
126         > $HOSTS || fail "can't truncate $HOSTS" 34
127         log "removing $HOSTS"
128         rm $HOSTS || fail "can't remove $HOSTS again" 36
129 fi
130
131 # mkdirmany test (bug 589)
132 log "running $MKDIRMANY $MOUNT/base$$ 100"
133 $MKDIRMANY $MOUNT/base$$ 100 || fail "mkdirmany failed"
134 log "removing mkdirmany directories"
135 rmdir $MOUNT/base$$* || fail "mkdirmany cleanup failed"
136
137 log "done"
138
139 NOWUSED=`df | awk "/$OSCTMP/ { print \\$3 }" | tail -n 1`
140 if [ `expr $NOWUSED - $USED` -gt 1024 ]; then
141         echo "Space not all freed: now ${NOWUSED}kB, was ${USED}kB." 1>&2
142 fi
143
144 if [ "$I_MOUNTED" = "yes" ]; then
145         sync && sleep 2 && sync     # wait for delete thread
146         $CLEANUP
147 fi