Automated checkin: version bump remove "pre" from version number for firefox 4.0b4...
[mozilla-central.git] / testing / sisyphus / bin / library.sh
blob44437948449c5e2e0620e7ae5ed0171f495c2d7c
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 checkProductBranch()
111 local product=$1
112 local branch=$2
114 case $product in
115 js|firefox)
118 error "product \"$product\" must be one of js or firefox" $LINENO
119 esac
121 case $branch in
122 1.8.0|1.8.1|1.9.0|1.9.1|1.9.2|1.9.3)
125 error "branch \"$branch\" must be one of 1.8.0 1.8.1 1.9.0 1.9.1 1.9.2 1.9.3" $LINENO
126 esac
130 # Darwin 8.11.1's |which| does not return a non-zero exit code if the
131 # program can not be found. Therefore, kludge around it.
132 findprogram()
134 local program=$1
135 local location=`which $program 2>&1`
136 if [[ ! -x $location ]]; then
137 return 1
139 return 0
142 debug()
144 if [[ -n "$DEBUG" ]]; then
145 echo "DEBUG: $@"
149 # console msg
151 # output message to console, ie. stderr
153 console()
155 echo -e "$@" 1>&2
158 # loaddata
160 # load data files into environment
161 loaddata()
163 local datafiles="$@"
164 local datafile
165 if [[ -n "$datafiles" ]]; then
166 for datafile in $datafiles; do
167 if [[ ! -e "$datafile" ]]; then
168 error "datafile $datafile does not exist"
170 cat $datafile | sed 's|^|data: |'
171 if ! source $datafile; then
172 error "Unable to load data file $datafile"
174 done
178 # dumpenvironment
180 # output environment to stdout
182 dumpenvironment()
184 set | grep '^[A-Z]' | sed 's|^|environment: |'
187 dumphardware()
189 echo "uname -a:`uname -a`"
190 echo "uname -s:`uname -s`"
191 echo "uname -n:`uname -n`"
192 echo "uname -r:`uname -r`"
193 echo "uname -v:`uname -v`"
194 echo "uname -m:`uname -m`"
195 echo "uname -p:`uname -p`"
196 if [[ "$OSID" != "darwin" ]]; then
197 echo "uname -i:`uname -i`"
198 echo "uname -o:`uname -o`"
201 ulimit -a | sed 's|^|ulimit:|'
203 if [[ -e /proc/cpuinfo ]]; then
204 cat /proc/cpuinfo | sed 's|^|cpuinfo:|'
206 if [[ -e /proc/meminfo ]]; then
207 cat /proc/meminfo | sed 's|^|meminfo:|'
209 if findprogram system_profiler; then
210 system_profiler | sed 's|^|system_profiler:|'
214 # dumpvars varname1, ...
216 # dumps name=value pairs to stdout for each variable named
217 # in argument list
219 dumpvars()
221 local argc=$#
222 local argn=1
224 while [ $argn -le $argc ]; do
225 local var=${!argn}
226 echo ${var}=${!var}
227 let argn=argn+1
228 done
231 # get_executable product branch directory
233 # writes path to product executable to stdout
235 get_executable()
237 local get_executable_product="$1"
238 local get_executable_branch="$2"
239 local get_executable_directory="$3"
241 if [[ -z "$get_executable_product" || \
242 -z "$get_executable_branch" || \
243 -z "$get_executable_directory" ]]; then
244 error "usage: get_executable product branch directory"
245 elif [[ ! -d "$get_executable_directory" ]]; then
246 error "get_executable: executable directory \"$get_executable_directory\" does not exist"
247 else
248 # should use /u+x,g+x,a+x but mac os x uses an obsolete find
249 # filter the output to remove extraneous file in dist/bin for
250 # cvs builds on mac os x.
251 local executable=`(
252 get_executable_name="$get_executable_product${EXE_EXT}"
253 case "$OSID" in
254 darwin)
255 get_executable_filter="Contents/MacOS/$get_executable_product"
258 get_executable_filter="$get_executable_product"
260 esac
261 if find "$get_executable_directory" -perm +111 -type f \
262 -name "$get_executable_name" | \
263 grep "$get_executable_filter"; then
264 true
268 if [[ -z "$executable" ]]; then
269 error "get_executable $product $branch $executablepath returned empty path" $LINENO
272 if [[ ! -x "$executable" ]]; then
273 error "executable \"$executable\" is not executable" $LINENO
276 echo $executable
280 function get_scriptname()
282 debug "\$0: $0"
284 local script
285 if [[ "$0" == "-bash" || "$0" == "bash" ]]; then
286 script="library.sh"
287 else
288 script=`basename $0`
290 echo $script
293 xbasename()
295 local path=$1
296 local suffix=$2
297 local result
299 if ! result=`basename -s $suffix $path 2>&1`; then
300 result=`basename $path $suffix`
303 echo $result
306 LIBRARYSH=1
308 MALLOC_CHECK_=${MALLOC_CHECK_:-2}
310 ulimit -c 0
312 # set path to make life easier
313 if ! echo ${PATH} | grep -q $TEST_DIR/bin; then
314 PATH=$TEST_DIR/bin:$PATH
317 # force en_US locale
318 if ! echo "$LANG" | grep -q en_US; then
319 LANG=en_US
320 LC_TIME=en_US
323 # handle sorting non-ascii logs on mac os x 10.5.3
324 LC_ALL=C
326 TEST_TIMEZONE=`date +%z`
328 # save starting directory
329 STARTDIR=`pwd`
331 # location of the script.
332 SCRIPTDIR=`dirname $0`
334 # don't attach to running instance
335 MOZ_NO_REMOTE=1
337 # don't restart
338 NO_EM_RESTART=1
340 # bypass profile manager
341 MOZ_BYPASS_PROFILE_AT_STARTUP=1
343 # ah crap handler timeout
344 MOZ_GDB_SLEEP=${MOZ_GDB_SLEEP:-10}
346 # no airbag
347 unset MOZ_AIRBAG
348 #MOZ_CRASHREPORTER_DISABLE=${MOZ_CRASHREPORTER_DISABLE:-1}
349 MOZ_CRASHREPORTER_NO_REPORT=${MOZ_CRASHREPORTER_NO_REPORT:-1}
351 #leak gauge
352 #NSPR_LOG_MODULES=DOMLeak:5,DocumentLeak:5,nsDocShellLeak:5
354 TEST_MEMORY="`memory.pl`"
356 # debug msg
358 # output debugging message to stdout if $DEBUG is set
360 DEBUG=${DEBUG:-""}
362 SCRIPT=`get_scriptname $0`
364 if [[ -z "$TEST_DIR" ]]; then
365 # get the "bin" directory
366 TEST_DIR=`dirname $0`
367 # get the "bin" directory parent
368 TEST_DIR=`dirname $TEST_DIR`
369 if [[ ! -e "${TEST_DIR}/bin/library.sh" ]]; then
370 error "BAD TEST_DIR $TEST_DIR"
374 TEST_HTTP=${TEST_HTTP:-test.mozilla.com}
375 TEST_STARTUP_TIMEOUT=${TEST_STARTUP_TIMEOUT:-30}
376 TEST_MACHINE=`uname -n`
378 kernel_name=`uname -s`
380 if [[ $kernel_name == 'Linux' ]]; then
381 OSID=linux
382 EXE_EXT=
383 TEST_KERNEL=`uname -r | sed 's|\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*|\1.\2.\3|'`
384 TEST_PROCESSORTYPE=`cat /proc/cpuinfo | grep vendor | uniq | sed 's|vendor.* : \(.*\)|\1|'`
385 TIMECOMMAND='/usr/bin/time -f "Elapsed time %e seconds, User %U seconds, System %S seconds, CPU %P, Memory: %M"'
387 if echo $TEST_PROCESSORTYPE | grep -q 'Intel'; then
388 TEST_PROCESSORTYPE=intel
389 elif echo $TEST_PROCESSORTYPE | grep -q 'AMD'; then
390 TEST_PROCESSORTYPE=amd
393 if uname -p | grep -q '64$'; then
394 TEST_PROCESSORTYPE=${TEST_PROCESSORTYPE}64
395 else
396 TEST_PROCESSORTYPE=${TEST_PROCESSORTYPE}32
399 elif [[ $kernel_name == 'Darwin' ]]; then
400 OSID=darwin
401 EXE_EXT=
402 TEST_KERNEL=`uname -r`
403 TEST_PROCESSORTYPE=`uname -p`
404 TIMEFORMAT="Elapsed time %E seconds, User %U seconds, System %S seconds, CPU %P%"
405 TIMECOMMAND=time
407 if [[ $TEST_PROCESSORTYPE == "i386" ]]; then
408 TEST_PROCESSORTYPE=intel
411 # assume 32bit for now...
412 TEST_PROCESSORTYPE=${TEST_PROCESSORTYPE}32
414 elif echo $kernel_name | grep -q CYGWIN; then
415 OSID=nt
416 EXE_EXT=".exe"
417 TEST_KERNEL=`echo $kernel_name | sed 's|[^.0-9]*\([.0-9]*\).*|\1|'`
418 TEST_PROCESSORTYPE=`cat /proc/cpuinfo | grep vendor | uniq | sed 's|vendor.* : \(.*\)|\1|'`
419 TIMECOMMAND='/usr/bin/time -f "Elapsed time %e seconds, User %U seconds, System %S seconds, CPU %P, Memory: %M"'
421 if echo $TEST_PROCESSORTYPE | grep -q 'Intel'; then
422 TEST_PROCESSORTYPE=intel
423 elif echo $TEST_PROCESSORTYPE | grep -q 'AMD'; then
424 TEST_PROCESSORTYPE=amd
427 if uname -p | grep -q '64$'; then
428 TEST_PROCESSORTYPE=${TEST_PROCESSORTYPE}64
429 else
430 TEST_PROCESSORTYPE=${TEST_PROCESSORTYPE}32
433 else
434 error "Unknown OS $kernel_name" $LINENO
437 case $TEST_PROCESSORTYPE in
438 *32)
439 if [[ $TEST_MEMORY -gt 4 ]]; then
440 TEST_MEMORY=4
443 esac
445 # no dialogs on asserts
446 XPCOM_DEBUG_BREAK=${XPCOM_DEBUG_BREAK:-warn}
448 if [[ -z "$BUILDDIR" ]]; then
449 case `uname -s` in
450 MINGW*)
451 export BUILDDIR=/c/work/mozilla/builds
454 export BUILDDIR=/work/mozilla/builds
456 esac