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