Whamcloud - gitweb
land 0.5.20.3 b_devel onto HEAD (b_devel will remain)
[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 SRCDIR="`dirname $0`"
8 fail() { 
9         echo "ERROR: $1" 1>&2
10         [ $2 ] && RC=$2 || RC=1
11         exit $RC
12 }
13
14 log() {
15         echo "$*"
16         lctl mark "$*"
17 }
18
19 export PATH=/sbin:/usr/sbin:$SRCDIR:$SRCDIR/../utils:$PATH
20
21 ERROR=
22 SRC=/etc
23 [ "$COUNT" ] || COUNT=1000
24
25 [ "$LCONF" ] || LCONF=$SRCDIR/../utils/lconf
26
27 [ "$MCREATE" ] || MCREATE=$SRCDIR/../tests/mcreate
28
29 [ "$MKDIRMANY" ] || MKDIRMANY=$SRCDIR/../tests/mkdirmany
30
31 while [ "$1" ]; do
32         case $1 in
33         *.xml) export NAME=`echo $1 | sed "s/.xml//"` ;;
34         esac
35         shift
36 done
37
38 OSCMT="`mount | awk '/ lustre_lite / { print $3 }' | tail -1`"
39 if [ -z "$OSCMT" ]; then
40         sh llmount.sh
41         OSCMT="`mount | awk '/ lustre_lite / { print $3 }' | tail -1`"
42         [ -z "$OSCMT" ] && fail "no lustre filesystem mounted" 1
43         I_MOUNTED="yes"
44 fi
45
46 OSCTMP=`echo $OSCMT | tr "/" "."`
47 USED=`df | awk "/$OSCTMP/ { print \\$3 }" | tail -1`
48 USED=`expr $USED + 16`  # Some space for the status file
49
50 # let's start slowly here...
51 log "touching $OSCMT"
52 touch $OSCMT || fail "can't touch $OSCMT" 2
53 HOSTS=$OSCMT/hosts.$$
54
55 # this will cause the following cp to trigger bug #620096
56 log "create an empty file $HOSTS"
57 mcreate $HOSTS
58
59 log "copying /etc/hosts to $HOSTS"
60 cp /etc/hosts $HOSTS || fail "can't cp /etc/hosts to $HOSTS" 3
61 log "comparing /etc/hosts and $HOSTS"
62 diff -u /etc/hosts $HOSTS || fail "$HOSTS different" 4
63 log "renaming $HOSTS to $HOSTS.ren"
64 mv $HOSTS $HOSTS.ren || fail "can't rename $HOSTS to $HOSTS.ren" 5
65 log "copying /etc/hosts to $HOSTS again"
66 cp /etc/hosts $HOSTS || fail "can't cp /etc/hosts to $HOSTS again" 6
67 log "truncating $HOSTS"
68 > $HOSTS || fail "can't truncate $HOSTS" 8
69 log "removing $HOSTS"
70 rm $HOSTS || fail "can't remove $HOSTS" 9
71
72 DST=$OSCMT/runtest.$$
73 # let's start slowly here...
74 log "creating $DST"
75 mkdir $DST || fail "can't mkdir $DST" 10
76
77 # ok, that hopefully worked, so let's do a little more, with files that
78 # haven't changed in the last day (hopefully they don't change during test)
79 FILES=`find $SRC -type f -mtime +1 -ctime +1 | head -$COUNT`
80 log "copying files from $SRC to $DST$SRC"
81 tar cf - $FILES | tar xvf - -C $DST || fail "copying $SRC" 11
82
83 log "comparing newly copied files"
84 for f in $FILES; do
85         [ $V ] && log "verifying $DST/$f"
86         diff -q $f $DST/$f || ERROR=11
87 done
88
89 [ "$ERROR" ] && fail "old and new files are different" $ERROR
90
91 sh llmountcleanup.sh || exit 19
92 sh llrmount.sh || exit 20
93
94 log "comparing previously copied files"
95 for f in $FILES; do
96         [ $V ] && log "verifying $DST/$f"
97         diff -q $f $DST/$f || ERROR=22
98 done
99
100 [ "$ERROR" ] && fail "old and new files are different on second diff" $ERROR
101
102 sh llmountcleanup.sh || exit 19
103 sh llrmount.sh || exit 20
104
105 log "renaming $HOSTS.ren to $HOSTS"
106 mv $HOSTS.ren $HOSTS || fail "can't rename $HOSTS.ren to $HOSTS" 32
107 log "truncating $HOSTS"
108 > $HOSTS || fail "can't truncate $HOSTS" 34
109 log "removing $HOSTS"
110 rm $HOSTS || fail "can't remove $HOSTS again" 36
111 log "removing $DST"
112 rm -r $V $DST || fail "can't remove $DST" 37
113
114 # mkdirmany test (bug 589)
115 log "running mkdirmany $OSCMT/base$$ 100"
116 $MKDIRMANY $OSCMT/base$$ 100 || fail "mkdirmany failed"
117 log "removing mkdirmany directories"
118 rmdir $OSCMT/base$$* || fail "mkdirmany cleanup failed"
119
120 log "done"
121
122 NOWUSED=`df | awk "/$OSCTMP/ { print \\$3 }" | tail -1`
123 if [ $NOWUSED -gt $USED ]; then
124         echo "Space not all freed: now ${NOWUSED}kB, was ${USED}kB." 1>&2
125         echo "This is normal on BA OSTs, because of subdirectories." 1>&2
126 fi
127
128 if [ "$I_MOUNTED" = "yes" ]; then
129         sh llmountcleanup.sh || exit 29
130 fi