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