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