def __init__(self, adb, *port_pairs): self._adb = adb.Adb() self._host_port = port_pairs[0].local_port new_port_pairs = [(port_pair.local_port, port_pair.remote_port) for port_pair in port_pairs] self._port_pairs = new_port_pairs if HasForwarder('Release'): constants.SetBuildType('Release') elif HasForwarder('Debug'): constants.SetBuildType('Debug') else: raise Exception('Build forwarder2') forwarder.Forwarder.Map(new_port_pairs, self._adb)
def main(argv): parser = optparse.OptionParser() parser.set_usage("usage: %prog [options] target") AddInstallAPKOption(parser) options, args = parser.parse_args(argv) if len(args) > 1 and options.apk: parser.error("Appending the apk as argument can't be used with --apk.") elif len(args) > 2: parser.error("Too many arguments.") constants.SetBuildType(options.build_type) ValidateInstallAPKOption(parser, options, args) 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] if not devices: raise Exception('Error: no connected devices') device_utils.DeviceUtils.parallel(devices).Install( options.apk, reinstall=options.keep_data)
def main(argv): logging.basicConfig(level=logging.INFO) parser = optparse.OptionParser() parser.add_option('--skip-wipe', action='store_true', default=False, help="Don't wipe device data during provisioning.") parser.add_option('--disable-location', action='store_true', default=False, help="Disallow Google location services on devices.") parser.add_option('-d', '--device', help='The serial number of the device to be provisioned') parser.add_option('-t', '--target', default='Debug', help='The build target') parser.add_option( '-r', '--auto-reconnect', action='store_true', help='Push binary which will reboot the device on adb disconnections.') options, args = parser.parse_args(argv[1:]) constants.SetBuildType(options.target) if args: print >> sys.stderr, 'Unused args %s' % args return 1 ProvisionDevices(options)
def Install(self, apk_path): """Installs specified package if necessary. Args: apk_path: Path to .apk file to install. """ if (os.path.exists(os.path.join( constants.GetOutDirectory('Release'), 'md5sum_bin_host'))): constants.SetBuildType('Release') elif (os.path.exists(os.path.join( constants.GetOutDirectory('Debug'), 'md5sum_bin_host'))): constants.SetBuildType('Debug') apk_package_name = apk_helper.GetPackageName(apk_path) return self._adb.ManagedInstall(apk_path, package_name=apk_package_name)
def ProcessCommonOptions(args): """Processes and handles all common options.""" run_tests_helper.SetLogLevel(args.verbose_count) constants.SetBuildType(args.build_type) if args.build_directory: constants.SetBuildDirectory(args.build_directory) if args.output_directory: constants.SetOutputDirectory(args.output_directory) devil_custom_deps = None if args.adb_path: devil_custom_deps = { 'adb': { devil_env.GetPlatform(): [args.adb_path] } } devil_chromium.Initialize( output_directory=constants.GetOutDirectory(), custom_deps=devil_custom_deps) # Some things such as Forwarder require ADB to be in the environment path. adb_dir = os.path.dirname(constants.GetAdbPath()) if adb_dir and adb_dir not in os.environ['PATH'].split(os.pathsep): os.environ['PATH'] = adb_dir + os.pathsep + os.environ['PATH']
def main(args): args = build_utils.ExpandFileArgs(args) parser = optparse.OptionParser() parser.add_option('--apk', help='Path to the apk.') parser.add_option('--script-host-path', help='Path on the host for the symlink script.') parser.add_option( '--script-device-path', help='Path on the device to push the created symlink script.') parser.add_option('--libraries', help='List of native libraries.') parser.add_option( '--target-dir', help='Device directory that contains the target libraries for symlinks.' ) parser.add_option('--stamp', help='Path to touch on success.') parser.add_option('--build-device-configuration', help='Path to build device configuration.') parser.add_option('--configuration-name', help='The build CONFIGURATION_NAME') options, _ = parser.parse_args(args) required_options = [ 'apk', 'libraries', 'script_host_path', 'script_device_path', 'target_dir', 'configuration_name' ] build_utils.CheckOptions(options, parser, required=required_options) constants.SetBuildType(options.configuration_name) CreateSymlinkScript(options) TriggerSymlinkScript(options) if options.stamp: build_utils.Touch(options.stamp)
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(argv): parser = optparse.OptionParser() parser.set_usage("usage: %prog [options] target") AddInstallAPKOption(parser) options, args = parser.parse_args(argv) if len(args) > 1 and options.apk: parser.error("Appending the apk as argument can't be used with --apk.") elif len(args) > 2: parser.error("Too many arguments.") constants.SetBuildType(options.build_type) ValidateInstallAPKOption(parser, options, args) devices = device_utils.DeviceUtils.HealthyDevices() if options.device: devices = [d for d in devices if d == options.device] if not devices: raise device_errors.DeviceUnreachableError(options.device) elif not devices: raise device_errors.NoDevicesError() device_utils.DeviceUtils.parallel(devices).Install( options.apk, reinstall=options.keep_data)
def main(argv): custom_handler = logging.StreamHandler(sys.stdout) custom_handler.setFormatter(run_tests_helper.CustomFormatter()) logging.getLogger().addHandler(custom_handler) logging.getLogger().setLevel(logging.INFO) parser = optparse.OptionParser() parser.add_option('--skip-wipe', action='store_true', default=False, help="Don't wipe device data during provisioning.") parser.add_option('--disable-location', action='store_true', default=False, help="Disallow Google location services on devices.") parser.add_option('-d', '--device', help='The serial number of the device to be provisioned') parser.add_option('-t', '--target', default='Debug', help='The build target') parser.add_option( '-r', '--auto-reconnect', action='store_true', help='Push binary which will reboot the device on adb disconnections.') options, args = parser.parse_args(argv[1:]) constants.SetBuildType(options.target) if args: print >> sys.stderr, 'Unused args %s' % args return 1 return ProvisionDevices(options)
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(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): logging.basicConfig(level=logging.INFO) parser = optparse.OptionParser() parser.add_option('-w', '--wipe', action='store_true', help='Wipe device data from all attached devices.') parser.add_option('-d', '--device', help='The serial number of the device to be provisioned') parser.add_option('-t', '--target', default='Debug', help='The build target') parser.add_option( '-r', '--auto-reconnect', action='store_true', help='Push binary which will reboot the device on adb disconnections.') options, args = parser.parse_args(argv[1:]) constants.SetBuildType(options.target) if args: print >> sys.stderr, 'Unused args %s' % args return 1 if options.wipe: devices = android_commands.GetAttachedDevices() for device_serial in devices: device = device_utils.DeviceUtils(device_serial) WipeDeviceData(device) device_utils.RebootDevices() else: ProvisionDevices(options)
def main(argv): parser = optparse.OptionParser() AddInstallAPKOption(parser) options, args = parser.parse_args(argv) constants.SetBuildType(options.build_type) ValidateInstallAPKOption(parser, options) if len(args) > 1: raise Exception('Error: Unknown argument:', args[1:]) retry_times = 5 retry_interval = 15 while retry_times > 0: devices = android_commands.GetAttachedDevices() if not devices: print 'No connected devices found, '\ 'kill adb server and retry in %d seconds...' % retry_interval android_commands.AndroidCommands().KillAdbServer() time.sleep(retry_interval) retry_interval *= 2 retry_times -= 1 else: break if not devices: raise Exception('Error: no connected devices') if not options.apk_package: options.apk_package = apk_helper.GetPackageName(options.apk) pool = multiprocessing.Pool(len(devices)) # Send a tuple (apk_path, apk_package, device) per device. pool.map(_InstallApk, zip([options.apk] * len(devices), [options.apk_package] * len(devices), [options.keep_data] * len(devices), devices))
def _SetupPrebuiltTools(device): """Some of the android pylib scripts we depend on are lame and expect binaries to be in the out/ directory. So we copy any prebuilt binaries there as a prereq.""" # TODO(bulach): Build the targets for x86/mips. device_tools = [ 'file_poller', 'forwarder_dist/device_forwarder', 'md5sum_dist/md5sum_bin', 'purge_ashmem', 'run_pie', ] host_tools = [ 'bitmaptools', 'md5sum_bin_host', ] platform_name = platform.GetHostPlatform().GetOSName() if platform_name == 'linux': host_tools.append('host_forwarder') arch_name = device.product_cpu_abi has_device_prebuilt = (arch_name.startswith('armeabi') or arch_name.startswith('arm64')) if not has_device_prebuilt: logging.warning('Unknown architecture type: %s' % arch_name) return all([binary_manager.LocalPath(t, platform_name, arch_name) for t in device_tools]) build_type = None for t in device_tools + host_tools: executable = os.path.basename(t) locally_built_path = binary_manager.LocalPath( t, platform_name, arch_name) if not build_type: build_type = _GetBuildTypeOfPath(locally_built_path) or 'Release' constants.SetBuildType(build_type) dest = os.path.join(constants.GetOutDirectory(), t) if not locally_built_path: logging.info('Setting up prebuilt %s', dest) if not os.path.exists(os.path.dirname(dest)): os.makedirs(os.path.dirname(dest)) platform_name = ('android' if t in device_tools else platform.GetHostPlatform().GetOSName()) bin_arch_name = (arch_name if t in device_tools else platform.GetHostPlatform().GetArchName()) prebuilt_path = binary_manager.FetchPath( executable, bin_arch_name, platform_name) if not prebuilt_path or not os.path.exists(prebuilt_path): raise NotImplementedError(""" %s must be checked into cloud storage. Instructions: http://www.chromium.org/developers/telemetry/upload_to_cloud_storage """ % t) shutil.copyfile(prebuilt_path, dest) os.chmod(dest, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) return True
def Install(self, apk_path): """Installs specified package if necessary. Args: apk_path: Path to .apk file to install. """ if (os.path.exists( os.path.join(constants.GetOutDirectory('Release'), 'md5sum_bin_host'))): constants.SetBuildType('Release') elif (os.path.exists( os.path.join(constants.GetOutDirectory('Debug'), 'md5sum_bin_host'))): constants.SetBuildType('Debug') self._device.Install(apk_path)
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 setUp(self): devices = adb_wrapper.AdbWrapper.Devices() assert devices, 'A device must be attached' self.adb = devices[0] self.adb.WaitForDevice() self.device = device_utils.DeviceUtils( self.adb, default_timeout=10, default_retries=0) default_build_type = os.environ.get('BUILDTYPE', 'Debug') constants.SetBuildType(default_build_type)
def main(): parser = optparse.OptionParser() parser.add_option('--output-format', default='html', help='The output format of the results file.') parser.add_option( '--output-dir', default=None, help='The directory for the output file. Default value is ' 'the base directory of this script.') options, _ = parser.parse_args() constants.SetBuildType(perf_test_utils.BUILD_TYPE) # Install APK device = GetDevice() device.EnableRoot() device.Install(perf_test_utils.APP_APK) # Start USB reverse tethering. android_rndis_forwarder.AndroidRndisForwarder( device, perf_test_utils.GetAndroidRndisConfig(device)) # Start HTTP server. http_server_doc_root = perf_test_utils.GenerateHttpTestResources() config_file = tempfile.NamedTemporaryFile() http_server = lighttpd_server.LighttpdServer( http_server_doc_root, port=perf_test_utils.HTTP_PORT, base_config_path=config_file.name) perf_test_utils.GenerateLighttpdConfig(config_file, http_server_doc_root, http_server) assert http_server.StartupHttpServer() config_file.close() # Start QUIC server. quic_server_doc_root = perf_test_utils.GenerateQuicTestResources(device) quic_server = perf_test_utils.QuicServer(quic_server_doc_root) quic_server.StartupQuicServer(device) # Launch Telemetry's benchmark_runner on CronetPerfTestBenchmark. # By specifying this file's directory as the benchmark directory, it will # allow benchmark_runner to in turn open this file up and find the # CronetPerfTestBenchmark class to run the benchmark. top_level_dir = os.path.dirname(os.path.realpath(__file__)) expectations_file = os.path.join(top_level_dir, 'expectations.config') runner_config = chromium_config.ChromiumConfig( top_level_dir=top_level_dir, benchmark_dirs=[top_level_dir], expectations_file=expectations_file) sys.argv.insert(1, 'run') sys.argv.insert(2, 'run.CronetPerfTestBenchmark') sys.argv.insert(3, '--browser=android-system-chrome') sys.argv.insert(4, '--output-format=' + options.output_format) if options.output_dir: sys.argv.insert(5, '--output-dir=' + options.output_dir) benchmark_runner.main(runner_config) # Shutdown. quic_server.ShutdownQuicServer() shutil.rmtree(quic_server_doc_root) http_server.ShutdownHttpServer() shutil.rmtree(http_server_doc_root)
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( '--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') options, _ = parser.parse_args() device = build_device.GetBuildDeviceFromPath( options.build_device_configuration) if not device: return constants.SetBuildType(options.configuration_name) 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(): # TODO: Filter splits using split-select. active_splits = options.split_apk_path if active_splits: device.adb.InstallMultiple([options.apk_path] + active_splits, reinstall=True) 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 ProcessCommonOptions(args): """Processes and handles all common options.""" run_tests_helper.SetLogLevel(args.verbose_count, add_handler=False) handler = logging_utils.ColorStreamHandler() handler.setFormatter(run_tests_helper.CustomFormatter()) logging.getLogger().addHandler(handler) constants.SetBuildType(args.build_type) if args.output_directory: constants.SetOutputDirectory(args.output_directory)
def main(): constants.SetBuildType(BUILD_TYPE) # Install APK device = GetDevice() device.EnableRoot() device.Install(APP_APK) # Start USB reverse tethering. # Port map is ignored for tethering; must create one to placate assertions. named_port_pair_map = { 'http': (forwarders.PortPair(0, 0)), 'https': None, 'dns': None } port_pairs = forwarders.PortPairs(**named_port_pair_map) forwarder = GetForwarderFactory(device).Create(port_pairs) # Start HTTP server. http_server_doc_root = GenerateHttpTestResources() config_file = tempfile.NamedTemporaryFile() http_server = lighttpd_server.LighttpdServer( http_server_doc_root, port=HTTP_PORT, base_config_path=config_file.name) GenerateLighttpdConfig(config_file, http_server_doc_root, http_server) assert http_server.StartupHttpServer() config_file.close() # Start QUIC server. quic_server_doc_root = GenerateQuicTestResources(device) quic_server = QuicServer(quic_server_doc_root) quic_server.StartupQuicServer(device) # Launch Telemetry's benchmark_runner on CronetPerfTestBenchmark. # By specifying this file's directory as the benchmark directory, it will # allow benchmark_runner to in turn open this file up and find the # CronetPerfTestBenchmark class to run the benchmark. top_level_dir = os.path.dirname(os.path.realpath(__file__)) # The perf config file is required to continue using dependencies on the # Chromium checkout in Telemetry. perf_config_file = os.path.join(REPOSITORY_ROOT, 'tools', 'perf', 'core', 'binary_dependencies.json') with open(perf_config_file, "w") as config_file: config_file.write('{"config_type": "BaseConfig"}') runner_config = benchmark_runner.ProjectConfig( top_level_dir=top_level_dir, benchmark_dirs=[top_level_dir], client_config=perf_config_file, default_chrome_root=REPOSITORY_ROOT) sys.argv.insert(1, 'run') sys.argv.insert(2, 'run.CronetPerfTestBenchmark') sys.argv.insert(3, '--android-rndis') benchmark_runner.main(runner_config) # Shutdown. quic_server.ShutdownQuicServer() shutil.rmtree(quic_server_doc_root) http_server.ShutdownHttpServer() shutil.rmtree(http_server_doc_root)
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): parser = GetHostStepsOptParser() options, args = parser.parse_args(argv[1:]) if args: return sys.exit('Unused args %s' % args) setattr(options, 'target', options.factory_properties.get('target', 'Debug')) setattr(options, 'extra_src', options.factory_properties.get('extra_src', '')) constants.SetBuildType(options.target) if options.steps: bb_utils.RunSteps(options.steps.split(','), GetHostStepCmds(), options)
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 Setup(test_options): """Create and return the test runner factory and tests. Args: test_options: A PerformanceOptions object. Returns: A tuple of (TestRunnerFactory, tests). """ # TODO(bulach): remove this once the bot side lands. BUG=318369 constants.SetBuildType('Release') if os.path.exists(constants.PERF_OUTPUT_DIR): shutil.rmtree(constants.PERF_OUTPUT_DIR) os.makedirs(constants.PERF_OUTPUT_DIR) # Before running the tests, kill any leftover server. test_environment.CleanupLeftoverProcesses() forwarder.Forwarder.UseMultiprocessing() if test_options.single_step: # Running a single command, build the tests structure. tests = [['single_step', test_options.single_step]] if test_options.steps: with file(test_options.steps, 'r') as f: tests = json.load(f) # The list is necessary to keep the steps order, but internally # the format is squashed from a list of lists into a single dict: # [["A", "cmd"], ["B", "cmd"]] into {"A": "cmd", "B": "cmd"} sorted_test_names = [i[0] for i in tests] tests_dict = dict(tests) if test_options.test_filter: sorted_test_names = fnmatch.filter(sorted_test_names, test_options.test_filter) tests_dict = dict((k, v) for k, v in tests_dict.iteritems() if k in sorted_test_names) flaky_steps = [] if test_options.flaky_steps: with file(test_options.flaky_steps, 'r') as f: flaky_steps = json.load(f) def TestRunnerFactory(device, shard_index): return test_runner.TestRunner(test_options, device, tests_dict, flaky_steps) return (TestRunnerFactory, sorted_test_names)
def ProcessCommonOptions(args): """Processes and handles all common options.""" run_tests_helper.SetLogLevel(args.verbose_count, add_handler=False) # pylint: disable=redefined-variable-type if args.verbose_count > 0: handler = logging_utils.ColorStreamHandler() else: handler = logging.StreamHandler(sys.stdout) # pylint: enable=redefined-variable-type handler.setFormatter(run_tests_helper.CustomFormatter()) logging.getLogger().addHandler(handler) constants.SetBuildType(args.build_type) if args.output_directory: constants.SetOutputDirectory(args.output_directory)
def main(argv): parser = optparse.OptionParser() parser.add_option('-d', '--device', help='The serial number of the device to be provisioned') parser.add_option('-t', '--target', default='Debug', help='The build target') parser.add_option( '-r', '--auto-reconnect', action='store_true', help='Push binary which will reboot the device on adb disconnections.') options, args = parser.parse_args(argv[1:]) constants.SetBuildType(options.target) if args: print >> sys.stderr, 'Unused args %s' % args return 1 ProvisionDevices(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('--blacklist-file', help='Device blacklist JSON file.') parser.add_option('--debug', action='store_const', const='Debug', dest='build_type', default='Release', help='Use Debug build of host tools instead of Release.') options, args = parser.parse_args(argv) run_tests_helper.SetLogLevel(options.verbose_count) devil_chromium.Initialize() if len(args) < 2 or not len(args) % 2: parser.error('Need even number of port pairs') sys.exit(1) try: port_pairs = [int(a) for a in args[1:]] port_pairs = zip(port_pairs[::2], port_pairs[1::2]) except ValueError: parser.error('Bad port number') sys.exit(1) blacklist = (device_blacklist.Blacklist(options.blacklist_file) if options.blacklist_file else None) device = device_utils.DeviceUtils.HealthyDevices( blacklist=blacklist, device_arg=options.device)[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 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(): constants.SetBuildType(BUILD_TYPE) # Install APK device = GetDevice() device.EnableRoot() device.Install(APP_APK) # Start USB reverse tethering. # Port map is ignored for tethering; must create one to placate assertions. named_port_pair_map = { 'http': (forwarders.PortPair(0, 0)), 'https': None, 'dns': None } port_pairs = forwarders.PortPairs(**named_port_pair_map) forwarder = GetForwarderFactory(device).Create(port_pairs) # Start HTTP server. http_server_doc_root = GenerateHttpTestResources() config_file = tempfile.NamedTemporaryFile() http_server = lighttpd_server.LighttpdServer( http_server_doc_root, port=HTTP_PORT, base_config_path=config_file.name) GenerateLighttpdConfig(config_file, http_server_doc_root, http_server) assert http_server.StartupHttpServer() config_file.close() # Start QUIC server. quic_server_doc_root = GenerateQuicTestResources(device) quic_server = QuicServer(quic_server_doc_root) quic_server.StartupQuicServer(device) # Launch Telemetry's benchmark_runner on CronetPerfTestBenchmark. # By specifying this file's directory as the benchmark directory, it will # allow benchmark_runner to in turn open this file up and find the # CronetPerfTestBenchmark class to run the benchmark. top_level_dir = os.path.dirname(os.path.realpath(__file__)) runner_config = benchmark_runner.ProjectConfig( top_level_dir=top_level_dir, benchmark_dirs=[top_level_dir]) sys.argv.insert(1, 'run') sys.argv.insert(2, 'run.CronetPerfTestBenchmark') sys.argv.insert(3, '--android-rndis') benchmark_runner.main(runner_config) # Shutdown. quic_server.ShutdownQuicServer() shutil.rmtree(quic_server_doc_root) http_server.ShutdownHttpServer() shutil.rmtree(http_server_doc_root)