def main(): parser = _CreateOptionParser() options, _ = parser.parse_args() devil_chromium.Initialize() devices = device_utils.DeviceUtils.HealthyDevices() device = devices[0] if len(devices) != 1 and options.device is None: logging.error( 'Several devices attached, must specify one with --device.') sys.exit(0) if options.device is not None: matching_devices = [d for d in devices if str(d) == options.device] if not matching_devices: logging.error('Device not found.') sys.exit(0) device = matching_devices[0] config = { 'url': options.url, 'skip_launcher_activity': options.skip_launcher_activity, 'speculated_url': options.speculated_url or options.url, 'parallel_url': options.parallel_url, 'warmup': options.warmup, 'speculation_mode': options.speculation_mode, 'delay_to_may_launch_url': options.delay_to_may_launch_url, 'delay_to_launch_url': options.delay_to_launch_url, 'cold': options.cold, } LoopOnDevice(device, [config], options.output_file, once=options.once)
def main(): devil_chromium.Initialize() usage = '%(prog)s --product={' + ','.join(PRODUCTS) + '} ...' product_parser = argparse.ArgumentParser(add_help=False, prog='run_android_wpt.py', usage=usage) product_parser.add_argument('--product', action='store', required=True, choices=PRODUCTS) add_emulator_args(product_parser) args, _ = product_parser.parse_known_args() product = args.product with get_device(args) as device: if not device: logger.error( 'There are no devices attached to this host. Exiting...') return adapter = _get_adapter(product, device) if adapter.options.verbose: if adapter.options.verbose == 1: logger.setLevel(logging.INFO) else: logger.setLevel(logging.DEBUG) # WPT setup for chrome and webview requires that PATH contains adb. platform_tools_path = os.path.dirname( devil_env.config.FetchPath('adb')) os.environ['PATH'] = ':'.join([platform_tools_path] + os.environ['PATH'].split(':')) return adapter.run_test()
def main(): parser = _CreateOptionParser() options, _ = parser.parse_args() devil_chromium.Initialize() devices = device_utils.DeviceUtils.HealthyDevices() device = devices[0] if len(devices) != 1 and options.device is None: logging.error( 'Several devices attached, must specify one with --device.') sys.exit(0) if options.device is not None: matching_devices = [d for d in devices if str(d) == options.device] if len(matching_devices) == 0: logging.error('Device not found.') sys.exit(0) device = matching_devices[0] with SetupWpr(device, options.wpr_archive, options.record, options.network_condition, options.wpr_log) as wpr_attributes: chrome_args = (_CHROME_ARGS + ['--prerender=' + options.prerender_mode] + wpr_attributes.chrome_args) with device_setup.FlagReplacer(device, '/data/local/tmp/chrome-command-line', chrome_args): LoopOnDevice(device, options.url, options.warmup, options.prerender_mode, options.delay_to_may_launch_url, options.delay_to_launch_url, options.cold, options.output_file, options.once)
def main(): adapter = WPTAndroidAdapter() adapter.parse_args() if adapter.options.verbose: if adapter.options.verbose == 1: logger.setLevel(logging.INFO) else: logger.setLevel(logging.DEBUG) devil_chromium.Initialize() # Only 1 device is supported for Android locally, this will work well with # sharding support via swarming infra. device = device_utils.DeviceUtils.HealthyDevices()[0] # WPT setup for chrome and webview requires that PATH contains adb. platform_tools_path = os.path.dirname(devil_env.config.FetchPath('adb')) os.environ['PATH'] = ':'.join([platform_tools_path] + os.environ['PATH'].split(':')) if adapter.options.product == 'android_weblayer': run_android_weblayer(device, adapter) elif adapter.options.product == 'android_webview': run_android_webview(device, adapter) elif adapter.options.product == 'chrome_android': run_chrome_android(device, adapter)
def main(argv): parser = argparse.ArgumentParser( usage='Usage: %(prog)s [options] device_port ' 'host_port [device_port_2 host_port_2] ...', description=__doc__) parser.add_argument( '-v', '--verbose', dest='verbose_count', default=0, action='count', help='Verbose level (multiple times for more)') parser.add_argument( '--device', help='Serial number of device we should use.') parser.add_argument( '--blacklist-file', help='Device blacklist JSON file.') parser.add_argument( '--debug', action='store_const', const='Debug', dest='build_type', default='Release', help='DEPRECATED: use --output-directory instead.') parser.add_argument( '--output-directory', help='Path to the root build directory.') parser.add_argument( 'ports', nargs='+', type=int, help='Port pair to reverse forward.') args = parser.parse_args(argv) run_tests_helper.SetLogLevel(args.verbose_count) if len(args.ports) < 2 or len(args.ports) % 2: parser.error('Need even number of port pairs') port_pairs = zip(args.ports[::2], args.ports[1::2]) if args.build_type: constants.SetBuildType(args.build_type) if args.output_directory: constants.SetOutputDirectory(args.output_directory) devil_chromium.Initialize(output_directory=constants.GetOutDirectory()) blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) device = device_utils.DeviceUtils.HealthyDevices( blacklist=blacklist, device_arg=args.device)[0] try: forwarder.Forwarder.Map(port_pairs, device) while True: time.sleep(60) except KeyboardInterrupt: sys.exit(0) finally: forwarder.Forwarder.UnmapAllDevicePorts(device)
def main(): parser = argparse.ArgumentParser() parser.add_argument('filename') args = parser.parse_args() devil_chromium.Initialize() if os.path.splitext(args.filename)[1] in ('.zip', '.apk', '.jar'): sizes, total_size = ExtractSizesFromZip(args.filename) else: single_set_of_sizes, total_size = _ExtractSizesFromDexFile( args.filename) sizes = {"": single_set_of_sizes} file_basename = os.path.basename(args.filename) for classes_dex_file, classes_dex_sizes in sizes.iteritems(): for dex_header_name, readable_name in CONTRIBUTORS_TO_DEX_CACHE.iteritems( ): if dex_header_name in classes_dex_sizes: perf_tests_results_helper.PrintPerfResult( '%s_%s_%s' % (file_basename, classes_dex_file, readable_name), 'total', [classes_dex_sizes[dex_header_name]], readable_name) perf_tests_results_helper.PrintPerfResult( '%s_DexCache_size' % (file_basename), 'total', [total_size], 'bytes of permanent dirty memory') return 0
def __init__(self, device=None): assert os.path.exists(ANDROID_DIR) sys.path.insert(0, ANDROID_DIR) # We import the dependencies only on demand, so that this file can be # imported unconditionally. import devil_chromium from devil.android import device_errors # pylint: disable=import-error from devil.android import device_utils # pylint: disable=import-error from devil.android.perf import cache_control # pylint: disable=import-error from devil.android.perf import perf_control # pylint: disable=import-error from devil.android.sdk import adb_wrapper # pylint: disable=import-error global cache_control global device_errors global perf_control devil_chromium.Initialize() if not device: # Detect attached device if not specified. devices = adb_wrapper.AdbWrapper.Devices() assert devices, 'No devices detected' assert len(devices) == 1, 'Multiple devices detected.' device = str(devices[0]) self.adb_wrapper = adb_wrapper.AdbWrapper(device) self.device = device_utils.DeviceUtils(self.adb_wrapper) # This remembers what we have already pushed to the device. self.pushed = set()
def main(): parser = CreateArgumentParser() args = parser.parse_args() devil_chromium.Initialize(output_directory=args.output_directory, adb_path=args.adb_path) apk = apk_helper.ApkHelper(args.apk_path) package_info = None for p in constants.PACKAGE_INFO.itervalues(): if p.package == apk.GetPackageName(): package_info = p break else: raise Exception('Unable to determine package info for %s' % args.apk_path) trace_directory = args.trace_directory if not trace_directory: trace_directory = os.path.join(args.output_directory, 'profile_data') profiler = AndroidProfileTool(args.output_directory, host_profile_dir=trace_directory, use_wpr=not args.no_wpr, urls=args.urls, simulate_user=args.simulate_user) profiler.CollectProfile(args.apk_path, package_info) return 0
def main(): parser = _CreateOptionParser() options, args = parser.parse_args() if len(args) != 1: parser.error("Incorrect number of arguments.") devil_chromium.Initialize() devices = device_utils.DeviceUtils.HealthyDevices() device = devices[0] if len(devices) != 1 and options.device is None: logging.error( 'Several devices attached, must specify one with --device.') sys.exit(0) if options.device is not None: matching_devices = [d for d in devices if str(d) == options.device] if not matching_devices: logging.error('Device not found.') sys.exit(0) device = matching_devices[0] with device_setup.RemoteWprHost(device, args[0], options.record, options.network_condition, out_log_path=options.wpr_log) as wpr_attr: RunChrome(device, options.cold, chrome_setup.CHROME_ARGS + wpr_attr.chrome_args, chrome.PACKAGE_INFO[options.chrome_package_name])
def main(): parser = argparse.ArgumentParser() parser.add_argument('--blacklist-file', help='Device blacklist JSON file.') set_asserts_group = parser.add_mutually_exclusive_group(required=True) set_asserts_group.add_argument( '--enable_asserts', dest='set_asserts', action='store_true', help='Sets the dalvik.vm.enableassertions property to "all"') set_asserts_group.add_argument( '--disable_asserts', dest='set_asserts', action='store_false', help='Removes the dalvik.vm.enableassertions property') args = parser.parse_args() devil_chromium.Initialize() blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) # TODO(jbudorick): Accept optional serial number and run only for the # specified device when present. devices = device_utils.DeviceUtils.parallel( device_utils.DeviceUtils.HealthyDevices(blacklist)) def set_java_asserts_and_restart(device): if device.SetJavaAsserts(args.set_asserts): device.RunShellCommand(['stop'], check_return=True) device.RunShellCommand(['start'], check_return=True) devices.pMap(set_java_asserts_and_restart) return 0
def main(): parser = argparse.ArgumentParser() parser.add_argument( '--arch', choices=['arm_64'], default='arm_64', help='Arch for CTS tests.') parser.add_argument( '--platform', choices=['L', 'M', 'N'], required=True, help='Android platform version for CTS tests.') parser.add_argument( '--skip-expected-failures', action='store_true', help='Option to skip all tests that are expected to fail.') parser.add_argument( '--apk-dir', help='Directory to load/save CTS APKs. Will try to load CTS APK ' 'from this directory before downloading from Google Storage ' 'and will then cache APK here.') args, test_runner_args = parser.parse_known_args() devil_chromium.Initialize() return DownloadAndRunCTS(args, test_runner_args)
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 __init__(self, args, _error_func): super(LocalDeviceEnvironment, self).__init__() self._blacklist = (device_blacklist.Blacklist(args.blacklist_file) if args.blacklist_file else None) self._device_serials = args.test_devices self._devices_lock = threading.Lock() self._devices = None self._concurrent_adb = args.enable_concurrent_adb self._enable_device_cache = args.enable_device_cache self._logcat_monitors = [] self._logcat_output_dir = args.logcat_output_dir self._logcat_output_file = args.logcat_output_file self._max_tries = 1 + args.num_retries self._skip_clear_data = args.skip_clear_data self._target_devices_file = args.target_devices_file self._tool_name = args.tool self._trace_output = None if hasattr(args, 'trace_output'): self._trace_output = args.trace_output devil_chromium.Initialize(output_directory=constants.GetOutDirectory(), adb_path=args.adb_path) # Some things such as Forwarder require ADB to be in the environment path. adb_dir = os.path.dirname(adb_wrapper.AdbWrapper.GetAdbPath()) if adb_dir and adb_dir not in os.environ['PATH'].split(os.pathsep): os.environ['PATH'] = adb_dir + os.pathsep + os.environ['PATH']
def main(): parser = argparse.ArgumentParser() parser.add_argument( '--apk-name', help='Name of the APK to which the dexfile corresponds.') parser.add_argument('dexfile') args = parser.parse_args() devil_chromium.Initialize() if not args.apk_name: dirname, basename = os.path.split(args.dexfile) while basename: if 'apk' in basename: args.apk_name = basename break dirname, basename = os.path.split(dirname) else: parser.error( 'Unable to determine apk name from %s, ' 'and --apk-name was not provided.' % args.dexfile) method_count = MethodCount(args.dexfile) perf_tests_results_helper.PrintPerfResult( '%s_methods' % args.apk_name, 'total', [method_count], 'methods') return 0
def CreateOrderfile(options, orderfile_updater_class=None): """Creates an orderfile. Args: options: As returned from optparse.OptionParser.parse_args() orderfile_updater_class: (OrderfileUpdater) subclass of OrderfileUpdater. Use to explicitly set an OrderfileUpdater class, the defaults are OrderfileUpdater, or OrderfileNoopUpdater if --public is set. Returns: True iff success. """ logging.basicConfig(level=logging.INFO) devil_chromium.Initialize(adb_path=options.adb_path) generator = OrderfileGenerator(options, orderfile_updater_class) try: if options.verify: generator._VerifySymbolOrder() elif options.commit_hashes: return generator.CommitStashedOrderfileHashes() elif options.upload_ready_orderfiles: return generator.UploadReadyOrderfiles() else: return generator.Generate() finally: json_output = json.dumps(generator.GetReportingData(), indent=2) + '\n' if options.json_file: with open(options.json_file, 'w') as f: f.write(json_output) print(json_output) return False
def main(): devil_chromium.Initialize() devices = device_utils.DeviceUtils.HealthyDevices() if not devices: logger.error( 'There are no devices attached to this host. Exiting script.') return 1 # Only 1 device is supported for Android locally, this will work well with # sharding support via swarming infra. device = devices[0] adapter = _get_adapter(device) if adapter.options.verbose: if adapter.options.verbose == 1: logger.setLevel(logging.INFO) else: logger.setLevel(logging.DEBUG) # WPT setup for chrome and webview requires that PATH contains adb. platform_tools_path = os.path.dirname(devil_env.config.FetchPath('adb')) os.environ['PATH'] = ':'.join([platform_tools_path] + os.environ['PATH'].split(':')) return adapter.run_test()
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) devil_chromium.Initialize() GenerateCoverageReport(args.lines_for_coverage_file, args.out, args.emma_dir)
def main(): adapter = WPTAndroidAdapter() adapter.parse_args() if adapter.options.verbose: if adapter.options.verbose == 1: logger.setLevel(logging.INFO) else: logger.setLevel(logging.DEBUG) devil_chromium.Initialize() # Only 1 device is supported for Android locally, this will work well with # sharding support via swarming infra. device = device_utils.DeviceUtils.HealthyDevices()[0] flags_file = FLAGS_FILE_MAP[adapter.options.product] all_flags = HOST_RESOLVER_ARGS + adapter.pass_through_binary_args if adapter.options.product == 'android_weblayer': all_flags += DISABLE_POPUP_ARGS logger.info('Setting flags in ' + flags_file + ' to: ' + str(all_flags)) flags = flag_changer.CustomCommandLineFlags(device, flags_file, all_flags) # WPT setup for chrome and webview requires that PATH contains adb. platform_tools_path = os.path.dirname(devil_env.config.FetchPath('adb')) os.environ['PATH'] = ':'.join([platform_tools_path] + os.environ['PATH'].split(':')) with flags: if adapter.options.product == 'android_weblayer': run_android_weblayer(device, adapter) elif adapter.options.product == 'android_webview': run_android_webview(device, adapter) elif adapter.options.product == 'chrome_android': run_chrome_android(device, adapter)
def CreateOrderfile(options, orderfile_updater_class): """Creates an oderfile. Args: options: As returned from optparse.OptionParser.parse_args() orderfile_updater_class: (OrderfileUpdater) subclass of OrderfileUpdater. Returns: True iff success. """ logging.basicConfig(level=logging.INFO) devil_chromium.Initialize(adb_path=options.adb_path) generator = OrderfileGenerator(options, orderfile_updater_class) try: if options.verify: generator._VerifySymbolOrder() elif options.upload_ready_orderfiles: return generator.UploadReadyOrderfiles() else: return generator.Generate() finally: json_output = json.dumps(generator.GetReportingData(), indent=2) + '\n' if options.json_file: with open(options.json_file, 'w') as f: f.write(json_output) print json_output return False
def main(): logging.basicConfig(level=logging.INFO) devil_chromium.Initialize() parser = _CreateArgumentParser() args = parser.parse_args() OPTIONS.SetParsedArgs(args) if os.path.exists(args.output_filename): logging.error('Output file %s already exists.' % args.output_filename) sys.exit(1) device = prefetch_predictor_common.FindDevice(args.device) if device is None: logging.error('Could not find device: %s.', args.device) sys.exit(1) delays = [int(x) for x in args.prefetch_delays_ms.split(',')] with open(args.output_filename, 'w') as f: f.write(','.join(customtabs_benchmark.RESULT_FIELDS) + '\n') while True: delay = delays[random.randint(0, len(delays) - 1)] _RunOnce(device, args.database, args.url, delay, args.output_filename, args.wpr_archive, args.network_condition) if args.once: return
def main(): parser = argparse.ArgumentParser() parser.add_argument('--render-results-dir', required=True, help='Path on device to look for render test images') parser.add_argument('--output-html-file', required=True, help='File to output the results webpage.') parser.add_argument('-d', '--device', dest='devices', action='append', default=[], help='Device to look for render test results on. ' 'Default is to look on all connected devices.') parser.add_argument('--adb-path', type=os.path.abspath, help='Absolute path to the adb binary to use.') parser.add_argument('--buildername', type=str, required=True, help='Bot buildername. Used to generate path to upload ' 'render test results') parser.add_argument('--build-number', type=str, required=True, help='Bot build number. Used to generate path to upload ' 'render test results') args = parser.parse_args() devil_chromium.Initialize(adb_path=args.adb_path) devices = device_utils.DeviceUtils.HealthyDevices(device_arg=args.devices) upload_dir = os.path.join(args.buildername, args.build_number) ProcessRenderTestResults( devices, args.render_results_dir, upload_dir, args.output_html_file)
def main(argv): parser = GetDeviceStepsOptParser() options, args = parser.parse_args(argv[1:]) devil_chromium.Initialize() if args: return sys.exit('Unused args %s' % args) unknown_tests = set(options.test_filter) - VALID_TESTS if unknown_tests: return sys.exit('Unknown tests %s' % list(unknown_tests)) setattr(options, 'target', options.factory_properties.get('target', 'Debug')) # pylint: disable=global-statement if options.chrome_output_dir: global CHROME_OUT_DIR global LOGCAT_DIR CHROME_OUT_DIR = options.chrome_output_dir LOGCAT_DIR = os.path.join(CHROME_OUT_DIR, 'logcat') if options.coverage_bucket: setattr(options, 'coverage_dir', os.path.join(CHROME_OUT_DIR, options.target, 'coverage')) return MainTestWrapper(options)
def main(): parser = argparse.ArgumentParser() parser.add_argument('--arch', choices=['arm64'], default='arm64', help='Arch for CTS tests.') parser.add_argument('--platform', choices=['L', 'M', 'N'], required=True, help='Android platform version for CTS tests.') parser.add_argument( '--skip-expected-failures', action='store_true', help='Option to skip all tests that are expected to fail.') parser.add_argument( '--apk-dir', help='Directory to load/save CTS APKs. Will try to load CTS APK ' 'from this directory before downloading from Google Storage ' 'and will then cache APK here.') parser.add_argument( '--test-launcher-summary-output', '--json-results-file', 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.') args, test_runner_args = parser.parse_known_args() devil_chromium.Initialize() return DownloadAndRunCTS(args, test_runner_args)
def main(): parser = optparse.OptionParser() parser.add_option('--apk-path', help='Path to .apk to install.') parser.add_option( '--split-apk-path', help='Path to .apk splits (can specify multiple times, causes ' '--install-multiple to be used.', action='append') parser.add_option('--android-sdk-tools', help='Path to the Android SDK build tools folder. ' + 'Required when using --split-apk-path.') parser.add_option( '--install-record', help='Path to install record (touched only when APK is installed).') parser.add_option('--build-device-configuration', help='Path to build device configuration.') parser.add_option('--stamp', help='Path to touch on success.') parser.add_option('--configuration-name', help='The build CONFIGURATION_NAME') parser.add_option('--output-directory', help='The output directory.') options, _ = parser.parse_args() constants.SetBuildType(options.configuration_name) devil_chromium.Initialize( output_directory=os.path.abspath(options.output_directory)) device = build_device.GetBuildDeviceFromPath( options.build_device_configuration) if not device: return serial_number = device.GetSerialNumber() apk_package = apk_helper.GetPackageName(options.apk_path) metadata_path = '%s.%s.device.time.stamp' % (options.apk_path, serial_number) # If the APK on the device does not match the one that was last installed by # the build, then the APK has to be installed (regardless of the md5 record). force_install = HasInstallMetadataChanged(device, apk_package, metadata_path) def Install(): if options.split_apk_path: device.InstallSplitApk(options.apk_path, options.split_apk_path) else: device.Install(options.apk_path, reinstall=True) RecordInstallMetadata(device, apk_package, metadata_path) build_utils.Touch(options.install_record) record_path = '%s.%s.md5.stamp' % (options.apk_path, serial_number) md5_check.CallAndRecordIfStale(Install, record_path=record_path, input_paths=[options.apk_path], force=force_install) if options.stamp: build_utils.Touch(options.stamp)
def main(raw_args): parser = argparse.ArgumentParser() logging_common.AddLoggingArguments(parser) parser.add_argument( '--adb', type=os.path.realpath, required=True, help='Path to adb binary.') parser.add_argument( '--device', help='Device serial.') parser.add_argument( '--lib', type=os.path.realpath, required=True, help='Path to asan library.') parser.add_argument( 'command', nargs='*', help='Command to run with ASAN installed.') args = parser.parse_args() # TODO(crbug.com/790202): Remove this after diagnosing issues # with android-asan. if not args.quiet: args.verbose += 1 logging_common.InitializeLogging(args) devil_chromium.Initialize(adb_path=args.adb) with Asan(args): if args.command: return subprocess.call(args.command) return 0
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.') 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(): logging.basicConfig(level=logging.WARNING) OPTIONS.AddGlobalArgument( 'clear_cache', True, 'clear browser cache before loading') OPTIONS.AddGlobalArgument( 'emulate_device', '', 'Name of the device to emulate. Must be present ' 'in --devices_file, or empty for no emulation.') OPTIONS.AddGlobalArgument('emulate_network', '', 'Type of network emulation. Empty for no emulation.') OPTIONS.AddGlobalArgument( 'local', False, 'run against local desktop chrome rather than device ' '(see also --local_binary and local_profile_dir)') OPTIONS.AddGlobalArgument( 'noads', False, 'ignore ad resources in modeling') OPTIONS.AddGlobalArgument( 'ad_rules', '', 'AdBlocker+ ad rules file.') OPTIONS.AddGlobalArgument( 'tracking_rules', '', 'AdBlocker+ tracking rules file.') OPTIONS.AddGlobalArgument( 'prefetch_delay_seconds', 5, 'delay after requesting load of prefetch page ' '(only when running full fetch)') OPTIONS.AddGlobalArgument( 'headless', False, 'Do not display Chrome UI (only works in local mode).') parser = argparse.ArgumentParser(description='Analyzes loading') parser.add_argument('command', help=' '.join(COMMAND_MAP.keys())) parser.add_argument('rest', nargs=argparse.REMAINDER) args = parser.parse_args() devil_chromium.Initialize() COMMAND_MAP.get(args.command, lambda _: InvalidCommand(args.command))(args.rest)
def __init__(self, args, output_manager, _error_func): super(LocalDeviceEnvironment, self).__init__(output_manager) self._current_try = 0 self._denylist = (device_denylist.Denylist(args.denylist_file) if args.denylist_file else None) self._device_serials = args.test_devices self._devices_lock = threading.Lock() self._devices = None self._concurrent_adb = args.enable_concurrent_adb self._enable_device_cache = args.enable_device_cache self._logcat_monitors = [] self._logcat_output_dir = args.logcat_output_dir self._logcat_output_file = args.logcat_output_file self._max_tries = 1 + args.num_retries self._preferred_abis = None self._recover_devices = args.recover_devices self._skip_clear_data = args.skip_clear_data self._tool_name = args.tool self._trace_output = None if hasattr(args, 'trace_output'): self._trace_output = args.trace_output self._trace_all = None if hasattr(args, 'trace_all'): self._trace_all = args.trace_all devil_chromium.Initialize(output_directory=constants.GetOutDirectory(), adb_path=args.adb_path) # Some things such as Forwarder require ADB to be in the environment path, # while others like Devil's bundletool.py require Java on the path. adb_dir = os.path.dirname(adb_wrapper.AdbWrapper.GetAdbPath()) if adb_dir and adb_dir not in os.environ['PATH'].split(os.pathsep): os.environ['PATH'] = os.pathsep.join( [adb_dir, host_paths.JAVA_PATH, os.environ['PATH']])
def main(): devil_chromium.Initialize() parser = argparse.ArgumentParser(description=""" List Java classes in an APK which fail ART class verification. """) parser.add_argument('--package', '-P', type=str, default=None, required=True, help='Specify the full application package name') parser.add_argument( '--mapping', '-m', type=os.path.realpath, default=None, help='Mapping file for the desired APK to deobfuscate class names') parser.add_argument( '--hide-summary', default=False, action='store_true', help='Do not output the total number of classes in each Status.') parser.add_argument( '--status', type=str, default='RetryVerificationAtRuntime', choices=STATUSES, help='Which category of classes to list at the end of the script') parser.add_argument( '--workdir', '-w', type=os.path.realpath, default=None, help=( 'Work directory for oatdump output (default = temporary ' 'directory). If specified, this will not be cleaned up at the end ' 'of the script (useful if you want to inspect oatdump output ' 'manually)')) script_common.AddEnvironmentArguments(parser) script_common.AddDeviceArguments(parser) logging_common.AddLoggingArguments(parser) args = parser.parse_args() script_common.InitializeEnvironment(args) logging_common.InitializeLogging(args) if args.workdir: if not os.path.isdir(args.workdir): raise RuntimeError('Specified working directory does not exist') RealMain(args.mapping, args.devices, args.package, args.status, args.hide_summary, args.workdir) # Assume the user wants the workdir to persist (useful for debugging). logging.warn('Not cleaning up explicitly-specified workdir: %s', args.workdir) else: with tempfile_ext.NamedTemporaryDirectory() as workdir: RealMain(args.mapping, args.devices, args.package, args.status, args.hide_summary, workdir)
def main(): argparser = argparse.ArgumentParser(description='Print APK size metrics.') argparser.add_argument('--min-pak-resource-size', type=int, default=20*1024, help='Minimum byte size of displayed pak resources.') argparser.add_argument('--chromium-output-directory', help='Location of the build artifacts.') argparser.add_argument('--chartjson', action='store_true', help='Sets output mode to chartjson.') argparser.add_argument('--output-dir', default='.', help='Directory to save chartjson to.') argparser.add_argument('--no-output-dir', action='store_true', help='Skip all measurements that rely on having ' 'output-dir') argparser.add_argument('--dump-static-initializers', action='store_true', help='Run dump-static-initializers.py to get the list' 'of static initializers (slow).') argparser.add_argument('-d', '--device', help='Dummy option for perf runner.') argparser.add_argument('--estimate-patch-size', action='store_true', help='Include patch size estimates. Useful for perf ' 'builders where a reference APK is available but adds ' '~3 mins to run time.') argparser.add_argument('--reference-apk-builder', default=apk_downloader.DEFAULT_BUILDER, help='Builder name to use for reference APK for patch ' 'size estimates.') argparser.add_argument('--reference-apk-bucket', default=apk_downloader.DEFAULT_BUCKET, help='Storage bucket holding reference APKs.') argparser.add_argument('apk', help='APK file path.') args = argparser.parse_args() chartjson = _BASE_CHART.copy() if args.chartjson else None if args.chromium_output_directory: constants.SetOutputDirectory(args.chromium_output_directory) if not args.no_output_dir: constants.CheckOutputDirectory() devil_chromium.Initialize() build_vars = _ReadBuildVars(constants.GetOutDirectory()) tools_prefix = os.path.join(constants.GetOutDirectory(), build_vars['android_tool_prefix']) else: tools_prefix = '' PrintApkAnalysis(args.apk, tools_prefix, chartjson=chartjson) _PrintDexAnalysis(args.apk, chartjson=chartjson) if args.estimate_patch_size: _PrintPatchSizeEstimate(args.apk, args.reference_apk_builder, args.reference_apk_bucket, chartjson=chartjson) if not args.no_output_dir: PrintPakAnalysis(args.apk, args.min_pak_resource_size) _PrintStaticInitializersCountFromApk( args.apk, tools_prefix, args.dump_static_initializers, chartjson=chartjson) if chartjson: results_path = os.path.join(args.output_dir, 'results-chart.json') logging.critical('Dumping json to %s', results_path) with open(results_path, 'w') as json_file: json.dump(chartjson, json_file)