Home | History | Annotate | Line # | Download | only in bin
reg-test revision 1.1
      1 #! /bin/bash
      2 
      3 #set -x
      4 
      5 ########################################################################
      6 #
      7 # File:    reg-test
      8 # Author:  Janis Johnson
      9 # Date:    2005/09/08
     10 #
     11 # For each of a list of patches, invoke separate tools to update
     12 # sources, do a build, and run one or more tests. 
     13 #
     14 # Define these in a file whose name is the argument to this script:
     15 #   REG_IDLIST: List of patch identifiers.
     16 #   REG_UPDATE: Pathname of script to update the source tree.
     17 #   REG_BUILD:  Pathname of script to build enough of the product to run
     18 #               the test.
     19 #   REG_TEST:   Pathname of script to run one or more tests.
     20 # Optional:
     21 #   VERBOSITY:  Default is 0, to print only errors and final message.
     22 #   DATE_IN_MSG If set to anything but 0, include the time and date in
     23 #               messages
     24 #   REG_STOP    Pathname of a file whose existence says to quit; default
     25 #               is STOP in the current directory.
     26 #
     27 #
     28 # Copyright (c) 2002, 2003, 2005 Free Software Foundation, Inc.
     29 #
     30 # This file is free software; you can redistribute it and/or modify
     31 # it under the terms of the GNU General Public License as published by
     32 # the Free Software Foundation; either version 3 of the License, or
     33 # (at your option) any later version.
     34 #
     35 # This program is distributed in the hope that it will be useful,
     36 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     37 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     38 # GNU General Public License for more details.
     39 #
     40 # For a copy of the GNU General Public License, write the the
     41 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     42 # Boston, MA 02111-1301, USA.
     43 #
     44 ########################################################################
     45 
     46 ########################################################################
     47 # Functions
     48 ########################################################################
     49 
     50 # Issue a message if its verbosity level is high enough.
     51 
     52 msg() {
     53   test ${1} -gt ${VERBOSITY}  && return
     54 
     55   if [ "x${DATE_IN_MSG}" = "x" ]; then
     56     echo "${2}"
     57   else
     58     echo "`${DATE}`  ${2}"
     59   fi
     60 }
     61 
     62 # Issue an error message and exit with a nonzero status.
     63 
     64 error() {
     65   msg 0 "error: ${1}"
     66   exit 1
     67 }
     68 
     69 # Build the components to test using sources as of a particular patch
     70 # and run a test case.  Pass each of the scripts the patch identifier
     71 # that we're testing; the first one needs it, the others can ignore it
     72 # if they want.
     73 
     74 process_patch () {
     75   TEST_ID=${1}
     76 
     77   ${REG_UPDATE} ${TEST_ID}
     78   if [ $? -ne 0 ]; then
     79     msg 0 "source update failed for id ${TEST_ID}"
     80     return
     81   fi
     82   ${REG_BUILD} ${TEST_ID}
     83   if [ $? -ne 0 ]; then
     84     msg 0 "build failed for id ${TEST_ID}"
     85     return
     86   fi
     87   ${REG_TEST} "${TEST_ID}"
     88 }
     89  
     90 ########################################################################
     91 # Main program (so to speak)
     92 ########################################################################
     93 
     94 # If DATE isn't defined, use the default date command; the configuration
     95 # file can override this.
     96 
     97 if [ "x${DATE}" = "x" ]; then
     98   DATE=date
     99 fi
    100 
    101 # Process the configuration file.
    102 
    103 if [ $# -ne 1 ]; then
    104   echo Usage: $0 config_file
    105   exit 1
    106 fi
    107 
    108 CONFIG=${1}
    109 if [ ! -f ${CONFIG} ]; then
    110   error "configuration file ${CONFIG} does not exist"
    111 fi
    112 
    113 # OK, the config file exists.  Source it, make sure required parameters
    114 # are defined and their files exist, and give default values to optional
    115 # parameters.
    116 
    117 . ${CONFIG}
    118 
    119 test "x${REG_IDLIST}" = "x" && error "REG_IDLIST is not defined"
    120 test "x${REG_UPDATE}" = "x" && error "REG_UPDATE is not defined"
    121 test "x${REG_BUILD}" = "x" && error "REG_BUILD is not defined"
    122 test "x${REG_TEST}" = "x" && error "REG_TEST is not defined"
    123 test -x ${REG_TEST} || error "REG_TEST is not an executable file"
    124 test "x${VERBOSITY}" = "x" && VERBOSITY=0
    125 test "x${REG_STOP}" = "x" && REG_STOP="STOP"
    126  
    127 msg 2 "REG_IDLIST = ${REG_IDLIST}"
    128 msg 2 "REG_UPDATE = ${REG_UPDATE}"
    129 msg 2 "REG_BUILD  = ${REG_BUILD}"
    130 msg 2 "REG_TEST   = ${REG_TEST}"
    131 msg 2 "VERBOSITY  = ${VERBOSITY}"
    132 
    133 # Process each patch identifier in the list.
    134 
    135 for TEST_ID in $REG_IDLIST; do
    136 
    137   # If a file called STOP appears, stop; this allows a clean way to
    138   # interrupt a search.
    139 
    140   if [ -f ${REG_STOP} ]; then
    141     msg 0 "STOP file detected"
    142     rm -f ${REG_STOP}
    143     exit 1
    144   fi
    145 
    146   # Process the new patch.
    147 
    148   msg 2 "process id ${TEST_ID}"
    149   process_patch ${TEST_ID}
    150 done
    151 
    152 msg 1 "done"
    153