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