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