Whamcloud - gitweb
Call common cleanup function.
[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 export PATH=/sbin:/usr/sbin:$SRCDIR:$PATH
15
16 cleanup() {
17         $LCONF --cleanup --dump /tmp/debug $OPTS
18         trap 0
19 }
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 OSCMT="`mount | awk '/ lustre_lite / { print $3 }' | tail -1`"
30 if [ -z "$OSCMT" ]; then
31         [ -z "$*" ] && fail "usage: $0 [--reformat] <conf>.xml" 1
32         $LCONF $@ || exit 1
33         trap cleanup 0
34         OSCMT="`mount | awk '/ lustre_lite / { print $3 }' | tail -1`"
35         [ -z "$OSCMT" ] && fail "no lustre filesystem mounted" 1
36 fi
37
38 while [ "$1" ]; do
39         case $1 in
40         -v|--verbose) V=-v;;
41         --reformat) : ;;
42         *) OPTS="$OPTS $1" ;;
43         esac
44         shift
45 done
46
47 OSCTMP=`echo $OSCMT | tr "/" "."`
48 USED=`df | awk "/$OSCTMP/ { print \\$3 }" | tail -1`
49 USED=`expr $USED + 16`  # Some space for the status file
50
51 # let's start slowly here...
52 echo "touching $OSCMT"
53 touch $OSCMT || fail "can't touch $OSCMT" 2
54 HOSTS=$OSCMT/hosts.$$
55
56 # this will cause the following cp to trigger bug #620096
57 #echo "create an empty file $HOSTS"
58 #$MCREATE $HOSTS
59
60 echo "copying /etc/hosts to $HOSTS"
61 cp /etc/hosts $HOSTS || fail "can't cp /etc/hosts to $HOSTS" 3
62 echo "comparing /etc/hosts and $HOSTS"
63 diff -u /etc/hosts $HOSTS || fail "$HOSTS different" 4
64 echo "renaming $HOSTS to $HOSTS.ren"
65 mv $HOSTS $HOSTS.ren || fail "can't rename $HOSTS to $HOSTS.ren" 5
66 echo "copying /etc/hosts to $HOSTS again"
67 cp /etc/hosts $HOSTS || fail "can't cp /etc/hosts to $HOSTS again" 6
68 echo "truncating $HOSTS"
69 > $HOSTS || fail "can't truncate $HOSTS" 8
70 echo "removing $HOSTS"
71 rm $HOSTS || fail "can't remove $HOSTS" 9
72
73 DST=$OSCMT/runtest.$$
74 # let's start slowly here...
75 echo "creating $DST"
76 mkdir $DST || fail "can't mkdir $DST" 10
77
78 # ok, that hopefully worked, so let's do a little more
79 FILES=`find $SRC -type f | head -$COUNT`
80 echo "copying files from $SRC to $DST$SRC"
81 tar cf - $FILES | tar xvf - -C $DST || fail "copying $SRC" 11
82
83 echo "comparing newly copied files"
84 for f in $FILES; do
85         [ $V ] && echo "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 cleanup || exit 19
92 $LCONF $OPTS || exit 20
93
94 echo "comparing previously copied files"
95 for f in $FILES; do
96         [ $V ] && echo "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 cleanup || exit 29
103 $LCONF $OPTS || exit 30
104
105 echo "renaming $HOSTS.ren to $HOSTS"
106 mv $HOSTS.ren $HOSTS || fail "can't rename $HOSTS.ren to $HOSTS" 32
107 echo "truncating $HOSTS"
108 > $HOSTS || fail "can't truncate $HOSTS" 34
109 echo "removing $HOSTS"
110 rm $HOSTS || fail "can't remove $HOSTS again" 36
111 echo "removing $DST"
112 rm -r $V $DST || fail "can't remove $DST" 37
113
114 NOWUSED=`df | awk "/$OSCTMP/ { print \\$3 }" | tail -1`
115 if [ $NOWUSED -gt $USED ]; then
116         echo "Space not all freed: now ${NOWUSED}kB, was ${USED}kB." 1>&2
117         echo "This is normal on BA OSTs, because of subdirectories." 1>&2
118 fi
119
120 cleanup $OPTS || exit 29