2efca68652e39b09c0f6ed9a8fb0585ad5c2cad8
[xfstests-dev.git] / tools / auto-qa
1 #!/bin/sh
2 #
3 # Copyright (c) 2000 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 EXTRA="-xfs-qa"
39 BOOT="/boot"
40 SOAK_PASSES="-1"
41 SOAK_STRESS="10000"
42 SOAK_PROC="3"
43
44
45 _log()
46 {
47     echo "$*" >&2
48     echo "$*" >> $LOG
49 }
50
51 _fail()
52 {
53     if [ "$started" = "1" ] 
54     then
55         echo "auto-qa stopped" | wall
56         started=0
57     fi
58
59     _log "$*"
60     
61     # send special email if a cron'd qa run fails
62     case $state
63     in
64         cron*)
65             mail -s "xfs qa status report" $ADMINEMAIL \
66                 < $LOG 2>&1
67         ;;
68     esac
69
70     status=1
71     exit 1
72 }
73
74 _get_kernel_version()
75 {
76     [ -x $WORKAREA ] \
77         || _fail "can't access workarea $WORKAREA"
78     [ -r $WORKAREA/linux/Makefile ] \
79         || _fail "can't read makefile $WORKAREA/linux/Makefile"
80
81     eval `awk '
82         BEGIN { FS = "[ \t=]+" }
83         /^VERSION =/ { a=$2 }
84         /^PATCHLEVEL =/ { b=$2 }
85         /^SUBLEVEL =/ { c=$2 }
86         /^EXTRAVERSION =/ { d=$2 }
87         END { 
88             print "VERSION=" a "." b "." c d " ; SVERSION=" a "." b "." c
89         }
90    ' < $WORKAREA/linux/Makefile`
91 }
92
93 # this should be constant
94
95 ROOT="$HOME/qa"
96 HOST=`hostname -s`
97 if [ ! -z "$CVSROOT" ]; then
98     WORKAREA="$ROOT/linux-2.4-xfs"
99 else
100     [ -z "$WORKAREA" ] && WORKAREA="$ROOT/linux-xfs"
101 fi
102 export WORKAREA
103
104
105 export PATH="/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin/ptools:/usr/local/bin"
106 STATE=$ROOT/qa.state
107 QADIR="$WORKAREA/cmd/xfstests"
108 SUDO="su -c"
109 CONFIG="$ROOT/$HOST.config"
110 COMMON_CONFIG="$WORKAREA/cmd/xfstests/common.config"
111 SH="/bin/sh"
112 LOG="$ROOT/qa.log"
113
114 # need to add auto-qa hosts here
115
116 case $HOST
117 in
118     fuzzy)
119         EMAIL="dxm@larry"
120         ADMINEMAIL="dxm@larry"
121         MODULAR=1
122         ;;
123     bruce)
124         EMAIL="dxm@larry"
125         ADMINEMAIL="dxm@larry"
126         MODULAR=1
127         ;;
128     sagan)
129         EMAIL="dxm@larry"
130         ADMINEMAIL="dxm@larry"
131         MODULAR=0
132         ;;
133     troppo)
134         EMAIL="nathans@larry"
135         ADMINEMAIL="nathans@larry"
136         MODULAR=0
137         ;;
138     goldfish)
139         EMAIL="nathans@larry"
140         ADMINEMAIL="nathans@larry"
141         MODULAR=1
142         ;;
143     *)
144         _fail "auto-qa: no configuration information for host '$HOST'"
145         ;;
146 esac
147
148 # do some cleanup on exit
149
150 _cleanup()
151 {
152     umount $SCRATCH_DEV &> /dev/null
153     umount $TEST_DEV &> /dev/null
154     if [ "$started" = 1 ]
155     then
156         echo "auto-qa stopped" | wall
157         started=0
158     fi
159 }
160 status=1
161 trap "_cleanup; exit \$status" 0 1 2 3 15
162
163 # clean exit
164
165 _success()
166 {
167     status=0
168     exit 0
169 }
170
171 _get_state()
172 {
173     state=`cat $STATE`
174 }
175
176 _set_state()
177 {
178     echo $1 > $STATE
179     _get_state
180 }
181
182 _change_state()
183 {
184     new=$1
185     
186     case $state
187     in
188         *-*)
189             case $new
190             in
191                 *-*)
192                     _set_state $new
193                     ;;
194                 *)
195                     _set_state `echo $state | sed "s/-.*$/-$new/"`
196                     ;;
197             esac
198             ;;
199         *)
200             _set_state $new
201             ;;
202     esac
203 }
204
205 _sudo()
206 {
207     $ROOT/su -c "$*" < /dev/null ;# HACK - we need a hacked su at the mo
208 }
209
210 _restart()
211 {
212     # erk - why won't this thing reboot reliably??
213     exec $ROOT/su -c "(shutdown -r 2 \"auto-qa rebooting\" ; sleep 10 ; reboot ; sleep 10 ; reboot )&" < /dev/null
214 }
215
216 _update_autoqa_file()
217 {
218     SELF="$ROOT/auto-qa"
219     SELF_UPDATE="cmd/xfstests/tools/auto-qa"
220     if [ -z "$CVSROOT" ]; then
221             cmd="p_tupdate $SELF_UPDATE"
222     else
223             cmd="cvs -z3 update $SELF_UPDATE"
224     fi
225     exec $SH -c "cd $WORKAREA ; $cmd; chmod +x $SELF_UPDATE ; exec $SELF"
226 }
227
228 _update_workarea()
229 {
230     if [ -z "$CVSROOT" ]; then
231         _log "        *** p_tupdate"
232         cd $WORKAREA 
233         p_tupdate 2>&1 \
234                         || _fail "            !!! p_tupdate failed"
235
236         _log "        *** p_check/p_purge"
237         cd $WORKAREA 
238         p_check -s | p_purge -yiu 2>&1 \
239                         || _fail "            !!! p_check/p_purge failed"
240
241         _log "        *** non-trunk files"
242         cd $WORKAREA 
243         p_list -c 2>&1 \
244                         || _fail "            !!! p_list failed"
245     else
246         _log "        *** cvs update"
247         cd $WORKAREA
248         cvs -z3 update -d
249     fi
250 }
251             
252
253 _log "*** linux-xfs QA (`date`)"
254
255 _get_state
256
257 # check preconditions for starting state
258 case $1
259 in
260     cron-init)
261         case $state
262         in
263             *done)
264                 ;;
265             *)
266                 _fail "    !!! cron-init while not in \"*done\" state"
267                 ;;
268         esac
269         ;;
270     cron-restarted)
271         # we don't auto restart after reboot, but cron the restart
272         # to happen a bit later - it's much easier and safer that way
273         if [ $state != "cron-restarted" ]
274         then
275             _fail "    !!! cron-restarted while not in \"cron-restarted\" state"
276         fi
277         ;;
278 esac
279
280 if [ "$1" != "" ]
281 then
282     _set_state $1
283 fi
284
285 [ $UID -eq 0 ]          && _fail "    !!! QA most be run as a normal user"
286 [ -d $ROOT ]            || _fail "    !!! QA root \"$ROOT\" not found"
287 [ -d $WORKAREA ]        || _fail "    !!! QA workarea \"$WORKAREA\" not found"
288 [ -r $CONFIG ]          || _fail "    !!! Can't read config file $CONFIG"
289 . $COMMON_CONFIG        || _fail "    !!! Couldn't source $COMMON_CONFIG"
290
291 _get_kernel_version
292 IMAGE="$BOOT/vmlinuz$EXTRA"
293 SYSTEMMAP="$BOOT/System.map-$VERSION$EXTRA"
294 MODULES="/lib/modules/$SVERSION"
295
296 cd $ROOT
297
298 started=1
299 echo "auto-qa started" | wall
300
301 while true
302 do
303     _get_state
304
305     _log "    *** state $state start (`date`)"
306     _log "        (user=$USER, host=$HOST)"
307     new_state=""
308
309     case $state
310     in
311         *init)
312             echo "" > $ROOT/qa.log
313             echo "" > $ROOT/qa.full
314             _log "******************************************************"
315             _log "QA init $VERSION (`date`)"
316             _log "******************************************************"
317             _log "--- kernel ($IMAGE)"
318             _log "--- modules ($MODULES)"
319
320             _change_state "inited"
321             _update_autoqa_file
322             ;;
323             
324         *inited)
325             _log "        *** QA initialized"
326             new_state="update"
327             ;;
328         
329         *update)
330             _update_workarea
331             new_state="clean"
332             ;;
333
334         *clean)
335             # we need to configure or else we might fail to clean
336             for pkg in attr acl xfsprogs xfsdump xfstests
337             do
338                 cd $WORKAREA/cmd/$pkg
339                 _log "        *** clean $pkg tools"
340                 make realclean 2>&1 \
341                         || _fail "            !!! clean $pkg failed"
342             done
343
344             _log "        *** clean linux"
345             cd $WORKAREA/linux
346             make mrproper 2>&1 \
347                         || _fail "            !!! clean linux failed"
348
349             _log "        *** install configuration file"
350             cp -f $CONFIG $WORKAREA/linux/.config 2>&1 \
351                         || _fail "            !!! failed to install config"
352             
353             _log "        *** remove version file"
354             rm -f include/linux/version.h 2>&1 \
355                         || _fail "            !!! failed to clean version"
356
357             new_state="reconfig"
358             ;;
359             
360         *reconfig)
361         
362             _log "        *** reconfig kernel"
363             
364             _change_state "clean" ; # we better start from scratch if this fails
365             
366             cd $WORKAREA/linux
367             # we want to use default options for any new config options.
368             echo -e "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" | \
369                 make EXTRAVERSION=$EXTRA oldconfig 2>&1 \
370                         || _fail "            !!! reconfig oldconfig failed"
371             make EXTRAVERSION=$EXTRA dep 2>&1 \
372                         || _fail "            !!! reconfig dep failed"
373
374             new_state="build"
375             ;;
376             
377         *build)
378             _log "        *** build kernel"
379             
380             _change_state "clean" ; # we better start from scratch if this fails
381             
382             cd $WORKAREA/linux
383             make -j2 EXTRAVERSION=$EXTRA bzImage 2>&1 \
384                         || _fail "            !!! build bzImage failed"
385             make -j2 EXTRAVERSION=$EXTRA modules 2>&1 \
386                         || _fail "            !!! build modules failed"
387                                     
388             _log "        *** build and install tools"
389             for pkg in attr acl xfsprogs xfsdump xfstests 
390             do
391                 cd $WORKAREA/cmd/$pkg
392
393                 # use e-fence - but this will only take effect on configure
394                 export MALLOCLIB=/usr/lib/libefence.a
395                 make configure 2>&1 \
396                         || _fail "            !!! configure $pkg failed"
397                 make default 2>&1 \
398                         || _fail "            !!! build $pkg failed"
399
400                 _sudo make install install-dev 2>&1 \
401                         || _fail "            !!! install $pkg failed"
402             done
403
404             new_state="install"
405             ;;
406             
407         *install)
408             _log "        *** blat old modules"
409             
410             _sudo rm -rf $MODULES
411             
412             _log "        *** install kernel"
413             cd $WORKAREA/linux
414             _sudo cp -f $WORKAREA/linux/arch/i386/boot/bzImage $IMAGE 2>&1 \
415                         || _fail "            !!! install kernel failed"
416             _sudo cp -f $WORKAREA/linux/System.map $SYSTEMMAP 2>&1 \
417                         || _fail "            !!! install kernel failed"
418             _sudo make EXTRAVERSION=$EXTRA modules_install 2>&1 \
419                         || _fail "            !!! install modules failed"
420
421             _log "        *** reinit lilo"
422             _sudo /sbin/lilo 2>&1 \
423                         || _fail "            !!! reinit lilo failed"
424             new_state="restart"
425             ;;
426             
427         *restart)
428             _log "            *** select qa kernel"
429             _sudo /sbin/lilo -R linux-xfs-qa 2>&1 \
430                         || _fail "            !!! lilo failed"
431             
432             _log "            *** prepare to restart"
433             _change_state "restarted"
434             
435             _log "            *** restarting"
436
437             _restart # doesn't return
438             ;;
439             
440         *restarted)
441             _log "            *** QA reentered after restart"
442             
443             new_state="check"
444             ;;
445           
446         *check)
447             uname=`uname -ar`
448             _log "            *** uname $uname"
449             _log "            *** user tools"
450             ls -l /sbin/*xfs* /usr/sbin/*xfs* 2>&1
451             _log "            *** kernel"
452             ls -l /boot/*$EXTRA*  2>&1
453             _log "            *** kernel modules"
454             ls -l /lib/modules/$SVERSION$EXTRA/kernel/fs/pagebuf/* \
455                   /lib/modules/$SVERSION$EXTRA/kernel/fs/xfs/*     \
456                   /lib/modules/$SVERSION$EXTRA/kernel/fs/xfs_support/* 
457             
458             if [ $MODULAR -eq 0 ]
459             then
460                 new_state="reset"
461             else
462                 new_state="probe"
463             fi
464             ;;
465             
466         *probe)
467             _log "            *** modules dependencies"
468             
469             _sudo depmod -a  2>&1 \
470                         || _fail "            !!! failed to depmod -a" 
471             
472             _log "            *** unmounting XFS mounts"
473             
474             _sudo umount -a -t xfs 2>&1
475             
476             _log "            *** removing modules"
477             
478             for m in xfsidbg xfs pagebuf kdbm_pg kdbm_vm
479             do
480                 _sudo rmmod $m 2> /dev/null
481             done
482             
483             _log "            *** installing modules"
484
485             _sudo modprobe xfs 2>&1 \
486                         || _fail "            !!! failed to modprobe xfs"
487
488             new_state="reset"
489             ;;
490             
491         *reset)
492             
493             _log "            *** unmounting TEST_DEV"
494             
495             _sudo umount $TEST_DEV 2>&1
496             
497             _log "            *** unmounting SCRATCH_DEV"
498             
499             _sudo umount $SCRATCH_DEV 2>&1
500             
501             _log "            *** clean TEST_DEV"
502             
503             _sudo mkfs -t xfs -f $TEST_DEV 2>&1 \
504                         || _fail "            !!! failed to mkfs TEST_DEV"
505             
506             _log "            *** mounting TEST_DEV"
507             
508             _sudo mount -t xfs $TEST_DEV $TEST_DIR 2>&1 \
509                         || _fail "            !!! failed to mount"
510                                     
511             new_state="run"
512             ;;
513             
514             
515         soak-run)
516             cd $QADIR
517             
518             _log "            *** run soak test"
519             _sudo ./soak $SOAK_PASSES $SOAK_STRESS $SOAK_PROC\
520                         || _fail "            !!! failed to run soak test"
521
522             new_state="done"
523             ;;
524             
525         *run)
526             cd $QADIR
527             
528             _log "            *** run tests"
529             _sudo ./check -l -g auto 2>&1 | tee $ROOT/qa.out
530             
531             _log ""
532             _log "            *** send status mail"
533             mail -s "xfs qa status report" $EMAIL < $ROOT/qa.out 2>&1
534         
535             new_state="done"
536             ;;
537             
538         *done)
539             _log "*** QA run complete"
540
541             _success
542             ;;
543             
544         *nothing)
545             new_state="done"
546             _log "    *** do nothing"
547             ;;
548             
549         *)
550             _fail "           !!! unknown state $state"
551             ;;
552     esac
553
554     _log "    *** state $state done (`date`)"
555     [ "$new_state" = "" ] && _fail "    !!! no new state set"
556     _change_state $new_state
557     
558 done