rearrange which hosts are using modular vs. built-in kernels.
[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     bruce)
119         EMAIL="nathans@larry"
120         ADMINEMAIL="nathans@larry"
121         MODULAR=0
122         ;;
123     sagan)
124         EMAIL="tes@larry"
125         ADMINEMAIL="tes@larry"
126         MODULAR=1
127         ;;
128     troppo)
129         EMAIL="kaos@larry"
130         ADMINEMAIL="kaos@larry"
131         MODULAR=0
132         ;;
133     frodo)
134         EMAIL="nathans@larry"
135         ADMINEMAIL="nathans@larry"
136         MODULAR=0
137         ;;
138     *)
139         _fail "auto-qa: no configuration information for host '$HOST'"
140         ;;
141 esac
142
143 # do some cleanup on exit
144
145 _cleanup()
146 {
147     umount $SCRATCH_DEV &> /dev/null
148     umount $TEST_DEV &> /dev/null
149     if [ "$started" = 1 ]
150     then
151         echo "auto-qa stopped" | wall
152         started=0
153     fi
154 }
155 status=1
156 trap "_cleanup; exit \$status" 0 1 2 3 15
157
158 # clean exit
159
160 _success()
161 {
162     status=0
163     exit 0
164 }
165
166 _get_state()
167 {
168     state=`cat $STATE`
169 }
170
171 _set_state()
172 {
173     echo $1 > $STATE
174     _get_state
175 }
176
177 _change_state()
178 {
179     new=$1
180     
181     case $state
182     in
183         *-*)
184             case $new
185             in
186                 *-*)
187                     _set_state $new
188                     ;;
189                 *)
190                     _set_state `echo $state | sed "s/-.*$/-$new/"`
191                     ;;
192             esac
193             ;;
194         *)
195             _set_state $new
196             ;;
197     esac
198 }
199
200 _sudo()
201 {
202     $ROOT/su -c "$*" < /dev/null ;# HACK - we need a hacked su at the mo
203 }
204
205 _restart()
206 {
207     # erk - why won't this thing reboot reliably??
208     exec $ROOT/su -c "(shutdown -r 2 \"auto-qa rebooting\" ; sleep 10 ; reboot ; sleep 10 ; reboot )&" < /dev/null
209 }
210
211 _update_autoqa_file()
212 {
213     SELF="$ROOT/auto-qa"
214     SELF_UPDATE="cmd/xfstests/tools/auto-qa"
215     if [ -z "$CVSROOT" ]; then
216             cmd="p_tupdate $SELF_UPDATE"
217     else
218             cmd="cvs -z3 update $SELF_UPDATE"
219     fi
220     exec $SH -c "cd $WORKAREA ; $cmd; chmod +x $SELF_UPDATE ; exec $SELF"
221 }
222
223 _update_workarea()
224 {
225     if [ -z "$CVSROOT" ]; then
226         _log "        *** p_tupdate"
227         cd $WORKAREA 
228         p_tupdate 2>&1 \
229                         || _fail "            !!! p_tupdate failed"
230
231         _log "        *** p_check/p_purge"
232         cd $WORKAREA 
233         p_check -s | p_purge -yiu 2>&1 \
234                         || _fail "            !!! p_check/p_purge failed"
235
236         _log "        *** non-trunk files"
237         cd $WORKAREA 
238         p_list -c 2>&1 \
239                         || _fail "            !!! p_list failed"
240     else
241         _log "        *** cvs update"
242         cd $WORKAREA
243         cvs -z3 update -d
244     fi
245 }
246             
247
248 _log "*** linux-xfs QA (`date`)"
249
250 _get_state
251
252 # check preconditions for starting state
253 case $1
254 in
255     cron-init)
256         case $state
257         in
258             *done)
259                 ;;
260             *)
261                 _fail "    !!! cron-init while not in \"*done\" state"
262                 ;;
263         esac
264         ;;
265     cron-restarted)
266         # we don't auto restart after reboot, but cron the restart
267         # to happen a bit later - it's much easier and safer that way
268         if [ $state != "cron-restarted" ]
269         then
270             _fail "    !!! cron-restarted while not in \"cron-restarted\" state"
271         fi
272         ;;
273 esac
274
275 if [ "$1" != "" ]
276 then
277     _set_state $1
278 fi
279
280 [ $UID -eq 0 ]          && _fail "    !!! QA most be run as a normal user"
281 [ -d $ROOT ]            || _fail "    !!! QA root \"$ROOT\" not found"
282 [ -d $WORKAREA ]        || _fail "    !!! QA workarea \"$WORKAREA\" not found"
283 [ -r $CONFIG ]          || _fail "    !!! Can't read config file $CONFIG"
284 . $COMMON_CONFIG        || _fail "    !!! Couldn't source $COMMON_CONFIG"
285
286 _get_kernel_version
287 IMAGE="$BOOT/vmlinuz$EXTRA"
288 SYSTEMMAP="$BOOT/System.map-$VERSION$EXTRA"
289 MODULES="/lib/modules/$SVERSION"
290
291 cd $ROOT
292
293 started=1
294 echo "auto-qa started" | wall
295
296 while true
297 do
298     _get_state
299
300     _log "    *** state $state start (`date`)"
301     _log "        (user=$USER, host=$HOST)"
302     new_state=""
303
304     case $state
305     in
306         *init)
307             echo "" > $ROOT/qa.log
308             echo "" > $ROOT/qa.full
309             _log "******************************************************"
310             _log "QA init $VERSION (`date`)"
311             _log "******************************************************"
312             _log "--- kernel ($IMAGE)"
313             _log "--- modules ($MODULES)"
314
315             _change_state "inited"
316             _update_autoqa_file
317             ;;
318             
319         *inited)
320             _log "        *** QA initialized"
321             new_state="update"
322             ;;
323         
324         *update)
325             _update_workarea
326             new_state="clean"
327             ;;
328
329         *clean)
330             # we need to configure or else we might fail to clean
331             for pkg in attr acl xfsprogs dmapi xfsdump xfstests
332             do
333                 cd $WORKAREA/cmd/$pkg
334                 _log "        *** clean $pkg tools"
335                 make realclean 2>&1 \
336                         || _fail "            !!! clean $pkg failed"
337             done
338
339             _log "        *** clean linux"
340             cd $WORKAREA/linux
341             make mrproper 2>&1 \
342                         || _fail "            !!! clean linux failed"
343
344             _log "        *** install configuration file"
345             cp -f $CONFIG $WORKAREA/linux/.config 2>&1 \
346                         || _fail "            !!! failed to install config"
347             
348             _log "        *** remove version file"
349             rm -f include/linux/version.h 2>&1 \
350                         || _fail "            !!! failed to clean version"
351
352             new_state="reconfig"
353             ;;
354             
355         *reconfig)
356         
357             _log "        *** reconfig kernel"
358             
359             _change_state "clean" ; # we better start from scratch if this fails
360             
361             cd $WORKAREA/linux
362             # we want to use default options for any new config options.
363             echo -e "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" | \
364                 make EXTRAVERSION=$EXTRA oldconfig 2>&1 \
365                         || _fail "            !!! reconfig oldconfig failed"
366             make EXTRAVERSION=$EXTRA dep 2>&1 \
367                         || _fail "            !!! reconfig dep failed"
368
369             new_state="build"
370             ;;
371             
372         *build)
373             _log "        *** build kernel"
374             
375             _change_state "clean" ; # we better start from scratch if this fails
376             
377             cd $WORKAREA/linux
378             make -j2 EXTRAVERSION=$EXTRA bzImage 2>&1 \
379                         || _fail "            !!! build bzImage failed"
380             make -j2 EXTRAVERSION=$EXTRA modules 2>&1 \
381                         || _fail "            !!! build modules failed"
382                                     
383             _log "        *** build and install tools"
384             for pkg in attr acl xfsprogs dmapi xfsdump xfstests 
385             do
386                 cd $WORKAREA/cmd/$pkg
387
388                 # use e-fence - but this will only take effect on configure
389                 export MALLOCLIB=/usr/lib/libefence.a
390                 make configure 2>&1 \
391                         || _fail "            !!! configure $pkg failed"
392                 make default 2>&1 \
393                         || _fail "            !!! build $pkg failed"
394
395                 _sudo make install install-dev 2>&1 \
396                         || _fail "            !!! install $pkg failed"
397
398                 # attr and acl now have install-lib targets as well
399                 [ $pkg == "attr" -o $pkg == "acl" ] || continue
400                 _sudo make install-lib 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/xfs/* \
455                   /lib/modules/$SVERSION$EXTRA/kernel/fs/xfs_support/* 
456             
457             if [ $MODULAR -eq 0 ]
458             then
459                 new_state="reset"
460             else
461                 new_state="probe"
462             fi
463             ;;
464             
465         *probe)
466             _log "            *** modules dependencies"
467             
468             _sudo depmod -a  2>&1 \
469                         || _fail "            !!! failed to depmod -a" 
470             
471             _log "            *** unmounting XFS mounts"
472             
473             _sudo umount -a -t xfs 2>&1
474             
475             _log "            *** removing modules"
476             
477             for m in xfsidbg xfs kdbm_pg kdbm_vm
478             do
479                 _sudo rmmod $m 2> /dev/null
480             done
481             
482             _log "            *** installing modules"
483
484             _sudo modprobe xfs 2>&1 \
485                         || _fail "            !!! failed to modprobe xfs"
486
487             new_state="reset"
488             ;;
489             
490         *reset)
491             
492             _log "            *** unmounting TEST_DEV"
493             
494             _sudo umount $TEST_DEV 2>&1
495             
496             _log "            *** unmounting SCRATCH_DEV"
497             
498             _sudo umount $SCRATCH_DEV 2>&1
499             
500             _log "            *** clean TEST_DEV"
501             
502             _sudo mkfs -t xfs -f $TEST_DEV 2>&1 \
503                         || _fail "            !!! failed to mkfs TEST_DEV"
504             
505             _log "            *** mounting TEST_DEV"
506             
507             _sudo mount -t xfs $TEST_DEV $TEST_DIR 2>&1 \
508                         || _fail "            !!! failed to mount"
509                                     
510             new_state="run"
511             ;;
512             
513             
514         soak-run)
515             cd $QADIR
516             
517             _log "            *** run soak test"
518             _sudo ./soak $SOAK_PASSES $SOAK_STRESS $SOAK_PROC\
519                         || _fail "            !!! failed to run soak test"
520
521             new_state="done"
522             ;;
523             
524         *run)
525             cd $QADIR
526             
527             _log "            *** run tests"
528             _sudo ./check -l -g auto 2>&1 | tee $ROOT/qa.out
529             
530             _log ""
531             _log "            *** send status mail"
532             mail -s "xfs qa status report" $EMAIL < $ROOT/qa.out 2>&1
533         
534             new_state="done"
535             ;;
536             
537         *done)
538             _log "*** QA run complete"
539
540             _success
541             ;;
542             
543         *nothing)
544             new_state="done"
545             _log "    *** do nothing"
546             ;;
547             
548         *)
549             _fail "           !!! unknown state $state"
550             ;;
551     esac
552
553     _log "    *** state $state done (`date`)"
554     [ "$new_state" = "" ] && _fail "    !!! no new state set"
555     _change_state $new_state
556     
557 done