def SetUp(self): self._avd_config.Install() emulator_instances = [ self._avd_config.CreateInstance() for _ in range(self._emulator_count) ] def start_emulator_instance(e): try: e.Start() return e except avd.AvdException: logging.exception('Failed to start emulator instance.') return None parallel_emulators = parallelizer.SyncParallelizer(emulator_instances) self._emulator_instances = [ emu for emu in parallel_emulators.pMap( start_emulator_instance).pGet(None) if emu is not None ] self._device_serials = [e.serial for e in self._emulator_instances] if not self._emulator_instances: raise Exception('Failed to start any instances of the emulator.') elif len(self._emulator_instances) < self._emulator_count: logging.warning( 'Running with fewer emulator instances than requested (%d vs %d)', len(self._emulator_instances), self._emulator_count) super(LocalEmulatorEnvironment, self).SetUp()
def main(raw_args): parser = argparse.ArgumentParser() subparsers = parser.add_subparsers() def add_common_arguments(p): script_common.AddDeviceArguments(p) p.add_argument( '--adb-path', help='Path to the adb binary.') p.add_argument( '-v', '--verbose', action='count', default=0, help='Print more information.') p.add_argument('command', nargs='*') @contextlib.contextmanager def remove_system_app(device, args): RemoveSystemApps(device, args.packages) yield remove_parser = subparsers.add_parser('remove') remove_parser.add_argument( '--package', dest='packages', nargs='*', required=True, help='The system package(s) to remove.') add_common_arguments(remove_parser) remove_parser.set_defaults(func=remove_system_app) @contextlib.contextmanager def replace_system_app(device, args): with ReplaceSystemApp(device, args.package, args.replace_with): yield replace_parser = subparsers.add_parser('replace') replace_parser.add_argument( '--package', required=True, help='The system package to replace.') replace_parser.add_argument( '--replace-with', metavar='APK', required=True, help='The APK with which the existing system app should be replaced.') add_common_arguments(replace_parser) replace_parser.set_defaults(func=replace_system_app) args = parser.parse_args(raw_args) run_tests_helper.SetLogLevel(args.verbose) devil_dynamic_config = devil_env.EmptyConfig() if args.adb_path: devil_dynamic_config['dependencies'].update( devil_env.LocalConfigItem( 'adb', devil_env.GetPlatform(), args.adb_path)) devil_env.config.Initialize(configs=[devil_dynamic_config]) devices = script_common.GetDevices(args.devices, args.blacklist_file) parallel_devices = parallelizer.SyncParallelizer( [args.func(d, args) for d in devices]) with parallel_devices: if args.command: return cmd_helper.Call(args.command) return 0
def main(raw_args): parser = argparse.ArgumentParser() subparsers = parser.add_subparsers() def add_common_arguments(p): script_common.AddDeviceArguments(p) script_common.AddEnvironmentArguments(p) p.add_argument('-v', '--verbose', action='count', default=0, help='Print more information.') p.add_argument('command', nargs='*') @contextlib.contextmanager def remove_system_app(device, args): RemoveSystemApps(device, args.packages) yield remove_parser = subparsers.add_parser('remove') remove_parser.add_argument('--package', dest='packages', nargs='*', required=True, help='The system package(s) to remove.') add_common_arguments(remove_parser) remove_parser.set_defaults(func=remove_system_app) @contextlib.contextmanager def replace_system_app(device, args): with ReplaceSystemApp(device, args.package, args.replace_with): yield replace_parser = subparsers.add_parser('replace') replace_parser.add_argument('--package', required=True, help='The system package to replace.') replace_parser.add_argument( '--replace-with', metavar='APK', required=True, help='The APK with which the existing system app should be replaced.') add_common_arguments(replace_parser) replace_parser.set_defaults(func=replace_system_app) args = parser.parse_args(raw_args) run_tests_helper.SetLogLevel(args.verbose) script_common.InitializeEnvironment(args) devices = script_common.GetDevices(args.devices, args.denylist_file) parallel_devices = parallelizer.SyncParallelizer( [args.func(d, args) for d in devices]) with parallel_devices: if args.command: return cmd_helper.Call(args.command) return 0
def Install(self, target_repo, artifacts, include_poms=False): logging.info('Installing %d artifacts...', len(artifacts)) downloaders = [_SingleArtifactDownloader(self, artifact, target_repo) for artifact in artifacts] if self._debug: for downloader in downloaders: downloader.Run(include_poms) else: parallelizer.SyncParallelizer(downloaders).Run(include_poms) logging.info('%d artifacts installed to %s', len(artifacts), target_repo)
def main(): parser = argparse.ArgumentParser() parser.add_argument('build_path', help='Path to android build.') parser.add_argument( '-w', '--wipe', action='store_true', help='If set, wipes user data') logging_common.AddLoggingArguments(parser) script_common.AddDeviceArguments(parser) args = parser.parse_args() logging_common.InitializeLogging(args) if args.blacklist_file: blacklist = device_blacklist.Blacklist(args.blacklist_file).Read() if blacklist: logger.critical('Device(s) in blacklist, not flashing devices:') for key in blacklist: logger.critical(' %s', key) return exit_codes.INFRA flashed_devices = [] failed_devices = [] def flash(device): try: device.FlashDevice(args.build_path, wipe=args.wipe) flashed_devices.append(device) except Exception: # pylint: disable=broad-except logger.exception('Device %s failed to flash.', str(device)) failed_devices.append(device) devices = [] try: adb_devices = script_common.GetDevices(args.devices, args.blacklist_file) devices += [fastboot_utils.FastbootUtils(device=d) for d in adb_devices] except device_errors.NoDevicesError: # Don't bail out if we're not looking for any particular device and there's # at least one sitting in fastboot mode. Note that if we ARE looking for a # particular device, and it's in fastboot mode, this will still fail. fastboot_devices = fastboot.Fastboot.Devices() if args.devices or not fastboot_devices: raise devices += [ fastboot_utils.FastbootUtils(fastbooter=d) for d in fastboot_devices ] parallel_devices = parallelizer.SyncParallelizer(devices) parallel_devices.pMap(flash) if flashed_devices: logger.info('The following devices were flashed:') logger.info(' %s', ' '.join(str(d) for d in flashed_devices)) if failed_devices: logger.critical('The following devices failed to flash:') logger.critical(' %s', ' '.join(str(d) for d in failed_devices)) return exit_codes.INFRA return 0
def SetUp(self): self._avd_config.Install() emulator_instances = [ self._avd_config.CreateInstance() for _ in range(self._emulator_count) ] def start_emulator_instance(e): def impl(e): try: e.Start( window=self._emulator_window, writable_system=self._writable_system) except avd.AvdException: logging.exception('Failed to start emulator instance.') return None try: device_utils.DeviceUtils(e.serial).WaitUntilFullyBooted() except base_error.BaseError: e.Stop() raise return e def retry_on_timeout(exc): return (isinstance(exc, device_errors.CommandTimeoutError) or isinstance(exc, reraiser_thread.TimeoutError)) return timeout_retry.Run( impl, timeout=120 if self._writable_system else 30, retries=2, args=[e], retry_if_func=retry_on_timeout) parallel_emulators = parallelizer.SyncParallelizer(emulator_instances) self._emulator_instances = [ emu for emu in parallel_emulators.pMap(start_emulator_instance).pGet(None) if emu is not None ] self._device_serials = [e.serial for e in self._emulator_instances] if not self._emulator_instances: raise Exception('Failed to start any instances of the emulator.') elif len(self._emulator_instances) < self._emulator_count: logging.warning( 'Running with fewer emulator instances than requested (%d vs %d)', len(self._emulator_instances), self._emulator_count) super(LocalEmulatorEnvironment, self).SetUp()
def testContextManager(self): in_context = [False for i in xrange(10)] @contextlib.contextmanager def enter_into_context(i): in_context[i] = True try: yield finally: in_context[i] = False parallelized_context = parallelizer.SyncParallelizer( [enter_into_context(i) for i in xrange(10)]) with parallelized_context: self.assertTrue(all(in_context)) self.assertFalse(any(in_context))
def main(raw_args): parser = argparse.ArgumentParser() def add_common_arguments(p): script_common.AddDeviceArguments(p) script_common.AddEnvironmentArguments(p) p.add_argument('-v', '--verbose', action='count', default=0, help='Print more information.') p.add_argument('command', nargs='*') @contextlib.contextmanager def use_webview_provider(device, args): with UseWebViewProvider(device, args.apk, args.expected_package): yield parser.add_argument('--apk', required=True, help='The apk to use as the provider.') parser.add_argument( '--expected-package', default='', help="Verify apk's package name matches value, disabled by default.") add_common_arguments(parser) parser.set_defaults(func=use_webview_provider) args = parser.parse_args(raw_args) run_tests_helper.SetLogLevel(args.verbose) script_common.InitializeEnvironment(args) devices = script_common.GetDevices(args.devices, args.denylist_file) parallel_devices = parallelizer.SyncParallelizer( [args.func(d, args) for d in devices]) with parallel_devices: if args.command: return cmd_helper.Call(args.command) return 0
def parallel_devices(self): return parallelizer.SyncParallelizer(self.devices)
def TearDown(self): try: super(LocalEmulatorEnvironment, self).TearDown() finally: parallelizer.SyncParallelizer(self._emulator_instances).Stop()