Bug 1441287 - [mozcrash] check_for_crashes should always return count of crashes. draft
authorHenrik Skupin <mail@hskupin.info>
Tue, 20 Mar 2018 13:44:56 +0100
changeset 769939 834e75201494f50166cc3809624a64bebe2b2a93
parent 769938 f608125657882cb750a66a9dfe332a38bc986e57
child 769940 8950894daddfc99a251f75064b183b7865349866
child 769951 7b0c774810646d6279b6652a8468736665fc3bbb
push id103264
push userbmo:hskupin@gmail.com
push dateTue, 20 Mar 2018 13:40:52 +0000
bugs1441287
milestone61.0a1
Bug 1441287 - [mozcrash] check_for_crashes should always return count of crashes. Right now if no minidump file is present in the minidump folder, the check_for_crashes method returns False. Whereby in all other cases the number of crashes is returned. To be consistent this method should always return a number, and in case of no minidumps it should be 0. MozReview-Commit-ID: 3DTgxn41TVn
testing/mozbase/mozcrash/mozcrash/mozcrash.py
testing/mozbase/mozcrash/tests/test_basic.py
testing/mozbase/mozcrash/tests/test_java_exception.py
testing/mozbase/mozcrash/tests/test_save_path.py
testing/mozbase/mozcrash/tests/test_stackwalk.py
testing/mozbase/mozcrash/tests/test_symbols_path.py
--- a/testing/mozbase/mozcrash/mozcrash/mozcrash.py
+++ b/testing/mozbase/mozcrash/mozcrash/mozcrash.py
@@ -85,19 +85,16 @@ def check_for_crashes(dump_directory,
         try:
             test_name = os.path.basename(sys._getframe(1).f_code.co_filename)
         except Exception:
             test_name = "unknown"
 
     crash_info = CrashInfo(dump_directory, symbols_path, dump_save_path=dump_save_path,
                            stackwalk_binary=stackwalk_binary)
 
-    if not crash_info.has_dumps:
-        return False
-
     crash_count = 0
     for info in crash_info:
         crash_count += 1
         if not quiet:
             stackwalk_output = ["Crash dump filename: %s" % info.minidump_path]
             if info.stackwalk_stderr:
                 stackwalk_output.append("stderr from minidump_stackwalk:")
                 stackwalk_output.append(info.stackwalk_stderr)
--- a/testing/mozbase/mozcrash/tests/test_basic.py
+++ b/testing/mozbase/mozcrash/tests/test_basic.py
@@ -5,28 +5,31 @@ from __future__ import absolute_import
 import mozunit
 
 import mozcrash
 from testcase import CrashTestCase
 
 
 class TestBasic(CrashTestCase):
 
-    def test_nodumps(self):
-        """Test that check_for_crashes returns False if no dumps are present."""
+    def test_no_dump_files(self):
+        """Test that check_for_crashes returns 0 if no dumps are present."""
         self.stdouts.append(["this is some output"])
-        self.assertFalse(mozcrash.check_for_crashes(self.tempdir,
-                                                    symbols_path='symbols_path',
-                                                    stackwalk_binary=self.stackwalk,
-                                                    quiet=True))
+
+        self.assertEqual(0, mozcrash.check_for_crashes(self.tempdir,
+                                                       symbols_path='symbols_path',
+                                                       stackwalk_binary=self.stackwalk,
+                                                       quiet=True))
 
-    def test_simple(self):
+    def test_dump_count(self):
         """Test that check_for_crashes returns True if a dump is present."""
-        self.create_minidump("test")
+        self.create_minidump("test1")
+        self.create_minidump("test2")
+        self.create_minidump("test3")
 
-        self.assert_(mozcrash.check_for_crashes(self.tempdir,
-                                                symbols_path='symbols_path',
-                                                stackwalk_binary=self.stackwalk,
-                                                quiet=True))
+        self.assertEqual(3, mozcrash.check_for_crashes(self.tempdir,
+                                                       symbols_path='symbols_path',
+                                                       stackwalk_binary=self.stackwalk,
+                                                       quiet=True))
 
 
 if __name__ == '__main__':
     mozunit.main()
--- a/testing/mozbase/mozcrash/tests/test_java_exception.py
+++ b/testing/mozbase/mozcrash/tests/test_java_exception.py
@@ -33,31 +33,31 @@ class TestJavaException(unittest.TestCas
             "    at org.mozilla.gecko.GeckoApp$21.run(GeckoApp.java:1833)",
             "01-30 20:15:41.937 E/GeckoAppShell( 1703):"
             "    at android.os.Handler.handleCallback(Handler.java:587)"]
 
     def test_uncaught_exception(self):
         """
         Test for an exception which should be caught
         """
-        self.assert_(mozcrash.check_for_java_exception(self.test_log, quiet=True))
+        self.assertEqual(1, mozcrash.check_for_java_exception(self.test_log, quiet=True))
 
     def test_truncated_exception(self):
         """
         Test for an exception which should be caught which
         was truncated
         """
         truncated_log = list(self.test_log)
         truncated_log[0], truncated_log[1] = truncated_log[1], truncated_log[0]
-        self.assert_(mozcrash.check_for_java_exception(truncated_log, quiet=True))
+        self.assertEqual(1, mozcrash.check_for_java_exception(truncated_log, quiet=True))
 
     def test_unchecked_exception(self):
         """
         Test for an exception which should not be caught
         """
         passable_log = list(self.test_log)
         passable_log[0] = "01-30 20:15:41.937 E/GeckoAppShell( 1703):" \
                           " >>> NOT-SO-BAD EXCEPTION FROM THREAD 9 (\"GeckoBackgroundThread\")"
-        self.assert_(not mozcrash.check_for_java_exception(passable_log, quiet=True))
+        self.assertEqual(0, mozcrash.check_for_java_exception(passable_log, quiet=True))
 
 
 if __name__ == '__main__':
     mozunit.main()
--- a/testing/mozbase/mozcrash/tests/test_save_path.py
+++ b/testing/mozbase/mozcrash/tests/test_save_path.py
@@ -13,21 +13,21 @@ from testcase import CrashTestCase
 class TestSavePath(CrashTestCase):
 
     def setUp(self):
         super(TestSavePath, self).setUp()
 
         self.create_minidump("test")
 
     def check_for_saved_minidump_files(self, save_path=None):
-        self.assert_(mozcrash.check_for_crashes(self.tempdir,
-                                                symbols_path='symbols_path',
-                                                stackwalk_binary=self.stackwalk,
-                                                dump_save_path=save_path,
-                                                quiet=True))
+        self.assertEqual(1, mozcrash.check_for_crashes(self.tempdir,
+                                                       symbols_path='symbols_path',
+                                                       stackwalk_binary=self.stackwalk,
+                                                       dump_save_path=save_path,
+                                                       quiet=True))
         if save_path is None:
             save_path = os.environ.get('MINIDUMP_SAVE_PATH', None)
 
         self.assert_(os.path.isfile(os.path.join(save_path, "test.dmp")))
         self.assert_(os.path.isfile(os.path.join(save_path, "test.extra")))
 
     def test_save_path_not_present(self):
         """Test that dump_save_path works when the directory doesn't exist."""
--- a/testing/mozbase/mozcrash/tests/test_stackwalk.py
+++ b/testing/mozbase/mozcrash/tests/test_stackwalk.py
@@ -12,16 +12,16 @@ from testcase import CrashTestCase
 
 class TestStackwalk(CrashTestCase):
 
     def test_stackwalk_envvar(self):
         """Test that check_for_crashes uses the MINIDUMP_STACKWALK environment var."""
         self.create_minidump("test.")
 
         os.environ['MINIDUMP_STACKWALK'] = self.stackwalk
-        self.assert_(mozcrash.check_for_crashes(self.tempdir,
-                                                symbols_path='symbols_path',
-                                                quiet=True))
+        self.assertEqual(1, mozcrash.check_for_crashes(self.tempdir,
+                                                       symbols_path='symbols_path',
+                                                       quiet=True))
         del os.environ['MINIDUMP_STACKWALK']
 
 
 if __name__ == '__main__':
     mozunit.main()
--- a/testing/mozbase/mozcrash/tests/test_symbols_path.py
+++ b/testing/mozbase/mozcrash/tests/test_symbols_path.py
@@ -15,20 +15,20 @@ from testcase import CrashTestCase
 
 
 class TestCrash(CrashTestCase):
 
     def test_symbol_path_not_present(self):
         """Test that no symbols path doesn't process the minidump."""
         self.create_minidump("test")
 
-        self.assert_(mozcrash.check_for_crashes(self.tempdir,
-                                                symbols_path=None,
-                                                stackwalk_binary=self.stackwalk,
-                                                quiet=True))
+        self.assertEqual(1, mozcrash.check_for_crashes(self.tempdir,
+                                                       symbols_path=None,
+                                                       stackwalk_binary=self.stackwalk,
+                                                       quiet=True))
 
     def test_symbol_path_url(self):
         """Test that passing a URL as symbols_path correctly fetches the URL."""
         self.create_minidump("test")
 
         data = {"retrieved": False}
 
         def make_zipfile():
@@ -47,17 +47,17 @@ class TestCrash(CrashTestCase):
         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,
-                                                symbols_path=symbol_url,
-                                                stackwalk_binary=self.stackwalk,
-                                                quiet=True))
+        self.assertEqual(1, mozcrash.check_for_crashes(self.tempdir,
+                                                       symbols_path=symbol_url,
+                                                       stackwalk_binary=self.stackwalk,
+                                                       quiet=True))
         self.assertTrue(data["retrieved"])
 
 
 if __name__ == '__main__':
     mozunit.main()