def main(): parser = argparse.ArgumentParser() parser.add_argument('--adb-path', help='Absolute path to the adb binary to use.') parser.add_argument('--blacklist-file', help='Device blacklist JSON file.') parser.add_argument('--known-devices-file', action='append', default=[], dest='known_devices_files', help='Path to known device lists.') parser.add_argument('-v', '--verbose', action='count', default=1, help='Log more information.') args = parser.parse_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]) blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) expected_devices = device_status.GetExpectedDevices(args.known_devices_files) usb_devices = set(lsusb.get_android_devices()) devices = [device_utils.DeviceUtils(s) for s in expected_devices.union(usb_devices)] RecoverDevices(devices, blacklist)
def testBlacklistFileDoesNotExist(self): with tempfile.NamedTemporaryFile() as blacklist_file: # Allow the temporary file to be deleted. pass test_blacklist = device_blacklist.Blacklist(blacklist_file.name) self.assertEquals({}, test_blacklist.Read())
def _GetAttachedDevices(blacklist_file, test_device): """Get all attached devices. Args: test_device: Name of a specific device to use. Returns: A list of attached devices. """ blacklist = (device_blacklist.Blacklist(blacklist_file) if blacklist_file else None) attached_devices = device_utils.DeviceUtils.HealthyDevices(blacklist) if test_device: test_device = [d for d in attached_devices if d == test_device] if not test_device: raise device_errors.DeviceUnreachableError( 'Did not find device %s among attached device. Attached devices: %s' % (test_device, ', '.join(attached_devices))) return test_device else: if not attached_devices: raise device_errors.NoDevicesError() return sorted(attached_devices)
def FindAllAvailableDevices(options): """Returns a list of available devices. """ # Disable Android device discovery when remote testing a CrOS device if options.cros_remote: return [] android_platform_options = options.remote_platform_options devices = [] try: if CanDiscoverDevices(): blacklist = None if android_platform_options.android_blacklist_file: blacklist = device_blacklist.Blacklist( android_platform_options.android_blacklist_file) devices = AndroidDevice.GetAllConnectedDevices(blacklist) finally: if not devices and _HasValidAdb(): try: adb_wrapper.AdbWrapper.KillServer() except device_errors.NoAdbError as e: logging.warning( 'adb reported as present, but NoAdbError thrown: %s', str(e)) return devices
def GetDevice(finder_options): """Return a Platform instance for the device specified by |finder_options|.""" android_platform_options = finder_options.remote_platform_options if not CanDiscoverDevices(): logging.info( 'No adb command found. Will not try searching for Android browsers.' ) return None if android_platform_options.android_blacklist_file: blacklist = device_blacklist.Blacklist( android_platform_options.android_blacklist_file) else: blacklist = None if (android_platform_options.device and android_platform_options.device in GetDeviceSerials(blacklist)): return AndroidDevice( android_platform_options.device, enable_performance_mode=not finder_options.no_performance_mode) devices = AndroidDevice.GetAllConnectedDevices(blacklist) if len(devices) == 0: logging.warn('No android devices found.') return None if len(devices) > 1: logging.warn( 'Multiple devices attached. Please specify one of the following:\n' + '\n'.join([' --device=%s' % d.device_id for d in devices])) return None return devices[0]
def main(argv): parser = argparse.ArgumentParser( usage='Usage: %(prog)s [options] device_port ' 'host_port [device_port_2 host_port_2] ...', description=__doc__) parser.add_argument( '-v', '--verbose', dest='verbose_count', default=0, action='count', help='Verbose level (multiple times for more)') parser.add_argument( '--device', help='Serial number of device we should use.') parser.add_argument( '--blacklist-file', help='Device blacklist JSON file.') parser.add_argument( '--debug', action='store_const', const='Debug', dest='build_type', default='Release', help='DEPRECATED: use --output-directory instead.') parser.add_argument( '--output-directory', help='Path to the root build directory.') parser.add_argument( 'ports', nargs='+', type=int, help='Port pair to reverse forward.') args = parser.parse_args(argv) run_tests_helper.SetLogLevel(args.verbose_count) if len(args.ports) < 2 or len(args.ports) % 2: parser.error('Need even number of port pairs') port_pairs = zip(args.ports[::2], args.ports[1::2]) if args.build_type: constants.SetBuildType(args.build_type) if args.output_directory: constants.SetOutputDirectory(args.output_directory) devil_chromium.Initialize(output_directory=constants.GetOutDirectory()) blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) device = device_utils.DeviceUtils.HealthyDevices( blacklist=blacklist, device_arg=args.device)[0] try: forwarder.Forwarder.Map(port_pairs, device) while True: time.sleep(60) except KeyboardInterrupt: sys.exit(0) finally: forwarder.Forwarder.UnmapAllDevicePorts(device)
def _GetAttachedDevices(blacklist_file, test_device, enable_cache, num_retries): """Get all attached devices. Args: blacklist_file: Path to device blacklist. test_device: Name of a specific device to use. enable_cache: Whether to enable checksum caching. Returns: A list of attached devices. """ blacklist = (device_blacklist.Blacklist(blacklist_file) if blacklist_file else None) attached_devices = device_utils.DeviceUtils.HealthyDevices( blacklist, enable_device_files_cache=enable_cache, default_retries=num_retries) if test_device: test_device = [d for d in attached_devices if d == test_device] if not test_device: raise device_errors.DeviceUnreachableError( 'Did not find device %s among attached device. Attached devices: %s' % (test_device, ', '.join(attached_devices))) return test_device else: if not attached_devices: raise device_errors.NoDevicesError() return sorted(attached_devices)
def main(argv): """Launches the device monitor. Polls the devices for their battery and cpu temperatures and scans the blacklist file every 60 seconds and dumps the data to DEVICE_FILE. """ parser = argparse.ArgumentParser( description='Launches the device monitor.') script_common.AddEnvironmentArguments(parser) parser.add_argument('--blacklist-file', help='Path to device blacklist file.') args = parser.parse_args(argv) logger = logging.getLogger() logger.setLevel(logging.DEBUG) handler = logging.handlers.RotatingFileHandler( '/tmp/device_monitor.log', maxBytes=10 * 1024 * 1024, backupCount=5) fmt = logging.Formatter('%(asctime)s %(levelname)s %(message)s', datefmt='%y%m%d %H:%M:%S') handler.setFormatter(fmt) logger.addHandler(handler) script_common.InitializeEnvironment(args) blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) logging.info('Device monitor running with pid %d, adb: %s, blacklist: %s', os.getpid(), args.adb_path, args.blacklist_file) while True: start = time.time() status_dict = get_all_status(blacklist) with open(DEVICE_FILE, 'wb') as f: json.dump(status_dict, f, indent=2, sort_keys=True) logging.info('Got status of all devices in %.2fs.', time.time() - start) time.sleep(60)
def main(): parser = argparse.ArgumentParser() parser.add_argument('--blacklist-file', help='Device blacklist JSON file.') set_asserts_group = parser.add_mutually_exclusive_group(required=True) set_asserts_group.add_argument( '--enable_asserts', dest='set_asserts', action='store_true', help='Sets the dalvik.vm.enableassertions property to "all"') set_asserts_group.add_argument( '--disable_asserts', dest='set_asserts', action='store_false', help='Removes the dalvik.vm.enableassertions property') args = parser.parse_args() blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) # TODO(jbudorick): Accept optional serial number and run only for the # specified device when present. devices = device_utils.DeviceUtils.parallel( device_utils.DeviceUtils.HealthyDevices(blacklist)) def set_java_asserts_and_restart(device): if device.SetJavaAsserts(args.set_asserts): device.RunShellCommand('stop') device.RunShellCommand('start') devices.pMap(set_java_asserts_and_restart) return 0
def __init__(self, args, output_manager, _error_func): super(LocalDeviceEnvironment, self).__init__(output_manager) self._blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) self._device_serials = args.test_devices self._devices_lock = threading.Lock() self._devices = None self._concurrent_adb = args.enable_concurrent_adb self._enable_device_cache = args.enable_device_cache self._logcat_monitors = [] self._logcat_output_dir = args.logcat_output_dir self._logcat_output_file = args.logcat_output_file self._max_tries = 1 + args.num_retries self._skip_clear_data = args.skip_clear_data self._tool_name = args.tool self._trace_output = None if hasattr(args, 'trace_output'): self._trace_output = args.trace_output self._trace_all = None if hasattr(args, 'trace_all'): self._trace_all = args.trace_all devil_chromium.Initialize(output_directory=constants.GetOutDirectory(), adb_path=args.adb_path) # Some things such as Forwarder require ADB to be in the environment path. adb_dir = os.path.dirname(adb_wrapper.AdbWrapper.GetAdbPath()) if adb_dir and adb_dir not in os.environ['PATH'].split(os.pathsep): os.environ['PATH'] = adb_dir + os.pathsep + os.environ['PATH']
def ProvisionDevices(args): blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) devices = [ d for d in device_utils.DeviceUtils.HealthyDevices(blacklist) if not args.emulators or d.adb.is_emulator ] if args.device: devices = [d for d in devices if d == args.device] if not devices: raise device_errors.DeviceUnreachableError(args.device) parallel_devices = device_utils.DeviceUtils.parallel(devices) if args.emulators: parallel_devices.pMap(SetProperties, args) else: parallel_devices.pMap(ProvisionDevice, blacklist, args) if args.auto_reconnect: _LaunchHostHeartbeat() blacklisted_devices = blacklist.Read() if blacklist else [] if args.output_device_blacklist: with open(args.output_device_blacklist, 'w') as f: json.dump(blacklisted_devices, f) if all(d in blacklisted_devices for d in devices): raise device_errors.NoDevicesError return 0
def main(argv): """Launches the device monitor. Polls the devices for their battery and cpu temperatures and scans the blacklist file every 60 seconds and dumps the data to DEVICE_FILE. """ parser = argparse.ArgumentParser( description='Launches the device monitor.') parser.add_argument('--adb-path', help='Path to adb binary.') parser.add_argument('--blacklist-file', help='Path to device blacklist file.') args = parser.parse_args(argv) 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]) blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) while True: status_dict = get_all_status(blacklist) with open(DEVICE_FILE, 'wb') as f: json.dump(status_dict, f, indent=2, sort_keys=True) time.sleep(60)
def main(): parser = argparse.ArgumentParser() logging_common.AddLoggingArguments(parser) script_common.AddEnvironmentArguments(parser) parser.add_argument('--blacklist-file', help='Device blacklist JSON file.') parser.add_argument('--known-devices-file', action='append', default=[], dest='known_devices_files', help='Path to known device lists.') parser.add_argument('--enable-usb-reset', action='store_true', help='Reset USB if necessary.') args = parser.parse_args() logging_common.InitializeLogging(args) script_common.InitializeEnvironment(args) blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) expected_devices = device_status.GetExpectedDevices(args.known_devices_files) usb_devices = set(lsusb.get_android_devices()) devices = [device_utils.DeviceUtils(s) for s in expected_devices.union(usb_devices)] RecoverDevices(devices, blacklist, enable_usb_reset=args.enable_usb_reset)
def main(): parser = argparse.ArgumentParser( 'Run an adb shell command on selected devices') parser.add_argument('cmd', help='Adb shell command to run.', nargs="+") parser.add_argument( '-d', '--device', action='append', dest='devices', help='Device to run cmd on. Runs on all devices if not ' 'specified. Set multiple times for multiple devices') parser.add_argument('-v', '--verbose', default=0, action='count', help='Verbose level (multiple times for more)') parser.add_argument('--blacklist-file', help='Device blacklist file.') parser.add_argument('--as-root', action='store_true', help='Run as root.') parser.add_argument('--json-output', help='File to dump json output to.') args = parser.parse_args() run_tests_helper.SetLogLevel(args.verbose) args.blacklist_file = device_blacklist.Blacklist( args.blacklist_file) if args.blacklist_file else None attached_devices = device_utils.DeviceUtils.HealthyDevices( blacklist=args.blacklist_file) if args.devices: selected_devices = [] attached_devices = {str(d): d for d in attached_devices} for serial in args.devices: if serial in attached_devices: selected_devices.append(attached_devices[serial]) else: logging.warning('Specified device %s not found.', serial) else: selected_devices = attached_devices if not selected_devices: raise device_errors.NoDevicesError p_out = ( device_utils.DeviceUtils.parallel(selected_devices).RunShellCommand( args.cmd, large_output=True, as_root=args.as_root, check_return=True).pGet(None)) data = {} for device, output in zip(selected_devices, p_out): for line in output: print '%s: %s' % (device, line) data[str(device)] = output if args.json_output: with open(args.json_output, 'w') as f: json.dump(data, f) return 0
def main(): parser = argparse.ArgumentParser() parser.add_argument('-l', '--output-linux-directory', required=True, help='Path to the root linux build directory.' ' Example: "out-linux/Debug"') subparsers = parser.add_subparsers(dest="subparser_name") start_parser = subparsers.add_parser('start') start_parser.set_defaults(func=_Start) AddStartArguments(start_parser) run_parser = subparsers.add_parser('run') run_parser.set_defaults(func=_Run) AddStartArguments(run_parser) load_parser = subparsers.add_parser('load') load_parser.set_defaults(func=_Load) load_parser.add_argument('-p', '--apk-path', required=True, help='The path to the APK to install. ' 'Including the name of the apk containing ' 'the application (with the .apk extension).') load_parser.add_argument('-u', '--optional-url', help='URL to navigate to.') stop_parser = subparsers.add_parser('stop') stop_parser.set_defaults(func=_Stop) args = parser.parse_args() json_file_path = os.path.join(SRC_PATH, args.output_linux_directory, ARGS_JSON_FILE) blacklist_file = '' serial = '' if args.subparser_name == 'start' or args.subparser_name == 'run': blacklist_file = args.blacklist_file serial = args.device else: if not _IsNonEmptyFile(json_file_path): logging.error('Cannot find json file: %s' + json_file_path) logging.error( 'Run `client_engine_integration.py {run,start}` first.') sys.exit(1) with open(json_file_path, 'r') as f: file_lines = f.readlines() jsonarg = json.loads(file_lines[0], object_hook=_FromJson) blacklist_file = jsonarg['args'].blacklist_file serial = jsonarg['args'].device blacklist = (device_blacklist.Blacklist(blacklist_file) if blacklist_file else None) device = device_utils.DeviceUtils.HealthyDevices(blacklist=blacklist, device_arg=serial)[0] args.func(args, json_file_path, device)
def ProvisionDevices(devices, blacklist_file, adb_key_files=None, disable_location=False, disable_mock_location=False, disable_network=False, disable_system_chrome=False, emulators=False, enable_java_debug=False, max_battery_temp=None, min_battery_level=None, output_device_blacklist=None, reboot_timeout=None, remove_system_webview=False, wipe=True): blacklist = (device_blacklist.Blacklist(blacklist_file) if blacklist_file else None) devices = script_common.GetDevices(devices, blacklist) devices = [d for d in devices if not emulators or d.adb.is_emulator] parallel_devices = device_utils.DeviceUtils.parallel(devices) steps = [] if wipe: steps += [ProvisionStep(lambda d: Wipe(d, adb_key_files), reboot=True)] steps += [ ProvisionStep(lambda d: SetProperties( d, enable_java_debug, disable_location, disable_mock_location), reboot=not emulators) ] if disable_network: steps.append(ProvisionStep(DisableNetwork)) if disable_system_chrome: steps.append(ProvisionStep(DisableSystemChrome)) if max_battery_temp: steps.append( ProvisionStep(lambda d: WaitForTemperature(d, max_battery_temp))) if min_battery_level: steps.append( ProvisionStep(lambda d: WaitForCharge(d, min_battery_level))) if remove_system_webview: steps.append(ProvisionStep(RemoveSystemWebView)) steps.append(ProvisionStep(SetDate)) steps.append(ProvisionStep(CheckExternalStorage)) parallel_devices.pMap(ProvisionDevice, steps, blacklist, reboot_timeout) blacklisted_devices = blacklist.Read() if blacklist else [] if output_device_blacklist: with open(output_device_blacklist, 'w') as f: json.dump(blacklisted_devices, f) if all(d in blacklisted_devices for d in devices): raise device_errors.NoDevicesError return 0
def main(argv): parser = optparse.OptionParser(usage='Usage: %prog [options] device_port ' 'host_port [device_port_2 host_port_2] ...', description=__doc__) parser.add_option('-v', '--verbose', dest='verbose_count', default=0, action='count', help='Verbose level (multiple times for more)') parser.add_option('--device', help='Serial number of device we should use.') parser.add_option('--blacklist-file', help='Device blacklist JSON file.') parser.add_option('--debug', action='store_const', const='Debug', dest='build_type', default='Release', help='Use Debug build of host tools instead of Release.') options, args = parser.parse_args(argv) run_tests_helper.SetLogLevel(options.verbose_count) devil_chromium.Initialize() if len(args) < 2 or not len(args) % 2: parser.error('Need even number of port pairs') sys.exit(1) try: port_pairs = [int(a) for a in args[1:]] port_pairs = zip(port_pairs[::2], port_pairs[1::2]) except ValueError: parser.error('Bad port number') sys.exit(1) blacklist = (device_blacklist.Blacklist(options.blacklist_file) if options.blacklist_file else None) devices = device_utils.DeviceUtils.HealthyDevices(blacklist) if options.device: device = next((d for d in devices if d == options.device), None) if not device: raise device_errors.DeviceUnreachableError(options.device) elif devices: device = devices[0] logging.info('No device specified. Defaulting to %s', devices[0]) else: raise device_errors.NoDevicesError() constants.SetBuildType(options.build_type) try: forwarder.Forwarder.Map(port_pairs, device) while True: time.sleep(60) except KeyboardInterrupt: sys.exit(0) finally: forwarder.Forwarder.UnmapAllDevicePorts(device)
def main(): custom_handler = logging.StreamHandler(sys.stdout) custom_handler.setFormatter(run_tests_helper.CustomFormatter()) logging.getLogger().addHandler(custom_handler) logging.getLogger().setLevel(logging.INFO) parser = optparse.OptionParser() parser.add_option('--device', help='The serial number of the device. If not specified ' 'will use all devices.') parser.add_option('--blacklist-file', help='Device blacklist JSON file.') parser.add_option( '-a', '--all-tombstones', action='store_true', help="""Resolve symbols for all tombstones, rather than just the most recent""") parser.add_option('-s', '--stack', action='store_true', help='Also include symbols for stack data') parser.add_option('-w', '--wipe-tombstones', action='store_true', help='Erase all tombstones from device after processing') parser.add_option('-j', '--jobs', type='int', default=4, help='Number of jobs to use when processing multiple ' 'crash stacks.') parser.add_option('--output-directory', help='Path to the root build directory.') options, _ = parser.parse_args() devil_chromium.Initialize() blacklist = (device_blacklist.Blacklist(options.blacklist_file) if options.blacklist_file else None) if options.output_directory: constants.SetOutputDirectory(options.output_directory) # Do an up-front test that the output directory is known. constants.CheckOutputDirectory() if options.device: devices = [device_utils.DeviceUtils(options.device)] else: devices = device_utils.DeviceUtils.HealthyDevices(blacklist) # This must be done serially because strptime can hit a race condition if # used for the first time in a multithreaded environment. # http://bugs.python.org/issue7980 tombstones = [] for device in devices: tombstones += _GetTombstonesForDevice(device, options) _ResolveTombstones(options.jobs, tombstones)
def main(): parser = argparse.ArgumentParser() AddArguments(parser) args = parser.parse_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]) blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) expected_devices = GetExpectedDevices(args.known_devices_files) usb_devices = set(lsusb.get_android_devices()) devices = [ device_utils.DeviceUtils(s) for s in expected_devices.union(usb_devices) ] statuses = DeviceStatus(devices, blacklist) # Log the state of all devices. _LogStatuses(statuses) # Update the last devices file(s). if args.overwrite_known_devices_files: for path in args.known_devices_files: device_list.WritePersistentDeviceList( path, [status['serial'] for status in statuses]) # Write device info to file for buildbot info display. _WriteBuildbotFile(args.buildbot_path, statuses) # Dump the device statuses to JSON. if args.json_output: with open(args.json_output, 'wb') as f: f.write( json.dumps(statuses, indent=4, sort_keys=True, separators=(',', ': '))) live_devices = [ status['serial'] for status in statuses if (status['adb_status'] == 'device' and not IsBlacklisted(status['serial'], blacklist)) ] # If all devices failed, or if there are no devices, it's an infra error. if not live_devices: logger.error('No available devices.') return 0 if live_devices else exit_codes.INFRA
def __init__(self, args, _error_func): super(LocalDeviceEnvironment, self).__init__() self._blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) self._device_serial = args.test_device self._devices_lock = threading.Lock() self._devices = [] self._max_tries = 1 + args.num_retries self._tool_name = args.tool
def main(): # Parse options. parser = optparse.OptionParser(description=__doc__, usage='screenshot.py [options] [filename]') parser.add_option('-d', '--device', metavar='ANDROID_DEVICE', help='Serial ' 'number of Android device to use.', default=None) parser.add_option('--blacklist-file', help='Device blacklist JSON file.') parser.add_option('-f', '--file', help='Save result to file instead of ' 'generating a timestamped file name.', metavar='FILE') parser.add_option('-v', '--verbose', help='Verbose logging.', action='store_true') video_options = optparse.OptionGroup(parser, 'Video capture') video_options.add_option('--video', help='Enable video capturing. Requires ' 'Android KitKat or later', action='store_true') video_options.add_option('-b', '--bitrate', help='Bitrate in megabits/s, ' 'from 0.1 to 100 mbps, %default mbps by default.', default=4, type='float') video_options.add_option('-r', '--rotate', help='Rotate video by 90 degrees.', default=False, action='store_true') video_options.add_option('-s', '--size', metavar='WIDTHxHEIGHT', help='Frame size to use instead of the device ' 'screen size.', default=None) parser.add_option_group(video_options) (options, args) = parser.parse_args() if len(args) > 1: parser.error('Too many positional arguments.') host_file = args[0] if args else options.file if options.verbose: logging.getLogger().setLevel(logging.DEBUG) blacklist = (device_blacklist.Blacklist(options.blacklist_file) if options.blacklist_file else None) devices = device_utils.DeviceUtils.HealthyDevices(blacklist) if options.device: device = next((d for d in devices if d == options.device), None) if not device: raise device_errors.DeviceUnreachableError(options.device) else: if len(devices) > 1: parser.error('Multiple devices are attached. ' 'Please specify device serial number with --device.') elif len(devices) == 1: device = devices[0] else: raise device_errors.NoDevicesError() if options.video: _CaptureVideo(device, host_file, options) else: _CaptureScreenshot(device, host_file) return 0
def main(): parser = argparse.ArgumentParser( description="Script to do semi-automated upgrade testing.") parser.add_argument('-v', '--verbose', action='count', help='Print verbose log information.') parser.add_argument('--blacklist-file', help='Device blacklist JSON file.') command_parsers = parser.add_subparsers(dest='command') subparser = command_parsers.add_parser('create_app_data') subparser.add_argument('--old-apk', required=True, help='Path to apk to update from.') subparser.add_argument('--app-data', required=True, help='Path to where the app data backup should be ' 'saved to.') subparser.add_argument('--package-name', help='Chrome apk package name.') subparser = command_parsers.add_parser('test_update') subparser.add_argument('--old-apk', required=True, help='Path to apk to update from.') subparser.add_argument('--new-apk', required=True, help='Path to apk to update to.') subparser.add_argument('--app-data', required=True, help='Path to where the app data backup is saved.') subparser.add_argument('--package-name', help='Chrome apk package name.') args = parser.parse_args() run_tests_helper.SetLogLevel(args.verbose) devil_chromium.Initialize() blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) devices = device_utils.DeviceUtils.HealthyDevices(blacklist) if not devices: raise device_errors.NoDevicesError() device = devices[0] logging.info('Using device %s for testing.', str(device)) package_name = (args.package_name if args.package_name else apk_helper.GetPackageName(args.old_apk)) if args.command == 'create_app_data': CreateAppData(device, args.old_apk, args.app_data, package_name) elif args.command == 'test_update': TestUpdate(device, args.old_apk, args.new_apk, args.app_data, package_name) else: raise Exception('Unknown test command: %s' % args.command)
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 main(): parser = argparse.ArgumentParser() logging_common.AddLoggingArguments(parser) script_common.AddEnvironmentArguments(parser) AddArguments(parser) args = parser.parse_args() logging_common.InitializeLogging(args) script_common.InitializeEnvironment(args) blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) expected_devices = GetExpectedDevices(args.known_devices_files) usb_devices = set(lsusb.get_android_devices()) devices = [ device_utils.DeviceUtils(s) for s in expected_devices.union(usb_devices) ] statuses = DeviceStatus(devices, blacklist) # Log the state of all devices. _LogStatuses(statuses) # Update the last devices file(s). if args.overwrite_known_devices_files: for path in args.known_devices_files: device_list.WritePersistentDeviceList( path, [status['serial'] for status in statuses]) # Write device info to file for buildbot info display. _WriteBuildbotFile(args.buildbot_path, statuses) # Dump the device statuses to JSON. if args.json_output: with open(args.json_output, 'wb') as f: f.write( json.dumps(statuses, indent=4, sort_keys=True, separators=(',', ': '))) live_devices = [ status['serial'] for status in statuses if (status['adb_status'] == 'device' and not IsBlacklisted(status['serial'], blacklist)) ] # If all devices failed, or if there are no devices, it's an infra error. if not live_devices: logger.error('No available devices.') return 0 if live_devices else exit_codes.INFRA
def main(): parser = argparse.ArgumentParser() AddArguments(parser) args = parser.parse_args() run_tests_helper.SetLogLevel(args.verbose) devil_custom_deps = None if args.adb_path: devil_custom_deps = { 'adb': { devil_env.GetPlatform(): [args.adb_path], }, } devil_env.config.Initialize(configs=devil_custom_deps) blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) expected_devices = GetExpectedDevices(args.known_devices_files) usb_devices = set(lsusb.get_android_devices()) devices = [ device_utils.DeviceUtils(s) for s in expected_devices.union(usb_devices) ] statuses = DeviceStatus(devices, blacklist) # Log the state of all devices. _LogStatuses(statuses) # Update the last devices file(s). if args.overwrite_known_devices_files: for path in args.known_devices_files: device_list.WritePersistentDeviceList( path, [status['serial'] for status in statuses]) # Write device info to file for buildbot info display. _WriteBuildbotFile(args.buildbot_path, statuses) # Dump the device statuses to JSON. if args.json_output: with open(args.json_output, 'wb') as f: f.write(json.dumps(statuses, indent=4)) live_devices = [ status['serial'] for status in statuses if (status['adb_status'] == 'device' and not IsBlacklisted(status['serial'], blacklist)) ] # If all devices failed, or if there are no devices, it's an infra error. return 0 if live_devices else exit_codes.INFRA
def testBlacklistFileIsEmpty(self): try: with tempfile.NamedTemporaryFile(delete=False) as blacklist_file: # Allow the temporary file to be closed. pass test_blacklist = device_blacklist.Blacklist(blacklist_file.name) self.assertEquals({}, test_blacklist.Read()) finally: if os.path.exists(blacklist_file.name): os.remove(blacklist_file.name)
def FindAllAvailableDevices(options): """Returns a list of available devices. """ if options.android_blacklist_file: blacklist = device_blacklist.Blacklist(options.android_blacklist_file) else: blacklist = None if not CanDiscoverDevices(): return [] else: return AndroidDevice.GetAllConnectedDevices(blacklist)
def __init__(self, args, _error_func): super(LocalDeviceEnvironment, self).__init__() self._blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) self._device_serial = args.test_device self._devices_lock = threading.Lock() self._devices = [] self._max_tries = 1 + args.num_retries self._tool_name = args.tool self._enable_device_cache = args.enable_device_cache self._incremental_install = args.incremental_install self._concurrent_adb = args.enable_concurrent_adb
def main(): custom_handler = logging.StreamHandler(sys.stdout) custom_handler.setFormatter(run_tests_helper.CustomFormatter()) logging.getLogger().addHandler(custom_handler) logging.getLogger().setLevel(logging.INFO) parser = argparse.ArgumentParser() parser.add_argument('--device', help='The serial number of the device. If not specified ' 'will use all devices.') parser.add_argument('--blacklist-file', help='Device blacklist JSON file.') parser.add_argument('-a', '--all-tombstones', action='store_true', help='Resolve symbols for all tombstones, rather than ' 'just the most recent.') parser.add_argument('-s', '--stack', action='store_true', help='Also include symbols for stack data') parser.add_argument('-w', '--wipe-tombstones', action='store_true', help='Erase all tombstones from device after processing') parser.add_argument('-j', '--jobs', type=int, default=4, help='Number of jobs to use when processing multiple ' 'crash stacks.') parser.add_argument('--output-directory', help='Path to the root build directory.') parser.add_argument('--adb-path', type=os.path.abspath, help='Path to the adb binary.') args = parser.parse_args() devil_chromium.Initialize(adb_path=args.adb_path) blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) if args.output_directory: constants.SetOutputDirectory(args.output_directory) # Do an up-front test that the output directory is known. constants.CheckOutputDirectory() if args.device: devices = [device_utils.DeviceUtils(args.device)] else: devices = device_utils.DeviceUtils.HealthyDevices(blacklist) # This must be done serially because strptime can hit a race condition if # used for the first time in a multithreaded environment. # http://bugs.python.org/issue7980 for device in devices: resolved_tombstones = ResolveTombstones( device, args.all_tombstones, args.stack, args.wipe_tombstones, args.jobs) for line in resolved_tombstones: logging.info(line)
def main(): parser = argparse.ArgumentParser() parser.add_argument('build_path', help='Path to android build.') parser.add_argument('-d', '--device', dest='devices', action='append', help='Device(s) to flash.') parser.add_argument('-v', '--verbose', default=0, action='count', help='Verbose level (multiple times for more)') parser.add_argument('-w', '--wipe', action='store_true', help='If set, wipes user data') parser.add_argument('--blacklist-file', help='Device blacklist file.') args = parser.parse_args() run_tests_helper.SetLogLevel(args.verbose) if args.blacklist_file: blacklist = device_blacklist.Blacklist(args.blacklist_file).Read() if blacklist: logging.critical('Device(s) in blacklist, not flashing devices:') for key in blacklist: logging.critical(' %s', key) return exit_codes.INFRA flashed_devices = [] failed_devices = [] def flash(device): fastboot = fastboot_utils.FastbootUtils(device) try: fastboot.FlashDevice(args.build_path, wipe=args.wipe) flashed_devices.append(device) except Exception: # pylint: disable=broad-except logging.exception('Device %s failed to flash.', str(device)) failed_devices.append(device) devices = script_common.GetDevices(args.devices, args.blacklist_file) device_utils.DeviceUtils.parallel(devices).pMap(flash) if flashed_devices: logging.info('The following devices were flashed:') logging.info(' %s', ' '.join(str(d) for d in flashed_devices)) if failed_devices: logging.critical('The following devices failed to flash:') logging.critical(' %s', ' '.join(str(d) for d in failed_devices)) return exit_codes.INFRA return 0