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