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