def _PathInLocalSdk(build_tool): build_tools_path = _build_tools_path.read() if not build_tools_path: raise dependency_manager.NoPathFoundError(build_tool, devil_env.GetPlatform()) candidate_path = os.path.join(build_tools_path, build_tool) if not os.path.exists(candidate_path): raise dependency_manager.NoPathFoundError(build_tool, devil_env.GetPlatform()) return candidate_path
def testGetPlatform(self): with mock.patch('platform.machine', mock.Mock(return_value='x86_64')): with mock.patch('sys.platform', mock.Mock(return_value='linux2')): platform = devil_env.GetPlatform() self.assertEquals(platform, 'linux2_x86_64') with mock.patch('sys.platform', mock.Mock(return_value='linux')): platform = devil_env.GetPlatform() self.assertEquals(platform, 'linux2_x86_64') platform = devil_env.GetPlatform(arch='arm64-v8a') self.assertEquals(platform, 'android_arm64-v8a') device = _MockDeviceUtils() platform = devil_env.GetPlatform(device=device) self.assertEquals(platform, 'android_arm64-v8a')
def main(raw_args): parser = argparse.ArgumentParser() parser.add_argument('-v', '--verbose', action='count', help='Log more.') parser.add_argument('-t', '--timeout', default=30, type=int, help='Seconds to wait for the devices.') parser.add_argument('--adb-path', help='ADB binary to use.') parser.add_argument('device_serials', nargs='*', metavar='SERIAL', help='Serials of the devices to wait for.') 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 = device_utils.DeviceUtils.HealthyDevices( device_arg=args.device_serials) parallel_devices = device_utils.DeviceUtils.parallel(devices) parallel_devices.WaitUntilFullyBooted(timeout=args.timeout) return 0
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 InitializeEnvironment(args): """Initializes devil based on the args added by AddEnvironmentArguments(). This initializes devil, and configures it to use the adb binary specified by the '--adb-path' flag (if provided by the user, otherwise this defaults to devil's copy of adb). Although this is one possible way to initialize devil, you should check if your project has prefered ways to initialize devil (ex. the chromium project uses devil_chromium.Initialize() to have different defaults for dependencies). This method requires having previously called AddEnvironmentArguments() on the relevant argparse.ArgumentParser. Note: you should only initialize devil once, and subsequent calls to any method wrapping devil_env.config.Initialize() will have no effect. Args: args: the parsed args returned by an argparse.ArgumentParser """ 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])
def ProcessCommonOptions(args): """Processes and handles all common options.""" run_tests_helper.SetLogLevel(args.verbose_count) constants.SetBuildType(args.build_type) if args.build_directory: constants.SetBuildDirectory(args.build_directory) if args.output_directory: constants.SetOutputDirectory(args.output_directory) devil_custom_deps = None if args.adb_path: devil_custom_deps = { 'adb': { devil_env.GetPlatform(): [args.adb_path] } } devil_chromium.Initialize( output_directory=constants.GetOutDirectory(), custom_deps=devil_custom_deps) # Some things such as Forwarder require ADB to be in the environment path. adb_dir = os.path.dirname(constants.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 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(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 InitializeEnvironment(args): 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])
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 Initialize(output_directory=None, custom_deps=None, adb_path=None): """Initializes devil with chromium's binaries and third-party libraries. This includes: - Libraries: - the android SDK ("android_sdk") - Build products: - host & device forwarder binaries ("forwarder_device" and "forwarder_host") - host & device md5sum binaries ("md5sum_device" and "md5sum_host") Args: output_directory: An optional path to the output directory. If not set, no built dependencies are configured. custom_deps: An optional dictionary specifying custom dependencies. This should be of the form: { 'dependency_name': { 'platform': 'path', ... }, ... } adb_path: An optional path to use for the adb binary. If not set, this uses the adb binary provided by the Android SDK. """ build_with_chromium = _BuildWithChromium() devil_dynamic_config = { 'config_type': 'BaseConfig', 'dependencies': {}, } if build_with_chromium and output_directory: # Non-chromium users of chromium's //build directory fetch build products # from google storage rather than use locally built copies. Chromium uses # locally-built copies so that changes to the tools can be easily tested. _UseLocalBuildProducts(output_directory, devil_dynamic_config) if custom_deps: devil_dynamic_config['dependencies'].update(custom_deps) if adb_path: devil_dynamic_config['dependencies'].update({ 'adb': { 'file_info': { devil_env.GetPlatform(): { 'local_paths': [adb_path] } } } }) config_files = [_DEVIL_CONFIG] if build_with_chromium else None devil_env.config.Initialize(configs=[devil_dynamic_config], config_files=config_files)
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 setUpClass(cls): custom_adb_path = os.environ.get('ADB_PATH') custom_deps = { 'config_type': 'BaseConfig', 'dependencies': {}, } if custom_adb_path: custom_deps['dependencies']['adb'] = { 'file_info': { devil_env.GetPlatform(): { 'local_paths': [custom_adb_path], }, }, } devil_env.config.Initialize(configs=[custom_deps])
def initialize_devil(): """Initialize devil to use adb from $PATH""" devil_dynamic_config = { 'config_type': 'BaseConfig', 'dependencies': { 'adb': { 'file_info': { devil_env.GetPlatform(): { 'local_paths': [os.path.abspath(find_executable('adb'))] } } } } } devil_env.config.Initialize(configs=[devil_dynamic_config])
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) 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) 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) 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 initialize_devil(): """Initialize devil to use adb from $PATH""" adb_path = find_adb() if adb_path is None: print >> sys.stderr, "Unable to find adb, is it in your path?" sys.exit(1) devil_dynamic_config = { 'config_type': 'BaseConfig', 'dependencies': { 'adb': { 'file_info': { devil_env.GetPlatform(): { 'local_paths': [os.path.abspath(adb_path)] } } } } } devil_env.config.Initialize(configs=[devil_dynamic_config])
def main(raw_args): parser = argparse.ArgumentParser() parser.add_argument('--adb-path', help='ADB binary path.') parser.add_argument( '--device', dest='devices', action='append', default=[], help='Devices for which the governor should be set. Defaults to all.') parser.add_argument('-v', '--verbose', action='count', help='Log more.') subparsers = parser.add_subparsers() set_governor = subparsers.add_parser('set-governor') set_governor.add_argument('governor', help='Desired CPU governor.') set_governor.set_defaults(func=SetScalingGovernor) get_governor = subparsers.add_parser('get-governor') get_governor.set_defaults(func=GetScalingGovernor) list_governors = subparsers.add_parser('list-governors') list_governors.set_defaults(func=ListAvailableGovernors) 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 = device_utils.DeviceUtils.HealthyDevices(device_arg=args.devices) parallel_devices = device_utils.DeviceUtils.parallel(devices) parallel_devices.pMap(args.func, args) return 0
def main(): logging.getLogger().setLevel(logging.INFO) parser = argparse.ArgumentParser() script_common.AddDeviceArguments(parser) parser.add_argument('--adb-path', help='Absolute path to the adb binary to use.') args = parser.parse_args() 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]) reboot_into_bootloader(args.devices) devices = [ d for d in fastboot.Fastboot.Devices() if not args.devices or str(d) in args.devices] parallel_devices = parallelizer.Parallelizer(devices) parallel_devices.pMap(unlock_bootloader).pGet(None) return 0
def main(): # Recommended options on perf bots: # --disable-network # TODO(tonyg): We eventually want network on. However, currently radios # can cause perfbots to drain faster than they charge. # --min-battery-level 95 # Some perf bots run benchmarks with USB charging disabled which leads # to gradual draining of the battery. We must wait for a full charge # before starting a run in order to keep the devices online. parser = argparse.ArgumentParser( description='Provision Android devices with settings required for bots.' ) parser.add_argument( '-d', '--device', metavar='SERIAL', help='the serial number of the device to be provisioned' ' (the default is to provision all devices attached)') 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('--phase', action='append', choices=_PHASES.ALL, dest='phases', help='Phases of provisioning to run. ' '(If omitted, all phases will be run.)') parser.add_argument('--skip-wipe', action='store_true', default=False, help="don't wipe device data during provisioning") parser.add_argument('--reboot-timeout', metavar='SECS', type=int, help='when wiping the device, max number of seconds to' ' wait after each reboot ' '(default: %s)' % _DEFAULT_TIMEOUTS.HELP_TEXT) parser.add_argument( '--min-battery-level', type=int, metavar='NUM', help='wait for the device to reach this minimum battery' ' level before trying to continue') parser.add_argument('--disable-location', action='store_true', help='disable Google location services on devices') parser.add_argument('--disable-mock-location', action='store_true', default=False, help='Set ALLOW_MOCK_LOCATION to false') parser.add_argument('--disable-network', action='store_true', help='disable network access on devices') parser.add_argument('--disable-java-debug', action='store_false', dest='enable_java_debug', default=True, help='disable Java property asserts and JNI checking') parser.add_argument('--disable-system-chrome', action='store_true', help='Disable the system chrome from devices.') parser.add_argument('--remove-system-webview', action='store_true', help='Remove the system webview from devices.') parser.add_argument('-t', '--target', default='Debug', help='the build target (default: %(default)s)') parser.add_argument('-r', '--auto-reconnect', action='store_true', help='push binary which will reboot the device on adb' ' disconnections') parser.add_argument('--adb-key-files', type=str, nargs='+', help='list of adb keys to push to device') parser.add_argument('-v', '--verbose', action='count', default=1, help='Log more information.') parser.add_argument( '--max-battery-temp', type=int, metavar='NUM', help='Wait for the battery to have this temp or lower.') parser.add_argument('--output-device-blacklist', help='Json file to output the device blacklist.') parser.add_argument( '--chrome-specific-wipe', action='store_true', help='only wipe chrome specific data during provisioning') parser.add_argument('--emulators', action='store_true', help='provision only emulators and ignore usb devices') args = parser.parse_args() constants.SetBuildType(args.target) 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_chromium.Initialize(custom_deps=devil_custom_deps) return ProvisionDevices(args)
def main(): parser = argparse.ArgumentParser() parser.add_argument('--out-dir', help='Directory where the device path is stored', default=os.path.join(host_paths.DIR_SOURCE_ROOT, 'out')) parser.add_argument('--restart-usb', action='store_true', help='DEPRECATED. ' 'This script now always tries to reset USB.') parser.add_argument('--json-output', help='Output JSON information into a specified file.') 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_custom_deps = None if args.adb_path: devil_custom_deps = { 'adb': { devil_env.GetPlatform(): [args.adb_path], }, } devil_chromium.Initialize(custom_deps=devil_custom_deps) blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) last_devices_path = os.path.join( args.out_dir, device_list.LAST_DEVICES_FILENAME) args.known_devices_files.append(last_devices_path) expected_devices = set() try: for path in args.known_devices_files: if os.path.exists(path): expected_devices.update(device_list.GetPersistentDeviceList(path)) except IOError: logging.warning('Problem reading %s, skipping.', path) logging.info('Expected devices:') for device in expected_devices: logging.info(' %s', device) usb_devices = set(lsusb.get_android_devices()) devices = [device_utils.DeviceUtils(s) for s in expected_devices.union(usb_devices)] RecoverDevices(devices, blacklist) statuses = DeviceStatus(devices, blacklist) # Log the state of all devices. for status in statuses: logging.info(status['serial']) adb_status = status.get('adb_status') blacklisted = status.get('blacklisted') logging.info(' USB status: %s', 'online' if status.get('usb_status') else 'offline') logging.info(' ADB status: %s', adb_status) logging.info(' Blacklisted: %s', str(blacklisted)) if adb_status == 'device' and not blacklisted: logging.info(' Device type: %s', status.get('ro.build.product')) logging.info(' OS build: %s', status.get('ro.build.id')) logging.info(' OS build fingerprint: %s', status.get('ro.build.fingerprint')) logging.info(' Battery state:') for k, v in status.get('battery', {}).iteritems(): logging.info(' %s: %s', k, v) logging.info(' IMEI slice: %s', status.get('imei_slice')) logging.info(' WiFi IP: %s', status.get('wifi_ip')) # Update the last devices file(s). 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. if os.path.exists('/home/chrome-bot'): with open('/home/chrome-bot/.adb_device_info', 'w') as f: for status in statuses: try: if status['adb_status'] == 'device': f.write('{serial} {adb_status} {build_product} {build_id} ' '{temperature:.1f}C {level}%\n'.format( serial=status['serial'], adb_status=status['adb_status'], build_product=status['type'], build_id=status['build'], temperature=float(status['battery']['temperature']) / 10, level=status['battery']['level'] )) elif status.get('usb_status', False): f.write('{serial} {adb_status}\n'.format( serial=status['serial'], adb_status=status['adb_status'] )) else: f.write('{serial} offline\n'.format( serial=status['serial'] )) except Exception: # pylint: disable=broad-except pass # 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 main(): parser = argparse.ArgumentParser() parser.add_argument('--json-output', help='Output JSON information into a specified file.') 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('--buildbot-path', '-b', default='/home/chrome-bot/.adb_device_info', help='Absolute path to buildbot file location') parser.add_argument('-v', '--verbose', action='count', default=1, help='Log more information.') parser.add_argument('-w', '--overwrite-known-devices-files', action='store_true', help='If set, overwrites known devices files wiht new ' 'values.') 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 Initialize(output_directory=None, custom_deps=None, adb_path=None): """Initializes devil with chromium's binaries and third-party libraries. This includes: - Libraries: - the android SDK ("android_sdk") - pymock ("pymock") - Build products: - host & device forwarder binaries ("forwarder_device" and "forwarder_host") - host & device md5sum binaries ("md5sum_device" and "md5sum_host") Args: output_directory: An optional path to the output directory. If not set, no built dependencies are configured. custom_deps: An optional dictionary specifying custom dependencies. This should be of the form: { 'dependency_name': { 'platform': 'path', ... }, ... } adb_path: An optional path to use for the adb binary. If not set, this uses the adb binary provided by the Android SDK. """ devil_dynamic_config = { 'config_type': 'BaseConfig', 'dependencies': {}, } if output_directory: output_directory = os.path.abspath(output_directory) devil_dynamic_config['dependencies'] = { dep_name: { 'file_info': { '%s_%s' % (dep_config['platform'], dep_config['arch']): { 'local_paths': [ os.path.join(output_directory, *dep_config['path_components']), ], } for dep_config in dep_configs } } for dep_name, dep_configs in _DEVIL_BUILD_PRODUCT_DEPS.iteritems() } if custom_deps: devil_dynamic_config['dependencies'].update(custom_deps) if adb_path: devil_dynamic_config['dependencies'].update({ 'adb': { 'file_info': { devil_env.GetPlatform(): { 'local_paths': [adb_path] } } } }) devil_env.config.Initialize( configs=[devil_dynamic_config], config_files=[_DEVIL_CONFIG])
def main(): parser = argparse.ArgumentParser() apk_group = parser.add_mutually_exclusive_group(required=True) apk_group.add_argument('--apk', dest='apk_name', help='DEPRECATED The name of the apk containing the' ' application (with the .apk extension).') apk_group.add_argument('apk_path', nargs='?', help='The path to the APK to install.') # TODO(jbudorick): Remove once no clients pass --apk_package parser.add_argument('--apk_package', help='DEPRECATED unused') parser.add_argument('--split', action='append', dest='splits', help='A glob matching the apk splits. ' 'Can be specified multiple times.') parser.add_argument('--keep_data', action='store_true', default=False, help='Keep the package data when installing ' 'the application.') parser.add_argument('--debug', action='store_const', const='Debug', dest='build_type', default=os.environ.get('BUILDTYPE', 'Debug'), help='If set, run test suites under out/Debug. ' 'Default is env var BUILDTYPE or Debug') parser.add_argument('--release', action='store_const', const='Release', dest='build_type', help='If set, run test suites under out/Release. ' 'Default is env var BUILDTYPE or Debug.') parser.add_argument( '-d', '--device', dest='devices', action='append', help='Target device for apk to install on. Enter multiple' ' times for multiple devices.') 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('-v', '--verbose', action='count', help='Enable verbose logging.') parser.add_argument('--downgrade', action='store_true', help='If set, allows downgrading of apk.') args = parser.parse_args() run_tests_helper.SetLogLevel(args.verbose) constants.SetBuildType(args.build_type) devil_custom_deps = None if args.adb_path: devil_custom_deps = { 'adb': { devil_env.GetPlatform(): [args.adb_path], }, } devil_chromium.Initialize(output_directory=constants.GetOutDirectory(), custom_deps=devil_custom_deps) apk = args.apk_path or args.apk_name if not apk.endswith('.apk'): apk += '.apk' if not os.path.exists(apk): apk = os.path.join(constants.GetOutDirectory(), 'apks', apk) if not os.path.exists(apk): parser.error('%s not found.' % apk) if args.splits: splits = [] base_apk_package = apk_helper.ApkHelper(apk).GetPackageName() for split_glob in args.splits: apks = [f for f in glob.glob(split_glob) if f.endswith('.apk')] if not apks: logging.warning('No apks matched for %s.', split_glob) for f in apks: helper = apk_helper.ApkHelper(f) if (helper.GetPackageName() == base_apk_package and helper.GetSplitName()): splits.append(f) blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) devices = device_utils.DeviceUtils.HealthyDevices(blacklist) if args.devices: devices = [d for d in devices if d in args.devices] if not devices: raise device_errors.DeviceUnreachableError(args.devices) elif not devices: raise device_errors.NoDevicesError() def blacklisting_install(device): try: if args.splits: device.InstallSplitApk(apk, splits, reinstall=args.keep_data, allow_downgrade=args.downgrade) else: device.Install(apk, reinstall=args.keep_data, allow_downgrade=args.downgrade) except device_errors.CommandFailedError: logging.exception('Failed to install %s', args.apk_name) if blacklist: blacklist.Extend([str(device)], reason='install_failure') logging.warning('Blacklisting %s', str(device)) except device_errors.CommandTimeoutError: logging.exception('Timed out while installing %s', args.apk_name) if blacklist: blacklist.Extend([str(device)], reason='install_timeout') logging.warning('Blacklisting %s', str(device)) device_utils.DeviceUtils.parallel(devices).pMap(blacklisting_install)
parser.add_argument( '-r', '--auto-reconnect', action='store_true', help=argparse.SUPPRESS) parser.add_argument( '-t', '--target', help=argparse.SUPPRESS) 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]) try: return ProvisionDevices( args.devices, args.blacklist_file, adb_key_files=args.adb_key_files, disable_location=args.disable_location, disable_mock_location=args.disable_mock_location, disable_network=args.disable_network, disable_system_chrome=args.disable_system_chrome, emulators=args.emulators, enable_java_debug=args.enable_java_debug, max_battery_temp=args.max_battery_temp,
def main(raw_args): # Recommended options on perf bots: # --disable-network # TODO(tonyg): We eventually want network on. However, currently radios # can cause perfbots to drain faster than they charge. # --min-battery-level 95 # Some perf bots run benchmarks with USB charging disabled which leads # to gradual draining of the battery. We must wait for a full charge # before starting a run in order to keep the devices online. parser = argparse.ArgumentParser( description='Provision Android devices with settings required for bots.' ) parser.add_argument( '-d', '--device', metavar='SERIAL', action='append', dest='devices', help='the serial number of the device to be provisioned ' '(the default is to provision all devices attached)') 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('--skip-wipe', action='store_true', default=False, help="don't wipe device data during provisioning") parser.add_argument('--reboot-timeout', metavar='SECS', type=int, help='when wiping the device, max number of seconds to' ' wait after each reboot ' '(default: %s)' % _DEFAULT_TIMEOUTS.HELP_TEXT) parser.add_argument( '--min-battery-level', type=int, metavar='NUM', help='wait for the device to reach this minimum battery' ' level before trying to continue') parser.add_argument('--disable-location', action='store_true', help='disable Google location services on devices') parser.add_argument('--disable-mock-location', action='store_true', default=False, help='Set ALLOW_MOCK_LOCATION to false') parser.add_argument('--disable-network', action='store_true', help='disable network access on devices') parser.add_argument('--disable-java-debug', action='store_false', dest='enable_java_debug', default=True, help='disable Java property asserts and JNI checking') parser.add_argument('--disable-system-chrome', action='store_true', help='Disable the system chrome from devices.') parser.add_argument('--remove-system-webview', action='store_true', help='Remove the system webview from devices.') parser.add_argument('--adb-key-files', type=str, nargs='+', help='list of adb keys to push to device') parser.add_argument('-v', '--verbose', action='count', default=1, help='Log more information.') parser.add_argument( '--max-battery-temp', type=int, metavar='NUM', help='Wait for the battery to have this temp or lower.') parser.add_argument('--output-device-blacklist', help='Json file to output the device blacklist.') parser.add_argument('--emulators', action='store_true', help='provision only emulators and ignore usb devices') 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]) try: return ProvisionDevices( args.devices, args.blacklist_file, adb_key_files=args.adb_key_files, disable_location=args.disable_location, disable_mock_location=args.disable_mock_location, disable_network=args.disable_network, disable_system_chrome=args.disable_system_chrome, emulators=args.emulators, enable_java_debug=args.enable_java_debug, max_battery_temp=args.max_battery_temp, min_battery_level=args.min_battery_level, output_device_blacklist=args.output_device_blacklist, reboot_timeout=args.reboot_timeout, remove_system_webview=args.remove_system_webview, wipe=not args.skip_wipe) except (device_errors.DeviceUnreachableError, device_errors.NoDevicesError): return exit_codes.INFRA