Bug 1223277 - Improve Marionette unit tests for delayed crashes. draft
authorHenrik Skupin <mail@hskupin.info>
Thu, 22 Jun 2017 11:45:10 +0200
changeset 599741 2870cedfe26c58bc3a9c60a82099fd456718d213
parent 599740 09e67923b22150ca49075f0b6566f61d209467dc
child 599742 e7723ca5aa711b6c22656b9db7ed4d569c2a7961
child 600719 f35b9ea06142abbd183a82e59f6121055adf5dd3
push id65580
push userbmo:hskupin@gmail.com
push dateFri, 23 Jun 2017 13:27:14 +0000
bugs1223277
milestone56.0a1
Bug 1223277 - Improve Marionette unit tests for delayed crashes. In case of delayed shutdowns of Firefox we currently miss to detect the created minidump files because the mozcrash mock gets removed right after the crash causing command has been executed. To prevent this the mock has to be active from setUp until tearDown. Also we should not silently ignore the case that the minidump folder cannot be deleted. Because it means no crash happened, or the folder has not been created. MozReview-Commit-ID: KncJ5BHi7M5
testing/marionette/harness/marionette_harness/tests/unit/test_crash.py
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_crash.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_crash.py
@@ -26,17 +26,17 @@ class MockMozCrash(object):
                   return true;
                 } catch (exc) {
                   return false;
                 }
             """)
 
     def check_for_crashes(self, dump_directory, *args, **kwargs):
         minidump_files = glob.glob('{}/*.dmp'.format(dump_directory))
-        shutil.rmtree(dump_directory, ignore_errors=True)
+        shutil.rmtree(dump_directory)
 
         if self.crash_reporter_enabled:
             return len(minidump_files)
         else:
             return len(minidump_files) == 0
 
     def log_crashes(self, logger, dump_directory, *args, **kwargs):
         return self.check_for_crashes(dump_directory, *args, **kwargs)
@@ -45,73 +45,71 @@ class MockMozCrash(object):
 class BaseCrashTestCase(MarionetteTestCase):
 
     # Reduce the timeout for faster processing of the tests
     socket_timeout = 10
 
     def setUp(self):
         super(BaseCrashTestCase, self).setUp()
 
-        self.mozcrash_mock = MockMozCrash(self.marionette)
+        # Monkey patch mozcrash to avoid crash info output only for our triggered crashes.
+        self.mozcrash = runner.mozcrash
+        runner.mozcrash = MockMozCrash(self.marionette)
+
         self.crash_count = self.marionette.crashed
         self.pid = self.marionette.process_id
         self.remote_uri = self.marionette.absolute_url("javascriptPage.html")
 
     def tearDown(self):
+        # Replace mockup with original mozcrash instance
+        runner.mozcrash = self.mozcrash
+
         self.marionette.crashed = self.crash_count
 
         super(BaseCrashTestCase, self).tearDown()
 
     def crash(self, chrome=True):
         context = 'chrome' if chrome else 'content'
         sandbox = None if chrome else 'system'
 
-        # Monkey patch mozcrash to avoid crash info output only for our triggered crashes.
-        mozcrash = runner.mozcrash
-        runner.mozcrash = self.mozcrash_mock
-
         socket_timeout = self.marionette.client.socket_timeout
+        self.marionette.client.socket_timeout = self.socket_timeout
 
         self.marionette.set_context(context)
         try:
-            self.marionette.client.socket_timeout = self.socket_timeout
             self.marionette.execute_script("""
               // Copied from crash me simple
               Components.utils.import("resource://gre/modules/ctypes.jsm");
 
               // ctypes checks for NULL pointer derefs, so just go near-NULL.
               var zero = new ctypes.intptr_t(8);
               var badptr = ctypes.cast(zero, ctypes.PointerType(ctypes.int32_t));
               var crash = badptr.contents;
             """, sandbox=sandbox)
         finally:
-            runner.mozcrash = mozcrash
             self.marionette.client.socket_timeout = socket_timeout
 
 
 class TestCrash(BaseCrashTestCase):
 
     def test_crash_chrome_process(self):
         self.assertRaisesRegexp(IOError, 'Process crashed',
                                 self.crash, chrome=True)
         self.assertEqual(self.marionette.crashed, 1)
         self.assertIsNone(self.marionette.session)
         self.assertRaisesRegexp(MarionetteException, 'Please start a session',
                                 self.marionette.get_url)
 
         self.marionette.start_session()
         self.assertNotEqual(self.marionette.process_id, self.pid)
 
-        # TODO: Bug 1314594 - Causes a hang for the communication between the
-        # chrome and frame script.
-        # self.marionette.get_url()
+        self.marionette.get_url()
 
     @run_if_e10s("Content crashes only exist in e10s mode")
     def test_crash_content_process(self):
-        # If e10s is disabled the chrome process crashes
         self.marionette.navigate(self.remote_uri)
 
         self.assertRaisesRegexp(IOError, 'Content process crashed',
                                 self.crash, chrome=False)
         self.assertEqual(self.marionette.crashed, 1)
         self.assertIsNone(self.marionette.session)
         self.assertRaisesRegexp(MarionetteException, 'Please start a session',
                                 self.marionette.get_url)