]> git.ipfire.org Git - thirdparty/squid.git/blob - test-builds.sh
Docs: Copyright updates for 2018 (#114)
[thirdparty/squid.git] / test-builds.sh
1 #!/bin/sh
2 #
3 ##
4 ## Copyright (C) 1996-2018 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=/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=/tmp/config.cache
50 remove_cache_file="false"
51 export cache_file
52 shift
53 ;;
54 *)
55 break
56 ;;
57 esac
58 done
59
60 logtee() {
61 if [ $verbose = yes ]; then
62 tee $1
63 else
64 cat >$1
65 fi
66 }
67
68 buildtest() {
69 opts=$1
70 action=$2
71 layer=`basename ${opts} .opts`
72 btlayer="bt${layer}"
73 log=${btlayer}.log
74 echo "TESTING: ${layer}"
75 if test -e ${btlayer}; then
76 chmod -R 777 ${btlayer};
77 fi
78 rm -f -r ${btlayer} || ( echo "FATAL: Failed to prepare test build sandpit." ; exit 1 )
79 mkdir ${btlayer}
80 if test "${verbose}" = "yes" ; then
81 ls -la ${btlayer}
82 fi
83 {
84 result=255
85 cd ${btlayer}
86 if test -e $top/test-suite/buildtest.sh ; then
87 $top/test-suite/buildtest.sh "${action}" ${opts} 2>&1
88 result=$?
89 elif test -e ../$top/test-suite/buildtest.sh ; then
90 ../$top/test-suite/buildtest.sh "${action}" ../${opts} 2>&1
91 result=$?
92 else
93 echo "Error: cannot find $top/test-suite/buildtest.sh script"
94 result=1
95 fi
96
97 # log the result for the outer script to notice
98 echo "buildtest.sh result is $result";
99 } 2>&1 | logtee ${log}
100
101 result=1 # failure by default
102 if grep -q '^buildtest.sh result is 0$' ${log}; then
103 result=0
104 fi
105
106 # Display BUILD parameters to double check that we are building the
107 # with the right parameters. TODO: Make less noisy.
108 grep -E "BUILD" ${log}
109
110 errors="^ERROR|\ error:|\ Error\ |No\ such|assertion\ failed|FAIL:|:\ undefined"
111 grep -E "${errors}" ${log}
112
113 if test $result -eq 0; then
114 # successful execution
115 if test "${verbose}" = "yes"; then
116 echo "Build OK. Global result is $globalResult."
117 fi
118 if test "${cleanup}" = "yes" ; then
119 echo "REMOVE DATA: ${btlayer}"
120 chmod -R 777 ${btlayer}
121 rm -f -r ${btlayer}
122 echo "REMOVE LOG: ${log}"
123 rm -f -r ${log}
124 fi
125 else
126 if test "${verbose}" != "yes" ; then
127 echo "Build Failed. Last log lines are:"
128 tail -20 ${log}
129 else
130 echo "Build FAILED."
131 fi
132 globalResult=1
133 fi
134 }
135
136 # if using cache, make sure to clear it up first
137 if [ -n "$cache_file" -a -e "$cache_file" -a "$remove_cache_file" = "true" ]; then
138 rm $cache_file
139 fi
140
141 # Decide what tests to run, $* contains test spec names or filenames.
142 # Use all knows specs if $* is empty or a special macro called 'all'.
143 if test -n "$*" -a "$*" != all; then
144 tests="$*"
145 else
146 tests=`ls -1 $top/test-suite/buildtests/layer*.opts`
147 fi
148
149 for t in $tests; do
150 if test -e "$t"; then
151 # A configuration file
152 cfg="$t"
153 elif test -e "$top/test-suite/buildtests/${t}.opts"; then
154 # A well-known configuration name
155 cfg="$top/test-suite/buildtests/${t}.opts"
156 else
157 echo "Error: Unknown test specs '$t'"
158 cfg=''
159 globalResult=1
160 fi
161
162 # run the test, if any
163 if test -n "$cfg"; then
164 buildtest "$cfg" "$action"
165 fi
166
167 # quit on errors unless we should $keepGoing
168 if test $globalResult -ne 0 -a $keepGoing != yes; then
169 exit $globalResult
170 fi
171 done
172
173 # if using cache, make sure to clear it up first
174 if [ -n "$cache_file" -a -e "$cache_file" -a "$remove_cache_file" = "true" ]; then
175 rm $cache_file
176 fi
177
178 exit $globalResult