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