Minor xfstests tweaks - report kernel version in check as in bench.
[xfstests-dev.git] / tools / auto-qa
1 #!/bin/sh
2 #
3 # Copyright (c) 2000-2003 Silicon Graphics, Inc.  All Rights Reserved.
4
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of version 2 of the GNU General Public License as
7 # published by the Free Software Foundation.
8
9 # This program is distributed in the hope that it would be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 # Further, this software is distributed without any warranty that it is
14 # free of the rightful claim of any third person regarding infringement
15 # or the like.  Any license provided herein, whether implied or
16 # otherwise, applies only to this software file.  Patent licenses, if
17 # any, provided herein do not apply to combinations of this program with
18 # other software, or any other product whatsoever.
19
20 # You should have received a copy of the GNU General Public License along
21 # with this program; if not, write the Free Software Foundation, Inc., 59
22 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
23
24 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
25 # Mountain View, CA  94043, or:
26
27 # http://www.sgi.com 
28
29 # For further information regarding this notice, see: 
30
31 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
32 #
33
34 # automatic qa system. 31/08/00 dxm@sgi.com
35
36 # configuration (you could tune this)
37
38 _log()
39 {
40     echo "$*" >&2
41     echo "$*" >> $LOG
42     sync
43 }
44
45 _fail()
46 {
47     if [ "$started" = "1" ] 
48     then
49         echo "auto-qa stopped" | wall
50         started=0
51     fi
52
53     _log "$*"
54     
55     # send special email if a cron'd qa run fails
56     case $state
57     in
58         cron*)
59             mail -s "XFS QA status report" $EMAIL < $LOG 2>&1
60         ;;
61     esac
62
63     status=1
64     exit 1
65 }
66
67 _get_kernel_version()
68 {
69     [ -x "$KWORKAREA" ] || return
70     [ -r "$KWORKAREA/Makefile" ] \
71         || _fail "can't read kernel makefile $KWORKAREA/Makefile"
72
73     eval `awk '
74         BEGIN { FS = "[ \t=]+" }
75         /^VERSION =/ { a=$2 }
76         /^PATCHLEVEL =/ { b=$2 }
77         /^SUBLEVEL =/ { c=$2 }
78         /^EXTRAVERSION =/ { d=$2 }
79         END { 
80             print "VERSION=" a "." b "." c d " ; SVERSION=" a "." b "." c
81         }
82    ' < $KWORKAREA/Makefile`
83 }
84
85 # this should be constant
86
87 ROOT="$HOME/qa"
88 HOST=`hostname -s`
89 if [ ! -z "$CVSROOT" ]; then
90     export WORKAREA="$ROOT/xfs-cmds"
91 else
92     [ -z "$WORKAREA" ] && export WORKAREA="$ROOT/xfs-cmds"
93 fi
94
95
96 export PATH="/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin/ptools:/usr/local/bin"
97 STATE=$ROOT/qa.state
98 QADIR="$WORKAREA/xfstests"
99 SUDO="su -c"
100 CONFIG="$ROOT/$HOST.config"
101 COMMON_CONFIG="$WORKAREA/xfstests/common.config"
102 SH="/bin/sh"
103 LOG="$ROOT/qa.log"
104
105 # do some cleanup on exit
106
107 _cleanup()
108 {
109     umount $SCRATCH_DEV &> /dev/null
110     umount $TEST_DEV &> /dev/null
111     if [ "$started" = 1 ]
112     then
113         echo "auto-qa stopped" | wall
114         started=0
115     fi
116 }
117 status=1
118 trap "_cleanup; exit \$status" 0 1 2 3 15
119
120 # clean exit
121
122 _success()
123 {
124     status=0
125     exit 0
126 }
127
128 _get_state()
129 {
130     state=`cat $STATE`
131 }
132
133 _set_state()
134 {
135     echo $1 > $STATE
136     _get_state
137 }
138
139 _change_state()
140 {
141     new=$1
142     
143     case $state
144     in
145         *-*)
146             case $new
147             in
148                 *-*)
149                     _set_state $new
150                     ;;
151                 *)
152                     _set_state `echo $state | sed "s/-.*$/-$new/"`
153                     ;;
154             esac
155             ;;
156         *)
157             _set_state $new
158             ;;
159     esac
160 }
161
162 _sudo()
163 {
164     $ROOT/su -c "$*" < /dev/null ;# HACK - we need a hacked su at the mo
165 }
166
167 _restart()
168 {
169     exec $ROOT/su -c "(shutdown -r now \"auto-qa rebooting\" )&" < /dev/null
170 }
171
172 _update_autoqa_file()
173 {
174     SELF="$ROOT/auto-qa"
175     SELF_UPDATE="xfstests/tools/auto-qa"
176     if [ -z "$CVSROOT" ]; then
177             cmd="p_tupdate $SELF_UPDATE"
178     else
179             cmd="cvs -z3 update $SELF_UPDATE"
180     fi
181     exec $SH -c "cd $WORKAREA ; $cmd; chmod +x $SELF_UPDATE ; exec $SELF"
182 }
183
184 _update_workarea()
185 {
186     if [ -z "$CVSROOT" ]; then
187         _log "  *** p_tupdate"
188         cd "$1"
189         WORKAREA="$1" p_tupdate 2>&1 \
190                         || _fail "          !!! p_tupdate failed"
191
192         _log "  *** p_check/p_purge"
193         cd "$1"
194         WORKAREA="$1" p_check -s | p_purge -yiu 2>&1 \
195                         || _fail "          !!! p_check/p_purge failed"
196
197         _log "  *** non-trunk files"
198         cd "$1"
199         WORKAREA="$1" p_list -c 2>&1 \
200                         || _fail "          !!! p_list failed"
201     else
202         _log "  *** cvs update"
203         cd "$1"
204         cvs -z3 update -d
205     fi
206 }
207
208 _test_mkfs_xfs()
209 {
210     TEST_OPTIONS=""
211     [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
212         TEST_OPTIONS="$TEST_OPTIONS -rrtdev=$TEST_RTDEV"
213     [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
214         TEST_OPTIONS="$TEST_OPTIONS -llogdev=$TEST_LOGDEV"
215     _sudo /sbin/mkfs.xfs -f $TEST_OPTIONS $MKFS_OPTIONS $* $TEST_DEV
216     mkfs_status=$?
217     if [ "$USE_BIG_LOOPFS" = yes ]; then
218         [ -z "$RETAIN_AG_BYTES" ] && RETAIN_AG_BYTES=0
219         _sudo $QADIR/tools/ag-wipe -q -r $RETAIN_AG_BYTES $TEST_DEV
220     fi
221     return $mkfs_status
222 }
223
224 _test_mount()
225 {
226     TEST_OPTIONS=""
227     [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
228         TEST_OPTIONS="$TEST_OPTIONS -ortdev=$TEST_RTDEV"
229     [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
230         TEST_OPTIONS="$TEST_OPTIONS -ologdev=$TEST_LOGDEV"
231     _sudo mount -t xfs $TEST_OPTIONS $* $TEST_DEV $TEST_DIR
232 }
233
234 _i386_install()
235 {
236     _sudo cp -f "$KWORKAREA/arch/i386/boot/bzImage" "$IMAGE" 2>&1 \
237                 || _fail "          !!! install kernel failed"
238     _sudo cp -f "$KWORKAREA/System.map" "$SYSTEMMAP" 2>&1 \
239                 || _fail "          !!! install kernel failed"
240     if [ -z "$KMODULES" -o "$KMODULES" = yes ]; then
241         _sudo make EXTRAVERSION=-$EXTRA modules_install 2>&1 \
242                 || _fail "          !!! install modules failed"
243     fi
244
245     if [ -z "$KINSTALL" -o "$KINSTALL" = lilo ]; then
246         _log "  *** reinit lilo"
247         _sudo /sbin/lilo 2>&1 \
248                 || _fail "          !!! reinit lilo failed"
249     fi
250 }
251
252 _i386_restart()
253 {
254     if [ -z "$KINSTALL" -o "$KINSTALL" = lilo ]; then
255         _sudo /sbin/lilo -R $EXTRA $KERNEL_OPTIONS 2>&1 \
256                 || _fail "          !!! lilo failed"
257     fi
258 }
259
260 _ia64_install()
261 {
262     echo not yet implemented
263 }
264
265 _ia64_restart()
266 {
267     echo not yet implemented
268 }
269
270
271 _log "*** XFS QA (`date`)"
272
273 _get_state
274
275 # check preconditions for starting state
276 case $1
277 in
278     cron-init)
279         case $state
280         in
281             *done)
282                 ;;
283             *)
284                 _fail "    !!! cron-init while not in \"*done\" state"
285                 ;;
286         esac
287         ;;
288     cron-restarted)
289         # we don't auto restart after reboot, but cron the restart
290         # to happen a bit later - it's much easier and safer that way
291         if [ "$state" != "cron-restarted" ]
292         then
293             _fail "    !!! cron-restarted while not in \"cron-restarted\" state"
294         fi
295         ;;
296 esac
297
298 if [ "$1" != "" ]
299 then
300     _set_state $1
301 fi
302
303 [ "$UID" -eq 0 ]        && _fail "    !!! QA most be run as a normal user"
304 [ -d "$ROOT" ]          || _fail "    !!! QA root \"$ROOT\" not found"
305 [ -d "$WORKAREA" ]      || _fail "    !!! QA workarea \"$WORKAREA\" not found"
306 [ -r "$CONFIG" ]        || _fail "    !!! Can't read config file $CONFIG"
307 . "$COMMON_CONFIG"      || _fail "    !!! Couldn't source $COMMON_CONFIG"
308
309 _get_kernel_version
310 IMAGE="$BOOT/vmlinuz-$EXTRA"
311 SYSTEMMAP="$BOOT/System.map-$VERSION-$EXTRA"
312 MODULES="/lib/modules/$SVERSION"
313
314 cd $ROOT
315
316 started=1
317 echo "auto-qa started" | wall
318
319 while true
320 do
321     _get_state
322
323     _log "    *** state $state start (`date`)"
324     _log "      (user=$USER, host=$HOST)"
325     new_state=""
326
327     case $state
328     in
329         *init)
330             echo "" > $ROOT/qa.log
331             echo "" > $ROOT/qa.full
332             _log "******************************************************"
333             _log "QA init $VERSION (`date`)"
334             _log "******************************************************"
335             _log "--- kernel ($IMAGE)"
336             [ -z "$KMODULES" -o "$KMODULES" = yes ] && \
337                 _log "--- modules ($MODULES)"
338
339             _change_state "inited"
340             _update_autoqa_file
341             ;;
342             
343         *inited)
344             _log "      *** QA initialized"
345             new_state="update"
346             ;;
347         
348         *update)
349             _update_workarea "$KWORKAREA"
350             _update_workarea "$WORKAREA"
351             new_state="cleantools"
352             ;;
353
354         *cleantools)
355             # we need to configure or else we might fail to clean
356             for pkg in attr acl xfsprogs dmapi xfsdump xfstests
357             do
358                 [ -d $WORKAREA/$pkg ] || continue
359                 cd $WORKAREA/$pkg
360                 _log "  *** clean $pkg tools"
361                 make realclean 2>&1 \
362                         || _fail "          !!! clean $pkg failed"
363             done
364             new_state="buildtools"
365             ;;
366
367         *buildtools)
368             _log "      *** build and install tools"
369             for pkg in attr acl xfsprogs dmapi xfsdump xfstests 
370             do
371                 [ -d $WORKAREA/$pkg ] || continue
372                 cd $WORKAREA/$pkg
373
374                 # use e-fence - but this will only take effect on configure
375                 make configure 2>&1 \
376                         || _fail "          !!! configure $pkg failed"
377                 make default 2>&1 \
378                         || _fail "          !!! build $pkg failed"
379
380                 _sudo make install install-dev 2>&1 \
381                         || _fail "          !!! install $pkg failed"
382
383                 # attr and acl now have install-lib targets as well
384                 [ "$pkg" = "attr" -o "$pkg" = "acl" ] || continue
385                 _sudo make install-lib 2>&1 \
386                         || _fail "          !!! install $pkg failed"
387             done
388
389             new_state="cleankernel"
390             ;;
391
392         *cleankernel)
393             _log "      *** clean kernel"
394             cd "$KWORKAREA"
395             make mrproper 2>&1 \
396                         || _fail "          !!! clean kernel failed"
397
398             _log "      *** install configuration file"
399             cp -f $CONFIG "$KWORKAREA/.config" 2>&1 \
400                         || _fail "          !!! failed to install config"
401             
402             _log "      *** remove version file"
403             rm -f include/linux/version.h 2>&1 \
404                         || _fail "          !!! failed to clean version"
405
406             new_state="reconfig"
407             ;;
408             
409         *reconfig)
410         
411             _log "      *** reconfig kernel"
412             
413             # we better start from scratch if this fails
414             _change_state "cleankernel"
415             
416             cd "$KWORKAREA"
417             # we want to use default options for any new config options.
418             echo -e "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" | \
419                 make EXTRAVERSION=-$EXTRA oldconfig 2>&1 \
420                         || _fail "          !!! reconfig oldconfig failed"
421             make EXTRAVERSION=-$EXTRA dep 2>&1 \
422                         || _fail "          !!! reconfig dep failed"
423
424             new_state="buildkernel"
425             ;;
426             
427         *buildkernel)
428             _log "      *** build kernel"
429             
430             _change_state "clean" ; # we better start from scratch if this fails
431             
432             cd "$KWORKAREA"
433             [ -z "$KTARGET" ] && KTARGET=bzImage
434             [ -z "$KMODULES" -o "$KMODULES" = yes ] && \
435                 KTARGET="$KTARGET modules"
436             make -j4 EXTRAVERSION=-$EXTRA $KTARGET 2>&1 \
437                         || _fail "          !!! build $KTARGET failed"
438             new_state="install"
439             ;;
440
441         *install)
442             _log "      *** blat old modules"
443             _sudo rm -rf $MODULES
444             
445             _log "      *** install kernel"
446             cd "$KWORKAREA"
447             case `uname -m`
448             in
449                 i386|i686)      _i386_install ;;
450                 ia64)           _ia64_install ;;
451             esac
452
453             if [ -z "$KRESTART" -o "$KRESTART" = yes ]; then
454                 new_state="restart"
455             else
456                 new_state="done"
457             fi
458             ;;
459             
460         *restart)
461             _log "          *** select qa kernel"
462             case `uname -m`
463             in
464                 i386|i686)      _i386_restart ;;
465                 ia64)           _ia64_restart ;;
466             esac
467
468             _log "          *** prepare to restart"
469             _change_state "restarted"
470             
471             _log "          *** restarting"
472
473             _restart # doesn't return
474             ;;
475             
476         *restarted)
477             _log "          *** QA reentered after restart"
478             
479             new_state="check"
480             ;;
481           
482         *check)
483             uname=`uname -a`
484             _log "          *** uname $uname"
485
486             if [ "$MODULAR" -eq 0 ]; then
487                 new_state="reset"
488             else
489                 new_state="probe"
490             fi
491             ;;
492             
493         *probe)
494             _log "          *** modules dependencies"
495             _sudo depmod -a  2>&1 \
496                         || _fail "          !!! failed to depmod -a" 
497             
498             _log "          *** unmounting XFS mounts"
499             _sudo umount -a -t xfs 2>&1
500             
501             _log "          *** removing modules"
502             for m in xfsidbg xfs kdbm_pg kdbm_vm
503             do
504                 _sudo rmmod $m 2> /dev/null
505             done
506             
507             _log "          *** installing modules"
508             _sudo modprobe xfs 2>&1 \
509                         || _fail "          !!! failed to modprobe xfs"
510
511             new_state="reset"
512             ;;
513             
514         *reset)
515             
516             _log "          *** unmounting TEST_DEV"
517             _sudo umount $TEST_DEV 2>&1
518             
519             _log "          *** unmounting SCRATCH_DEV"
520             _sudo umount $SCRATCH_DEV 2>&1
521             
522             _log "          *** clean TEST_DEV"
523             _test_mkfs_xfs 2>&1 \
524                         || _fail "          !!! failed to mkfs TEST_DEV"
525             
526             _log "          *** mounting TEST_DEV"
527             _test_mount 2>&1 \
528                         || _fail "          !!! failed to mount"
529                                     
530             new_state="run"
531             ;;
532             
533         soak-run)
534             cd $QADIR
535             
536             _log "          *** run soak test"
537             _sudo ./soak $SOAK_PASSES $SOAK_STRESS $SOAK_PROC \
538                         || _fail "          !!! failed to run soak test"
539
540             new_state="done"
541             ;;
542             
543         bench-run)
544             cd $QADIR
545             
546             # $BENCHMARK is typically unset, which equates to "all"
547             #
548             _log "          *** run benchmarks"
549             _sudo ./bench $BENCH_PASSES `id -nu && id -ng` $BENCHMARK \
550                         || _fail "          !!! failed to run benchmarks"
551
552             _log ""
553             _log "          *** send results mail"
554             mail -s "XFS QA benchmark results" $EMAIL < $QADIR/bench.out 2>&1
555         
556             new_state="done"
557             ;;
558             
559         *run)
560             cd $QADIR
561             
562             _log "          *** run tests ($CHECK_OPTIONS)"
563             _sudo ./check -l $CHECK_OPTIONS 2>&1 | tee $ROOT/qa.out
564             
565             _log ""
566             _log "          *** send status mail"
567             mail -s "XFS QA status report" $EMAIL < $ROOT/qa.out 2>&1
568         
569             new_state="done"
570             ;;
571             
572         *done)
573             _log "*** QA run complete"
574
575             _success
576             ;;
577             
578         *nothing)
579             new_state="done"
580             _log "    *** do nothing"
581             ;;
582             
583         *)
584             _fail "        !!! unknown state $state"
585             ;;
586     esac
587
588     _log "    *** state $state done (`date`)"
589     [ "$new_state" = "" ] && _fail "    !!! no new state set"
590     _change_state $new_state
591     
592 done