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