reg-test 4.2 KB

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