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