Bug 469523 - xpcshell-tests: enable leak log in tinderbox (log); (Hv1) Use automationutils.dumpLeakLog(), fix/update automationutils.processLeakLog() log messages
authorSerge Gautherie <sgautherie.bz@free.fr>
Wed, 16 Sep 2009 17:50:03 +0200
changeset 32532 bb40c09d164a95f17df1fb23abb9f5859e374fda
parent 32531 1348d3ce063d1e3567360d34551cd11e92dd73d0
child 32533 ba331f3a3daf7f5b34e66c7311fc83dda161a342
push idunknown
push userunknown
push dateunknown
bugs469523
milestone1.9.3a1pre
Bug 469523 - xpcshell-tests: enable leak log in tinderbox (log); (Hv1) Use automationutils.dumpLeakLog(), fix/update automationutils.processLeakLog() log messages r=ted.mielczarek
build/automationutils.py
testing/xpcshell/runxpcshelltests.py
--- a/build/automationutils.py
+++ b/build/automationutils.py
@@ -113,17 +113,17 @@ def dumpLeakLog(leakLogFile, filter = Fa
 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!")
+    log.info("WARNING | automationutils.processLeakLog() | 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+)")
@@ -145,47 +145,47 @@ def processLeakLog(leakLogFile, leakThre
     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!")
+      log.info("TEST-UNEXPECTED-FAIL | automationutils.processLeakLog() | 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" \
+        leakLog = "TEST-UNEXPECTED-FAIL | automationutils.processLeakLog() | leaked" \
                   " %d bytes during test execution" % bytesLeaked
       elif bytesLeaked > 0:
-        leakLog = "TEST-PASS | runtests-leaks | WARNING leaked" \
+        leakLog = "TEST-PASS | automationutils.processLeakLog() | WARNING leaked" \
                   " %d bytes during test execution" % bytesLeaked
       else:
-        leakLog = "TEST-PASS | runtests-leaks | no leaks detected!"
+        leakLog = "TEST-PASS | automationutils.processLeakLog() | 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 "
+        log.info("%(prefix)s | automationutils.processLeakLog() | 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!")
+    log.info("TEST-UNEXPECTED-FAIL | automationutils.processLeakLog() | missing output line for total leaks!")
   leaks.close()
--- a/testing/xpcshell/runxpcshelltests.py
+++ b/testing/xpcshell/runxpcshelltests.py
@@ -39,17 +39,17 @@
 
 import re, sys, os, os.path, logging, shutil
 import tempfile
 from glob import glob
 from optparse import OptionParser
 from subprocess import Popen, PIPE, STDOUT
 from tempfile import mkdtemp
 
-from automationutils import addCommonOptions, checkForCrashes
+from automationutils import addCommonOptions, checkForCrashes, dumpLeakLog
 
 # Init logging
 log = logging.getLogger()
 handler = logging.StreamHandler(sys.stdout)
 log.setLevel(logging.INFO)
 log.addHandler(handler)
 
 def readManifest(manifest):
@@ -102,33 +102,16 @@ def runTests(xpcshell, testdirs=[], xreP
   # Don't launch the crash reporter client
   env["MOZ_CRASHREPORTER_NO_REPORT"] = "1"
 
   # Enable leaks (only) detection to its own log file.
   # Each test will overwrite it.
   leakLogFile = os.path.join(tempfile.gettempdir(), "runxpcshelltests_leaks.log")
   env["XPCOM_MEM_LEAK_LOG"] = leakLogFile
 
-  def processLeakLog(leakLogFile):
-    """Process the leak log."""
-    # For the time being, don't warn (nor "info") if the log file is not there. (Bug 469523)
-    if not os.path.exists(leakLogFile):
-      return None
-
-    leaks = open(leakLogFile, "r")
-    leakReport = leaks.read()
-    leaks.close()
-
-    # Only check whether an actual leak was reported.
-    if "0 TOTAL " in leakReport:
-      # For the time being, simply copy the log. (Bug 469523)
-      print leakReport.rstrip("\n")
-
-    return leakReport
-
   if xrePath is None:
     xrePath = os.path.dirname(xpcshell)
   else:
     xrePath = os.path.abspath(xrePath)
   if sys.platform == 'win32':
     env["PATH"] = env["PATH"] + ";" + xrePath
   elif sys.platform in ('os2emx', 'os2knix'):
     os.environ["BEGINLIBPATH"] = xrePath + ";" + env["BEGINLIBPATH"]
@@ -244,24 +227,27 @@ def runTests(xpcshell, testdirs=[], xreP
   %s
   <<<<<<<""" % (test, proc.returncode, stdout)
         checkForCrashes(testdir, symbolsPath, testName=test)
         failCount += 1
       else:
         print "TEST-PASS | %s | test passed" % test
         passCount += 1
 
-      leakReport = processLeakLog(leakLogFile)
+      dumpLeakLog(leakLogFile, True)
 
       if stdout is not None:
         try:
           f = open(test + '.log', 'w')
           f.write(stdout)
-          if leakReport:
-            f.write(leakReport)
+
+          if os.path.exists(leakLogFile):
+            leaks = open(leakLogFile, "r")
+            f.write(leaks.read())
+            leaks.close()
         finally:
           if f:
             f.close()
 
       # Remove the leak detection file (here) so it can't "leak" to the next test.
       # The file is not there if leak logging was not enabled in the xpcshell build.
       if os.path.exists(leakLogFile):
         os.remove(leakLogFile)