--- a/testing/mozbase/docs/mozrunner.rst
+++ b/testing/mozbase/docs/mozrunner.rst
@@ -108,35 +108,35 @@ gecko process.
Using a device runner
---------------------
The previous examples used a GeckoRuntimeRunner. If you want to control a
gecko process on a remote device, you need to use a DeviceRunner. The api is
nearly identical except you don't pass in a binary, instead you create a device
-object. For example, for B2G (Firefox OS) emulators you might do:
+object. For example to run Firefox for Android on the emulator, you might do:
.. code-block:: python
- from mozrunner import B2GEmulatorRunner
+ from mozrunner import FennecEmulatorRunner
- b2g_home = 'path/to/B2G'
- runner = B2GEmulatorRunner(arch='arm', b2g_home=b2g_home)
+ avd_home = 'path/to/avd'
+ runner = FennecEmulatorRunner(app='org.mozilla.fennec', avd_home=avd_home)
runner.start()
runner.wait()
Device runners have a `device` object. Remember that the gecko process runs on
the device. In the case of the emulator, it is possible to start the
device independently of the gecko process.
.. code-block:: python
- runner.device.start() # launches the emulator (which also launches gecko)
- runner.start() # stops the gecko process, installs the profile, restarts the gecko process
+ runner.device.start() # launches the emulator
+ runner.start() # stops the gecko process (if started), installs the profile, (re)starts the gecko process
Runner API Documentation
------------------------
Application Runners
~~~~~~~~~~~~~~~~~~~
.. automodule:: mozrunner.runners
@@ -165,13 +165,13 @@ Device API Documentation
Generally using the device classes directly shouldn't be required, but in some
cases it may be desirable.
Device
~~~~~~
.. autoclass:: mozrunner.devices.Device
:members:
-Emulator
-~~~~~~~~
-.. autoclass:: mozrunner.devices.Emulator
+EmulatorAVD
+~~~~~~~~~~~
+.. autoclass:: mozrunner.devices.EmulatorAVD
:show-inheritance:
:members:
--- a/testing/mozbase/mozrunner/mozrunner/application.py
+++ b/testing/mozbase/mozrunner/mozrunner/application.py
@@ -1,33 +1,31 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import
from abc import ABCMeta, abstractmethod
from distutils.spawn import find_executable
-import glob
import os
import posixpath
-from mozdevice import DeviceManagerADB, DMError, DroidADB
+from mozdevice import DeviceManagerADB, DroidADB
from mozprofile import (
Profile,
FirefoxProfile,
ThunderbirdProfile
)
here = os.path.abspath(os.path.dirname(__file__))
def get_app_context(appname):
context_map = {'default': DefaultContext,
- 'b2g': B2GContext,
'firefox': FirefoxContext,
'thunderbird': ThunderbirdContext,
'fennec': FennecContext}
if appname not in context_map:
raise KeyError("Application '%s' not supported!" % appname)
return context_map[appname]
@@ -122,130 +120,14 @@ class FennecContext(RemoteContext):
if not self._remote_profiles_ini:
self._remote_profiles_ini = posixpath.join(
self.dm.getAppRoot(self.remote_process),
'files', 'mozilla', 'profiles.ini'
)
return self._remote_profiles_ini
-class B2GContext(RemoteContext):
- _remote_settings_db = None
-
- def __init__(self, b2g_home=None, adb_path=None):
- self.homedir = b2g_home or os.environ.get('B2G_HOME')
-
- if self.homedir is not None and not os.path.isdir(self.homedir):
- raise OSError('Homedir \'%s\' does not exist!' % self.homedir)
-
- self._adb = adb_path
- self._update_tools = None
- self._fastboot = None
-
- self.remote_binary = '/system/bin/b2g.sh'
- self.remote_bundles_dir = '/system/b2g/distribution/bundles'
- self.remote_busybox = '/system/bin/busybox'
- self.remote_process = '/system/b2g/b2g'
- self.remote_profiles_ini = '/data/b2g/mozilla/profiles.ini'
- self.remote_settings_json = '/system/b2g/defaults/settings.json'
- self.remote_idb_dir = '/data/local/storage/permanent/chrome/idb'
- self.remote_test_root = '/data/local/tests'
- self.remote_webapps_dir = '/data/local/webapps'
-
- self.remote_backup_files = [
- self.remote_settings_json,
- self.remote_webapps_dir,
- ]
-
- @property
- def fastboot(self):
- if self._fastboot is None:
- self._fastboot = self.which('fastboot')
- return self._fastboot
-
- @property
- def update_tools(self):
- if self._update_tools is None and self.homedir is not None:
- self._update_tools = os.path.join(self.homedir, 'tools', 'update-tools')
- return self._update_tools
-
- @property
- def bindir(self):
- if self._bindir is None and self.homedir is not None:
- # TODO get this via build configuration
- path = os.path.join(self.homedir, 'out', 'host', '*', 'bin')
- paths = glob.glob(path)
- if paths:
- self._bindir = paths[0]
- return self._bindir
-
- @property
- def remote_settings_db(self):
- if not self._remote_settings_db:
- for filename in self.dm.listFiles(self.remote_idb_dir):
- if filename.endswith('ssegtnti.sqlite'):
- self._remote_settings_db = posixpath.join(self.remote_idb_dir, filename)
- break
- else:
- raise DMError("Could not find settings db in '%s'!" % self.remote_idb_dir)
- return self._remote_settings_db
-
- def stop_application(self):
- self.dm.shellCheckOutput(['stop', 'b2g'])
-
- def setup_profile(self, profile):
- # For some reason user.js in the profile doesn't get picked up.
- # Manually copy it over to prefs.js. See bug 1009730 for more details.
- self.dm.moveTree(posixpath.join(self.remote_profile, 'user.js'),
- posixpath.join(self.remote_profile, 'prefs.js'))
-
- if self.dm.fileExists(posixpath.join(self.remote_profile, 'settings.json')):
- # On devices, settings.json is only read from the profile if
- # the system location doesn't exist.
- if self.dm.fileExists(self.remote_settings_json):
- self.dm.removeFile(self.remote_settings_json)
-
- # Delete existing settings db and create a new empty one to force new
- # settings to be loaded.
- self.dm.removeFile(self.remote_settings_db)
- self.dm.shellCheckOutput(['touch', self.remote_settings_db])
-
- # On devices, the webapps are located in /data/local/webapps instead of the profile.
- # In some cases we may need to replace the existing webapps, in others we may just
- # need to leave them in the profile. If the system app is present in the profile
- # webapps, it's a good indication that they should replace the existing ones wholesale.
- profile_webapps = posixpath.join(self.remote_profile, 'webapps')
- if self.dm.dirExists(posixpath.join(profile_webapps, 'system.gaiamobile.org')):
- self.dm.removeDir(self.remote_webapps_dir)
- self.dm.moveTree(profile_webapps, self.remote_webapps_dir)
-
- # On devices extensions are installed in the system dir
- extension_dir = os.path.join(profile.profile, 'extensions', 'staged')
- if os.path.isdir(extension_dir):
- # Copy the extensions to the B2G bundles dir.
- for filename in os.listdir(extension_dir):
- path = posixpath.join(self.remote_bundles_dir, filename)
- if self.dm.fileExists(path):
- self.dm.removeFile(path)
- self.dm.pushDir(extension_dir, self.remote_bundles_dir)
-
- def cleanup_profile(self):
- # Delete any bundled extensions
- extension_dir = posixpath.join(self.remote_profile, 'extensions', 'staged')
- if self.dm.dirExists(extension_dir):
- for filename in self.dm.listFiles(extension_dir):
- try:
- self.dm.removeDir(posixpath.join(self.remote_bundles_dir, filename))
- except DMError:
- pass
-
- if self.dm.fileExists(posixpath.join(self.remote_profile, 'settings.json')):
- # Force settings.db to be restored to defaults
- self.dm.removeFile(self.remote_settings_db)
- self.dm.shellCheckOutput(['touch', self.remote_settings_db])
-
-
class FirefoxContext(object):
profile_class = FirefoxProfile
class ThunderbirdContext(object):
profile_class = ThunderbirdProfile
--- a/testing/mozbase/mozrunner/mozrunner/base/device.py
+++ b/testing/mozbase/mozrunner/mozrunner/base/device.py
@@ -15,17 +15,17 @@ import mozfile
from .runner import BaseRunner
from ..devices import BaseEmulator
class DeviceRunner(BaseRunner):
"""
The base runner class used for running gecko on
- remote devices (or emulators), such as B2G.
+ remote devices (or emulators).
"""
env = {'MOZ_CRASHREPORTER': '1',
'MOZ_CRASHREPORTER_NO_REPORT': '1',
'MOZ_CRASHREPORTER_SHUTDOWN': '1',
'MOZ_HIDE_RESULTS_TABLE': '1',
'MOZ_LOG': 'signaling:3,mtransport:4,DataChannel:4,jsep:4,MediaPipelineFactory:4',
'R_LOG_LEVEL': '6',
'R_LOG_DESTINATION': 'stderr',
--- a/testing/mozbase/mozrunner/mozrunner/devices/__init__.py
+++ b/testing/mozbase/mozrunner/mozrunner/devices/__init__.py
@@ -1,15 +1,15 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import
-from .emulator import BaseEmulator, Emulator, EmulatorAVD
+from .emulator import BaseEmulator, EmulatorAVD
from .base import Device
from mozrunner.devices import emulator_battery
from mozrunner.devices import emulator_geo
from mozrunner.devices import emulator_screen
-__all__ = ['BaseEmulator', 'Emulator', 'EmulatorAVD', 'Device',
+__all__ = ['BaseEmulator', 'EmulatorAVD', 'Device',
'emulator_battery', 'emulator_geo', 'emulator_screen']
--- a/testing/mozbase/mozrunner/mozrunner/devices/emulator.py
+++ b/testing/mozbase/mozrunner/mozrunner/devices/emulator.py
@@ -190,85 +190,16 @@ class BaseEmulator(Device):
return self._get_telnet_response(command)
def __del__(self):
if self.telnet:
self.telnet.write('exit\n')
self.telnet.read_all()
-class Emulator(BaseEmulator):
-
- def __init__(self, app_ctx, arch, resolution=None, sdcard=None, userdata=None,
- no_window=None, binary=None, **kwargs):
- super(Emulator, self).__init__(app_ctx, arch=arch, binary=binary, **kwargs)
-
- # emulator args
- self.resolution = resolution or '320x480'
- self._sdcard_size = sdcard
- self._sdcard = None
- self.userdata = tempfile.NamedTemporaryFile(prefix='userdata-qemu', dir=self.tmpdir)
- self.initdata = userdata if userdata else os.path.join(self.arch.sysdir, 'userdata.img')
- self.no_window = no_window
-
- @property
- def sdcard(self):
- if self._sdcard_size and not self._sdcard:
- self._sdcard = SDCard(self, self._sdcard_size).path
- else:
- return self._sdcard
-
- @property
- def args(self):
- """
- Arguments to pass into the emulator binary.
- """
- qemu_args = super(Emulator, self).args
- qemu_args.extend([
- '-kernel', self.arch.kernel,
- '-sysdir', self.arch.sysdir,
- '-data', self.userdata.name,
- '-initdata', self.initdata,
- '-wipe-data'])
- if self.no_window:
- qemu_args.append('-no-window')
- if self.sdcard:
- qemu_args.extend(['-sdcard', self.sdcard])
- qemu_args.extend(['-memory', '512',
- '-partition-size', '512',
- '-verbose',
- '-skin', self.resolution,
- '-gpu', 'on',
- '-qemu'] + self.arch.extra_args)
- return qemu_args
-
- def connect(self):
- """
- Connects to a running device. If no serial was specified in the
- constructor, defaults to the first entry in `adb devices`.
- """
- if self.connected:
- return
-
- super(Emulator, self).connect()
- self.geo.set_default_location()
- self.screen.initialize()
-
- # setup DNS fix for networking
- self.app_ctx.dm.shellCheckOutput(['setprop', 'net.dns1', '10.0.2.3'])
-
- def cleanup(self):
- """
- Cleans up and kills the emulator, if it was started by mozrunner.
- """
- super(Emulator, self).cleanup()
- # Remove temporary files
- self.userdata.close()
-
-
class EmulatorAVD(BaseEmulator):
def __init__(self, app_ctx, binary, avd, port=5554, **kwargs):
super(EmulatorAVD, self).__init__(app_ctx, binary=binary, avd=avd, **kwargs)
self.port = port
@property
def args(self):
--- a/testing/mozbase/mozrunner/mozrunner/runners.py
+++ b/testing/mozbase/mozrunner/mozrunner/runners.py
@@ -1,23 +1,23 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
"""
This module contains a set of shortcut methods that create runners for commonly
-used Mozilla applications, such as Firefox or B2G emulator.
+used Mozilla applications, such as Firefox, Firefox for Android or Thunderbird.
"""
from __future__ import absolute_import
from .application import get_app_context
-from .base import DeviceRunner, GeckoRuntimeRunner, FennecRunner
-from .devices import Emulator, EmulatorAVD, Device
+from .base import GeckoRuntimeRunner, FennecRunner
+from .devices import EmulatorAVD
def Runner(*args, **kwargs):
"""
Create a generic GeckoRuntime runner.
:param binary: Path to binary.
:param cmdargs: Arguments to pass into binary.
@@ -69,37 +69,16 @@ def ThunderbirdRunner(*args, **kwargs):
:param show_crash_reporter: allow the crash reporter window to pop up.
Defaults to False.
:returns: A GeckoRuntimeRunner for Thunderbird.
"""
kwargs['app_ctx'] = get_app_context('thunderbird')()
return GeckoRuntimeRunner(*args, **kwargs)
-def B2GDesktopRunner(*args, **kwargs):
- """
- Create a B2G desktop runner.
-
- :param binary: Path to b2g desktop binary.
- :param cmdargs: Arguments to pass into binary.
- :param profile: Profile object to use.
- :param env: Environment variables to pass into the gecko process.
- :param clean_profile: If True, restores profile back to original state.
- :param process_class: Class used to launch the binary.
- :param process_args: Arguments to pass into process_class.
- :param symbols_path: Path to symbol files used for crash analysis.
- :param show_crash_reporter: allow the crash reporter window to pop up.
- Defaults to False.
- :returns: A GeckoRuntimeRunner for b2g desktop.
- """
- # There is no difference between a generic and b2g desktop runner,
- # but expose a separate entry point for clarity.
- return Runner(*args, **kwargs)
-
-
def FennecEmulatorRunner(avd='mozemulator-4.3',
adb_path=None,
avd_home=None,
logdir=None,
serial=None,
binary=None,
app='org.mozilla.fennec',
**kwargs):
@@ -128,87 +107,14 @@ def FennecEmulatorRunner(avd='mozemulato
'binary': binary,
'serial': serial,
'logdir': logdir}
return FennecRunner(device_class=EmulatorAVD,
device_args=device_args,
**kwargs)
-def B2GEmulatorRunner(arch='arm',
- b2g_home=None,
- adb_path=None,
- logdir=None,
- binary=None,
- no_window=None,
- resolution=None,
- sdcard=None,
- userdata=None,
- **kwargs):
- """
- Create a B2G emulator runner.
-
- :param arch: The architecture of the emulator, either 'arm' or 'x86'. Defaults to 'arm'.
- :param b2g_home: Path to root B2G repository.
- :param logdir: Path to save logfiles such as logcat and qemu output.
- :param no_window: Run emulator without a window.
- :param resolution: Screen resolution to set emulator to, e.g '800x1000'.
- :param sdcard: Path to local emulated sdcard storage.
- :param userdata: Path to custom userdata image.
- :param profile: Profile object to use.
- :param env: Environment variables to pass into the b2g.sh process.
- :param clean_profile: If True, restores profile back to original state.
- :param process_class: Class used to launch the b2g.sh process.
- :param process_args: Arguments to pass into the b2g.sh process.
- :param symbols_path: Path to symbol files used for crash analysis.
- :returns: A DeviceRunner for B2G emulators.
- """
- kwargs['app_ctx'] = get_app_context('b2g')(b2g_home, adb_path=adb_path)
- device_args = {'app_ctx': kwargs['app_ctx'],
- 'arch': arch,
- 'binary': binary,
- 'resolution': resolution,
- 'sdcard': sdcard,
- 'userdata': userdata,
- 'no_window': no_window,
- 'logdir': logdir}
- return DeviceRunner(device_class=Emulator,
- device_args=device_args,
- **kwargs)
-
-
-def B2GDeviceRunner(b2g_home=None,
- adb_path=None,
- logdir=None,
- serial=None,
- **kwargs):
- """
- Create a B2G device runner.
-
- :param b2g_home: Path to root B2G repository.
- :param logdir: Path to save logfiles such as logcat.
- :param serial: Serial of device to connect to as seen in `adb devices`.
- :param profile: Profile object to use.
- :param env: Environment variables to pass into the b2g.sh process.
- :param clean_profile: If True, restores profile back to original state.
- :param process_class: Class used to launch the b2g.sh process.
- :param process_args: Arguments to pass into the b2g.sh process.
- :param symbols_path: Path to symbol files used for crash analysis.
- :returns: A DeviceRunner for B2G devices.
- """
- kwargs['app_ctx'] = get_app_context('b2g')(b2g_home, adb_path=adb_path)
- device_args = {'app_ctx': kwargs['app_ctx'],
- 'logdir': logdir,
- 'serial': serial}
- return DeviceRunner(device_class=Device,
- device_args=device_args,
- **kwargs)
-
-
runners = {
'default': Runner,
- 'b2g_desktop': B2GDesktopRunner,
- 'b2g_emulator': B2GEmulatorRunner,
- 'b2g_device': B2GDeviceRunner,
'firefox': FirefoxRunner,
'thunderbird': ThunderbirdRunner,
'fennec': FennecEmulatorRunner
}