3 # Script which does some basic tests to ensure we haven't regressed.
5 LUSTRE=${LUSTRE:-$(dirname $0)/..}
6 . $LUSTRE/tests/test-framework.sh
10 RUNTESTS_SRC=${RUNTESTS_SRC:-"/etc /usr/bin"}
11 RT_SRC_ARR=($RUNTESTS_SRC)
12 [ "$COUNT" ] || COUNT=10000
13 [ "$SLOW" = "no" ] && COUNT=1000
17 [ "$MKDIRMANY" ] || MKDIRMANY="createmany -d"
18 [ "$STATMANY" ] || STATMANY="statmany -s"
19 [ "$RMDIRMANY" ] || RMDIRMANY="unlinkmany -d"
21 check_and_setup_lustre
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"'
30 sleep 5 # let MDS refresh aggregated statfs
31 # Include some extra space for the status file
33 echo "usage before starting test"
36 local dfused=$(df -P $DIR | awk '{ print $3 }' | tail -n 1)
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.$$
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"
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"
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"
74 test_mkdir -p $dst || error "can't mkdir $dst"
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
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 " \
86 stack_trap "rm -f $findfiles"
87 COUNT=$(xargs -0 -n 1 echo < $findfiles | wc -l)
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)"
92 tar cf - --null --files-from $findfiles | \
93 tar xvf - -C $dst > /dev/null || error "copying $RUNTESTS_SRC"
95 log "comparing $COUNT newly copied files at $(date)"
97 cat $findfiles | tr "\0" "\n" | $EXCLUDE_FL | ( rc=0; while read -r f; do
98 diff -q "$f" "$dst/$f" || rc=$?
100 (( rc == 0 )) || error_exit "Before remount. Files differ: rc=$rc" )
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)))"
107 stopall || error "stopall failed"
108 setupall || error "setupall failed"
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=$?
114 (( rc == 0 )) || error_exit "Post remount. Files differ: rc=$rc" )
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"
123 stopall || error "stopall failed (2)"
124 setupall || error "setupall failed (2)"
126 log "After second remount. running $RMDIRMANY $dst/d $COUNT"
127 $RMDIRMANY $dst/d $COUNT || error "$RMDIRMANY cleanup failed"
130 rm -r $dst || error "can't remove $dst"
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"
148 wait_delete_completed
149 sleep 5 # let MDS refresh aggregated statfs
150 echo "usage after removing all files"
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"
157 log "Space was freed: now ${nowdfused}kB, was ${dfused}kB."
160 run_test 1 "All Runtests"
162 complete_test $SECONDS
163 check_and_cleanup_lustre