Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / testing / sisyphus / bin / library.sh
blobd5741ee04aa58371625044679a04640fb572b009
1 # -*- Mode: Shell-script; tab-width: 2; indent-tabs-mode: nil; -*-
2 # ***** BEGIN LICENSE BLOCK *****
3 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 # The contents of this file are subject to the Mozilla Public License Version
6 # 1.1 (the "License"); you may not use this file except in compliance with
7 # the License. You may obtain a copy of the License at
8 # http://www.mozilla.org/MPL/
10 # Software distributed under the License is distributed on an "AS IS" basis,
11 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 # for the specific language governing rights and limitations under the
13 # License.
15 # The Original Code is mozilla.org code.
17 # The Initial Developer of the Original Code is
18 # Mozilla Corporation.
19 # Portions created by the Initial Developer are Copyright (C) 2006.
20 # the Initial Developer. All Rights Reserved.
22 # Contributor(s):
23 # Bob Clary <bob@bclary.com>
25 # Alternatively, the contents of this file may be used under the terms of
26 # either the GNU General Public License Version 2 or later (the "GPL"), or
27 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 # in which case the provisions of the GPL or the LGPL are applicable instead
29 # of those above. If you wish to allow use of your version of this file only
30 # under the terms of either the GPL or the LGPL, and not to allow others to
31 # use your version of this file under the terms of the MPL, indicate your
32 # decision by deleting the provisions above and replace them with the notice
33 # and other provisions required by the GPL or the LGPL. If you do not delete
34 # the provisions above, a recipient may use your version of this file under
35 # the terms of any one of the MPL, the GPL or the LGPL.
37 # ***** END LICENSE BLOCK *****
39 # This script contains a number of variables, functions, etc which
40 # are reused across a number of scripts. It should be included in each
41 # script prior to any other commands as follows:
43 # source $TEST_DIR/bin/library.sh
45 if [[ -n "$DEBUG" ]]; then
46 echo "calling $0 $@" 1>&2
49 # export variables
50 set -a
52 # in the event of an untrapped script error tail the test log,
53 # if it exists, to stderr then echo a FATAL ERROR message to the
54 # test log and stderr.
56 function _err()
58 local rc=$?
59 debug "_err: $0"
61 if [[ "$rc" -gt 0 ]]; then
62 if [[ -n "$TEST_LOG" ]]; then
63 echo -e "\nFATAL ERROR in $0 exit code $rc\n" >> $TEST_LOG
64 else
65 echo -e "\nFATAL ERROR in $0 exit code $rc\n" 1>&2
68 exit $rc
71 trap "_err" ERR
73 function _exit()
75 local rc=$?
76 local currscript=`get_scriptname $0`
78 debug "_exit: $0"
80 if [[ "$rc" -gt 0 && -n "$TEST_LOG" && "$SCRIPT" == "$currscript" ]]; then
81 # only tail the log once at the top level script
82 tail $TEST_LOG 1>&2
86 trap "_exit" EXIT
88 # error message
89 # output error message end exit 2
91 error()
93 local message=$1
94 local lineno=$2
96 debug "error: $0:$LINENO"
98 echo -e "FATAL ERROR in script $0:$lineno $message\n" 1>&2
99 if [[ "$0" == "-bash" || "$0" == "bash" ]]; then
100 return 0
102 exit 2
106 if [[ -z "$LIBRARYSH" ]]; then
107 # skip remainder of script if it has already included
109 # Darwin 8.11.1's |which| does not return a non-zero exit code if the
110 # program can not be found. Therefore, kludge around it.
111 findprogram()
113 local program=$1
114 local location=`which $program 2>&1`
115 if [[ ! -x $location ]]; then
116 return 1
118 return 0
121 debug()
123 if [[ -n "$DEBUG" ]]; then
124 echo "DEBUG: $@"
128 # console msg
130 # output message to console, ie. stderr
132 console()
134 echo -e "$@" 1>&2
137 # loaddata
139 # load data files into environment
140 loaddata()
142 local datafiles="$@"
143 local datafile
144 if [[ -n "$datafiles" ]]; then
145 for datafile in $datafiles; do
146 if [[ ! -e "$datafile" ]]; then
147 error "datafile $datafile does not exist"
149 cat $datafile | sed 's|^|data: |'
150 if ! source $datafile; then
151 error "Unable to load data file $datafile"
153 done
157 # dumpenvironment
159 # output environment to stdout
161 dumpenvironment()
163 set | grep '^[A-Z]' | sed 's|^|environment: |'
166 dumphardware()
168 echo "uname -a:`uname -a`"
169 echo "uname -s:`uname -s`"
170 echo "uname -n:`uname -n`"
171 echo "uname -r:`uname -r`"
172 echo "uname -v:`uname -v`"
173 echo "uname -m:`uname -m`"
174 echo "uname -p:`uname -p`"
175 if [[ "$OSID" != "darwin" ]]; then
176 echo "uname -i:`uname -i`"
177 echo "uname -o:`uname -o`"
180 ulimit -a | sed 's|^|ulimit:|'
182 if [[ -e /proc/cpuinfo ]]; then
183 cat /proc/cpuinfo | sed 's|^|cpuinfo:|'
185 if [[ -e /proc/meminfo ]]; then
186 cat /proc/meminfo | sed 's|^|meminfo:|'
188 if findprogram system_profiler; then
189 system_profiler | sed 's|^|system_profiler:|'
193 # dumpvars varname1, ...
195 # dumps name=value pairs to stdout for each variable named
196 # in argument list
198 dumpvars()
200 local argc=$#
201 local argn=1
203 while [ $argn -le $argc ]; do
204 local var=${!argn}
205 echo ${var}=${!var}
206 let argn=argn+1
207 done
210 # get_executable product branch directory
212 # writes path to product executable to stdout
214 get_executable()
216 local get_executable_product="$1"
217 local get_executable_branch="$2"
218 local get_executable_directory="$3"
220 if [[ -z "$get_executable_product" || \
221 -z "$get_executable_branch" || \
222 -z "$get_executable_directory" ]]; then
223 error "usage: get_executable product branch directory"
224 elif [[ ! -d "$get_executable_directory" ]]; then
225 error "get_executable: executable directory \"$get_executable_directory\" does not exist"
226 else
227 # should use /u+x,g+x,a+x but mac os x uses an obsolete find
228 # filter the output to remove extraneous file in dist/bin for
229 # cvs builds on mac os x.
230 local executable=`(
231 get_executable_name="$get_executable_product${EXE_EXT}"
232 case "$OSID" in
233 darwin)
234 get_executable_filter="Contents/MacOS/$get_executable_product"
235 if [[ "$get_executable_product" == "thunderbird" ]]; then
236 get_executable_name="$get_executable_product-bin"
240 get_executable_filter="$get_executable_product"
242 esac
243 if find "$get_executable_directory" -perm +111 -type f \
244 -name "$get_executable_name" | \
245 grep "$get_executable_filter"; then
246 true
250 if [[ -z "$executable" ]]; then
251 error "get_executable $product $branch $executablepath returned empty path" $LINENO
254 if [[ ! -x "$executable" ]]; then
255 error "executable \"$executable\" is not executable" $LINENO
258 echo $executable
262 function get_scriptname()
264 debug "\$0: $0"
266 local script
267 if [[ "$0" == "-bash" || "$0" == "bash" ]]; then
268 script="library.sh"
269 else
270 script=`basename $0`
272 echo $script
275 LIBRARYSH=1
277 MALLOC_CHECK_=${MALLOC_CHECK_:-2}
279 ulimit -c 0
281 # set path to make life easier
282 if ! echo ${PATH} | grep -q $TEST_DIR/bin; then
283 PATH=$TEST_DIR/bin:$PATH
286 # force en_US locale
287 if ! echo "$LANG" | grep -q en_US; then
288 LANG=en_US
289 LC_TIME=en_US
292 # handle sorting non-ascii logs on mac os x 10.5.3
293 LC_ALL=C
295 TEST_TIMEZONE=`date +%z`
297 # save starting directory
298 STARTDIR=`pwd`
300 # location of the script.
301 SCRIPTDIR=`dirname $0`
303 # don't attach to running instance
304 MOZ_NO_REMOTE=1
306 # don't restart
307 NO_EM_RESTART=1
309 # bypass profile manager
310 MOZ_BYPASS_PROFILE_AT_STARTUP=1
312 # ah crap handler timeout
313 MOZ_GDB_SLEEP=${MOZ_GDB_SLEEP:-10}
315 # no airbag
316 unset MOZ_AIRBAG
317 #MOZ_CRASHREPORTER_DISABLE=${MOZ_CRASHREPORTER_DISABLE:-1}
318 MOZ_CRASHREPORTER_NO_REPORT=${MOZ_CRASHREPORTER_NO_REPORT:-1}
320 #leak gauge
321 #NSPR_LOG_MODULES=DOMLeak:5,DocumentLeak:5,nsDocShellLeak:5
323 TEST_CPUSPEED="`mips.pl`"
324 TEST_MEMORY="`memory.pl`"
326 # debug msg
328 # output debugging message to stdout if $DEBUG is set
330 DEBUG=${DEBUG:-""}
332 SCRIPT=`get_scriptname $0`
334 if [[ -z "$TEST_DIR" ]]; then
335 # get the "bin" directory
336 TEST_DIR=`dirname $0`
337 # get the "bin" directory parent
338 TEST_DIR=`dirname $TEST_DIR`
339 if [[ ! -e "${TEST_DIR}/bin/library.sh" ]]; then
340 error "BAD TEST_DIR $TEST_DIR"
344 TEST_HTTP=${TEST_HTTP:-test.mozilla.com}
345 TEST_STARTUP_TIMEOUT=${TEST_STARTUP_TIMEOUT:-30}
346 TEST_MACHINE=`uname -n`
348 kernel_name=`uname -s`
350 if [[ $kernel_name == 'Linux' ]]; then
351 OSID=linux
352 EXE_EXT=
353 TEST_KERNEL=`uname -r | sed 's|\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)[-.0-9]*\.\([a-zA-Z0-9]*\)|\1.\2.\3|'`
354 TEST_PROCESSORTYPE=`cat /proc/cpuinfo | grep vendor | uniq | sed 's|vendor.* : \(.*\)|\1|'`
355 TIMECOMMAND='/usr/bin/time -f "Elapsed time %e seconds, User %U seconds, System %S seconds, CPU %P, Memory: %M"'
357 if echo $TEST_PROCESSORTYPE | grep -q 'Intel'; then
358 TEST_PROCESSORTYPE=intel
359 elif echo $TEST_PROCESSORTYPE | grep -q 'AMD'; then
360 TEST_PROCESSORTYPE=amd
363 if uname -p | grep -q '64$'; then
364 TEST_PROCESSORTYPE=${TEST_PROCESSORTYPE}64
365 else
366 TEST_PROCESSORTYPE=${TEST_PROCESSORTYPE}32
369 elif [[ $kernel_name == 'Darwin' ]]; then
370 OSID=darwin
371 EXE_EXT=
372 TEST_KERNEL=`uname -r`
373 TEST_PROCESSORTYPE=`uname -p`
374 TIMEFORMAT="Elapsed time %E seconds, User %U seconds, System %S seconds, CPU %P%"
375 TIMECOMMAND=time
377 if [[ $TEST_PROCESSORTYPE == "i386" ]]; then
378 TEST_PROCESSORTYPE=intel
381 # assume 32bit for now...
382 TEST_PROCESSORTYPE=${TEST_PROCESSORTYPE}32
384 elif echo $kernel_name | grep -q CYGWIN; then
385 OSID=nt
386 EXE_EXT=".exe"
387 TEST_KERNEL=`echo $kernel_name | sed 's|[^.0-9]*\([.0-9]*\).*|\1|'`
388 TEST_PROCESSORTYPE=`cat /proc/cpuinfo | grep vendor | uniq | sed 's|vendor.* : \(.*\)|\1|'`
389 TIMECOMMAND='/usr/bin/time -f "Elapsed time %e seconds, User %U seconds, System %S seconds, CPU %P, Memory: %M"'
391 if echo $TEST_PROCESSORTYPE | grep -q 'Intel'; then
392 TEST_PROCESSORTYPE=intel
393 elif echo $TEST_PROCESSORTYPE | grep -q 'AMD'; then
394 TEST_PROCESSORTYPE=amd
397 if uname -p | grep -q '64$'; then
398 TEST_PROCESSORTYPE=${TEST_PROCESSORTYPE}64
399 else
400 TEST_PROCESSORTYPE=${TEST_PROCESSORTYPE}32
403 else
404 error "Unknown OS $kernel_name" $LINENO
407 case $TEST_PROCESSORTYPE in
408 *32)
409 if [[ $TEST_MEMORY -gt 4 ]]; then
410 TEST_MEMORY=4
413 esac
415 # no dialogs on asserts
416 XPCOM_DEBUG_BREAK=${XPCOM_DEBUG_BREAK:-warn}
418 if [[ -z "$BUILDDIR" ]]; then
419 case `uname -s` in
420 MINGW*)
421 export BUILDDIR=/c/work/mozilla/builds
424 export BUILDDIR=/work/mozilla/builds
426 esac