]> git.ipfire.org Git - thirdparty/squid.git/blob - test-builds.sh
Windows: cf_gen requires a .exe extension
[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 remove_cache_file="true"
13 while [ $# -ge 1 ]; do
14 case "$1" in
15 --cleanup)
16 cleanup="yes"
17 shift
18 ;;
19 --verbose)
20 verbose="yes"
21 shift
22 ;;
23 --keep-going)
24 keepGoing="yes"
25 shift
26 ;;
27 --use-config-cache)
28 #environment variable will be picked up by buildtest.sh
29 cache_file=/tmp/config.cache.$$
30 export cache_file
31 shift
32 ;;
33 --aggressively-use-config-cache)
34 #environment variable will be picked up by buildtest.sh
35 #note: use ONLY if you know what you're doing
36 cache_file=/tmp/config.cache
37 remove_cache_file="false"
38 export cache_file
39 shift
40 ;;
41 *)
42 break
43 ;;
44 esac
45 done
46
47 logtee() {
48 if [ $verbose = yes ]; then
49 tee $1
50 else
51 cat >$1
52 fi
53 }
54
55 buildtest() {
56 opts=$1
57 layer=`basename ${opts} .opts`
58 btlayer="bt${layer}"
59 log=${btlayer}.log
60 echo "TESTING: ${layer}"
61 if test -e ${btlayer}; then
62 chmod -R 777 ${btlayer};
63 fi
64 rm -f -r ${btlayer} || ( echo "FATAL: Failed to prepare test build sandpit." ; exit 1 )
65 mkdir ${btlayer}
66 if test "${verbose}" = "yes" ; then
67 ls -la ${btlayer}
68 fi
69 {
70 result=255
71 cd ${btlayer}
72 if test -e $top/test-suite/buildtest.sh ; then
73 $top/test-suite/buildtest.sh ${opts} 2>&1
74 result=$?
75 elif test -e ../$top/test-suite/buildtest.sh ; then
76 ../$top/test-suite/buildtest.sh ../${opts} 2>&1
77 result=$?
78 else
79 echo "Error: cannot find $top/test-suite/buildtest.sh script"
80 result=1
81 fi
82
83 # log the result for the outer script to notice
84 echo "buildtest.sh result is $result";
85 } 2>&1 | logtee ${log}
86
87 result=1 # failure by default
88 if grep -q '^buildtest.sh result is 0$' ${log}; then
89 result=0
90 fi
91
92 # Display BUILD parameters to double check that we are building the
93 # with the right parameters. TODO: Make less noisy.
94 grep -E "BUILD" ${log}
95
96 errors="^ERROR|\ error:|\ Error\ |No\ such|assertion\ failed|FAIL:|:\ undefined"
97 grep -E "${errors}" ${log}
98
99 if test $result -eq 0; then
100 # successful execution
101 if test "${verbose}" = "yes"; then
102 echo "Build OK. Global result is $globalResult."
103 fi
104 if test "${cleanup}" = "yes" ; then
105 echo "REMOVE DATA: ${btlayer}"
106 chmod -R 777 ${btlayer}
107 rm -f -r ${btlayer}
108 echo "REMOVE LOG: ${log}"
109 rm -f -r ${log}
110 fi
111 else
112 if test "${verbose}" != "yes" ; then
113 echo "Build Failed. Last log lines are:"
114 tail -20 ${log}
115 else
116 echo "Build FAILED."
117 fi
118 globalResult=1
119 fi
120 }
121
122 # if using cache, make sure to clear it up first
123 if [ -n "$cache_file" -a -e "$cache_file" -a "$remove_cache_file" = "true" ]; then
124 rm $cache_file
125 fi
126
127 # Decide what tests to run, $* contains test spec names or filenames.
128 # Use all knows specs if $* is empty or a special macro called 'all'.
129 if test -n "$*" -a "$*" != all; then
130 tests="$*"
131 else
132 tests=`ls -1 $top/test-suite/buildtests/layer*.opts`
133 fi
134
135 for t in $tests; do
136 if test -e "$t"; then
137 # A configuration file
138 cfg="$t"
139 elif test -e "$top/test-suite/buildtests/${t}.opts"; then
140 # A well-known configuration name
141 cfg="$top/test-suite/buildtests/${t}.opts"
142 else
143 echo "Error: Unknown test specs '$t'"
144 cfg=''
145 globalResult=1
146 fi
147
148 # run the test, if any
149 if test -n "$cfg"; then
150 buildtest $cfg
151 fi
152
153 # quit on errors unless we should $keepGoing
154 if test $globalResult -ne 0 -a $keepGoing != yes; then
155 exit $globalResult
156 fi
157 done
158
159 # if using cache, make sure to clear it up first
160 if [ -n "$cache_file" -a -e "$cache_file" -a "$remove_cache_file" = "true" ]; then
161 rm $cache_file
162 fi
163
164 exit $globalResult