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 /bin"}
11 [ "$COUNT" ] || COUNT=10000
12 [ "$SLOW" = "no" ] && COUNT=1000
14 [ "$MKDIRMANY" ] || MKDIRMANY="createmany -d"
15 [ "$STATMANY" ] || STATMANY="statmany -s"
16 [ "$RMDIRMANY" ] || RMDIRMANY="unlinkmany -d"
18 check_and_setup_lustre
21 sleep 5 # let MDS refresh aggregated statfs
22 # Include some extra space for the status file
24 echo "usage before starting test"
27 local dfused=$(df -P $DIR | awk '{ print $3 }' | tail -n 1)
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.$$
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"
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"
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"
65 test_mkdir -p $dst || error "can't mkdir $dst"
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
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 " \
77 stack_trap "rm -f $findfiles"
78 COUNT=$(xargs -0 -n 1 echo < $findfiles | wc -l)
80 log "copying $COUNT files from $RUNTESTS_SRC to $dst$RUNTESTS_SRC " \
82 tar cf - --null --files-from $findfiles | \
83 tar xvf - -C $dst > /dev/null || error "copying $RUNTESTS_SRC"
85 log "comparing $COUNT newly copied files at $(date)"
87 cat $findfiles | tr "\0" "\n" | ( rc=0; while read f; do
88 diff -q "$f" "$dst/$f" || rc=18
90 [ "$rc" = 0 ] || error_exit "old and new files are different: rc=$rc" )
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)))"
97 stopall || error "stopall failed"
98 setupall || error "setupall failed"
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
104 [ "$rc" = 0 ] || error_exit "old and new files are different: rc=$rc" )
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"
112 stopall || error "stopall failed (2)"
113 setupall || error "setupall failed (2)"
115 log "running $RMDIRMANY $dst/d $COUNT"
116 $RMDIRMANY $dst/d $COUNT || error "$RMDIRMANY cleanup failed"
119 rm -r $dst || error "can't remove $dst"
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"
137 wait_delete_completed
138 sleep 5 # let MDS refresh aggregated statfs
139 echo "usage after removing all files"
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"
146 log "Space was freed: now ${nowdfused}kB, was ${dfused}kB."
149 run_test 1 "All Runtests"
152 check_and_cleanup_lustre