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