def main(argv): logging.basicConfig(level=logging.INFO, format='# %(asctime)-15s: %(message)s') run_tests_helper.SetLogLevel(verbose_count=1) if not CheckSDK(): logging.critical( 'ERROR: android_tools does not exist. Make sure your .gclient file ' 'contains the right \'target_os\' entry. See ' 'https://code.google.com/p/chromium/wiki/AndroidBuildInstructions for ' 'more information.') return 1 # Download system images only if needed. if CheckARMv7Image(): logging.info('The ARMv7 image is already present.') else: GetARMv7Image() if CheckX86Image(): logging.info('The x86 image is already present.') else: GetX86Image() # Make sure KVM packages are installed and enabled. if CheckKVM(): logging.info('KVM already installed and enabled.') else: InstallKVM()
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) if len(args) < 2 or not len(args) % 2: parser.error('Need even number of port pairs') sys.exit(1) try: port_pairs = map(int, args[1:]) port_pairs = zip(port_pairs[::2], port_pairs[1::2]) except ValueError: parser.error('Bad port number') sys.exit(1) if options.blacklist_file: blacklist = device_blacklist.Blacklist(options.blacklist_file) else: blacklist = 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(argv): option_parser = optparse.OptionParser() test_options_parser.AddGTestOptions(option_parser) options, args = option_parser.parse_args(argv) if len(args) > 1: option_parser.error('Unknown argument: %s' % args[1:]) run_tests_helper.SetLogLevel(options.verbose_count) if options.out_directory: cmd_helper.OutDirectory.set(options.out_directory) if options.use_emulator: emulator.DeleteAllTempAVDs() failed_tests_count = Dispatch(options) # Failures of individual test suites are communicated by printing a # STEP_FAILURE message. # Returning a success exit status also prevents the buildbot from incorrectly # marking the last suite as failed if there were failures in other suites in # the batch (this happens because the exit status is a sum of all failures # from all suites, but the buildbot associates the exit status only with the # most recent step). if options.exit_code: return failed_tests_count return 0
def main(): argparser = argparse.ArgumentParser() argparser.add_argument('--out', required=True, type=str, help='Report output file path.') argparser.add_argument('--emma-dir', required=True, type=str, help='EMMA HTML report directory.') argparser.add_argument( '--lines-for-coverage-file', required=True, type=str, help='File containing a JSON object. Should contain a ' 'dict mapping file names to lists of line numbers of ' 'code for which coverage information is desired.') argparser.add_argument('-v', '--verbose', action='count', help='Print verbose log information.') args = argparser.parse_args() run_tests_helper.SetLogLevel(args.verbose) GenerateCoverageReport(args.lines_for_coverage_file, args.out, args.emma_dir)
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('--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('--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.') args = parser.parse_args() constants.SetBuildType(args.target) run_tests_helper.SetLogLevel(args.verbose) return ProvisionDevices(args)
def main(argv): parser = optparse.OptionParser(usage='Usage: %prog [options]', 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( '-f', '--fields', dest='fields', default='jank_count,max_frame_delay,avg_surface_fps,' 'frame_lengths', help='Comma separated list of fields to display or "all".') parser.add_option('-d', '--delay', dest='delay', default=1, type='float', help='Time in seconds to sleep between updates.') options, args = parser.parse_args(argv) run_tests_helper.SetLogLevel(options.verbose_count) adb = android_commands.AndroidCommands(options.device) collector = surface_stats_collector.SurfaceStatsCollector(adb) collector.DisableWarningAboutEmptyData() fields = options.fields.split(',') row_count = None try: collector.Start() while True: time.sleep(options.delay) results = collector.SampleResults() results = _MergeResults(results, fields) if not results: continue terminal_height = _GetTerminalHeight() if row_count is None or (terminal_height and row_count >= terminal_height - 3): _PrintColumnTitles(results) row_count = 0 _PrintResults(results) row_count += 1 except KeyboardInterrupt: sys.exit(0) finally: collector.Stop()
def main(argv): option_parser = optparse.OptionParser() test_options_parser.AddGTestOptions(option_parser) options, args = option_parser.parse_args(argv) if len(args) > 1: option_parser.error('Unknown argument: %s' % args[1:]) run_tests_helper.SetLogLevel(options.verbose_count) return dispatch.Dispatch(options)
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('--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) if len(args) < 2 or not len(args) % 2: parser.error('Need even number of port pairs') sys.exit(1) try: port_pairs = map(int, args[1:]) port_pairs = zip(port_pairs[::2], port_pairs[1::2]) except ValueError: parser.error('Bad port number') sys.exit(1) devices = android_commands.GetAttachedDevices() if options.device: if options.device not in devices: raise Exception('Error: %s not in attached devices %s' % (options.device, ','.join(devices))) devices = [options.device] else: if not devices: raise Exception('Error: no connected devices') print "No device specified. Defaulting to " + devices[0] device = device_utils.DeviceUtils(devices[0]) 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(argv): opt_parser = optparse.OptionParser( description='Install dependencies for running the Android emulator') opt_parser.add_option( '--api-level', dest='api_level', help='The API level (e.g., 19 for Android 4.4) to ensure is available', type='int', default=DEFAULT_ANDROID_API_LEVEL) opt_parser.add_option('-v', dest='verbose', action='store_true', help='enable verbose logging') options, _ = opt_parser.parse_args(argv[1:]) # run_tests_helper will set logging to INFO or DEBUG # We achieve verbose output by configuring it with 2 (==DEBUG) verbosity = 1 if (options.verbose): verbosity = 2 logging.basicConfig(level=logging.INFO, format='# %(asctime)-15s: %(message)s') run_tests_helper.SetLogLevel(verbose_count=verbosity) # Calls below will download emulator SDK and/or system images only if needed. if CheckSDK(): logging.info( 'android_emulator_sdk/ already exists, skipping download.') else: GetSDK() # Check target. The target has to be installed in order to run the emulator. if CheckSDKPlatform(options.api_level): logging.info('SDK platform android-%d already present, skipping.' % options.api_level) else: logging.info('SDK platform android-%d not present, installing.' % options.api_level) GetSDKPlatform(options.api_level) # Download the x86 system image only if needed. if CheckX86Image(options.api_level): logging.info('x86 image for android-%d already present, skipping.' % options.api_level) else: GetX86Image(options.api_level) # Make sure KVM packages are installed and enabled. if CheckKVM(): logging.info('KVM already installed and enabled.') else: InstallKVM()
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) if args.adb_path: constants.SetAdbPath(args.adb_path) # 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): option_parser = optparse.OptionParser() test_options_parser.AddInstrumentationOptions(option_parser) options, args = option_parser.parse_args(argv) test_options_parser.ValidateInstrumentationOptions(option_parser, options, args) run_tests_helper.SetLogLevel(options.verbose_count) ret = 1 try: ret = DispatchInstrumentationTests(options) finally: buildbot_report.PrintStepResultIfNeeded(options, ret) return ret
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) if args.blacklist_file: blacklist = device_blacklist.Blacklist(args.blacklist_file) else: blacklist = 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(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('--host', help='Host address to forward to from the host machine. ' '127.0.0.1 by default', default='127.0.0.1') 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) if len(args) < 2 or not len(args) % 2: parser.error('Need even number of port pairs') sys.exit(1) try: port_pairs = map(int, args[1:]) port_pairs = zip(port_pairs[::2], port_pairs[1::2]) except ValueError: parser.error('Bad port number') sys.exit(1) adb = android_commands.AndroidCommands(options.device) tool = CreateTool(None, adb) forwarder_instance = forwarder.Forwarder(adb, options.build_type) try: forwarder_instance.Run(port_pairs, tool, options.host) while True: time.sleep(60) except KeyboardInterrupt: sys.exit(0) finally: forwarder_instance.Close()
def ProcessCommonOptions(options, error_func): """Processes and handles all common options.""" run_tests_helper.SetLogLevel(options.verbose_count) constants.SetBuildType(options.build_type) if options.build_directory: constants.SetBuildDirectory(options.build_directory) if options.output_directory: constants.SetOutputDirectort(options.output_directory) if options.adb_path: constants.SetAdbPath(options.adb_path) # 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'] if options.environment not in constants.VALID_ENVIRONMENTS: error_func('--environment must be one of: %s' % ', '.join(constants.VALID_ENVIRONMENTS))
def main(): parser = argparse.ArgumentParser() parser.add_argument('-v', '--verbose', action='count') parser.add_argument('-s', '--serial') parser.add_argument('--bus', type=int) parser.add_argument('--device', type=int) args = parser.parse_args() run_tests_helper.SetLogLevel(args.verbose) if args.serial: reset_android_usb(args.serial) elif args.bus and args.device: reset_usb(args.bus, args.device) else: parser.error('Unable to determine target. ' 'Specify --serial or BOTH --bus and --device.') 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.') 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 = 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.') args = parser.parse_args() run_tests_helper.SetLogLevel(args.verbose) devices = device_utils.DeviceUtils.HealthyDevices() device = devices[0] logging.info('Using device %s for testing.' % str(device)) if args.command == 'create_app_data': CreateAppData(device, args.old_apk, args.app_data) elif args.command == 'test_update': TestUpdate(device, args.old_apk, args.new_apk, args.app_data) else: raise Exception('Unknown test command: %s' % args.command)
def main(argv): logging.basicConfig(level=logging.INFO, format='# %(asctime)-15s: %(message)s') run_tests_helper.SetLogLevel(verbose_count=1) # Calls below will download emulator SDK and/or system images only if needed. if CheckSDK(): logging.info( 'android_emulator_sdk/ already exists, skipping download.') else: GetSDK() # Download the x86 system image only if needed. if CheckX86Image(): logging.info('The x86 image is already present, skipping download.') else: GetX86Image() # Make sure KVM packages are installed and enabled. if CheckKVM(): logging.info('KVM already installed and enabled.') else: InstallKVM()
def main(argv): logging.basicConfig(level=logging.INFO, format='# %(asctime)-15s: %(message)s') run_tests_helper.SetLogLevel(verbose_count=1) # Calls below will download emulator SDK and/or system images only if needed. if CheckSDK(): logging.info('android_tools directory already exists (not downloading).') else: GetSDK() logging.info('Emulator deps for ARM emulator complete.') if CheckX86Image(): logging.info('system-images directory already exists.') else: GetX86Image() # Make sure KVM packages are installed and enabled. if CheckKVM(): logging.info('KVM already installed and enabled.') else: InstallKVM()
def main(): parser = optparse.OptionParser() parser.add_option('', '--out-dir', help='Directory where the device path is stored', default=os.path.join(constants.DIR_SOURCE_ROOT, 'out')) parser.add_option( '--no-provisioning-check', action='store_true', help='Will not check if devices are provisioned properly.') parser.add_option('--device-status-dashboard', action='store_true', help='Output device status data for dashboard.') parser.add_option('--restart-usb', action='store_true', help='Restart USB ports before running device check.') parser.add_option('--json-output', help='Output JSON information into a specified file.') parser.add_option('-v', '--verbose', action='count', default=1, help='Log more information.') options, args = parser.parse_args() if args: parser.error('Unknown options %s' % args) run_tests_helper.SetLogLevel(options.verbose) # Remove the last build's "bad devices" before checking device statuses. device_blacklist.ResetBlacklist() try: expected_devices = device_list.GetPersistentDeviceList( os.path.join(options.out_dir, device_list.LAST_DEVICES_FILENAME)) except IOError: expected_devices = [] devices = device_utils.DeviceUtils.HealthyDevices() device_serials = [d.adb.GetDeviceSerial() for d in devices] # Only restart usb if devices are missing. if set(expected_devices) != set(device_serials): logging.warning('expected_devices: %s', expected_devices) logging.warning('devices: %s', device_serials) KillAllAdb() retries = 5 usb_restarted = True if options.restart_usb: if not RestartUsb(): usb_restarted = False bb_annotations.PrintWarning() logging.error('USB reset stage failed, ' 'wait for any device to come back.') while retries: logging.info('retry adb devices...') time.sleep(1) devices = device_utils.DeviceUtils.HealthyDevices() device_serials = [d.adb.GetDeviceSerial() for d in devices] if set(expected_devices) == set(device_serials): # All devices are online, keep going. break if not usb_restarted and devices: # The USB wasn't restarted, but there's at least one device online. # No point in trying to wait for all devices. break retries -= 1 types, builds, batteries, errors, devices_ok, json_data = ([], [], [], [], [], []) if devices: types, builds, batteries, errors, devices_ok, json_data = (zip( *[DeviceInfo(dev, options) for dev in devices])) # 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 device in json_data: try: f.write('%s %s %s %.1fC %s%%\n' % (device['serial'], device['type'], device['build'], float(device['battery']['temperature']) / 10, device['battery']['level'])) except Exception: pass err_msg = CheckForMissingDevices(options, devices) or [] unique_types = list(set(types)) unique_builds = list(set(builds)) bb_annotations.PrintMsg('Online devices: %d. Device types %s, builds %s' % (len(devices), unique_types, unique_builds)) for j in json_data: logging.info('Device %s (%s)', j.get('serial'), j.get('type')) logging.info(' Build: %s (%s)', j.get('build'), j.get('build_detail')) logging.info(' Current Battery Service state:') for k, v in j.get('battery', {}).iteritems(): logging.info(' %s: %s', k, v) logging.info(' IMEI slice: %s', j.get('imei_slice')) logging.info(' WiFi IP: %s', j.get('wifi_ip')) for dev, dev_errors in zip(devices, errors): if dev_errors: err_msg += ['%s errors:' % str(dev)] err_msg += [' %s' % error for error in dev_errors] if err_msg: bb_annotations.PrintWarning() for e in err_msg: logging.error(e) from_address = '*****@*****.**' to_addresses = ['*****@*****.**'] bot_name = os.environ.get('BUILDBOT_BUILDERNAME') slave_name = os.environ.get('BUILDBOT_SLAVENAME') subject = 'Device status check errors on %s, %s.' % (slave_name, bot_name) SendEmail(from_address, to_addresses, [], subject, '\n'.join(err_msg)) if options.device_status_dashboard: offline_devices = [ device_utils.DeviceUtils(a) for a in adb_wrapper.AdbWrapper.Devices(is_ready=False) if a.GetState() == 'offline' ] perf_tests_results_helper.PrintPerfResult('BotDevices', 'OnlineDevices', [len(devices)], 'devices') perf_tests_results_helper.PrintPerfResult('BotDevices', 'OfflineDevices', [len(offline_devices)], 'devices', 'unimportant') for dev, battery in zip(devices, batteries): perf_tests_results_helper.PrintPerfResult('DeviceBattery', str(dev), [battery], '%', 'unimportant') if options.json_output: with open(options.json_output, 'wb') as f: f.write(json.dumps(json_data, indent=4)) num_failed_devs = 0 for device_ok, device in zip(devices_ok, devices): if not device_ok: logging.warning('Blacklisting %s', str(device)) device_blacklist.ExtendBlacklist([str(device)]) num_failed_devs += 1 if num_failed_devs == len(devices): return 2 if not devices: return 1
def ProcessCommonOptions(options): """Processes and handles all common options.""" run_tests_helper.SetLogLevel(options.verbose_count) constants.SetBuildType(options.build_type)
def main(): parser = argparse.ArgumentParser() parser.add_argument('apk_path', help='The path to the APK to install.') parser.add_argument('--split', action='append', dest='splits', help='A glob matching the apk splits. ' 'Can be specified multiple times.') parser.add_argument('--native_lib', dest='native_libs', help='Path to native library (repeatable)', action='append', default=[]) parser.add_argument('--dex-file', dest='dex_files', help='Path to dex files (repeatable)', action='append', default=[]) parser.add_argument('-d', '--device', dest='device', help='Target device for apk to install on.') parser.add_argument('--uninstall', action='store_true', default=False, help='Remove the app and all side-loaded files.') parser.add_argument('--output-directory', help='Path to the root build directory.') parser.add_argument('--no-threading', action='store_false', default=True, dest='threading', help='Do not install and push concurrently') parser.add_argument( '--no-cache', action='store_false', default=True, dest='cache', help='Do not use cached information about what files are ' 'currently on the target device.') parser.add_argument('--show-proguard-warning', action='store_true', default=False, help='Print a warning about proguard being disabled') parser.add_argument('--dont-even-try', help='Prints this message and exits.') parser.add_argument('-v', '--verbose', dest='verbose_count', default=0, action='count', help='Verbose level (multiple times for more)') args = parser.parse_args() run_tests_helper.SetLogLevel(args.verbose_count) constants.SetBuildType('Debug') if args.output_directory: constants.SetOutputDirectory(args.output_directory) devil_chromium.Initialize(output_directory=constants.GetOutDirectory()) if args.dont_even_try: logging.fatal(args.dont_even_try) return 1 # Retries are annoying when commands fail for legitimate reasons. Might want # to enable them if this is ever used on bots though. device = device_utils.DeviceUtils.HealthyDevices( device_arg=args.device, default_retries=0, enable_device_files_cache=True)[0] apk = apk_helper.ToHelper(args.apk_path) if args.uninstall: Uninstall(device, apk.GetPackageName(), enable_device_cache=args.cache) else: Install(device, apk, split_globs=args.splits, native_libs=args.native_libs, dex_files=args.dex_files, enable_device_cache=args.cache, use_concurrency=args.threading, show_proguard_warning=args.show_proguard_warning)
def main(): parser = argparse.ArgumentParser() parser.add_argument('--out-dir', help='Directory where the device path is stored', default=os.path.join(constants.DIR_SOURCE_ROOT, 'out')) parser.add_argument('--no-provisioning-check', action='store_true', help='Will not check if devices are provisioned ' 'properly.') parser.add_argument('--device-status-dashboard', action='store_true', help='Output device status data for dashboard.') 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('--blacklist-file', help='Device blacklist JSON file.') parser.add_argument('-v', '--verbose', action='count', default=1, help='Log more information.') args = parser.parse_args() run_tests_helper.SetLogLevel(args.verbose) if args.blacklist_file: blacklist = device_blacklist.Blacklist(args.blacklist_file) else: # TODO(jbudorick): Remove this once bots pass the blacklist file. blacklist = device_blacklist.Blacklist(device_blacklist.BLACKLIST_JSON) devices = RecoverDevices(blacklist, args.out_dir) types, builds, batteries, errors, devices_ok, json_data = ([], [], [], [], [], []) if devices: types, builds, batteries, errors, devices_ok, json_data = (zip( *[DeviceInfo(dev, args) for dev in devices])) # 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 device in json_data: try: f.write('%s %s %s %.1fC %s%%\n' % (device['serial'], device['type'], device['build'], float(device['battery']['temperature']) / 10, device['battery']['level'])) except Exception: pass err_msg = CheckForMissingDevices(args, devices) or [] unique_types = list(set(types)) unique_builds = list(set(builds)) bb_annotations.PrintMsg('Online devices: %d. Device types %s, builds %s' % (len(devices), unique_types, unique_builds)) for j in json_data: logging.info('Device %s (%s)', j.get('serial'), j.get('type')) logging.info(' Build: %s (%s)', j.get('build'), j.get('build_detail')) logging.info(' Current Battery Service state:') for k, v in j.get('battery', {}).iteritems(): logging.info(' %s: %s', k, v) logging.info(' IMEI slice: %s', j.get('imei_slice')) logging.info(' WiFi IP: %s', j.get('wifi_ip')) for dev, dev_errors in zip(devices, errors): if dev_errors: err_msg += ['%s errors:' % str(dev)] err_msg += [' %s' % error for error in dev_errors] if err_msg: bb_annotations.PrintWarning() for e in err_msg: logging.error(e) from_address = '*****@*****.**' to_addresses = ['*****@*****.**'] bot_name = os.environ.get('BUILDBOT_BUILDERNAME') slave_name = os.environ.get('BUILDBOT_SLAVENAME') subject = 'Device status check errors on %s, %s.' % (slave_name, bot_name) SendEmail(from_address, to_addresses, [], subject, '\n'.join(err_msg)) if args.device_status_dashboard: offline_devices = [ device_utils.DeviceUtils(a) for a in adb_wrapper.AdbWrapper.Devices(desired_state=None) if a.GetState() == 'offline' ] perf_tests_results_helper.PrintPerfResult('BotDevices', 'OnlineDevices', [len(devices)], 'devices') perf_tests_results_helper.PrintPerfResult('BotDevices', 'OfflineDevices', [len(offline_devices)], 'devices', 'unimportant') for dev, battery in zip(devices, batteries): perf_tests_results_helper.PrintPerfResult('DeviceBattery', str(dev), [battery], '%', 'unimportant') if args.json_output: with open(args.json_output, 'wb') as f: f.write(json.dumps(json_data, indent=4)) num_failed_devs = 0 for device_ok, device in zip(devices_ok, devices): if not device_ok: logging.warning('Blacklisting %s', str(device)) blacklist.Extend([str(device)]) num_failed_devs += 1 if num_failed_devs == len(devices): return 2 if not devices: return 1
def main(): parser = argparse.ArgumentParser() parser.add_argument( '-v', '--verbose', action='count', help='Enable verbose logging.') parser.add_argument( '-a', '--auxclasspath', default=None, dest='auxclasspath', help='Set aux classpath for analysis.') parser.add_argument( '--auxclasspath-gyp', dest='auxclasspath_gyp', help='A gyp list containing the aux classpath for analysis') parser.add_argument( '-o', '--only-analyze', default=None, dest='only_analyze', help='Only analyze the given classes and packages.') parser.add_argument( '-e', '--exclude', default=None, dest='exclude', help='Exclude bugs matching given filter.') parser.add_argument( '-l', '--release-build', action='store_true', dest='release_build', help='Analyze release build instead of debug.') parser.add_argument( '-f', '--findbug-args', default=None, dest='findbug_args', help='Additional findbug arguments.') parser.add_argument( '-b', '--base-dir', default=_DEFAULT_BASE_DIR, dest='base_dir', help='Base directory for configuration file.') parser.add_argument( '--output-file', dest='output_file', help='Path to save the output to.') parser.add_argument( '--stamp', help='Path to touch on success.') parser.add_argument( '--depfile', help='Path to the depfile. This must be specified as the ' "action's first output.") parser.add_argument( 'jar_paths', metavar='JAR_PATH', nargs='+', help='JAR file to analyze') args = parser.parse_args(build_utils.ExpandFileArgs(sys.argv[1:])) run_tests_helper.SetLogLevel(args.verbose) if args.auxclasspath: args.auxclasspath = args.auxclasspath.split(':') elif args.auxclasspath_gyp: args.auxclasspath = build_utils.ParseGypList(args.auxclasspath_gyp) if args.base_dir: if not args.exclude: args.exclude = os.path.join(args.base_dir, 'findbugs_exclude.xml') findbugs_command, findbugs_warnings = findbugs.Run( args.exclude, args.only_analyze, args.auxclasspath, args.output_file, args.findbug_args, args.jar_paths) if findbugs_warnings: print print '*' * 80 print 'FindBugs run via:' print findbugs_command print print 'FindBugs reported the following issues:' for warning in sorted(findbugs_warnings): print str(warning) print '*' * 80 print else: if args.depfile: build_utils.WriteDepfile( args.depfile, build_utils.GetPythonDependencies() + args.auxclasspath + args.jar_paths) if args.stamp: build_utils.Touch(args.stamp) return len(findbugs_warnings)
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='device', help='Target device for apk to install on.') parser.add_argument('-v', '--verbose', action='count', help='Enable verbose logging.') args = parser.parse_args() run_tests_helper.SetLogLevel(args.verbose) constants.SetBuildType(args.build_type) 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) devices = device_utils.DeviceUtils.HealthyDevices() if args.device: devices = [d for d in devices if d == args.device] if not devices: raise device_errors.DeviceUnreachableError(args.device) elif not devices: raise device_errors.NoDevicesError() def blacklisting_install(device): try: if args.splits: device.InstallSplitApk(apk, splits, reinstall=args.keep_data) else: device.Install(apk, reinstall=args.keep_data) except device_errors.CommandFailedError: logging.exception('Failed to install %s', args.apk_name) device_blacklist.ExtendBlacklist([str(device)]) logging.warning('Blacklisting %s', str(device)) except device_errors.CommandTimeoutError: logging.exception('Timed out while installing %s', args.apk_name) device_blacklist.ExtendBlacklist([str(device)]) logging.warning('Blacklisting %s', str(device)) device_utils.DeviceUtils.parallel(devices).pMap(blacklisting_install)
def main(): parser = argparse.ArgumentParser() parser.add_argument('apk_path', help='The path to the APK to install.') parser.add_argument('--split', action='append', dest='splits', help='A glob matching the apk splits. ' 'Can be specified multiple times.') parser.add_argument('--lib-dir', help='Path to native libraries directory.') parser.add_argument('--dex-files', help='List of dex files to push.', action='append', default=[]) parser.add_argument('-d', '--device', dest='device', help='Target device for apk to install on.') parser.add_argument('--uninstall', action='store_true', default=False, help='Remove the app and all side-loaded files.') parser.add_argument('--output-directory', help='Path to the root build directory.') parser.add_argument('--no-threading', action='store_true', default=False, help='Do not install and push concurrently') parser.add_argument('-v', '--verbose', dest='verbose_count', default=0, action='count', help='Verbose level (multiple times for more)') args = parser.parse_args() run_tests_helper.SetLogLevel(args.verbose_count) constants.SetBuildType('Debug') if args.output_directory: constants.SetOutputDirectory(args.output_directory) main_timer = time_profile.TimeProfile() install_timer = time_profile.TimeProfile() push_native_timer = time_profile.TimeProfile() push_dex_timer = time_profile.TimeProfile() if args.device: # Retries are annoying when commands fail for legitimate reasons. Might want # to enable them if this is ever used on bots though. device = device_utils.DeviceUtils(args.device, default_retries=0) else: devices = device_utils.DeviceUtils.HealthyDevices(default_retries=0) if not devices: raise device_errors.NoDevicesError() elif len(devices) == 1: device = devices[0] else: all_devices = device_utils.DeviceUtils.parallel(devices) msg = ('More than one device available.\n' 'Use --device=SERIAL to select a device.\n' 'Available devices:\n') descriptions = all_devices.pMap(lambda d: d.build_description).pGet(None) for d, desc in zip(devices, descriptions): msg += ' %s (%s)\n' % (d, desc) raise Exception(msg) apk_help = apk_helper.ApkHelper(args.apk_path) apk_package = apk_help.GetPackageName() device_incremental_dir = '/data/local/tmp/incremental-app-%s' % apk_package if args.uninstall: device.Uninstall(apk_package) device.RunShellCommand(['rm', '-rf', device_incremental_dir], check_return=True) logging.info('Uninstall took %s seconds.', main_timer.GetDelta()) return if device.build_version_sdk >= version_codes.MARSHMALLOW: if apk_help.HasIsolatedProcesses(): raise Exception('Cannot use perform incremental installs on Android M+ ' 'without first disabling isolated processes. Use GN arg: ' 'disable_incremental_isolated_processes=true to do so.') # Install .apk(s) if any of them have changed. def do_install(): install_timer.Start() if args.splits: splits = [] for split_glob in args.splits: splits.extend((f for f in glob.glob(split_glob))) device.InstallSplitApk(args.apk_path, splits, reinstall=True, allow_cached_props=True, permissions=()) else: device.Install(args.apk_path, reinstall=True, permissions=()) install_timer.Stop(log=False) # Push .so and .dex files to the device (if they have changed). def do_push_files(): if args.lib_dir: push_native_timer.Start() device_lib_dir = posixpath.join(device_incremental_dir, 'lib') device.PushChangedFiles([(args.lib_dir, device_lib_dir)], delete_device_stale=True) push_native_timer.Stop(log=False) if args.dex_files: push_dex_timer.Start() # Put all .dex files to be pushed into a temporary directory so that we # can use delete_device_stale=True. with build_utils.TempDir() as temp_dir: device_dex_dir = posixpath.join(device_incremental_dir, 'dex') # Ensure no two files have the same name. transformed_names = _TransformDexPaths(args.dex_files) for src_path, dest_name in zip(args.dex_files, transformed_names): shutil.copyfile(src_path, os.path.join(temp_dir, dest_name)) device.PushChangedFiles([(temp_dir, device_dex_dir)], delete_device_stale=True) push_dex_timer.Stop(log=False) # Create 2 lock files: # * install.lock tells the app to pause on start-up (until we release it). # * firstrun.lock is used by the app to pause all secondary processes until # the primary process finishes loading the .dex / .so files. def create_lock_files(): # Creates or zeros out lock files. cmd = ('D="%s";' 'mkdir -p $D &&' 'echo -n >$D/install.lock 2>$D/firstrun.lock') device.RunShellCommand(cmd % device_incremental_dir, check_return=True) # The firstrun.lock is released by the app itself. def release_installer_lock(): device.RunShellCommand('echo > %s/install.lock' % device_incremental_dir, check_return=True) create_lock_files() # Concurrency here speeds things up quite a bit, but DeviceUtils hasn't # been designed for multi-threading. Enabling only because this is a # developer-only tool. if args.no_threading: do_install() do_push_files() else: reraiser_thread.RunAsync((do_install, do_push_files)) release_installer_lock() logging.info('Took %s seconds (install=%s, libs=%s, dex=%s)', main_timer.GetDelta(), install_timer.GetDelta(), push_native_timer.GetDelta(), push_dex_timer.GetDelta())
def main(): parser = argparse.ArgumentParser() parser.add_argument('apk_path', help='The path to the APK to install.') parser.add_argument('--split', action='append', dest='splits', help='A glob matching the apk splits. ' 'Can be specified multiple times.') parser.add_argument('--native_lib', dest='native_libs', help='Path to native library (repeatable)', action='append', default=[]) parser.add_argument('--dex-file', dest='dex_files', help='Path to dex files (repeatable)', action='append', default=[]) parser.add_argument('-d', '--device', dest='device', help='Target device for apk to install on.') parser.add_argument('--uninstall', action='store_true', default=False, help='Remove the app and all side-loaded files.') parser.add_argument('--output-directory', help='Path to the root build directory.') parser.add_argument('--no-threading', action='store_false', default=True, dest='threading', help='Do not install and push concurrently') parser.add_argument( '--no-cache', action='store_false', default=True, dest='cache', help='Do not use cached information about what files are ' 'currently on the target device.') parser.add_argument('--show-proguard-warning', action='store_true', default=False, help='Print a warning about proguard being disabled') parser.add_argument('-v', '--verbose', dest='verbose_count', default=0, action='count', help='Verbose level (multiple times for more)') args = parser.parse_args() run_tests_helper.SetLogLevel(args.verbose_count) constants.SetBuildType('Debug') if args.output_directory: constants.SetOutputDirectory(args.output_directory) if args.device: # Retries are annoying when commands fail for legitimate reasons. Might want # to enable them if this is ever used on bots though. device = device_utils.DeviceUtils(args.device, default_retries=0, enable_device_files_cache=True) else: devices = device_utils.DeviceUtils.HealthyDevices( default_retries=0, enable_device_files_cache=True) if not devices: raise device_errors.NoDevicesError() elif len(devices) == 1: device = devices[0] else: all_devices = device_utils.DeviceUtils.parallel(devices) msg = ('More than one device available.\n' 'Use --device=SERIAL to select a device.\n' 'Available devices:\n') descriptions = all_devices.pMap( lambda d: d.build_description).pGet(None) for d, desc in zip(devices, descriptions): msg += ' %s (%s)\n' % (d, desc) raise Exception(msg) apk = apk_helper.ToHelper(args.apk_path) if args.uninstall: Uninstall(device, apk.GetPackageName()) else: Install(device, apk, split_globs=args.splits, native_libs=args.native_libs, dex_files=args.dex_files, enable_device_cache=args.cache, use_concurrency=args.threading, show_proguard_warning=args.show_proguard_warning)
def ProcessCommonOptions(options): """Processes and handles all common options.""" run_tests_helper.SetLogLevel(options.verbose_count)