]> git.ipfire.org Git - thirdparty/squid.git/blob - test-builds.sh
merged 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 chmod -R 777 ${btlayer}
47 rm -f -r ${btlayer} && mkdir ${btlayer}
48 {
49 result=255
50 cd ${btlayer}
51 if test -e $top/test-suite/buildtest.sh ; then
52 $top/test-suite/buildtest.sh ${opts} 2>&1
53 result=$?
54 elif test -e ../$top/test-suite/buildtest.sh ; then
55 ../$top/test-suite/buildtest.sh ../${opts} 2>&1
56 result=$?
57 else
58 echo "Error: cannot find $top/test-suite/buildtest.sh script"
59 result=1
60 fi
61
62 # log the result for the outer script to notice
63 echo "buildtest.sh result is $result";
64 } 2>&1 | logtee ${log}
65
66 result=1 # failure by default
67 if grep -q '^buildtest.sh result is 0$' ${log}; then
68 result=0
69 fi
70
71 # Display BUILD parameters to double check that we are building the
72 # with the right parameters. TODO: Make less noisy.
73 grep -E "BUILD" ${log}
74
75 errors="^ERROR|\ error:|\ Error\ |No\ such|assertion\ failed|FAIL:|:\ undefined"
76 grep -E "${errors}" ${log}
77
78 if test "${cleanup}" = "yes" ; then
79 echo "REMOVE DATA: ${btlayer}"
80 chmod -R 777 ${btlayer}
81 rm -f -r ${btlayer}
82 fi
83
84 if test $result -eq 0; then
85 # successful execution
86 if test "$verbose" = yes; then
87 echo "Build OK. Global result is $globalResult."
88 fi
89 else
90 echo "Build Failed. Last log lines are:"
91 tail -20 ${log}
92 globalResult=1
93 fi
94
95 if test "${cleanup}" = "yes" ; then
96 echo "REMOVE LOG: ${log}"
97 rm -f -r ${log}
98 fi
99 }
100
101 # Decide what tests to run, $* contains test spec names or filenames.
102 # Use all knows specs if $* is empty or a special macro called 'all'.
103 if test -n "$*" -a "$*" != all; then
104 tests="$*"
105 else
106 tests=`ls -1 $top/test-suite/buildtests/layer*.opts`
107 fi
108
109 for t in $tests; do
110 if test -e "$t"; then
111 # A configuration file
112 cfg="$t"
113 elif test -e "$top/test-suite/buildtests/${t}.opts"; then
114 # A well-known configuration name
115 cfg="$top/test-suite/buildtests/${t}.opts"
116 else
117 echo "Error: Unknown test specs '$t'"
118 cfg=''
119 globalResult=1
120 fi
121
122 # run the test, if any
123 if test -n "$cfg"; then
124 buildtest $cfg
125 fi
126
127 # quit on errors unless we should $keepGoing
128 if test $globalResult -ne 0 -a $keepGoing != yes; then
129 exit $globalResult
130 fi
131 done
132
133 exit $globalResult