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