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