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
Родитель 5ca1aef816
Коммит 2c71fa221e
1 изменённых файлов: 39 добавлений и 41 удалений

Просмотреть файл

@ -100,8 +100,9 @@ class RemoteRunner(Runner):
class B2GRunner(RemoteRunner): class B2GRunner(RemoteRunner):
def __init__(self, profile, devicemanager, marionette, context_chrome=True, def __init__(self, profile, devicemanager, marionette=None, context_chrome=True,
test_script=None, test_script_args=None, **kwargs): test_script=None, test_script_args=None,
marionette_port=None, emulator=None, **kwargs):
RemoteRunner.__init__(self, profile, devicemanager, **kwargs) RemoteRunner.__init__(self, profile, devicemanager, **kwargs)
self.log = mozlog.getLogger('B2GRunner') self.log = mozlog.getLogger('B2GRunner')
@ -120,7 +121,22 @@ class B2GRunner(RemoteRunner):
'NO_EM_RESTART': '1', } 'NO_EM_RESTART': '1', }
self.env.update(tmp_env) self.env.update(tmp_env)
self.last_test = "automation" self.last_test = "automation"
self.marionette = marionette 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.context_chrome = context_chrome
self.test_script = test_script self.test_script = test_script
self.test_script_args = test_script_args self.test_script_args = test_script_args
@ -144,8 +160,8 @@ class B2GRunner(RemoteRunner):
self.outputTimeout = outputTimeout self.outputTimeout = outputTimeout
self._setup_remote_profile() self._setup_remote_profile()
# reboot device so it starts up with the proper profile # reboot device so it starts up with the proper profile
if not self.marionette.emulator: if not self.emulator:
self._reboot_device() self.dm.reboot(wait=True)
#wait for wlan to come up #wait for wlan to come up
if not self._wait_for_net(): if not self._wait_for_net():
raise Exception("network did not come up, please configure the network" + 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 # Set up port forwarding again for Marionette, since any that
# existed previously got wiped out by the reboot. # existed previously got wiped out by the reboot.
if not self.marionette.emulator: if self.emulator is None:
subprocess.Popen([self.dm._adbPath, subprocess.Popen([self.dm._adbPath,
'forward', 'forward',
'tcp:%s' % self.marionette.port, 'tcp:%s' % self.marionette_port,
'tcp:%s' % self.marionette.port]).communicate() '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() self.marionette.wait_for_port()
# start a marionette session # start a marionette session
@ -189,18 +213,15 @@ class B2GRunner(RemoteRunner):
else: else:
self.marionette.set_context(self.marionette.CONTEXT_CONTENT) self.marionette.set_context(self.marionette.CONTEXT_CONTENT)
# run the script that starts the tests
if self.test_script: def start_tests(self):
if os.path.isfile(self.test_script): # run the script that starts the tests
script = open(self.test_script, 'r') if os.path.isfile(self.test_script):
self.marionette.execute_script(script.read(), script_args=self.test_script_args) script = open(self.test_script, 'r')
script.close() self.marionette.execute_script(script.read(), script_args=self.test_script_args)
elif isinstance(self.test_script, basestring): script.close()
self.marionette.execute_script(self.test_script, script_args=self.test_script_args) elif isinstance(self.test_script, basestring):
else: self.marionette.execute_script(self.test_script, script_args=self.test_script_args)
# assumes the tests are started on startup automatically
pass
def on_output(self, line): def on_output(self, line):
match = re.findall(r"TEST-START \| ([^\s]*)", 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.log.testFail(msg % (self.last_test, timeout))
self.check_for_crashes() 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): def _get_device_status(self, serial=None):
# If we know the device serial number, we look for that, # If we know the device serial number, we look for that,
# otherwise we use the (presumably only) device shown in 'adb devices'. # otherwise we use the (presumably only) device shown in 'adb devices'.