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