Bug 885591 - Add a silent argument to check_for_crashes. r=jhammel
authorJonathan Griffin <jgriffin@mozilla.com>
Thu, 20 Jun 2013 17:04:21 -0700
changeset 135917 7ba8c86f1a567fe821b6ecd70c594d42a5422e06
parent 135916 9274b04dcc5da17d728daef4f5ea8c107e068c85
child 135918 03fcdac57879d4b98125e461a942475ab5689a55
child 135954 8fe4e8968c88cc1b87d3675f99e64733a93707a4
child 136054 42b501546ca7b0665d42d19804ddcedec0e4f199
push id29877
push userryanvm@gmail.com
push dateFri, 21 Jun 2013 00:12:34 +0000
treeherdermozilla-inbound@03fcdac57879 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjhammel
bugs885591
milestone24.0a1
first release with
nightly linux32
7ba8c86f1a56 / 24.0a1 / 20130621031051 / files
nightly linux64
7ba8c86f1a56 / 24.0a1 / 20130621031051 / files
nightly mac
7ba8c86f1a56 / 24.0a1 / 20130621031051 / files
nightly win32
7ba8c86f1a56 / 24.0a1 / 20130621031051 / files
nightly win64
7ba8c86f1a56 / 24.0a1 / 20130621031051 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 885591 - Add a silent argument to check_for_crashes. r=jhammel
testing/mozbase/mozcrash/mozcrash/mozcrash.py
testing/mozbase/mozcrash/tests/test.py
--- a/testing/mozbase/mozcrash/mozcrash/mozcrash.py
+++ b/testing/mozbase/mozcrash/mozcrash/mozcrash.py
@@ -16,17 +16,18 @@ import urllib2
 import zipfile
 
 from mozfile import extract_zip
 from mozfile import is_url
 
 def check_for_crashes(dump_directory, symbols_path,
                       stackwalk_binary=None,
                       dump_save_path=None,
-                      test_name=None):
+                      test_name=None,
+                      quiet=False):
     """
     Print a stack trace for minidump files left behind by a crashing program.
 
     `dump_directory` will be searched for minidump files. Any minidump files found will
     have `stackwalk_binary` executed on them, with `symbols_path` passed as an extra
     argument.
 
     `stackwalk_binary` should be a path to the minidump_stackwalk binary.
@@ -39,16 +40,19 @@ def check_for_crashes(dump_directory, sy
 
     If `dump_save_path` is set, it should be a path to a directory in which to copy minidump
     files for safekeeping after a stack trace has been printed. If not set, the environment
     variable MINIDUMP_SAVE_PATH will be checked and its value used if it is not empty.
 
     If `test_name` is set it will be used as the test name in log output. If not set the
     filename of the calling function will be used.
 
+    If `quiet` is set, no PROCESS-CRASH message will be printed to stdout if a
+    crash is detected.
+
     Returns True if any minidumps were found, False otherwise.
     """
     dumps = glob.glob(os.path.join(dump_directory, '*.dmp'))
     if not dumps:
         return False
 
     if stackwalk_binary is None:
         stackwalk_binary = os.environ.get('MINIDUMP_STACKWALK', None)
@@ -115,18 +119,19 @@ def check_for_crashes(dump_directory, sy
                 if not symbols_path:
                     stackwalk_output.append("No symbols path given, can't process dump.")
                 if not stackwalk_binary:
                     stackwalk_output.append("MINIDUMP_STACKWALK not set, can't process dump.")
                 elif stackwalk_binary and not os.path.exists(stackwalk_binary):
                     stackwalk_output.append("MINIDUMP_STACKWALK binary not found: %s" % stackwalk_binary)
             if not top_frame:
                 top_frame = "Unknown top frame"
-            print "PROCESS-CRASH | %s | application crashed [%s]" % (test_name, top_frame)
-            print '\n'.join(stackwalk_output)
+            if not quiet:
+                print "PROCESS-CRASH | %s | application crashed [%s]" % (test_name, top_frame)
+                print '\n'.join(stackwalk_output)
             if dump_save_path is None:
                 dump_save_path = os.environ.get('MINIDUMP_SAVE_PATH', None)
             if dump_save_path:
                 # This code did not previously create the directory,
                 # so there may be a file hanging out with its name.
                 if os.path.isfile(dump_save_path):
                     os.unlink(dump_save_path)
                 if not os.path.isdir(dump_save_path):
--- a/testing/mozbase/mozcrash/tests/test.py
+++ b/testing/mozbase/mozcrash/tests/test.py
@@ -50,93 +50,100 @@ class TestCrash(unittest.TestCase):
 
     def test_nodumps(self):
         """
         Test that check_for_crashes returns False if no dumps are present.
         """
         self.stdouts.append(["this is some output"])
         self.assertFalse(mozcrash.check_for_crashes(self.tempdir,
                                                     'symbols_path',
-                                                    stackwalk_binary=self.stackwalk))
+                                                    stackwalk_binary=self.stackwalk,
+                                                    quiet=True))
 
     def test_simple(self):
         """
         Test that check_for_crashes returns True if a dump is present.
         """
         open(os.path.join(self.tempdir, "test.dmp"), "w").write("foo")
         self.stdouts.append(["this is some output"])
         self.assert_(mozcrash.check_for_crashes(self.tempdir,
                                                 'symbols_path',
-                                                stackwalk_binary=self.stackwalk))
+                                                stackwalk_binary=self.stackwalk,
+                                                quiet=True))
 
     def test_stackwalk_envvar(self):
         """
         Test that check_for_crashes uses the MINIDUMP_STACKWALK environment var.
         """
         open(os.path.join(self.tempdir, "test.dmp"), "w").write("foo")
         self.stdouts.append(["this is some output"])
         os.environ['MINIDUMP_STACKWALK'] = self.stackwalk
         self.assert_(mozcrash.check_for_crashes(self.tempdir,
-                                                'symbols_path'))
+                                                'symbols_path',
+                                                quiet=True))
         del os.environ['MINIDUMP_STACKWALK']
 
     def test_save_path(self):
         """
         Test that dump_save_path works.
         """
         open(os.path.join(self.tempdir, "test.dmp"), "w").write("foo")
         save_path = os.path.join(self.tempdir, "saved")
         os.mkdir(save_path)
         self.stdouts.append(["this is some output"])
         self.assert_(mozcrash.check_for_crashes(self.tempdir,
                                                 'symbols_path',
                                                 stackwalk_binary=self.stackwalk,
-                                                dump_save_path=save_path))
+                                                dump_save_path=save_path,
+                                                quiet=True))
         self.assert_(os.path.isfile(os.path.join(save_path, "test.dmp")))
 
     def test_save_path_not_present(self):
         """
         Test that dump_save_path works when the directory doesn't exist.
         """
         open(os.path.join(self.tempdir, "test.dmp"), "w").write("foo")
         save_path = os.path.join(self.tempdir, "saved")
         self.stdouts.append(["this is some output"])
         self.assert_(mozcrash.check_for_crashes(self.tempdir,
                                                 'symbols_path',
                                                 stackwalk_binary=self.stackwalk,
-                                                dump_save_path=save_path))
+                                                dump_save_path=save_path,
+                                                quiet=True))
         self.assert_(os.path.isfile(os.path.join(save_path, "test.dmp")))
 
     def test_save_path_isfile(self):
         """
         Test that dump_save_path works when the directory doesn't exist,
         but a file with the same name exists.
         """
         open(os.path.join(self.tempdir, "test.dmp"), "w").write("foo")
         save_path = os.path.join(self.tempdir, "saved")
         open(save_path, "w").write("junk")
         self.stdouts.append(["this is some output"])
         self.assert_(mozcrash.check_for_crashes(self.tempdir,
                                                 'symbols_path',
                                                 stackwalk_binary=self.stackwalk,
-                                                dump_save_path=save_path))
+                                                dump_save_path=save_path,
+                                                quiet=True))
         self.assert_(os.path.isfile(os.path.join(save_path, "test.dmp")))
 
     def test_save_path_envvar(self):
         """
         Test that the MINDUMP_SAVE_PATH environment variable works.
         """
         open(os.path.join(self.tempdir, "test.dmp"), "w").write("foo")
         save_path = os.path.join(self.tempdir, "saved")
         os.mkdir(save_path)
         self.stdouts.append(["this is some output"])
         os.environ['MINIDUMP_SAVE_PATH'] = save_path
         self.assert_(mozcrash.check_for_crashes(self.tempdir,
                                                 'symbols_path',
-                                                stackwalk_binary=self.stackwalk))
+                                                stackwalk_binary=self.stackwalk,
+                                                quiet=True))
         del os.environ['MINIDUMP_SAVE_PATH']
         self.assert_(os.path.isfile(os.path.join(save_path, "test.dmp")))
 
     def test_symbol_path_url(self):
         """
         Test that passing a URL as symbols_path correctly fetches the URL.
         """
         open(os.path.join(self.tempdir, "test.dmp"), "w").write("foo")
@@ -153,12 +160,13 @@ class TestCrash(unittest.TestCase):
             return (200, headers, make_zipfile())
         httpd = mozhttpd.MozHttpd(port=0,
                                   urlhandlers=[{'method':'GET', 'path':'/symbols', 'function':get_symbols}])
         httpd.start()
         symbol_url = urlparse.urlunsplit(('http', '%s:%d' % httpd.httpd.server_address,
                                         '/symbols','',''))
         self.assert_(mozcrash.check_for_crashes(self.tempdir,
                                                 symbol_url,
-                                                stackwalk_binary=self.stackwalk))
+                                                stackwalk_binary=self.stackwalk,
+                                                quiet=True))
 
 if __name__ == '__main__':
     unittest.main()