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