builder 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #!/bin/sh
  2. # build_test - a build testing script
  3. #
  4. # Copyright (C) 2008 by Xorcom <support@xorcom.com>
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. #
  20. # Setup:
  21. #
  22. # 0. Copy this script under build_tools/ and
  23. #
  24. # chmod +x build_tools/builder
  25. #
  26. # 1. Make sure you have git and sqlite3 installed. If the sqlite3 binary
  27. # is called differently, fix the line "SQLITE=" in the script or in
  28. # build_tools/test_build.conf .
  29. #
  30. # 2. Run:
  31. #
  32. # ./build_tools/test_kernel_git init /path/to/some/dir
  33. #
  34. # /path/to/some/dir must exist . This will download a recent kernel
  35. # git repository to /path/to/some/dir/linux-2.6 . Use
  36. # './build_tools/test_kernel_git update' to pull a fresh update there.
  37. #
  38. # 3. Run:
  39. #
  40. # ./build_tools/builder init
  41. #
  42. #
  43. # Usage:
  44. #
  45. # ./build_tools build
  46. #
  47. # The past results are in a sqlite database in the logs subdirectory. For
  48. # a simple list of results:
  49. #
  50. # ./build_tools report
  51. #
  52. # You can also look at the build log for a specific build in the logs
  53. # directory.
  54. BIN_DIR=`dirname $0`
  55. BASE_DIR=`dirname $BIN_DIR`
  56. SQLITE=sqlite3
  57. HOSTS="localhost"
  58. LOGS_DIR="$BASE_DIR/logs"
  59. DB=$LOGS_DIR/builds.db
  60. BUILD_SCRIPT=$BIN_DIR/test_kernel_git
  61. KERNELS_localhost="2.6.12 2.6.18 2.6.25"
  62. usage() {
  63. me=`basename $0`
  64. echo "$me: test building Zaptel/DAHDI with various kernels"
  65. echo ""
  66. echo "Usage: $0 command <optional parameters>"
  67. echo " init Create results directory and database."
  68. echo " build [<kernels>] Run the test builds. The default list: "
  69. echo " $KERNELS_localhost"
  70. echo " report [<filter>] Print all results [matching <filter>]"
  71. echo " Default is to print all the resaults."
  72. echo ""
  73. echo "Filters:"
  74. echo " failed: Only failed tests."
  75. echo " fail_type <type> Where fail_type matches <type>."
  76. echo " 2.6* Only builds for a matching kernel version."
  77. echo " Else: Match a string from the build name, which "
  78. echo " is essentially the time it started."
  79. echo ""
  80. }
  81. set -e
  82. if [ -r $BIN_DIR/test_build.conf ]; then . $BIN_DIR/test_build.conf; fi
  83. # Runs the test script, logs the result, and fails if the test command
  84. # has failed.
  85. build_and_check() {
  86. test_name="$1"
  87. test_cmd="$2"
  88. log_file="$3"
  89. results_str="$4"
  90. fail_type=''
  91. set +e
  92. $BUILD_SCRIPT $test_cmd >$log_file 2>&1
  93. rc=$?
  94. set -e
  95. if [ $rc != 0 ]; then
  96. fail_type="$test_name"
  97. echo "$results_str, $rc, '$fail_type', '$log_file');" | $SQLITE $DB
  98. fi
  99. return $rc
  100. }
  101. build_zaptel() {
  102. build_name="$1"
  103. host="$2"
  104. kvers="$3"
  105. log_base="build__${build_name}__${host}__${kvers}"
  106. log_base_full="$LOGS_DIR/$log_base"
  107. log_file="$log_base_full.log"
  108. results_str="INSERT INTO results VALUES ('$build_name', '$host', '$kvers'"
  109. # Due to 'set -e' a failed test exists the script.
  110. build_and_check setver "setver $kvers" "$log_file" "$results_str"
  111. build_and_check clean "test clean" "$log_file" "$results_str"
  112. build_and_check build "build" "$log_file" "$results_str"
  113. # If we got here, all was well.
  114. echo "$results_str, 0, 'complete', '$log_file');" | $SQLITE $DB
  115. }
  116. case "$1" in
  117. init)
  118. mkdir -p $LOGS_DIR
  119. cat <<EOF | $SQLITE $DB
  120. CREATE TABLE runs(name TEXT PRIMARY KEY, time INTEGER DEFAULT CURRENT_TIMESTAMP, driver_ver TEXT);
  121. CREATE TABLE results(name TEXT, system TEXT, kvers TEXT, result INTEGER, fail_type TEXT, log TEXT);
  122. EOF
  123. mkdir -p $LOGS_DIR
  124. ;;
  125. build)
  126. cd $BASE_DIR
  127. shift
  128. if [ "$*" != '' ]; then KERNELS_localhost="$*"; fi
  129. driver_ver=`$BUILD_SCRIPT version_driver`
  130. build_name=`date '+%Y%m%d-%H%M%si'`
  131. echo "INSERT INTO runs (name, driver_ver) VALUES ('$build_name', '$driver_ver');" | $SQLITE $DB
  132. for host in $HOSTS; do
  133. eval kernels="\$KERNELS_$host"
  134. for kvers in $kernels; do
  135. build_zaptel $build_name $host $kvers
  136. done
  137. done
  138. ;;
  139. report)
  140. case "$2" in
  141. '') where='1=1' ;;
  142. failed) where='result != 0' ;;
  143. fail_type) where="fail_type like \"%$3%\"" ;;
  144. 2.6*) where="kvers like \"$2%\"" ;;
  145. *) where="name like \"%$2%\"" ;;
  146. esac
  147. echo "select * from results where $where;" | $SQLITE $DB
  148. ;;
  149. *)
  150. usage
  151. echo >&2 "$0: Unknown command '$1'. Aborting."
  152. exit 1
  153. esac