Whamcloud - gitweb
LU-17744 ldiskfs: mballoc stats fixes
[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
5 LUSTRE=${LUSTRE:-$(dirname $0)/..}
6 . $LUSTRE/tests/test-framework.sh
7 init_test_env $@
8 init_logging
9
10 RUNTESTS_SRC=${RUNTESTS_SRC:-"/etc /bin"}
11 [ "$COUNT" ] || COUNT=10000
12 [ "$SLOW" = "no" ] && COUNT=1000
13
14 [ "$MKDIRMANY" ] || MKDIRMANY="createmany -d"
15 [ "$STATMANY" ] || STATMANY="statmany -s"
16 [ "$RMDIRMANY" ] || RMDIRMANY="unlinkmany -d"
17
18 check_and_setup_lustre
19 force_new_seq_all
20
21 test_1() {
22         sleep 5 # let MDS refresh aggregated statfs
23         # Include some extra space for the status file
24
25         echo "usage before starting test"
26         $LFS df
27         $LFS df -i
28         local dfused=$(df -P $DIR | awk '{ print $3 }' | tail -n 1)
29         local truncsize=123
30
31         # let's start slowly here...
32         local stime=$(date +%s)
33         log "touching $DIR at $(date) (@$stime)"
34         touch $DIR || error "can't touch $DIR"
35         local hfile=$DIR/hosts.$$
36
37         if [ $COUNT -gt 10 -o $COUNT -eq 0 ]; then
38                 # this will cause the following cp to trigger bug #620096
39                 log "create an empty file $hfile"
40                 mcreate $hfile
41                 log "copying /etc/hosts to $hfile"
42                 cp /etc/hosts $hfile || error "can't cp /etc/hosts to $hfile"
43                 log "comparing /etc/hosts and $hfile"
44                 diff -u /etc/hosts $hfile || error "$hfile different"
45                 log "renaming $hfile to $hfile.ren"
46                 mv $hfile $hfile.ren ||
47                         error "can't rename $hfile to $hfile.ren"
48                 log "copying /etc/hosts to $hfile again"
49                 cp /etc/hosts $hfile ||
50                         error "can't cp /etc/hosts to $hfile again"
51                 log "truncating $hfile"
52                 > $hfile || error "can't truncate $hfile"
53                 log "removing $hfile"
54                 rm $hfile || error "can't remove $hfile"
55                 log "copying /etc/hosts to $hfile.2"
56                 cp /etc/hosts $hfile.2 ||
57                         error "can't cp /etc/hosts to $hfile.2"
58                 log "truncating $hfile.2 to $truncsize bytes"
59                 $TRUNCATE $hfile.2 $truncsize || error "can't truncate $hfile.2"
60                 checkstat -s $truncsize $hfile.2 ||
61                         error "$hfile.2 isn't $truncsize bytes"
62         fi
63
64         local dst=$DIR/$tdir
65         log "creating $dst"
66         test_mkdir -p $dst || error "can't mkdir $dst"
67
68         # let's do a little more, with files that haven't changed in the
69         # last day (hopefully they don't change during test)
70         local findfiles=$TMP/runtests.files
71
72         # use "NUL" instead of newline as filename terminator, bug 19702
73         find $RUNTESTS_SRC -type f -mtime +1 | head -n $COUNT | \
74               tr '\n' '\0' > $findfiles
75         [ -s "$findfiles" ] ||
76                 error "$RUNTESTS_SRC contains only files modifed less than " \
77                       "2 days ago"
78         stack_trap "rm -f $findfiles"
79         COUNT=$(xargs -0 -n 1 echo < $findfiles | wc -l)
80
81         log "copying $COUNT files from $RUNTESTS_SRC to $dst$RUNTESTS_SRC " \
82             "at $(date)"
83         tar cf - --null --files-from $findfiles | \
84                 tar xvf - -C $dst > /dev/null || error "copying $RUNTESTS_SRC"
85
86         log "comparing $COUNT newly copied files at $(date)"
87
88         cat $findfiles | tr "\0" "\n" | ( rc=0; while read -r f; do
89                 diff -q "$f" "$dst/$f" || rc=18
90         done
91         [ "$rc" = 0 ] || error_exit "old and new files are different: rc=$rc" )
92
93         # mkdirmany test (bug 589)
94         log "running $MKDIRMANY $dst/d $COUNT"
95         $MKDIRMANY $dst/d $COUNT || error "$MKDIRMANY failed"
96         log "finished at $(date) ($(($(date +%s) - stime)))"
97
98         stopall || error "stopall failed"
99         setupall || error "setupall failed"
100
101         log "comparing $COUNT previously copied files"
102         cat $findfiles | tr "\0" "\n" | ( rc=0; while read -r f; do
103                 diff -q "$f" "$dst/$f" || rc=22
104         done
105         [ "$rc" = 0 ] || error_exit "old and new files are different: rc=$rc" )
106
107         log "running $STATMANY $dst/d $COUNT $((COUNT * 2))"
108         $STATMANY $dst/d $COUNT $((COUNT * 2)) ||
109                 error "$STATMANY $dst/d failed"
110         echo "usage after creating all files"
111         $LFS df
112         $LFS df -i
113         stopall || error "stopall failed (2)"
114         setupall || error "setupall failed (2)"
115
116         log "running $RMDIRMANY $dst/d $COUNT"
117         $RMDIRMANY $dst/d $COUNT || error "$RMDIRMANY cleanup failed"
118
119         log "removing $dst"
120         rm -r $dst || error "can't remove $dst"
121
122         if [ $COUNT -gt 10 -o $COUNT -eq 0 ]; then
123                 log "renaming $hfile.ren to $hfile"
124                 mv $hfile.ren $hfile ||
125                         error "can't rename $hfile.ren to $hfile"
126                 log "truncating $hfile"
127                 > $hfile || error "can't truncate $hfile"
128                 log "removing $hfile"
129                 rm $hfile || error "can't remove $hfile again"
130                 log "verifying $hfile.2 is $truncsize bytes"
131                 checkstat -s $truncsize $hfile.2 ||
132                         error "$hfile.2 isn't $truncsize bytes"
133                 rm $hfile.2 || error "can't remove $hfile.2"
134         fi
135
136         log "done"
137
138         wait_delete_completed
139         sleep 5 # let MDS refresh aggregated statfs
140         echo "usage after removing all files"
141         $LFS df
142         $LFS df -i
143         local nowdfused=$(($(df -P $DIR | awk '{ print $3 }' | tail -n 1)))
144         if [ $(expr $nowdfused - $dfused) -gt $(fs_log_size) ]; then
145                 error "Space not all freed: now ${nowdfused}kB, was ${dfused}kB"
146         else
147                 log "Space was freed: now ${nowdfused}kB, was ${dfused}kB."
148         fi
149 }
150 run_test 1 "All Runtests"
151
152 complete_test $SECONDS
153 check_and_cleanup_lustre
154 exit_status