Bug 423235 - Make leak detection always run but only be fatal if the threshold is exceeded, for better leak visibility when --leak-threshold isn't specified; also removes the need for me to maintain a --leak-threshold=0 local change without committing it. r=sayrer, a=testonlychange
authorjwalden@mit.edu
Sat, 15 Mar 2008 21:11:44 -0700
changeset 13136 89056e6f16d727b8d6ea86a9eedb09f11f4381a7
parent 13135 adb094e785e183a85e7d07bd6d1b1e4cb27bb397
child 13137 9f4aba0889abcf62054582c9e61c338adc995ec5
push idunknown
push userunknown
push dateunknown
reviewerssayrer, testonlychange
bugs423235
milestone1.9b5pre
Bug 423235 - Make leak detection always run but only be fatal if the threshold is exceeded, for better leak visibility when --leak-threshold isn't specified; also removes the need for me to maintain a --leak-threshold=0 local change without committing it. r=sayrer, a=testonlychange
testing/mochitest/runtests.py.in
--- a/testing/mochitest/runtests.py.in
+++ b/testing/mochitest/runtests.py.in
@@ -157,17 +157,17 @@ class MochitestOptions(optparse.OptionPa
     defaults["browserArgs"] = []
 
     self.add_option("--leak-threshold",
                     action = "store", type = "int", dest = "leakThreshold",
                     help = "fail if the number of bytes leaked through "
                            "refcounted objects (or bytes in classes with "
                            "MOZ_COUNT_CTOR and MOZ_COUNT_DTOR) is greater "
                            "than the given number")
-    defaults["leakThreshold"] = -1
+    defaults["leakThreshold"] = float("Inf")
 
     # -h, --help are automatically handled by OptionParser
 
     self.set_defaults(**defaults)
 
     usage = """\
 Usage instructions for runtests.py.
 All arguments are optional.
@@ -318,62 +318,62 @@ Are you executing $objdir/_tests/testing
       urlOpts.append("logFile=" + encodeURIComponent(options.logFile))
     if options.fileLevel:
       urlOpts.append("fileLevel=" + encodeURIComponent(options.fileLevel))
     if options.consoleLevel:
       urlOpts.append("consoleLevel=" + encodeURIComponent(options.consoleLevel))
     if len(urlOpts) > 0:
       testURL += "?" + "&".join(urlOpts)
 
-  if options.leakThreshold >= 0:
-    browserEnv["XPCOM_MEM_BLOAT_LOG"] = LEAK_REPORT_FILE
+  browserEnv["XPCOM_MEM_BLOAT_LOG"] = LEAK_REPORT_FILE
 
   start = automation.runApp(testURL, browserEnv, options.app, PROFILE_DIRECTORY,
                             options.browserArgs)
 
   server.stop()
 
-  if not os.path.exists(LEAK_REPORT_FILE) and options.leakThreshold >= 0:
-    print "WARNING refcount logging is off, so leak detection has been disabled"
-  elif options.leakThreshold >= 0:
+  if not os.path.exists(LEAK_REPORT_FILE):
+    print "WARNING refcount logging is off, so leaks can't be detected!"
+  else:
     leaks = open(LEAK_REPORT_FILE, "r")
     for line in leaks:
       print line,
     leaks.close()
 
     threshold = options.leakThreshold
     leaks = open(LEAK_REPORT_FILE, "r")
     #                  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+)")
     thresholdExceeded = False
     seenTotal = False
+    prefix = "WARNING"
     for line in leaks:
       matches = lineRe.match(line)
       if not matches:
         continue
       name = matches.group("name")
       if "TOTAL" == name:
         seenTotal = True
         bytesLeaked = int(matches.group("bytesLeaked"))
         if bytesLeaked > threshold:
           thresholdExceeded = True
+          prefix = "ERROR FAIL"
           print ("ERROR FAIL leaked %(actual)d bytes during test "
                  "execution (should have leaked no more than "
                  "%(expect)d bytes)") % { "actual": bytesLeaked,
                                           "expect": threshold }
         elif bytesLeaked > 0:
           print "WARNING leaked %d bytes during test execution" % bytesLeaked
       else:
         numLeaked = int(matches.group("numLeaked"))
         if numLeaked != 0:
-          prefix = thresholdExceeded and "ERROR FAIL" or "WARNING"
           if numLeaked > 1:
             instance = "instances"
             rest = " each (%s bytes total)" % matches.group("bytesLeaked")
           else:
             instance = "instance"
             rest = ""
           vars = { "prefix": prefix,
                    "numLeaked": numLeaked,