From ffaf504ec0abf64b93ebcc31922bf88ecb4910ca Mon Sep 17 00:00:00 2001 From: William Lachance Date: Tue, 21 Jan 2014 10:01:50 +0000 Subject: [PATCH] Bug 960063 - Make sure we don't try to have two concurrent marionette sessions;r=davehunt --- src/eideticker/eideticker/device.py | 7 ++-- src/eideticker/eideticker/runtest.py | 53 ++++++++++++++++------------ 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/src/eideticker/eideticker/device.py b/src/eideticker/eideticker/device.py index d0463a8..f5623a7 100644 --- a/src/eideticker/eideticker/device.py +++ b/src/eideticker/eideticker/device.py @@ -393,6 +393,7 @@ def setupMarionette(self): self.marionette = marionette.Marionette() self._logger.info("Waiting for Marionette...") self.marionette.wait_for_port() + self._logger.info("Marionette ready, starting session") self.marionette.start_session() if 'b2g' not in self.marionette.session: raise mozdevice.DMError("bad session value %s returned by start_session" % @@ -421,9 +422,12 @@ def cleanup(self): self.removeDir('/'.join(['/sdcard', item])) def stopB2G(self): - #restart b2g so we start with a clean slate + self._logger.info("Stopping B2G") + if self.marionette and self.marionette.session: self.marionette.delete_session() + self.marionette = None + self.shellCheckOutput(['stop', 'b2g']) # Wait for a bit to make sure B2G has completely shut down. tries = 100 @@ -477,7 +481,6 @@ class B2GADB(EidetickerB2GMixin, mozdevice.DeviceManagerADB): def __init__(self, **kwargs): mozdevice.DeviceManagerADB.__init__(self, **kwargs) self._init() # custom eideticker init steps - self.setupMarionette() @property def type(self): diff --git a/src/eideticker/eideticker/runtest.py b/src/eideticker/eideticker/runtest.py index 8dcfd0f..dc10a5c 100644 --- a/src/eideticker/eideticker/runtest.py +++ b/src/eideticker/eideticker/runtest.py @@ -15,24 +15,27 @@ def prepare_test(testkey, device_prefs): # prepare test logic -- currently only done on b2g if device_prefs['devicetype'] == 'b2g': testinfo = get_testinfo(testkey) + device = getDevice(**device_prefs) + # HACK: we need to setup marionette here so we can instantiate a + # b2gpopulate instance inside the device object (even though we + # wind up deleting the same marionette instance in just a moment... + # FIXME: find some less convoluted way of getting the same behaviour) + device.setupMarionette() test = get_test(testinfo, devicetype = device_prefs['devicetype'], device=device, appname=testinfo.get('appname')) # reset B2G device's state for test - logger.info("Resetting B2G and cleaning up...") + logger.info("Stopping B2G and cleaning up...") device.stopB2G() device.cleanup() - # even if we're populating the database, we need to restart b2g so - # b2gpopulate has access to a marionette connection - if hasattr(test, 'populate_databases'): logger.info("Populating database...") test.populate_databases() - logger.info("Restarting b2g") + logger.info("Starting B2G") device.startB2G() device.unlock() device.killApps() @@ -41,6 +44,9 @@ def prepare_test(testkey, device_prefs): logger.info("Doing initial setup on app for test") test.prepare_app() + # close down marionette so we can create a new session later + device.marionette.delete_session() + def run_test(testkey, capture_device, appname, capture_name, device_prefs, extra_prefs={}, test_type=None, profile_file=None, wifi_settings_file=None, request_log_file=None, @@ -70,26 +76,8 @@ def run_test(testkey, capture_device, appname, capture_name, elif no_capture: capture_file = None - # Create a device object to interface with the phone device = getDevice(**device_prefs) - if device_prefs['devicetype'] == 'b2g': - - if sync_time: - # if we're synchronizing time, we need to connect to the network - wifi_settings = json.loads(open(wifi_settings_file).read()) - device.connectWIFI(wifi_settings) - - # unlock device, so it doesn't go to sleep - device.unlock() - - # reset orientation to default for this type of device - device.resetOrientation() - - # synchronize time unless instructed not to - if sync_time: - device.synchronizeTime() - capture_metadata = { 'name': capture_name, 'testpath': testinfo['relpath'], @@ -140,6 +128,25 @@ def run_test(testkey, capture_device, appname, capture_name, docroot = TEST_DIR, tempdir = EIDETICKER_TEMP_DIR) + if device_prefs['devicetype'] == 'b2g': + + device.setupMarionette() + + if sync_time: + # if we're synchronizing time, we need to connect to the network + wifi_settings = json.loads(open(wifi_settings_file).read()) + device.connectWIFI(wifi_settings) + + # unlock device, so it doesn't go to sleep + device.unlock() + + # reset orientation to default for this type of device + device.resetOrientation() + + # synchronize time unless instructed not to + if sync_time: + device.synchronizeTime() + test.run() test.cleanup()