Whamcloud - gitweb
LU-1538 tests: clean up runtests code style
[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 [ "$MCREATE" ] || MCREATE=mcreate
23
24 [ "$MKDIRMANY" ] || MKDIRMANY="createmany -d"
25 [ "$RMDIRMANY" ] || RMDIRMANY="unlinkmany -d"
26
27 check_and_setup_lustre
28 test_1() {
29 # Include some extra space for the status file
30 USED=$(df -P $DIR | awk '{ print $3 }' | tail -n 1)
31
32 # let's start slowly here...
33 START=$(date +%s)
34 log "touching $DIR at $(date) (@$START)"
35 touch $DIR || error "can't touch $DIR" 2
36 HOSTS=$DIR/hosts.$$
37 TRUNCSIZE=123
38
39 if [ $COUNT -gt 10 -o $COUNT -eq 0 ]; then
40         # this will cause the following cp to trigger bug #620096
41         log "create an empty file $HOSTS"
42         mcreate $HOSTS
43         log "copying /etc/hosts to $HOSTS"
44         cp /etc/hosts $HOSTS || error "can't cp /etc/hosts to $HOSTS" 3
45         log "comparing /etc/hosts and $HOSTS"
46         diff -u /etc/hosts $HOSTS || error "$HOSTS different" 4
47         log "renaming $HOSTS to $HOSTS.ren"
48         mv $HOSTS $HOSTS.ren || error "can't rename $HOSTS to $HOSTS.ren" 5
49         log "copying /etc/hosts to $HOSTS again"
50         cp /etc/hosts $HOSTS || error "can't cp /etc/hosts to $HOSTS again" 6
51         log "truncating $HOSTS"
52         > $HOSTS || error "can't truncate $HOSTS" 8
53         log "removing $HOSTS"
54         rm $HOSTS || error "can't remove $HOSTS" 9
55         log "copying /etc/hosts to $HOSTS.2"
56         cp /etc/hosts $HOSTS.2 || error "can't cp /etc/hosts to $HOSTS.2" 7
57         log "truncating $HOSTS.2 to $TRUNCSIZE bytes"
58         $TRUNCATE $HOSTS.2 $TRUNCSIZE || error "can't truncate $HOSTS.2" 10
59         checkstat -s $TRUNCSIZE $HOSTS.2 ||
60                 error "$HOSTS.2 isn't $TRUNCSIZE bytes" 11
61 fi
62
63 DST=$DIR/$tdir
64 # let's start slowly here...
65 log "creating $DST"
66 test_mkdir -p $DST || error "can't mkdir $DST" 12
67
68 # ok, that hopefully worked, so let's do a little more, with files that
69 # haven't changed in the last day (hopefully they don't change during test)
70 FILES=$TMP/runtests.files
71 # use "NUL" instead of newline as filename terminator, bug 19702 
72 find $RUNTESTS_SRC -type f -mtime +1 | head -n $COUNT | tr '\n' '\0' > $FILES
73 [ -s "$FILES" ] ||
74         error "$RUNTESTS_SRC contains only files modifed less than 2 days ago"
75 COUNT=$(xargs -0 -n 1 echo < $FILES | wc -l)
76
77 log "copying $COUNT files from $RUNTESTS_SRC to $DST$RUNTESTS_SRC at $(date)"
78 tar cf - --null --files-from $FILES | tar xvf - -C $DST > /dev/null ||
79         error "copying $RUNTESTS_SRC" 17
80
81 log "comparing $COUNT newly copied files at $(date)"
82
83 cat $FILES | tr "\0" "\n" | ( rc=0; while read f; do
84         [ $V ] && log "verifying $DST/$f"
85         diff -q "$f" "$DST/$f" || rc=18
86 done
87 [ "$rc" = 0 ] || error_exit "old and new files are different: rc=$rc" ) 
88
89 log "finished at $(date) ($(($(date +%s) - START)))"
90
91 stopall || exit 19
92 setupall || exit 20
93
94 log "comparing $COUNT previously copied files"
95 cat $FILES | tr "\0" "\n" | ( rc=0; while read f; do
96         [ $V ] && log "verifying $DST/$f"
97         diff -q "$f" "$DST/$f" || rc=22
98 done
99 [ "$rc" = 0 ] || error_exit "old and new files are different: rc=$rc" )
100
101 stopall || exit 21
102 setupall || exit 22
103
104 log "removing $DST"
105 rm -r $V $DST || error "can't remove $DST" 37
106
107 if [ $COUNT -gt 10 -o $COUNT -eq 0 ]; then
108         log "renaming $HOSTS.ren to $HOSTS"
109         mv $HOSTS.ren $HOSTS || error "can't rename $HOSTS.ren to $HOSTS" 32
110         log "truncating $HOSTS"
111         > $HOSTS || error "can't truncate $HOSTS" 34
112         log "removing $HOSTS"
113         rm $HOSTS || error "can't remove $HOSTS again" 36
114         log "verifying $HOSTS.2 is $TRUNCSIZE bytes"
115         checkstat -s $TRUNCSIZE $HOSTS.2 || \
116                 error "$HOSTS.2 isn't $TRUNCSIZE bytes" 37
117         rm $HOSTS.2 || error "can't remove $HOSTS.2" 38
118 fi
119
120 # mkdirmany test (bug 589)
121 test_mkdir -p $DST
122 log "running $MKDIRMANY $DST/d 100"
123 $MKDIRMANY $DST/d 100 || error "$MKDIRMANY failed"
124 log "running $RMDIRMANY $DST/d 100"
125 $RMDIRMANY $DST/d 100 || error "$RMDIRMANY cleanup failed"
126
127 log "done"
128
129 wait_delete_completed
130 NOWUSED=$(($(df -P $DIR | awk '{ print $3 }' | tail -n 1)))
131 if [ $(expr $NOWUSED - $USED) -gt 1024 ]; 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