Bug 1274395 - Delete pending crash reports before running tests; r=jmaher
authorGeoff Brown <gbrown@mozilla.com>
Wed, 25 May 2016 14:48:42 -0600
changeset 371105 6251c1e010a14c930402ae2dcefb2dce38679640
parent 371104 0ffc66933c30c941fc7ab26d7458377047dec9c1
child 371106 836c207f205f3e0f9e40a447a568c8a8b71a59e6
push id19232
push userbmo:gps@mozilla.com
push dateWed, 25 May 2016 22:36:54 +0000
reviewersjmaher
bugs1274395
milestone49.0a1
Bug 1274395 - Delete pending crash reports before running tests; r=jmaher
layout/tools/reftest/reftestcommandline.py
layout/tools/reftest/runreftest.py
testing/mochitest/mochitest_options.py
testing/mochitest/runtests.py
testing/mozbase/mozcrash/mozcrash/mozcrash.py
testing/mozharness/configs/unittests/linux_unittest.py
testing/mozharness/configs/unittests/mac_unittest.py
testing/mozharness/configs/unittests/win_unittest.py
--- a/layout/tools/reftest/reftestcommandline.py
+++ b/layout/tools/reftest/reftestcommandline.py
@@ -212,16 +212,22 @@ class ReftestArgumentsParser(argparse.Ar
                           dest="specialPowersExtensionPath",
                           help="Path to the special powers extension")
 
         self.add_argument("--suite",
                           choices=["reftest", "crashtest", "jstestbrowser"],
                           default=None,
                           help=argparse.SUPPRESS)
 
+        self.add_argument("--cleanup-crashes",
+                          action = "store_true",
+                          dest = "cleanupCrashes",
+                          default = False,
+                          help = "Delete pending crash reports before running tests.")
+
         self.add_argument("tests",
                           metavar="TEST_PATH",
                           nargs="*",
                           help="Path to test file, manifest file, or directory containing tests")
 
         mozlog.commandline.add_logging_group(self)
 
     def get_ip(self):
--- a/layout/tools/reftest/runreftest.py
+++ b/layout/tools/reftest/runreftest.py
@@ -407,16 +407,19 @@ class RefTest(object):
         # Despite our efforts to clean up servers started by this script, in practice
         # we still see infrequent cases where a process is orphaned and interferes
         # with future tests, typically because the old server is keeping the port in use.
         # Try to avoid those failures by checking for and killing orphan servers before
         # trying to start new ones.
         self.killNamedOrphans('ssltunnel')
         self.killNamedOrphans('xpcshell')
 
+        if options.cleanupCrashes:
+            mozcrash.cleanup_pending_crash_reports()
+
         manifests = self.resolver.resolveManifests(options, tests)
         if options.filter:
             manifests[""] = options.filter
 
         if not getattr(options, 'runTestsInParallel', False):
             return self.runSerialTests(manifests, options, cmdargs)
 
         cpuCount = multiprocessing.cpu_count()
--- a/testing/mochitest/mochitest_options.py
+++ b/testing/mochitest/mochitest_options.py
@@ -554,16 +554,23 @@ class MochitestArguments(ArgumentContain
           "help": "Timeout while waiting for the marionette port to open.",
           "suppress": True,
           }],
         [["--marionette-socket-timeout"],
          {"default": None,
           "help": "Timeout while waiting to receive a message from the marionette server.",
           "suppress": True,
           }],
+        [["--cleanup-crashes"],
+         {"action": "store_true",
+          "dest": "cleanupCrashes",
+          "default": False,
+          "help": "Delete pending crash reports before running tests.",
+          "suppress": True,
+          }],
     ]
 
     defaults = {
         # Bug 1065098 - The geckomediaplugin process fails to produce a leak
         # log for some reason.
         'ignoreMissingLeaks': ["geckomediaplugin"],
         'extensionsToExclude': ['specialpowers'],
         # Set server information on the args object
--- a/testing/mochitest/runtests.py
+++ b/testing/mochitest/runtests.py
@@ -2201,16 +2201,19 @@ class MochitestDesktop(MochitestBase):
         # Despite our efforts to clean up servers started by this script, in practice
         # we still see infrequent cases where a process is orphaned and interferes
         # with future tests, typically because the old server is keeping the port in use.
         # Try to avoid those failures by checking for and killing orphan servers before
         # trying to start new ones.
         self.killNamedOrphans('ssltunnel')
         self.killNamedOrphans('xpcshell')
 
+        if options.cleanupCrashes:
+            mozcrash.cleanup_pending_crash_reports()
+
         # Until we have all green, this only runs on bc*/dt*/mochitest-chrome
         # jobs, not jetpack*, a11yr (for perf reasons), or plain
 
         testsToRun = self.getTestsToRun(options)
         if not options.runByDir:
             return self.runMochitests(options, testsToRun)
 
         # code for --run-by-dir
--- a/testing/mozbase/mozcrash/mozcrash/mozcrash.py
+++ b/testing/mozbase/mozcrash/mozcrash/mozcrash.py
@@ -2,16 +2,17 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
 __all__ = [
     'check_for_crashes',
     'check_for_java_exception',
     'kill_and_get_minidump',
     'log_crashes',
+    'cleanup_pending_crash_reports',
 ]
 
 import glob
 import os
 import re
 import shutil
 import signal
 import subprocess
@@ -486,16 +487,45 @@ def kill_and_get_minidump(pid, dump_dire
     if mozinfo.isWin:
         write_minidump(pid, dump_directory, utility_path)
     elif mozinfo.isLinux or mozinfo.isMac:
         os.kill(pid, signal.SIGABRT)
         needs_killing = False
     if needs_killing:
         kill_pid(pid)
 
+def cleanup_pending_crash_reports():
+    """
+    Delete any pending crash reports.
+
+    The presence of pending crash reports may be reported by the browser,
+    affecting test results; it is best to ensure that these are removed
+    before starting any browser tests.
+
+    Firefox stores pending crash reports in "<UAppData>/Crash Reports".
+    If the browser is not running, it cannot provide <UAppData>, so this
+    code tries to anticipate its value.
+
+    See dom/system/OSFileConstants.cpp for platform variations of <UAppData>.
+    """
+    if mozinfo.isWin:
+        location = os.path.expanduser("~\\AppData\\Roaming\\Mozilla\\Firefox\\Crash Reports")
+    elif mozinfo.isMac:
+        location = os.path.expanduser("~/Library/Application Support/firefox/Crash Reports")
+    else:
+        location = os.path.expanduser("~/.mozilla/firefox/Crash Reports")
+    logger = get_logger()
+    if os.path.exists(location):
+        try:
+            mozfile.remove(location)
+            logger.info("Removed pending crash reports at '%s'" % location)
+        except:
+            pass
+
+
 if __name__ == '__main__':
     import argparse
     parser = argparse.ArgumentParser()
     parser.add_argument('--stackwalk-binary', '-b')
     parser.add_argument('--dump-save-path', '-o')
     parser.add_argument('--test-name', '-n')
     parser.add_argument('dump_directory')
     parser.add_argument('symbols_path')
--- a/testing/mozharness/configs/unittests/linux_unittest.py
+++ b/testing/mozharness/configs/unittests/linux_unittest.py
@@ -124,16 +124,17 @@ config = {
                 "--symbols-path=%(symbols_path)s",
                 "--certificate-path=tests/certs",
                 "--setpref=webgl.force-enabled=true",
                 "--quiet",
                 "--log-raw=%(raw_log_file)s",
                 "--log-errorsummary=%(error_summary_file)s",
                 "--use-test-media-devices",
                 "--screenshot-on-fail",
+                "--cleanup-crashes",
             ],
             "run_filename": "runtests.py",
             "testsdir": "mochitest"
         },
         "mozbase": {
             "options": [
                 "-b",
                 "%(binary_path)s"
@@ -154,16 +155,17 @@ config = {
         "reftest": {
             "options": [
                 "--appname=%(binary_path)s",
                 "--utility-path=tests/bin",
                 "--extra-profile-file=tests/bin/plugins",
                 "--symbols-path=%(symbols_path)s",
                 "--log-raw=%(raw_log_file)s",
                 "--log-errorsummary=%(error_summary_file)s",
+                "--cleanup-crashes",
             ],
             "run_filename": "runreftest.py",
             "testsdir": "reftest"
         },
         "xpcshell": {
             "options": [
                 "--symbols-path=%(symbols_path)s",
                 "--test-plugin-path=%(test_plugin_path)s",
--- a/testing/mozharness/configs/unittests/mac_unittest.py
+++ b/testing/mozharness/configs/unittests/mac_unittest.py
@@ -78,16 +78,17 @@ config = {
                 "--utility-path=tests/bin",
                 "--extra-profile-file=tests/bin/plugins",
                 "--symbols-path=%(symbols_path)s",
                 "--certificate-path=tests/certs",
                 "--quiet",
                 "--log-raw=%(raw_log_file)s",
                 "--log-errorsummary=%(error_summary_file)s",
                 "--screenshot-on-fail",
+                "--cleanup-crashes",
             ],
             "run_filename": "runtests.py",
             "testsdir": "mochitest"
         },
         "mozbase": {
             "options": [
                 "-b",
                 "%(binary_path)s"
@@ -106,16 +107,17 @@ config = {
             "testsdir": "mozmill"
         },
         "reftest": {
             "options": [
                 "--appname=%(binary_path)s",
                 "--utility-path=tests/bin",
                 "--extra-profile-file=tests/bin/plugins",
                 "--symbols-path=%(symbols_path)s"
+                "--cleanup-crashes",
             ],
             "run_filename": "runreftest.py",
             "testsdir": "reftest"
         },
         "xpcshell": {
             "options": [
                 "--symbols-path=%(symbols_path)s",
                 "--test-plugin-path=%(test_plugin_path)s",
--- a/testing/mozharness/configs/unittests/win_unittest.py
+++ b/testing/mozharness/configs/unittests/win_unittest.py
@@ -89,16 +89,17 @@ config = {
                 "--utility-path=tests/bin",
                 "--extra-profile-file=tests/bin/plugins",
                 "--symbols-path=%(symbols_path)s",
                 "--certificate-path=tests/certs",
                 "--quiet",
                 "--log-raw=%(raw_log_file)s",
                 "--log-errorsummary=%(error_summary_file)s",
                 "--screenshot-on-fail",
+                "--cleanup-crashes",
             ],
             "run_filename": "runtests.py",
             "testsdir": "mochitest"
         },
         "mozbase": {
             "options": [
                 "-b",
                 "%(binary_path)s"
@@ -119,16 +120,17 @@ config = {
         "reftest": {
             "options": [
                 "--appname=%(binary_path)s",
                 "--utility-path=tests/bin",
                 "--extra-profile-file=tests/bin/plugins",
                 "--symbols-path=%(symbols_path)s",
                 "--log-raw=%(raw_log_file)s",
                 "--log-errorsummary=%(error_summary_file)s",
+                "--cleanup-crashes",
             ],
             "run_filename": "runreftest.py",
             "testsdir": "reftest"
         },
         "xpcshell": {
             "options": [
                 "--symbols-path=%(symbols_path)s",
                 "--test-plugin-path=%(test_plugin_path)s",