Bug 988382 - Allow B2GRunner to be created without starting a marionette session, r=ahal

This commit is contained in:
James Graham 2014-03-31 15:13:35 +01:00
parent 5ca1aef816
commit 2c71fa221e

View File

@ -100,8 +100,9 @@ class RemoteRunner(Runner):
class B2GRunner(RemoteRunner):
def __init__(self, profile, devicemanager, marionette, context_chrome=True,
test_script=None, test_script_args=None, **kwargs):
def __init__(self, profile, devicemanager, marionette=None, context_chrome=True,
test_script=None, test_script_args=None,
marionette_port=None, emulator=None, **kwargs):
RemoteRunner.__init__(self, profile, devicemanager, **kwargs)
self.log = mozlog.getLogger('B2GRunner')
@ -120,7 +121,22 @@ class B2GRunner(RemoteRunner):
'NO_EM_RESTART': '1', }
self.env.update(tmp_env)
self.last_test = "automation"
self.marionette = marionette
if self.marionette is not None:
if marionette_port is None:
marionette_port = self.marionette.port
elif self.marionette.port != marionette_port:
raise ValueError("Got a marionette object and a port but they don't match")
if emulator is None:
emulator = marionette.emulator
elif marionette.emulator != emulator:
raise ValueError("Got a marionette object and an emulator argument but they don't match")
self.marionette_port = marionette_port
self.emulator = emulator
self.context_chrome = context_chrome
self.test_script = test_script
self.test_script_args = test_script_args
@ -144,8 +160,8 @@ class B2GRunner(RemoteRunner):
self.outputTimeout = outputTimeout
self._setup_remote_profile()
# reboot device so it starts up with the proper profile
if not self.marionette.emulator:
self._reboot_device()
if not self.emulator:
self.dm.reboot(wait=True)
#wait for wlan to come up
if not self._wait_for_net():
raise Exception("network did not come up, please configure the network" +
@ -161,11 +177,19 @@ class B2GRunner(RemoteRunner):
# Set up port forwarding again for Marionette, since any that
# existed previously got wiped out by the reboot.
if not self.marionette.emulator:
if self.emulator is None:
subprocess.Popen([self.dm._adbPath,
'forward',
'tcp:%s' % self.marionette.port,
'tcp:%s' % self.marionette.port]).communicate()
'tcp:%s' % self.marionette_port,
'tcp:2828']).communicate()
if self.marionette is not None:
self.start_marionette()
if self.test_script is not None:
self.start_tests()
def start_marionette(self):
self.marionette.wait_for_port()
# start a marionette session
@ -189,18 +213,15 @@ class B2GRunner(RemoteRunner):
else:
self.marionette.set_context(self.marionette.CONTEXT_CONTENT)
# run the script that starts the tests
if self.test_script:
if os.path.isfile(self.test_script):
script = open(self.test_script, 'r')
self.marionette.execute_script(script.read(), script_args=self.test_script_args)
script.close()
elif isinstance(self.test_script, basestring):
self.marionette.execute_script(self.test_script, script_args=self.test_script_args)
else:
# assumes the tests are started on startup automatically
pass
def start_tests(self):
# run the script that starts the tests
if os.path.isfile(self.test_script):
script = open(self.test_script, 'r')
self.marionette.execute_script(script.read(), script_args=self.test_script_args)
script.close()
elif isinstance(self.test_script, basestring):
self.marionette.execute_script(self.test_script, script_args=self.test_script_args)
def on_output(self, line):
match = re.findall(r"TEST-START \| ([^\s]*)", line)
@ -221,29 +242,6 @@ class B2GRunner(RemoteRunner):
self.log.testFail(msg % (self.last_test, timeout))
self.check_for_crashes()
def _reboot_device(self):
serial, status = self._get_device_status()
buf = StringIO()
self.dm.shell('/system/bin/reboot', buf)
buf.close()
# The reboot command can return while adb still thinks the device is
# connected, so wait a little bit for it to disconnect from adb.
time.sleep(10)
# wait for device to come back to previous status
self.log.info('waiting for device to come back online after reboot')
start = time.time()
rserial, rstatus = self._get_device_status(serial)
while rstatus != 'device':
if time.time() - start > 120:
# device hasn't come back online in 2 minutes, something's wrong
raise Exception("Device %s (status: %s) not back online after reboot" % (serial, rstatus))
time.sleep(5)
rserial, rstatus = self._get_device_status(serial)
self.log.info('device: %s, status: %s' % (serial, rstatus))
def _get_device_status(self, serial=None):
# If we know the device serial number, we look for that,
# otherwise we use the (presumably only) device shown in 'adb devices'.