Whamcloud - gitweb
dd645606161125bc3470d183ff204ef2d403944c
[fs/lustre-release.git] / lustre / tests / runtests
1 #!/bin/bash
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 init_logging
17
18 RUNTESTS_SRC=${RUNTESTS_SRC:-"/etc /bin"}
19 [ "$COUNT" ] || COUNT=10000
20 [ "$SLOW" = "no" ] && COUNT=1000
21
22 [ "$MKDIRMANY" ] || MKDIRMANY="createmany -d"
23 [ "$RMDIRMANY" ] || RMDIRMANY="unlinkmany -d"
24
25 check_and_setup_lustre
26 test_1() {
27 sleep 5 # let MDS refresh aggregated statfs
28 # Include some extra space for the status file
29 USED=$(df -P $DIR | awk '{ print $3 }' | tail -n 1)
30
31 # let's start slowly here...
32 START=$(date +%s)
33 log "touching $DIR at $(date) (@$START)"
34 touch $DIR || error "can't touch $DIR" 2
35 HOSTS=$DIR/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         log "copying /etc/hosts to $HOSTS.2"
55         cp /etc/hosts $HOSTS.2 || error "can't cp /etc/hosts to $HOSTS.2" 7
56         log "truncating $HOSTS.2 to $TRUNCSIZE bytes"
57         $TRUNCATE $HOSTS.2 $TRUNCSIZE || error "can't truncate $HOSTS.2" 10
58         checkstat -s $TRUNCSIZE $HOSTS.2 ||
59                 error "$HOSTS.2 isn't $TRUNCSIZE bytes" 11
60 fi
61
62 DST=$DIR/$tdir
63 # let's start slowly here...
64 log "creating $DST"
65 test_mkdir -p $DST || error "can't mkdir $DST" 12
66
67 # ok, that hopefully worked, so let's do a little more, with files that
68 # haven't changed in the last day (hopefully they don't change during test)
69 FILES=$TMP/runtests.files
70 # use "NUL" instead of newline as filename terminator, bug 19702 
71 find $RUNTESTS_SRC -type f -mtime +1 | head -n $COUNT | tr '\n' '\0' > $FILES
72 [ -s "$FILES" ] ||
73         error "$RUNTESTS_SRC contains only files modifed less than 2 days ago"
74 COUNT=$(xargs -0 -n 1 echo < $FILES | wc -l)
75
76 log "copying $COUNT files from $RUNTESTS_SRC to $DST$RUNTESTS_SRC at $(date)"
77 tar cf - --null --files-from $FILES | tar xvf - -C $DST > /dev/null ||
78         error "copying $RUNTESTS_SRC" 17
79
80 log "comparing $COUNT newly copied files at $(date)"
81
82 cat $FILES | tr "\0" "\n" | ( rc=0; while read f; do
83         [ $V ] && log "verifying $DST/$f"
84         diff -q "$f" "$DST/$f" || rc=18
85 done
86 [ "$rc" = 0 ] || error_exit "old and new files are different: rc=$rc" ) 
87
88 log "finished at $(date) ($(($(date +%s) - START)))"
89
90 stopall || exit 19
91 setupall || exit 20
92
93 log "comparing $COUNT previously copied files"
94 cat $FILES | tr "\0" "\n" | ( rc=0; while read f; do
95         [ $V ] && log "verifying $DST/$f"
96         diff -q "$f" "$DST/$f" || rc=22
97 done
98 [ "$rc" = 0 ] || error_exit "old and new files are different: rc=$rc" )
99
100 stopall || exit 21
101 setupall || exit 22
102
103 log "removing $DST"
104 rm -r $V $DST || error "can't remove $DST" 37
105
106 if [ $COUNT -gt 10 -o $COUNT -eq 0 ]; then
107         log "renaming $HOSTS.ren to $HOSTS"
108         mv $HOSTS.ren $HOSTS || error "can't rename $HOSTS.ren to $HOSTS" 32
109         log "truncating $HOSTS"
110         > $HOSTS || error "can't truncate $HOSTS" 34
111         log "removing $HOSTS"
112         rm $HOSTS || error "can't remove $HOSTS again" 36
113         log "verifying $HOSTS.2 is $TRUNCSIZE bytes"
114         checkstat -s $TRUNCSIZE $HOSTS.2 || \
115                 error "$HOSTS.2 isn't $TRUNCSIZE bytes" 37
116         rm $HOSTS.2 || error "can't remove $HOSTS.2" 38
117 fi
118
119 # mkdirmany test (bug 589)
120 test_mkdir -p $DST
121 log "running $MKDIRMANY $DST/d 100"
122 $MKDIRMANY $DST/d 100 || error "$MKDIRMANY failed"
123 log "running $RMDIRMANY $DST/d 100"
124 $RMDIRMANY $DST/d 100 || error "$RMDIRMANY cleanup failed"
125
126 log "done"
127
128 wait_delete_completed
129 sleep 5 # let MDS refresh aggregated statfs
130 NOWUSED=$(($(df -P $DIR | awk '{ print $3 }' | tail -n 1)))
131 if [ $(expr $NOWUSED - $USED) -gt $(fs_log_size) ]; then
132         error "Space not all freed: now ${NOWUSED}kB, was ${USED}kB."
133 else
134         log "Space was freed: now ${NOWUSED}kB, was ${USED}kB."
135 fi
136 }
137 run_test 1 "All Runtests"
138
139 complete $SECONDS
140 rm -f $FILES
141 check_and_cleanup_lustre
142 exit_status