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