Title: [215824] trunk/Tools
Revision
215824
Author
[email protected]
Date
2017-04-26 13:23:32 -0700 (Wed, 26 Apr 2017)

Log Message

webkitpy: Teardown iOS Simulators on exit if managed Simulators are still running
https://bugs.webkit.org/show_bug.cgi?id=171293

Reviewed by Aakash Jain.

We should make an effort to teardown simulators which we booted even when an exception is
thrown while booting. Make some IOSSimulatorPort functions into static methods and register
one of these functions to be run at exit to ensure any devices webkitpy is managing gets
torn down.

* Scripts/webkitpy/layout_tests/controllers/manager.py:
(Manager._set_up_run): Rely on exit handlers to teardown, not exceptions.
* Scripts/webkitpy/port/ios_simulator.py:
(IOSSimulatorPort._teardown_managed_simulators): Function run on exit which will kill all
iOS simulators and teardown and managed devices.
(IOSSimulatorPort._create_simulators): Register teardown function.
(IOSSimulatorPort.clean_up_test_run): Move device teardown to _teardown_managed_simulators.
(IOSSimulatorPort._remove_device): Deleted.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (215823 => 215824)


--- trunk/Tools/ChangeLog	2017-04-26 20:09:42 UTC (rev 215823)
+++ trunk/Tools/ChangeLog	2017-04-26 20:23:32 UTC (rev 215824)
@@ -1,3 +1,24 @@
+2017-04-26  Jonathan Bedard  <[email protected]>
+
+        webkitpy: Teardown iOS Simulators on exit if managed Simulators are still running
+        https://bugs.webkit.org/show_bug.cgi?id=171293
+
+        Reviewed by Aakash Jain.
+
+        We should make an effort to teardown simulators which we booted even when an exception is
+        thrown while booting. Make some IOSSimulatorPort functions into static methods and register
+        one of these functions to be run at exit to ensure any devices webkitpy is managing gets
+        torn down.
+
+        * Scripts/webkitpy/layout_tests/controllers/manager.py:
+        (Manager._set_up_run): Rely on exit handlers to teardown, not exceptions.
+        * Scripts/webkitpy/port/ios_simulator.py:
+        (IOSSimulatorPort._teardown_managed_simulators): Function run on exit which will kill all
+        iOS simulators and teardown and managed devices.
+        (IOSSimulatorPort._create_simulators): Register teardown function.
+        (IOSSimulatorPort.clean_up_test_run): Move device teardown to _teardown_managed_simulators.
+        (IOSSimulatorPort._remove_device): Deleted.
+
 2017-04-26  Joanmarie Diggs  <[email protected]>
 
         [ATK] Implement support for new ARIA 1.1 values of aria-haspopup

Modified: trunk/Tools/Scripts/webkitpy/layout_tests/controllers/manager.py (215823 => 215824)


--- trunk/Tools/Scripts/webkitpy/layout_tests/controllers/manager.py	2017-04-26 20:09:42 UTC (rev 215823)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/controllers/manager.py	2017-04-26 20:23:32 UTC (rev 215824)
@@ -188,11 +188,7 @@
         # Create the output directory if it doesn't already exist.
         self._port.host.filesystem.maybe_make_directory(self._results_directory)
 
-        try:
-            self._port.setup_test_run(self._options.device_class)
-        except:
-            self._port.clean_up_test_run()
-            raise
+        self._port.setup_test_run(self._options.device_class)
         return True
 
     def run(self, args):

Modified: trunk/Tools/Scripts/webkitpy/port/ios_simulator.py (215823 => 215824)


--- trunk/Tools/Scripts/webkitpy/port/ios_simulator.py	2017-04-26 20:09:42 UTC (rev 215823)
+++ trunk/Tools/Scripts/webkitpy/port/ios_simulator.py	2017-04-26 20:23:32 UTC (rev 215824)
@@ -20,6 +20,7 @@
 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+import atexit
 import logging
 import os
 import re
@@ -180,6 +181,35 @@
     def _set_device_class(self, device_class):
         self._device_class = device_class if device_class else self.DEFAULT_DEVICE_CLASS
 
+    # This function may be called more than once.
+    def _teardown_managed_simulators(self):
+        if not self._using_dedicated_simulators():
+            return
+        self._quit_ios_simulator()
+
+        for i in xrange(len(Simulator.managed_devices)):
+            simulator_path = self.get_simulator_path(i)
+            device_udid = Simulator.managed_devices[i].udid
+            Simulator.remove_device(i)
+
+            if not os.path.exists(simulator_path):
+                continue
+            try:
+                self._executive.run_command([IOSSimulatorPort.LSREGISTER_PATH, "-u", simulator_path])
+
+                _log.debug('rmtree %s', simulator_path)
+                self._filesystem.rmtree(simulator_path)
+
+                logs_path = self._filesystem.join(self._filesystem.expanduser("~"), "Library/Logs/CoreSimulator/", device_udid)
+                _log.debug('rmtree %s', logs_path)
+                self._filesystem.rmtree(logs_path)
+
+                saved_state_path = self._filesystem.join(self._filesystem.expanduser("~"), "Library/Saved Application State/", IOSSimulatorPort.SIMULATOR_BUNDLE_ID + str(i) + ".savedState")
+                _log.debug('rmtree %s', saved_state_path)
+                self._filesystem.rmtree(saved_state_path)
+            except:
+                _log.warning('Unable to remove Simulator' + str(i))
+
     def _create_simulators(self):
         if (self.default_child_processes() < self.child_processes()):
             _log.warn('You have specified very high value({0}) for --child-processes'.format(self.child_processes()))
@@ -187,6 +217,7 @@
             _log.warn('This is very likely to fail.')
 
         if self._using_dedicated_simulators():
+            atexit.register(lambda: self._teardown_managed_simulators())
             self._createSimulatorApps()
 
             for i in xrange(self.child_processes()):
@@ -245,7 +276,6 @@
     def clean_up_test_run(self):
         super(IOSSimulatorPort, self).clean_up_test_run()
         _log.debug("clean_up_test_run")
-        self._quit_ios_simulator()
         fifos = [path for path in os.listdir('/tmp') if re.search('org.webkit.(DumpRenderTree|WebKitTestRunner).*_(IN|OUT|ERROR)', path)]
         for fifo in fifos:
             try:
@@ -257,29 +287,7 @@
         if not self._using_dedicated_simulators():
             return
 
-        for i in xrange(self.child_processes()):
-            simulator_path = self.get_simulator_path(i)
-            device_udid = self._testing_device(i).udid
-            self._remove_device(i)
-
-            if not os.path.exists(simulator_path):
-                continue
-            try:
-                self._executive.run_command([self.LSREGISTER_PATH, "-u", simulator_path])
-
-                _log.debug('rmtree %s', simulator_path)
-                self._filesystem.rmtree(simulator_path)
-
-                logs_path = self._filesystem.join(self._filesystem.expanduser("~"), "Library/Logs/CoreSimulator/", device_udid)
-                _log.debug('rmtree %s', logs_path)
-                self._filesystem.rmtree(logs_path)
-
-                saved_state_path = self._filesystem.join(self._filesystem.expanduser("~"), "Library/Saved Application State/", self.SIMULATOR_BUNDLE_ID + str(i) + ".savedState")
-                _log.debug('rmtree %s', saved_state_path)
-                self._filesystem.rmtree(saved_state_path)
-
-            except:
-                _log.warning('Unable to remove Simulator' + str(i))
+        self._teardown_managed_simulators()
         IOSSimulatorPort._DEVICE_MAP = {}
 
     def setup_environ_for_server(self, server_name=None):
@@ -317,9 +325,6 @@
     def _create_device(self, number):
         return Simulator.create_device(number, self.simulator_device_type(), self.simulator_runtime)
 
-    def _remove_device(self, number):
-        Simulator.remove_device(number)
-
     def get_simulator_path(self, suffix=""):
         return os.path.join(self.SIMULATOR_DIRECTORY, "Simulator" + str(suffix) + ".app")
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to