def run_gtest(self, test_dir, shuffle, test_filter, package, adb_path, device_serial, remote_test_root, libxul_path, symbols_path, enable_webrender): """ Launch the test app, run gtest, collect test results and wait for completion. Return False if a crash or other failure is detected, else True. """ update_mozinfo() self.device = mozdevice.ADBDevice(adb=adb_path, device=device_serial, test_root=remote_test_root, logger_name=LOGGER_NAME, verbose=True) root = self.device.test_root self.remote_profile = posixpath.join(root, 'gtest-profile') self.remote_minidumps = posixpath.join(root, 'gtest-minidumps') self.remote_log = posixpath.join(root, 'gtest.log') self.remote_libdir = posixpath.join('/data', 'local', 'gtest') self.package = package self.cleanup() self.device.mkdir(self.remote_profile, parents=True) self.device.mkdir(self.remote_minidumps, parents=True) self.device.mkdir(self.remote_libdir, parents=True) log.info("Running Android gtest") if not self.device.is_app_installed(self.package): raise Exception("%s is not installed on this device" % self.package) # Push the gtest libxul.so to the device. The harness assumes an architecture- # appropriate library is specified and pushes it to the arch-agnostic remote # directory. # TODO -- consider packaging the gtest libxul.so in an apk self.device.push(libxul_path, self.remote_libdir) # Push support files to device. Avoid sub-directories so that libxul.so # is not included. for f in glob.glob(os.path.join(test_dir, "*")): if not os.path.isdir(f): self.device.push(f, self.remote_profile) env = self.build_environment(shuffle, test_filter, enable_webrender) args = ["-unittest", "--gtest_death_test_style=threadsafe", "-profile %s" % self.remote_profile] if 'geckoview' in self.package: activity = "TestRunnerActivity" self.device.launch_activity(self.package, activity_name=activity, e10s=False, # gtest is non-e10s on desktop moz_env=env, extra_args=args) else: self.device.launch_fennec(self.package, moz_env=env, extra_args=args) waiter = AppWaiter(self.device, self.remote_log) timed_out = waiter.wait(self.package) self.shutdown(use_kill=True if timed_out else False) if self.check_for_crashes(symbols_path): return False return True
def __init__(self, *args, **kwargs): ExecutorBrowser.__init__(self, *args, **kwargs) import sys, subprocess self.device = mozdevice.ADBDevice() self.device.forward("tcp:%s" % self.marionette_port, "tcp:2828") self.executor = None self.marionette = None self.gaia_device = None self.gaia_apps = None
def device(self): if not self._device and self.adb_path: try: import mozdevice self._device = mozdevice.ADBDevice(adb=self.adb_path, device=self.device_serial, verbose=True) self.info("New mozdevice with adb=%s, device=%s" % (self.adb_path, self.device_serial)) except AttributeError: # As in adb_path, above. pass return self._device
def setup_kwargs(self, kwargs): from . import android import mozdevice # We don't support multiple channels for android yet if kwargs["browser_channel"] is None: kwargs["browser_channel"] = "nightly" if kwargs["prefs_root"] is None: prefs_root = self.browser.install_prefs( kwargs["binary"], self.venv.path, channel=kwargs["browser_channel"]) kwargs["prefs_root"] = prefs_root if kwargs["package_name"] is None: kwargs["package_name"] = "org.mozilla.geckoview.test" app = kwargs["package_name"] if kwargs["device_serial"] is None: kwargs["device_serial"] = "emulator-5554" # We're running on an emulator so ensure that's set up if kwargs["device_serial"].startswith("emulator-"): emulator = android.install(logger, reinstall=False, no_prompt=not self.prompt) android.start(logger, emulator=emulator, reinstall=False) install = False if hasattr(self, "_install_browser"): if self.prompt_install("geckoview-test"): install = True apk_path = self.browser.install( self.venv.path, channel=kwargs["browser_channel"]) if "ADB_PATH" not in os.environ: adb_path = os.path.join(android.get_sdk_path(None), "platform-tools", "adb") os.environ["ADB_PATH"] = adb_path adb_path = os.environ["ADB_PATH"] device = mozdevice.ADBDevice(adb=adb_path, device=kwargs["device_serial"]) if install: device.uninstall_app(app) device.install_app(apk_path) elif not device.is_app_installed(app): raise WptrunError("app %s not installed on device %s" % (app, kwargs["device_serial"]))
def mock_adb_object(): """Patches the __init__ method call when instantiating ADBDevice. ADBDevice normally requires instantiated objects in order to execute its commands. With a pytest-mock patch, we are able to mock the initialization of the ADBDevice object. By yielding the instantiated mock object, unit tests can be run that call methods that require an instantiated object. :yields: ADBDevice - mock instance of ADBDevice object """ with patch.object(mozdevice.ADBDevice, '__init__', lambda self: None): yield mozdevice.ADBDevice()