]> git.ipfire.org Git - thirdparty/squid.git/blob - test-builds.sh
Source Format Enforcement (#763)
[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 --progress)
37 verbose="progress"
38 shift
39 ;;
40 --keep-going)
41 keepGoing="yes"
42 shift
43 ;;
44 --use-config-cache)
45 #environment variable will be picked up by buildtest.sh
46 cache_file=${cache_file:-/tmp/config.cache.$$}
47 export cache_file
48 shift
49 ;;
50 --aggressively-use-config-cache)
51 #environment variable will be picked up by buildtest.sh
52 #note: use ONLY if you know what you're doing
53 cache_file=${cache_file:-/tmp/config.cache}
54 remove_cache_file="false"
55 export cache_file
56 shift
57 ;;
58 --config-cache-file)
59 cache_file="$2"
60 remove_cache_file="false"
61 export cache_file
62 shift 2
63 ;;
64 *)
65 break
66 ;;
67 esac
68 done
69
70 logtee() {
71 case $verbose in
72 yes)
73 tee $1
74 ;;
75 progress)
76 tee $1 | awk '{printf "."; n++; if (!(n % 80)) print "" } END {print ""}'
77 ;;
78 *)
79 cat >$1
80 esac
81 }
82
83 buildtest() {
84 opts=$1
85 action=$2
86 layer=`basename ${opts} .opts`
87 btlayer="bt${layer}"
88 log=${btlayer}.log
89 echo "TESTING: ${layer}"
90 if test -e ${btlayer}; then
91 chmod -R 777 ${btlayer};
92 fi
93 rm -f -r ${btlayer} || ( echo "FATAL: Failed to prepare test build sandpit." ; exit 1 )
94 mkdir ${btlayer}
95 if test "${verbose}" = "yes" ; then
96 ls -la ${btlayer}
97 fi
98 {
99 result=255
100 cd ${btlayer}
101 if test -e $top/test-suite/buildtest.sh ; then
102 $top/test-suite/buildtest.sh "${action}" ${opts} 2>&1
103 result=$?
104 elif test -e ../$top/test-suite/buildtest.sh ; then
105 ../$top/test-suite/buildtest.sh "${action}" ../${opts} 2>&1
106 result=$?
107 else
108 echo "Error: cannot find $top/test-suite/buildtest.sh script"
109 result=1
110 fi
111
112 # log the result for the outer script to notice
113 echo "buildtest.sh result is $result";
114 } 2>&1 | logtee ${log}
115
116 result=1 # failure by default
117 if grep -q '^buildtest.sh result is 0$' ${log}; then
118 result=0
119 fi
120
121 # Display BUILD parameters to double check that we are building the
122 # with the right parameters. TODO: Make less noisy.
123 grep -E "BUILD" ${log}
124
125 errors="^ERROR|\ error:|\ Error\ |No\ such|assertion\ failed|FAIL:|:\ undefined"
126 grep -E "${errors}" ${log}
127
128 if test $result -eq 0; then
129 # successful execution
130 if test "${verbose}" = "yes"; then
131 echo "Build OK. Global result is $globalResult."
132 fi
133 if test "${cleanup}" = "yes" ; then
134 echo "REMOVE DATA: ${btlayer}"
135 chmod -R 777 ${btlayer}
136 rm -f -r ${btlayer}
137 echo "REMOVE LOG: ${log}"
138 rm -f -r ${log}
139 fi
140 else
141 if test "${verbose}" != "yes" ; then
142 echo "Build Failed."
143 echo "Log start: ${log}"
144 cat ${log}
145 echo "Log end: ${log}"
146 else
147 echo "Build FAILED."
148 fi
149 globalResult=1
150 fi
151 }
152
153 # if using cache, make sure to clear it up first
154 if [ -n "$cache_file" -a -e "$cache_file" -a "$remove_cache_file" = "true" ]; then
155 rm $cache_file
156 fi
157
158 if [ -f "$top/configure" -a -f "$top/libltdl/configure" ]; then
159 echo "Already bootstrapped, skipping step"
160 else
161 (cd "$top"; ./bootstrap.sh)
162 fi
163
164 # Decide what tests to run, $* contains test spec names or filenames.
165 # Use all knows specs if $* is empty or a special macro called 'all'.
166 if test -n "$*" -a "$*" != all; then
167 tests="$*"
168 else
169 tests=`ls -1 $top/test-suite/buildtests/layer*.opts`
170 fi
171
172 for t in $tests; do
173 if test -e "$t"; then
174 # A configuration file
175 cfg="$t"
176 elif test -e "$top/test-suite/buildtests/${t}.opts"; then
177 # A well-known configuration name
178 cfg="$top/test-suite/buildtests/${t}.opts"
179 else
180 echo "Error: Unknown test specs '$t'"
181 cfg=''
182 globalResult=1
183 fi
184
185 # run the test, if any
186 if test -n "$cfg"; then
187 buildtest "$cfg" "$action"
188 fi
189
190 # quit on errors unless we should $keepGoing
191 if test $globalResult -ne 0 -a $keepGoing != yes; then
192 exit $globalResult
193 fi
194 done
195
196 # if using cache, make sure to clear it up first
197 if [ -n "$cache_file" -a -e "$cache_file" -a "$remove_cache_file" = "true" ]; then
198 rm $cache_file
199 fi
200
201 exit $globalResult