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
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.
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
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.
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
65 echo -e "\nFATAL ERROR in $0 exit code $rc\n" 1>&2
76 local currscript
=`get_scriptname $0`
80 if [[ "$rc" -gt 0 && -n "$TEST_LOG" && "$SCRIPT" == "$currscript" ]]; then
81 # only tail the log once at the top level script
89 # output error message end exit 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
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.
114 local location
=`which $program 2>&1`
115 if [[ ! -x $location ]]; then
123 if [[ -n "$DEBUG" ]]; then
130 # output message to console, ie. stderr
139 # load data files into environment
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"
159 # output environment to stdout
163 set |
grep '^[A-Z]' |
sed 's|^|environment: |'
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
203 while [ $argn -le $argc ]; do
210 # get_executable product branch directory
212 # writes path to product executable to stdout
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"
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.
231 get_executable_name="$get_executable_product${EXE_EXT}"
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"
243 if find "$get_executable_directory" -perm +111 -type f \
244 -name "$get_executable_name" | \
245 grep "$get_executable_filter"; then
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
262 function get_scriptname
()
267 if [[ "$0" == "-bash" ||
"$0" == "bash" ]]; then
277 MALLOC_CHECK_
=${MALLOC_CHECK_:-2}
281 # set path to make life easier
282 if ! echo ${PATH} |
grep -q $TEST_DIR/bin
; then
283 PATH
=$TEST_DIR/bin
:$PATH
287 if ! echo "$LANG" |
grep -q en_US
; then
292 # handle sorting non-ascii logs on mac os x 10.5.3
295 TEST_TIMEZONE
=`date +%z`
297 # save starting directory
300 # location of the script.
301 SCRIPTDIR
=`dirname $0`
303 # don't attach to running instance
309 # bypass profile manager
310 MOZ_BYPASS_PROFILE_AT_STARTUP
=1
312 # ah crap handler timeout
313 MOZ_GDB_SLEEP
=${MOZ_GDB_SLEEP:-10}
317 #MOZ_CRASHREPORTER_DISABLE=${MOZ_CRASHREPORTER_DISABLE:-1}
318 MOZ_CRASHREPORTER_NO_REPORT
=${MOZ_CRASHREPORTER_NO_REPORT:-1}
321 #NSPR_LOG_MODULES=DOMLeak:5,DocumentLeak:5,nsDocShellLeak:5
323 TEST_CPUSPEED
="`mips.pl`"
324 TEST_MEMORY
="`memory.pl`"
328 # output debugging message to stdout if $DEBUG is set
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
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
366 TEST_PROCESSORTYPE
=${TEST_PROCESSORTYPE}32
369 elif [[ $kernel_name == 'Darwin' ]]; then
372 TEST_KERNEL
=`uname -r`
373 TEST_PROCESSORTYPE
=`uname -p`
374 TIMEFORMAT
="Elapsed time %E seconds, User %U seconds, System %S seconds, CPU %P%"
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
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
400 TEST_PROCESSORTYPE
=${TEST_PROCESSORTYPE}32
404 error
"Unknown OS $kernel_name" $LINENO
407 case $TEST_PROCESSORTYPE in
409 if [[ $TEST_MEMORY -gt 4 ]]; then
415 # no dialogs on asserts
416 XPCOM_DEBUG_BREAK
=${XPCOM_DEBUG_BREAK:-warn}
418 if [[ -z "$BUILDDIR" ]]; then
421 export BUILDDIR
=/c
/work
/mozilla
/builds
424 export BUILDDIR
=/work
/mozilla
/builds