def main(): parser = argparse.ArgumentParser(description=""" Removes the preinstalled WebView APKs to avoid signature mismatches during development. """) script_common.AddEnvironmentArguments(parser) script_common.AddDeviceArguments(parser) logging_common.AddLoggingArguments(parser) args = parser.parse_args() logging_common.InitializeLogging(args) devil_chromium.Initialize(adb_path=args.adb_path) devices = device_utils.DeviceUtils.HealthyDevices(device_arg=args.devices) device_utils.DeviceUtils.parallel(devices).pMap(RemovePreinstalledWebViews)
def main(raw_args): parser = argparse.ArgumentParser() parser.add_argument('--debug', action='store_true', help='Get additional debugging mode') parser.add_argument( '--output-directory', help='the path to the build output directory, such as out/Debug') parser.add_argument('--report-path', default='report.html', help='Report path') parser.add_argument('--adb-path', help='Absolute path to the adb binary to use.') parser.add_argument('--record-options', help=('Set recording options for app_profiler.py command.' ' Example: "-e task-clock:u -f 1000 -g --duration' ' 10" where -f means sampling frequency per second.' ' Try `app_profiler.py record -h` for more ' ' information. Note that not setting this defaults' ' to the default record options.')) parser.add_argument('--show-file-line', action='store_true', help='Show file name and lines in the result.') parser.add_argument( '--system-wide', action='store_true', help=('Whether to profile system wide (without launching' 'an app).')) script_common.AddDeviceArguments(parser) logging_common.AddLoggingArguments(parser) args = parser.parse_args(raw_args) logging_common.InitializeLogging(args) devil_chromium.Initialize(adb_path=args.adb_path) devices = script_common.GetDevices(args.devices, args.blacklist_file) device = devices[0] if len(devices) > 1: raise device_errors.MultipleDevicesError(devices) with tempfile_ext.NamedTemporaryDirectory( prefix='tmp_simpleperf') as tmp_dir: runner = SimplePerfRunner( device, args, tmp_dir, StackAddressInterpreter(args, tmp_dir)) runner.Run()
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): fastboot = fastboot_utils.FastbootUtils(device) try: fastboot.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 = script_common.GetDevices(args.devices, args.blacklist_file) device_utils.DeviceUtils.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(description=""" Configures WebView to start recording a netlog. This script chooses a suitable netlog filename for the application, and will pull the netlog off the device when the user terminates the script (with ctrl-C). For a more complete usage guide, open your web browser to: https://chromium.googlesource.com/chromium/src/+/HEAD/android_webview/docs/net-debugging.md """) parser.add_argument( '--package', required=True, type=str, help='Package name of the application you intend to use.') parser.add_argument('--force', default=False, action='store_true', help='Suppress user checks.') script_common.AddEnvironmentArguments(parser) script_common.AddDeviceArguments(parser) logging_common.AddLoggingArguments(parser) args = parser.parse_args() logging_common.InitializeLogging(args) devil_chromium.Initialize(adb_path=args.adb_path) # Only use a single device, for the sake of simplicity (of implementation and # user experience). devices = device_utils.DeviceUtils.HealthyDevices(device_arg=args.devices) device = devices[0] if len(devices) > 1: raise device_errors.MultipleDevicesError(devices) package_name = args.package device_netlog_file_name = 'netlog.json' device_netlog_path = os.path.join( device.GetApplicationDataDirectory(package_name), 'app_webview', device_netlog_file_name) CheckAppNotRunning(device, package_name, args.force) # Append to the existing flags, to allow users to experiment with other # features/flags enabled. The CustomCommandLineFlags will restore the original # flag state after the user presses 'ctrl-C'. changer = flag_changer.FlagChanger(device, WEBVIEW_COMMAND_LINE) new_flags = changer.GetCurrentFlags() new_flags.append('--log-net-log={}'.format(device_netlog_path)) logging.info('Running with flags %r', new_flags) with flag_changer.CustomCommandLineFlags(device, WEBVIEW_COMMAND_LINE, new_flags): print( 'Netlog will start recording as soon as app starts up. Press ctrl-C ' 'to stop recording.') _WaitUntilCtrlC() host_netlog_path = 'netlog.json' print('Pulling netlog to "%s"' % host_netlog_path) # The netlog file will be under the app's uid, which the default shell doesn't # have permission to read (but root does). Prefer this to EnableRoot(), which # restarts the adb daemon. device.PullFile(device_netlog_path, host_netlog_path, as_root=True) device.RemovePath(device_netlog_path, as_root=True)
def main(): parser = argparse.ArgumentParser() parser.add_argument( '--arch', choices=list(set(_SUPPORTED_ARCH_DICT.values())), default=None, type=str, help=('Architecture to for CTS tests. Will auto-determine based on ' 'the device ro.product.cpu.abi property.')) parser.add_argument( '--cts-release', # TODO(aluo): --platform is deprecated (the meaning is unclear). '--platform', choices=sorted(set(SDK_PLATFORM_DICT.values())), required=False, default=None, help='Which CTS release to use for the run. This should generally be <= ' 'device OS level (otherwise, the newer tests will fail). If ' 'unspecified, the script will auto-determine the release based on ' 'device OS level.') parser.add_argument( '--skip-expected-failures', action='store_true', help= "Option to skip all tests that are expected to fail. Can't be used " "with test filters.") parser.add_argument('--apk-dir', help='Directory to extract CTS APKs to. ' 'Will use temp directory by default.') parser.add_argument( '--test-launcher-summary-output', '--json-results-file', '--write-full-results-to', '--isolated-script-test-output', dest='json_results_file', type=os.path.realpath, help='If set, will dump results in JSON form to the specified file. ' 'Note that this will also trigger saving per-test logcats to ' 'logdog.') parser.add_argument('-m', '--module-apk', dest='module_apk', help='CTS module apk name in ' + _WEBVIEW_CTS_GCS_PATH_FILE + ' file, without the path prefix.') test_filter.AddFilterOptions(parser) script_common.AddDeviceArguments(parser) logging_common.AddLoggingArguments(parser) args, test_runner_args = parser.parse_known_args() logging_common.InitializeLogging(args) devil_chromium.Initialize() test_runner_args.extend(ForwardArgsToTestRunner(args)) devices = script_common.GetDevices(args.devices, args.blacklist_file) device = devices[0] if len(devices) > 1: logging.warning( 'Detection of arch and cts-release will use 1st of %d ' 'devices: %s', len(devices), device.serial) arch = args.arch or DetermineArch(device) cts_release = args.cts_release or DetermineCtsRelease(device) if (args.test_filter_file or args.test_filter or args.isolated_script_test_filter): # TODO(aluo): auto-determine the module based on the test filter and the # available tests in each module if not args.module_apk: args.module_apk = 'CtsWebkitTestCases.apk' platform_modules = GetCTSModuleNames(arch, cts_release) if args.module_apk and args.module_apk not in platform_modules: raise Exception('--module-apk for arch==' + arch + 'and cts_release==' + cts_release + ' must be one of: ' + ', '.join(platform_modules)) # Need to uninstall all previous cts webkit packages so that the # MockContentProvider names won't conflict with a previously installed # one under a different package name. This is due to CtsWebkitTestCases's # package name change from M to N versions of the tests while keeping the # MockContentProvider's authority string the same. UninstallAnyCtsWebkitPackages(device) return RunAllCTSTests(args, arch, cts_release, test_runner_args)
def main(raw_args): parser = argparse.ArgumentParser() def add_common_arguments(parser): logging_common.AddLoggingArguments(parser) script_common.AddEnvironmentArguments(parser) parser.add_argument( '--avd-config', type=os.path.realpath, metavar='PATH', required=True, help='Path to an AVD config text protobuf.') subparsers = parser.add_subparsers() install_parser = subparsers.add_parser( 'install', help='Install the CIPD packages specified in the given config.') add_common_arguments(install_parser) def install_cmd(args): avd.AvdConfig(args.avd_config).Install() return 0 install_parser.set_defaults(func=install_cmd) create_parser = subparsers.add_parser( 'create', help='Create an AVD CIPD package according to the given config.') add_common_arguments(create_parser) create_parser.add_argument( '--snapshot', action='store_true', help='Snapshot the AVD before creating the CIPD package.') create_parser.add_argument( '--force', action='store_true', help='Pass --force to AVD creation.') create_parser.add_argument( '--keep', action='store_true', help='Keep the AVD after creating the CIPD package.') create_parser.add_argument( '--cipd-json-output', type=os.path.realpath, metavar='PATH', help='Path to which `cipd create` should dump json output ' 'via -json-output.') create_parser.add_argument( '--dry-run', action='store_true', help='Skip the CIPD package creation after creating the AVD.') def create_cmd(args): avd.AvdConfig(args.avd_config).Create( force=args.force, snapshot=args.snapshot, keep=args.keep, cipd_json_output=args.cipd_json_output, dry_run=args.dry_run) return 0 create_parser.set_defaults(func=create_cmd) start_parser = subparsers.add_parser( 'start', help='Start an AVD instance with the given config.', formatter_class=argparse.ArgumentDefaultsHelpFormatter) start_parser.add_argument( '--no-read-only', action='store_false', dest='read_only', default=True, help='Run a modifiable emulator. Will save snapshots on exit.') start_parser.add_argument( '--writable-system', action='store_true', default=False, help='Makes system & vendor image writable after adb remount.') start_parser.add_argument( '--emulator-window', action='store_true', default=False, help='Enable graphical window display on the emulator.') start_parser.add_argument( '--gpu-mode', default='swiftshader_indirect', help='Override the mode of hardware OpenGL ES emulation indicated by the ' 'AVD. See "emulator -help-gpu" for a full list of modes. Note when set ' 'to "host", it needs a valid DISPLAY env, even if "--emulator-window" is ' 'false, and it will not work under remote sessions like chrome remote ' 'desktop.') start_parser.add_argument( '--debug-tags', help='Comma-separated list of debug tags. This can be used to enable or ' 'disable debug messages from specific parts of the emulator, e.g. ' 'init, snapshot. See "emulator -help-debug-tags" ' 'for a full list of tags.') add_common_arguments(start_parser) def start_cmd(args): inst = avd.AvdConfig(args.avd_config).CreateInstance() inst.Start(read_only=args.read_only, snapshot_save=not args.read_only, window=args.emulator_window, writable_system=args.writable_system, gpu_mode=args.gpu_mode, debug_tags=args.debug_tags) print('%s started (pid: %d)' % (str(inst), inst._emulator_proc.pid)) return 0 start_parser.set_defaults(func=start_cmd) args = parser.parse_args(raw_args) logging_common.InitializeLogging(args) devil_chromium.Initialize(adb_path=args.adb_path) return args.func(args)
def main(raw_args): parser = argparse.ArgumentParser() def add_common_arguments(parser): logging_common.AddLoggingArguments(parser) script_common.AddEnvironmentArguments(parser) parser.add_argument('--avd-config', type=os.path.realpath, metavar='PATH', required=True, help='Path to an AVD config text protobuf.') subparsers = parser.add_subparsers() install_parser = subparsers.add_parser( 'install', help='Install the CIPD packages specified in the given config.') add_common_arguments(install_parser) def install_cmd(args): avd.AvdConfig(args.avd_config).Install() return 0 install_parser.set_defaults(func=install_cmd) create_parser = subparsers.add_parser( 'create', help='Create an AVD CIPD package according to the given config.') add_common_arguments(create_parser) create_parser.add_argument( '--snapshot', action='store_true', help='Snapshot the AVD before creating the CIPD package.') create_parser.add_argument('--force', action='store_true', help='Pass --force to AVD creation.') create_parser.add_argument( '--keep', action='store_true', help='Keep the AVD after creating the CIPD package.') create_parser.add_argument( '--cipd-json-output', type=os.path.realpath, metavar='PATH', help='Path to which `cipd create` should dump json output ' 'via -json-output.') def create_cmd(args): avd.AvdConfig(args.avd_config).Create( force=args.force, snapshot=args.snapshot, keep=args.keep, cipd_json_output=args.cipd_json_output) return 0 create_parser.set_defaults(func=create_cmd) start_parser = subparsers.add_parser( 'start', help='Start an AVD instance with the given config.') add_common_arguments(start_parser) def start_cmd(args): inst = avd.AvdConfig(args.avd_config).CreateInstance() inst.Start(read_only=False, snapshot_save=True) print('%s started (pid: %d)' % (str(inst), inst._emulator_proc.pid)) return 0 start_parser.set_defaults(func=start_cmd) args = parser.parse_args(raw_args) logging_common.InitializeLogging(args) devil_chromium.Initialize(adb_path=args.adb_path) return args.func(args)
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.' ) logging_common.AddLoggingArguments(parser) script_common.AddDeviceArguments(parser) script_common.AddEnvironmentArguments(parser) parser.add_argument('--adb-key-files', type=str, nargs='+', help='list of adb keys to push to device') 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='DEPRECATED: use --remove-system-packages com.android.google ' 'Disable the system chrome from devices.') parser.add_argument('--emulators', action='store_true', help='provision only emulators and ignore usb devices ' '(this will not wipe emulators)') parser.add_argument( '--max-battery-temp', type=int, metavar='NUM', help='Wait for the battery to have this temp or lower.') 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('--output-device-denylist', help='Json file to output the device denylist.') 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( '--remove-system-apps', nargs='*', dest='system_app_remove_list', help='DEPRECATED: use --remove-system-packages instead. ' 'The names of system apps to remove. ') parser.add_argument('--remove-system-packages', nargs='*', dest='system_package_remove_list', help='The names of system packages to remove.') parser.add_argument('--remove-system-webview', action='store_true', help='DEPRECATED: use --remove-system-packages ' 'com.google.android.webview com.android.webview ' 'Remove the system webview from devices.') parser.add_argument('--skip-wipe', action='store_true', default=False, help='do not wipe device data during provisioning') # No-op arguments for compatibility with build/android/provision_devices.py. # TODO(jbudorick): Remove these once all callers have stopped using them. parser.add_argument('--chrome-specific-wipe', action='store_true', help=argparse.SUPPRESS) parser.add_argument('--phase', action='append', help=argparse.SUPPRESS) 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) logging_common.InitializeLogging(args) script_common.InitializeEnvironment(args) try: return ProvisionDevices( args.devices, args.denylist_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_denylist=args.output_device_denylist, reboot_timeout=args.reboot_timeout, remove_system_webview=args.remove_system_webview, system_app_remove_list=args.system_app_remove_list, system_package_remove_list=args.system_package_remove_list, wipe=not args.skip_wipe and not args.emulators) except (device_errors.DeviceUnreachableError, device_errors.NoDevicesError): logging.exception('Unable to provision local devices.') return exit_codes.INFRA
def main(): parser = argparse.ArgumentParser(description=__doc__) parser.usage = '''%(prog)s --name FILENAME [--device SERIAL] [flags...] No flags: Prints existing command-line file. Empty string: Deletes command-line file. Otherwise: Writes command-line file. ''' parser.add_argument( '--name', required=True, help='Name of file where to store flags on the device.') parser.add_argument('-e', '--executable', dest='executable', default='chrome', help='(deprecated) No longer used.') script_common.AddEnvironmentArguments(parser) script_common.AddDeviceArguments(parser) logging_common.AddLoggingArguments(parser) args, remote_args = parser.parse_known_args() script_common.InitializeEnvironment(args) logging_common.InitializeLogging(args) devices = device_utils.DeviceUtils.HealthyDevices(device_arg=args.devices, default_retries=0) all_devices = device_utils.DeviceUtils.parallel(devices) if not remote_args: # No args == do not update, just print flags. remote_args = None action = '' elif len(remote_args) == 1 and not remote_args[0]: # Single empty string arg == delete flags remote_args = [] action = 'Deleted command line file. ' else: action = 'Wrote command line file. ' is_webview = args.name == 'webview-command-line' def update_flags(device): if device.IsUserBuild() and is_webview: raise device_errors.CommandFailedError( 'WebView only respects flags on a userdebug or eng device, yours ' 'is a user build.', device) elif device.IsUserBuild(): logging.warning( 'Your device (%s) is a user build; Chrome may or may not pick up ' 'your commandline flags. Check your ' '"command_line_on_non_rooted_enabled" preference, or switch ' 'devices.', device) changer = flag_changer.FlagChanger(device, args.name) if remote_args is not None: flags = changer.ReplaceFlags(remote_args) else: flags = changer.GetCurrentFlags() return (device, device.build_description, flags) updated_values = all_devices.pMap(update_flags).pGet(None) print '%sCurrent flags (in %s):' % (action, args.name) for d, desc, flags in updated_values: if flags: # Shell-quote flags for easy copy/paste as new args on the terminal. quoted_flags = ' '.join( cmd_helper.SingleQuote(f) for f in sorted(flags)) else: quoted_flags = '( empty )' print ' %s (%s): %s' % (d, desc, quoted_flags) return 0
def main(raw_args): parser = argparse.ArgumentParser() def add_common_arguments(parser): logging_common.AddLoggingArguments(parser) script_common.AddEnvironmentArguments(parser) parser.add_argument( '--avd-config', type=os.path.realpath, metavar='PATH', required=True, help='Path to an AVD config text protobuf.') subparsers = parser.add_subparsers() install_parser = subparsers.add_parser( 'install', help='Install the CIPD packages specified in the given config.') add_common_arguments(install_parser) def install_cmd(args): avd.AvdConfig(args.avd_config).Install() return 0 install_parser.set_defaults(func=install_cmd) create_parser = subparsers.add_parser( 'create', help='Create an AVD CIPD package according to the given config.') add_common_arguments(create_parser) create_parser.add_argument( '--snapshot', action='store_true', help='Snapshot the AVD before creating the CIPD package.') create_parser.add_argument( '--force', action='store_true', help='Pass --force to AVD creation.') create_parser.add_argument( '--keep', action='store_true', help='Keep the AVD after creating the CIPD package.') create_parser.add_argument( '--cipd-json-output', type=os.path.realpath, metavar='PATH', help='Path to which `cipd create` should dump json output ' 'via -json-output.') create_parser.add_argument( '--dry-run', action='store_true', help='Skip the CIPD package creation after creating the AVD.') def create_cmd(args): avd.AvdConfig(args.avd_config).Create( force=args.force, snapshot=args.snapshot, keep=args.keep, cipd_json_output=args.cipd_json_output, dry_run=args.dry_run) return 0 create_parser.set_defaults(func=create_cmd) start_parser = subparsers.add_parser( 'start', help='Start an AVD instance with the given config.') start_parser.add_argument( '--no-read-only', action='store_false', dest='read_only', default=True, help='Run a modifiable emulator. Will save snapshots on exit.') start_parser.add_argument( '--emulator-window', action='store_true', default=False, help='Enable graphical window display on the emulator.') start_parser.add_argument( '--debug-tags', help='Comma-separated list of debug tags. This can be used to enable or ' 'disable debug messages from specific parts of the emulator, e.g. ' 'init, snapshot. See "emulator -help-debug-tags" ' 'for a full list of tags.') add_common_arguments(start_parser) def start_cmd(args): inst = avd.AvdConfig(args.avd_config).CreateInstance() inst.Start( read_only=args.read_only, snapshot_save=not args.read_only, window=args.emulator_window, debug_tags=args.debug_tags) print('%s started (pid: %d)' % (str(inst), inst._emulator_proc.pid)) return 0 start_parser.set_defaults(func=start_cmd) args = parser.parse_args(raw_args) logging_common.InitializeLogging(args) devil_chromium.Initialize(adb_path=args.adb_path) return args.func(args)
def main(): parser = argparse.ArgumentParser( description=DESC, formatter_class=argparse.RawTextHelpFormatter) logging_common.AddLoggingArguments(parser) subparsers = parser.add_subparsers(dest='cmd') all_subparser = subparsers.add_parser( ALL_CMD, help='Performs all other sub-commands, in the correct order. This is' ' usually what you want.') add_dessert_arg(all_subparser) add_workdir_arg(all_subparser, False) download_subparser = subparsers.add_parser( DOWNLOAD_CMD, help='Only downloads files to workdir for later use by other' ' sub-commands.') add_dessert_arg(download_subparser) add_workdir_arg(download_subparser, True) cipd_subparser = subparsers.add_parser( CIPD_UPDATE_CMD, help='Create a new CIPD package version for CTS tests. This requires' ' that {} was completed in the same workdir.'.format(DOWNLOAD_CMD)) add_workdir_arg(cipd_subparser, True) checkout_subparser = subparsers.add_parser( CHECKOUT_UPDATE_CMD, help='Updates files in the current git branch. This requires that {} was' ' completed in the same workdir.'.format(CIPD_UPDATE_CMD)) add_workdir_arg(checkout_subparser, True) args = parser.parse_args() logging_common.InitializeLogging(args) temp_workdir = None if args.workdir is None: temp_workdir = tempfile.mkdtemp() workdir = temp_workdir else: workdir = args.workdir if not os.path.isdir(workdir): raise ValueError( '--workdir {} should already be a directory.'.format(workdir)) if not os.access(workdir, os.W_OK | os.X_OK): raise ValueError('--workdir {} is not writable.'.format(workdir)) try: cts_updater = UpdateCTS(work_dir=workdir, repo_root=cts_utils.SRC_DIR) if args.cmd == DOWNLOAD_CMD: cts_updater.download_cts_cmd(platforms=args.dessert) elif args.cmd == CIPD_UPDATE_CMD: cts_updater.create_cipd_cmd() elif args.cmd == CHECKOUT_UPDATE_CMD: cts_updater.update_repository_cmd() elif args.cmd == ALL_CMD: cts_updater.download_cts_cmd() cts_updater.create_cipd_cmd() cts_updater.update_repository_cmd() finally: if temp_workdir is not None: logging.info('Removing temporary workdir %s', temp_workdir) shutil.rmtree(temp_workdir)
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.denylist_file: denylist = device_denylist.Denylist(args.denylist_file).Read() if denylist: logger.critical('Device(s) in denylist, not flashing devices:') for key in denylist: 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.denylist_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(description=__doc__) parser.usage = '''%(prog)s --name FILENAME [--device SERIAL] [flags...] No flags: Prints existing command-line file. Empty string: Deletes command-line file. Otherwise: Writes command-line file. ''' parser.add_argument( '--name', required=True, help='Name of file where to store flags on the device.') parser.add_argument('-e', '--executable', dest='executable', default='chrome', help='(deprecated) No longer used.') script_common.AddEnvironmentArguments(parser) script_common.AddDeviceArguments(parser) logging_common.AddLoggingArguments(parser) args, remote_args = parser.parse_known_args() script_common.InitializeEnvironment(args) logging_common.InitializeLogging(args) devices = device_utils.DeviceUtils.HealthyDevices(device_arg=args.devices, default_retries=0) all_devices = device_utils.DeviceUtils.parallel(devices) if not remote_args: # No args == do not update, just print flags. remote_args = None action = '' elif len(remote_args) == 1 and not remote_args[0]: # Single empty string arg == delete flags remote_args = [] action = 'Deleted command line file. ' else: action = 'Wrote command line file. ' def update_flags(device): CheckBuildTypeSupportsFlags(device, args.name) changer = flag_changer.FlagChanger(device, args.name) if remote_args is not None: flags = changer.ReplaceFlags(remote_args) else: flags = changer.GetCurrentFlags() return (device, device.build_description, flags) updated_values = all_devices.pMap(update_flags).pGet(None) print '%sCurrent flags (in %s):' % (action, args.name) for d, desc, flags in updated_values: if flags: # Shell-quote flags for easy copy/paste as new args on the terminal. quoted_flags = ' '.join( cmd_helper.SingleQuote(f) for f in sorted(flags)) else: quoted_flags = '( empty )' print ' %s (%s): %s' % (d, desc, quoted_flags) return 0
def main(raw_args): parser = argparse.ArgumentParser() def add_common_arguments(parser): logging_common.AddLoggingArguments(parser) script_common.AddEnvironmentArguments(parser) parser.add_argument('--avd-config', type=os.path.realpath, metavar='PATH', required=True, help='Path to an AVD config text protobuf.') subparsers = parser.add_subparsers() install_parser = subparsers.add_parser( 'install', help='Install the CIPD packages specified in the given config.') add_common_arguments(install_parser) def install_cmd(args): AvdConfig(args.avd_config).Install() return 0 install_parser.set_defaults(func=install_cmd) create_parser = subparsers.add_parser( 'create', help='Create an AVD CIPD package according to the given config.') add_common_arguments(create_parser) create_parser.add_argument( '--snapshot', action='store_true', help='Snapshot the AVD before creating the CIPD package.') create_parser.add_argument('--force', action='store_true', help='Pass --force to AVD creation.') create_parser.add_argument( '--keep', action='store_true', help='Keep the AVD after creating the CIPD package.') create_parser.add_argument( '--cipd-json-output', type=os.path.realpath, metavar='PATH', help='Path to which `cipd create` should dump json output ' 'via -json-output.') def create_cmd(args): AvdConfig(args.avd_config).Create( force=args.force, snapshot=args.snapshot, keep=args.keep, cipd_json_output=args.cipd_json_output) return 0 create_parser.set_defaults(func=create_cmd) # TODO(jbudorick): Expose `start` as a subcommand. args = parser.parse_args(raw_args) logging_common.InitializeLogging(args) devil_chromium.Initialize(adb_path=args.adb_path) return args.func(args)
def main(): parser = argparse.ArgumentParser() parser.add_argument( '--arch', choices=list(set(_SUPPORTED_ARCH_DICT.values())), default=None, type=str, help=('Architecture to for CTS tests. Will auto-determine based on ' 'the device ro.product.cpu.abi property.')) parser.add_argument('--platform', choices=['L', 'M', 'N', 'O'], required=False, default=None, help='Android platform version for CTS tests. ' 'Will auto-determine based on SDK level by default.') parser.add_argument( '--skip-expected-failures', action='store_true', help= "Option to skip all tests that are expected to fail. Can't be used " "with test filters.") parser.add_argument('--apk-dir', help='Directory to extract CTS APKs to. ' 'Will use temp directory by default.') parser.add_argument( '--test-launcher-summary-output', '--json-results-file', '--write-full-results-to', '--isolated-script-test-output', dest='json_results_file', type=os.path.realpath, help='If set, will dump results in JSON form to the specified file. ' 'Note that this will also trigger saving per-test logcats to ' 'logdog.') parser.add_argument('-m', '--module-apk', dest='module_apk', help='CTS module apk name in ' + _WEBVIEW_CTS_GCS_PATH_FILE + ' file, without the path prefix.') test_filter.AddFilterOptions(parser) script_common.AddDeviceArguments(parser) logging_common.AddLoggingArguments(parser) args, test_runner_args = parser.parse_known_args() logging_common.InitializeLogging(args) devil_chromium.Initialize() devices = script_common.GetDevices(args.devices, args.blacklist_file) device = devices[0] if len(devices) > 1: logging.warning( 'Only single device supported, using 1st of %d devices: %s', len(devices), device.serial) test_runner_args.extend(['-d', device.serial]) if args.platform is None: args.platform = DeterminePlatform(device) if args.platform is None: raise Exception('Could not auto-determine device platform, ' 'please specifiy --platform') arch = args.arch if args.arch else DetermineArch(device) if (args.test_filter_file or args.test_filter or args.isolated_script_test_filter): if args.skip_expected_failures: # TODO(aluo): allow both options to be used together so that expected # failures in the filtered test set can be skipped raise Exception( '--skip-expected-failures and test filters are mutually' ' exclusive') # TODO(aluo): auto-determine the module based on the test filter and the # available tests in each module if not args.module_apk: args.module_apk = 'CtsWebkitTestCases.apk' platform_modules = GetCTSModuleNames(arch, args.platform) if args.module_apk and args.module_apk not in platform_modules: raise Exception('--module-apk for arch==' + arch + 'and platform==' + args.platform + ' must be one of: ' + ', '.join(platform_modules)) return RunAllCTSTests(args, arch, test_runner_args)
def main(args): TEST_CASES.update({ p.product_name(): p for p in [ChromeFinchTestCase, WebViewFinchTestCase, WebLayerFinchTestCase] }) parser = argparse.ArgumentParser(prog='run_finch_smoke_tests_android.py') parser.add_argument( '--test-case', choices=TEST_CASES.keys(), # TODO(rmhasan): Remove default values after # adding arguments to test suites. Also make # this argument required. default='webview', help='Name of test case') parser.add_argument('--finch-seed-path', default=TEST_SEED_PATH, type=os.path.realpath, help='Path to the finch seed') parser.add_argument('--browser-apk', '--webview-shell-apk', '--weblayer-shell-apk', help='Path to the browser apk', type=os.path.realpath, required=True) parser.add_argument('--webview-provider-apk', type=os.path.realpath, help='Path to the WebView provider apk') parser.add_argument('--browser-activity-name', action='store', help='Browser activity name') parser.add_argument('--write-full-results-to', '--isolated-script-test-output', action='store', type=os.path.realpath, default=os.path.join(os.getcwd(), 'output.json'), help='Path to output directory') add_emulator_args(parser) script_common.AddDeviceArguments(parser) script_common.AddEnvironmentArguments(parser) logging_common.AddLoggingArguments(parser) options, _ = parser.parse_known_args(args) devil_chromium.Initialize(adb_path=options.adb_path) logging_common.InitializeLogging(options) with get_device(options) as device, \ TEST_CASES[options.test_case](device, options) as test_case, \ test_case.install_apks(): device.EnableRoot() log_mon = logcat_monitor.LogcatMonitor( device.adb, output_file=os.path.join( os.path.dirname(options.write_full_results_to), '%s_finch_smoke_tests_logcat.txt' % test_case.product_name()), filter_specs=_LOGCAT_FILTERS) log_mon.Start() device.RunShellCommand( ['pm', 'clear', get_package_name(options.browser_apk)], check_return=True) tests_pass = False with_seed_res = TestResult.Fail without_seed_res = TestResult.Fail if test_case.run_tests('without finch seed') != 0: test_case.install_seed() tests_pass = test_case.run_tests('with finch seed') without_seed_res = TestResult.Pass if tests_pass: with_seed_res = TestResult.Pass log_mon.Stop() json_results = get_json_results(with_seed_res, without_seed_res) with open(options.write_full_results_to, 'w') as json_out: json_out.write(json.dumps(json_results, indent=4)) # Return zero exit code if tests pass return not tests_pass