]> git.ipfire.org Git - thirdparty/squid.git/blob - test-builds.sh
Merge from trunk
[thirdparty/squid.git] / test-builds.sh
1 #!/bin/sh
2 #
3 # Run all or some build tests for a given OS environment.
4 #
5 top=`dirname $0`
6
7 globalResult=0
8
9 cleanup="no"
10 verbose="no"
11 keepGoing="no"
12 while [ $# -ge 1 ]; do
13 case "$1" in
14 --cleanup)
15 cleanup="yes"
16 shift
17 ;;
18 --verbose)
19 verbose="yes"
20 shift
21 ;;
22 --keep-going)
23 keepGoing="yes"
24 shift
25 ;;
26 *)
27 break
28 ;;
29 esac
30 done
31
32 logtee() {
33 if [ $verbose = yes ]; then
34 tee $1
35 else
36 cat >$1
37 fi
38 }
39
40 buildtest() {
41 opts=$1
42 layer=`basename ${opts} .opts`
43 btlayer="bt${layer}"
44 log=${btlayer}.log
45 echo "TESTING: ${layer}"
46 rm -f -r ${btlayer} && mkdir ${btlayer}
47 {
48 result=255
49 cd ${btlayer}
50 if test -e $top/test-suite/buildtest.sh ; then
51 $top/test-suite/buildtest.sh ${opts} 2>&1
52 result=$?
53 elif test -e ../$top/test-suite/buildtest.sh ; then
54 ../$top/test-suite/buildtest.sh ../${opts} 2>&1
55 result=$?
56 else
57 echo "Error: cannot find $top/test-suite/buildtest.sh script"
58 result=1
59 fi
60
61 # log the result for the outer script to notice
62 echo "buildtest.sh result is $result";
63 } 2>&1 | logtee ${log}
64
65 result=1 # failure by default
66 if grep -q '^buildtest.sh result is 0$' ${log}; then
67 result=0
68 fi
69
70 # Display BUILD parameters to double check that we are building the
71 # with the right parameters. TODO: Make less noisy.
72 grep -E "BUILD" ${log}
73
74 errors="^ERROR|\ error:|\ Error\ |No\ such|assertion\ failed|FAIL:|:\ undefined"
75 grep -E "${errors}" ${log}
76
77 if test "${cleanup}" = "yes" ; then
78 echo "REMOVE DATA: ${btlayer}"
79 rm -f -r ${btlayer}
80 fi
81
82 if test $result -eq 0; then
83 # successful execution
84 if test "$verbose" = yes; then
85 echo "Build OK. Global result is $globalResult."
86 fi
87 else
88 echo "Build Failed. Last log lines are:"
89 tail -5 ${log}
90 globalResult=1
91 fi
92
93 if test "${cleanup}" = "yes" ; then
94 echo "REMOVE LOG: ${log}"
95 rm -f -r ${log}
96 fi
97 }
98
99 # Decide what tests to run, $* contains test spec names or filenames.
100 # Use all knows specs if $* is empty or a special macro called 'all'.
101 if test -n "$*" -a "$*" != all; then
102 tests="$*"
103 else
104 tests=`ls -1 $top/test-suite/buildtests/layer*.opts`
105 fi
106
107 for t in $tests; do
108 if test -e "$t"; then
109 # A configuration file
110 cfg="$t"
111 elif test -e "$top/test-suite/buildtests/${t}.opts"; then
112 # A well-known configuration name
113 cfg="$top/test-suite/buildtests/${t}.opts"
114 else
115 echo "Error: Unknown test specs '$t'"
116 cfg=''
117 globalResult=1
118 fi
119
120 # run the test, if any
121 if test -n "$cfg"; then
122 buildtest $cfg
123 fi
124
125 # quit on errors unless we should $keepGoing
126 if test $globalResult -ne 0 -a $keepGoing != yes; then
127 exit $globalResult
128 fi
129 done
130
131 exit $globalResult