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