Merge for "Backed out changeset: f6bf83b50648" of

Bug 469523 - xpcshell-tests: enable leak log in tinderbox (log);  (Fv1) Move code to automationutils.py from automation.py.in
which fails on Windows boxes (though works locally :-/)
This commit is contained in:
Serge Gautherie 2009-08-26 22:38:42 +02:00
commit cf129893d1
4 changed files with 131 additions and 173 deletions

View File

@ -70,6 +70,8 @@ __all__ = [
"DEFAULT_APP", "DEFAULT_APP",
"CERTS_SRC_DIR", "CERTS_SRC_DIR",
"environment", "environment",
"dumpLeakLog",
"processLeakLog",
"IS_TEST_BUILD", "IS_TEST_BUILD",
"IS_DEBUG_BUILD", "IS_DEBUG_BUILD",
"SYMBOLS_PATH", "SYMBOLS_PATH",
@ -430,6 +432,109 @@ def environment(env = None, xrePath = DIST_BIN, crashreporter = True):
# RUN THE APP # # RUN THE APP #
############### ###############
def dumpLeakLog(leakLogFile, filter = False):
"""Process the leak log, without parsing it.
Use this function if you want the raw log only.
Use it preferably with the |XPCOM_MEM_LEAK_LOG| environment variable.
"""
# Don't warn (nor "info") if the log file is not there.
if not os.path.exists(leakLogFile):
return
leaks = open(leakLogFile, "r")
leakReport = leaks.read()
leaks.close()
# Only |XPCOM_MEM_LEAK_LOG| reports can be actually filtered out.
# Only check whether an actual leak was reported.
if filter and not "0 TOTAL " in leakReport:
return
# Simply copy the log.
log.info(leakReport.rstrip("\n"))
def processLeakLog(leakLogFile, leakThreshold = 0):
"""Process the leak log, parsing it.
Use this function if you want an additional PASS/FAIL summary.
It must be used with the |XPCOM_MEM_BLOAT_LOG| environment variable.
"""
if not os.path.exists(leakLogFile):
log.info("WARNING refcount logging is off, so leaks can't be detected!")
return
# Per-Inst Leaked Total Rem ...
# 0 TOTAL 17 192 419115886 2 ...
# 833 nsTimerImpl 60 120 24726 2 ...
lineRe = re.compile(r"^\s*\d+\s+(?P<name>\S+)\s+"
r"(?P<size>-?\d+)\s+(?P<bytesLeaked>-?\d+)\s+"
r"-?\d+\s+(?P<numLeaked>-?\d+)")
leaks = open(leakLogFile, "r")
for line in leaks:
matches = lineRe.match(line)
if (matches and
int(matches.group("numLeaked")) == 0 and
matches.group("name") != "TOTAL"):
continue
log.info(line.rstrip())
leaks.close()
leaks = open(leakLogFile, "r")
seenTotal = False
prefix = "TEST-PASS"
for line in leaks:
matches = lineRe.match(line)
if not matches:
continue
name = matches.group("name")
size = int(matches.group("size"))
bytesLeaked = int(matches.group("bytesLeaked"))
numLeaked = int(matches.group("numLeaked"))
if size < 0 or bytesLeaked < 0 or numLeaked < 0:
log.info("TEST-UNEXPECTED-FAIL | runtests-leaks | negative leaks caught!")
if name == "TOTAL":
seenTotal = True
elif name == "TOTAL":
seenTotal = True
# Check for leaks.
if bytesLeaked < 0 or bytesLeaked > leakThreshold:
prefix = "TEST-UNEXPECTED-FAIL"
leakLog = "TEST-UNEXPECTED-FAIL | runtests-leaks | leaked" \
" %d bytes during test execution" % bytesLeaked
elif bytesLeaked > 0:
leakLog = "TEST-PASS | runtests-leaks | WARNING leaked" \
" %d bytes during test execution" % bytesLeaked
else:
leakLog = "TEST-PASS | runtests-leaks | no leaks detected!"
# Remind the threshold if it is not 0, which is the default/goal.
if leakThreshold != 0:
leakLog += " (threshold set at %d bytes)" % leakThreshold
# Log the information.
log.info(leakLog)
else:
if numLeaked != 0:
if numLeaked > 1:
instance = "instances"
rest = " each (%s bytes total)" % matches.group("bytesLeaked")
else:
instance = "instance"
rest = ""
log.info("%(prefix)s | runtests-leaks | leaked %(numLeaked)d %(instance)s of %(name)s "
"with size %(size)s bytes%(rest)s" %
{ "prefix": prefix,
"numLeaked": numLeaked,
"instance": instance,
"name": name,
"size": matches.group("size"),
"rest": rest })
if not seenTotal:
log.info("TEST-UNEXPECTED-FAIL | runtests-leaks | missing output line for total leaks!")
leaks.close()
def runApp(testURL, env, app, profileDir, extraArgs, def runApp(testURL, env, app, profileDir, extraArgs,
runSSLTunnel = False, utilityPath = DIST_BIN, runSSLTunnel = False, utilityPath = DIST_BIN,
xrePath = DIST_BIN, certPath = CERTS_SRC_DIR, xrePath = DIST_BIN, certPath = CERTS_SRC_DIR,

View File

@ -1,74 +1,33 @@
# import sys, glob, os, subprocess, logging
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is The Mozilla Foundation
# Portions created by the Initial Developer are Copyright (C) 2009
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Serge Gautherie <sgautherie.bz@free.fr>
# Ted Mielczarek <ted.mielczarek@gmail.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK ***** */
import glob, logging, os, subprocess, sys
import re
__all__ = [ __all__ = [
"addCommonOptions", "addCommonOptions",
"checkForCrashes", "checkForCrashes",
"dumpLeakLog", ]
"processLeakLog",
]
log = logging.getLogger() log = logging.getLogger()
def addCommonOptions(parser, defaults={}): def addCommonOptions(parser, defaults={}):
parser.add_option("--xre-path", parser.add_option("--xre-path",
action = "store", type = "string", dest = "xrePath", action = "store", type = "string", dest = "xrePath",
# individual scripts will set a sane default # individual scripts will set a sane default
default = None, default = None,
help = "absolute path to directory containing XRE (probably xulrunner)") help = "absolute path to directory containing XRE (probably xulrunner)")
if 'SYMBOLS_PATH' not in defaults: if 'SYMBOLS_PATH' not in defaults:
defaults['SYMBOLS_PATH'] = None defaults['SYMBOLS_PATH'] = None
parser.add_option("--symbols-path", parser.add_option("--symbols-path",
action = "store", type = "string", dest = "symbolsPath", action = "store", type = "string", dest = "symbolsPath",
default = defaults['SYMBOLS_PATH'], default = defaults['SYMBOLS_PATH'],
help = "absolute path to directory containing breakpad symbols") help = "absolute path to directory containing breakpad symbols")
def checkForCrashes(dumpDir, symbolsPath, testName=None): def checkForCrashes(dumpDir, symbolsPath, testName=None):
stackwalkPath = os.environ.get('MINIDUMP_STACKWALK', None) stackwalkPath = os.environ.get('MINIDUMP_STACKWALK', None)
# try to get the caller's filename if no test name is given # try to get the caller's filename if no test name is given
if testName is None: if testName is None:
try: try:
testName = os.path.basename(sys._getframe(1).f_code.co_filename) testName = os.path.basename(sys._getframe(1).f_code.co_filename)
except: except:
testName = "unknown" testName = "unknown"
foundCrash = False foundCrash = False
dumps = glob.glob(os.path.join(dumpDir, '*.dmp')) dumps = glob.glob(os.path.join(dumpDir, '*.dmp'))
@ -82,110 +41,6 @@ def checkForCrashes(dumpDir, symbolsPath, testName=None):
os.remove(d) os.remove(d)
extra = os.path.splitext(d)[0] + ".extra" extra = os.path.splitext(d)[0] + ".extra"
if os.path.exists(extra): if os.path.exists(extra):
os.remove(extra) os.remove(extra)
foundCrash = True foundCrash = True
return foundCrash return foundCrash
def dumpLeakLog(leakLogFile, filter = False):
"""Process the leak log, without parsing it.
Use this function if you want the raw log only.
Use it preferably with the |XPCOM_MEM_LEAK_LOG| environment variable.
"""
# Don't warn (nor "info") if the log file is not there.
if not os.path.exists(leakLogFile):
return
leaks = open(leakLogFile, "r")
leakReport = leaks.read()
leaks.close()
# Only |XPCOM_MEM_LEAK_LOG| reports can be actually filtered out.
# Only check whether an actual leak was reported.
if filter and not "0 TOTAL " in leakReport:
return
# Simply copy the log.
log.info(leakReport.rstrip("\n"))
def processLeakLog(leakLogFile, leakThreshold = 0):
"""Process the leak log, parsing it.
Use this function if you want an additional PASS/FAIL summary.
It must be used with the |XPCOM_MEM_BLOAT_LOG| environment variable.
"""
if not os.path.exists(leakLogFile):
log.info("WARNING refcount logging is off, so leaks can't be detected!")
return
# Per-Inst Leaked Total Rem ...
# 0 TOTAL 17 192 419115886 2 ...
# 833 nsTimerImpl 60 120 24726 2 ...
lineRe = re.compile(r"^\s*\d+\s+(?P<name>\S+)\s+"
r"(?P<size>-?\d+)\s+(?P<bytesLeaked>-?\d+)\s+"
r"-?\d+\s+(?P<numLeaked>-?\d+)")
leaks = open(leakLogFile, "r")
for line in leaks:
matches = lineRe.match(line)
if (matches and
int(matches.group("numLeaked")) == 0 and
matches.group("name") != "TOTAL"):
continue
log.info(line.rstrip())
leaks.close()
leaks = open(leakLogFile, "r")
seenTotal = False
prefix = "TEST-PASS"
for line in leaks:
matches = lineRe.match(line)
if not matches:
continue
name = matches.group("name")
size = int(matches.group("size"))
bytesLeaked = int(matches.group("bytesLeaked"))
numLeaked = int(matches.group("numLeaked"))
if size < 0 or bytesLeaked < 0 or numLeaked < 0:
log.info("TEST-UNEXPECTED-FAIL | runtests-leaks | negative leaks caught!")
if name == "TOTAL":
seenTotal = True
elif name == "TOTAL":
seenTotal = True
# Check for leaks.
if bytesLeaked < 0 or bytesLeaked > leakThreshold:
prefix = "TEST-UNEXPECTED-FAIL"
leakLog = "TEST-UNEXPECTED-FAIL | runtests-leaks | leaked" \
" %d bytes during test execution" % bytesLeaked
elif bytesLeaked > 0:
leakLog = "TEST-PASS | runtests-leaks | WARNING leaked" \
" %d bytes during test execution" % bytesLeaked
else:
leakLog = "TEST-PASS | runtests-leaks | no leaks detected!"
# Remind the threshold if it is not 0, which is the default/goal.
if leakThreshold != 0:
leakLog += " (threshold set at %d bytes)" % leakThreshold
# Log the information.
log.info(leakLog)
else:
if numLeaked != 0:
if numLeaked > 1:
instance = "instances"
rest = " each (%s bytes total)" % matches.group("bytesLeaked")
else:
instance = "instance"
rest = ""
log.info("%(prefix)s | runtests-leaks | leaked %(numLeaked)d %(instance)s of %(name)s "
"with size %(size)s bytes%(rest)s" %
{ "prefix": prefix,
"numLeaked": numLeaked,
"instance": instance,
"name": name,
"size": matches.group("size"),
"rest": rest })
if not seenTotal:
log.info("TEST-UNEXPECTED-FAIL | runtests-leaks | missing output line for total leaks!")
leaks.close()

View File

@ -20,7 +20,6 @@
# the Initial Developer. All Rights Reserved. # the Initial Developer. All Rights Reserved.
# #
# Contributor(s): # Contributor(s):
# Serge Gautherie <sgautherie.bz@free.fr>
# Ted Mielczarek <ted.mielczarek@gmail.com> # Ted Mielczarek <ted.mielczarek@gmail.com>
# #
# Alternatively, the contents of this file may be used under the terms of # Alternatively, the contents of this file may be used under the terms of
@ -45,7 +44,7 @@ import sys, shutil, os, os.path
SCRIPT_DIRECTORY = os.path.abspath(os.path.realpath(os.path.dirname(sys.argv[0]))) SCRIPT_DIRECTORY = os.path.abspath(os.path.realpath(os.path.dirname(sys.argv[0])))
sys.path.append(SCRIPT_DIRECTORY) sys.path.append(SCRIPT_DIRECTORY)
import automation import automation
from automationutils import addCommonOptions, processLeakLog from automationutils import addCommonOptions
from optparse import OptionParser from optparse import OptionParser
from tempfile import mkdtemp from tempfile import mkdtemp
@ -152,7 +151,7 @@ Are you executing $objdir/_tests/reftest/runreftest.py?""" \
["-silent"], ["-silent"],
xrePath=options.xrePath, xrePath=options.xrePath,
symbolsPath=options.symbolsPath) symbolsPath=options.symbolsPath)
# We don't care to call |processLeakLog()| for this step. # We don't care to call |automation.processLeakLog()| for this step.
automation.log.info("\nREFTEST INFO | runreftest.py | Performing extension manager registration: end.") automation.log.info("\nREFTEST INFO | runreftest.py | Performing extension manager registration: end.")
# Remove the leak detection file so it can't "leak" to the tests run. # Remove the leak detection file so it can't "leak" to the tests run.
@ -167,7 +166,7 @@ Are you executing $objdir/_tests/reftest/runreftest.py?""" \
["-reftest", reftestlist], ["-reftest", reftestlist],
xrePath=options.xrePath, xrePath=options.xrePath,
symbolsPath=options.symbolsPath) symbolsPath=options.symbolsPath)
processLeakLog(leakLogFile, options.leakThreshold) automation.processLeakLog(leakLogFile, options.leakThreshold)
automation.log.info("\nREFTEST INFO | runreftest.py | Running tests: end.") automation.log.info("\nREFTEST INFO | runreftest.py | Running tests: end.")
finally: finally:
if profileDir is not None: if profileDir is not None:

View File

@ -22,7 +22,6 @@
# Contributor(s): # Contributor(s):
# Robert Sayre <sayrer@gmail.com> # Robert Sayre <sayrer@gmail.com>
# Jeff Walden <jwalden+bmo@mit.edu> # Jeff Walden <jwalden+bmo@mit.edu>
# Serge Gautherie <sgautherie.bz@free.fr>
# #
# Alternatively, the contents of this file may be used under the terms of # Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or # either the GNU General Public License Version 2 or later (the "GPL"), or
@ -53,7 +52,7 @@ from urllib import quote_plus as encodeURIComponent
import urllib2 import urllib2
import commands import commands
import automation import automation
from automationutils import addCommonOptions, processLeakLog from automationutils import addCommonOptions
# Path to the test script on the server # Path to the test script on the server
TEST_SERVER_HOST = "localhost:8888" TEST_SERVER_HOST = "localhost:8888"
@ -474,7 +473,7 @@ Are you executing $objdir/_tests/testing/mochitest/runtests.py?"""
PROFILE_DIRECTORY, ["-silent"], PROFILE_DIRECTORY, ["-silent"],
xrePath = options.xrePath, xrePath = options.xrePath,
symbolsPath=options.symbolsPath) symbolsPath=options.symbolsPath)
# We don't care to call |processLeakLog()| for this step. # We don't care to call |automation.processLeakLog()| for this step.
automation.log.info("\nINFO | runtests.py | Performing extension manager registration: end.") automation.log.info("\nINFO | runtests.py | Performing extension manager registration: end.")
# Remove the leak detection file so it can't "leak" to the tests run. # Remove the leak detection file so it can't "leak" to the tests run.
@ -497,7 +496,7 @@ Are you executing $objdir/_tests/testing/mochitest/runtests.py?"""
# spew to console shouldn't disrupt the leak information table we print next. # spew to console shouldn't disrupt the leak information table we print next.
server.stop() server.stop()
processLeakLog(LEAK_REPORT_FILE, options.leakThreshold) automation.processLeakLog(LEAK_REPORT_FILE, options.leakThreshold)
automation.log.info("\nINFO | runtests.py | Running tests: end.") automation.log.info("\nINFO | runtests.py | Running tests: end.")
# delete the profile and manifest # delete the profile and manifest