def testWaitUntilFullyBooted(self): a = self._getTestAdbWrapper() d = device_utils.DeviceUtils(a) a.Reboot() while a.GetState() == 'device': time.sleep(0.1) d.WaitUntilFullyBooted(wifi=True) self.assertEquals( '1', a.Shell('getprop sys.boot_completed').splitlines()[0]) self.assertTrue( a.Shell('pm path android').splitlines()[0].startswith('package:')) self.assertTrue(a.Shell('ls $EXTERNAL_STORAGE')) self.assertTrue( 'Wi-Fi is enabled' in a.Shell('dumpsys wifi').splitlines())
def _GetDeviceAddresses(self, excluded_iface): """Returns the IP addresses on all connected devices. Excludes interface |excluded_iface| on the selected device. """ my_device = str(self._device) addresses = [] for device_serial in android_device.GetDeviceSerials(): device = device_utils.DeviceUtils(device_serial) if device_serial == my_device: excluded = excluded_iface else: excluded = 'no interfaces excluded on other devices' addresses += [line.split()[3] for line in device.RunShellCommand('ip -o -4 addr') if excluded not in line] return addresses
def testHasRoot(self): a = self._getTestAdbWrapper() d = device_utils.DeviceUtils(a) secure_prop = a.Shell('getprop ro.secure').strip() if secure_prop == '1': build_type_prop = a.Shell('getprop ro.build.type').strip() if build_type_prop == 'userdebug': adb_root_prop = a.Shell('getprop service.adb.root').strip() if adb_root_prop is None or adb_root_prop == '0': self.assertFalse(d.HasRoot()) else: self.assertTrue(d.HasRoot()) else: self.assertFalse(d.HasRoot()) else: self.assertTrue(d.HasRoot())
def __init__(self, options): super(AndroidPlatform, self).__init__(options) LoadAndroidBuildTools(options.android_build_tools) if not options.device: # Detect attached device if not specified. devices = pylib.android_commands.GetAttachedDevices(hardware=True, emulator=False, offline=False) assert devices and len(devices) == 1, ( "None or multiple devices detected. Please specify the device on " "the command-line with --device") options.device = devices[0] adb_wrapper = pylib.android_commands.AndroidCommands(options.device) self.device = device_utils.DeviceUtils(adb_wrapper) self.adb = adb_wrapper.Adb()
def WipeDevicesIfPossible(devices): devices_to_reboot = [] for device_serial in devices: device = device_utils.DeviceUtils(device_serial) if not device.old_interface.EnableAdbRoot(): continue WipeDeviceData(device) devices_to_reboot.append(device) if devices_to_reboot: try: device_utils.DeviceUtils.parallel(devices_to_reboot).Reboot(True) except errors.DeviceUnresponsiveError: pass for device_serial in devices_to_reboot: device.WaitUntilFullyBooted(timeout=90)
def main(): 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('--device', help='The serial number of the device. If not specified ' 'will use all devices.') parser.add_option( '-a', '--all-tombstones', action='store_true', help="""Resolve symbols for all tombstones, rather than just the most recent""") parser.add_option('-s', '--stack', action='store_true', help='Also include symbols for stack data') parser.add_option('-w', '--wipe-tombstones', action='store_true', help='Erase all tombstones from device after processing') parser.add_option('-j', '--jobs', type='int', default=4, help='Number of jobs to use when processing multiple ' 'crash stacks.') options, _ = parser.parse_args() if options.device: devices = [options.device] else: devices = android_commands.GetAttachedDevices() # This must be done serially because strptime can hit a race condition if # used for the first time in a multithreaded environment. # http://bugs.python.org/issue7980 tombstones = [] for device_serial in devices: device = device_utils.DeviceUtils(device_serial) tombstones += _GetTombstonesForDevice(device, options) _ResolveTombstones(options.jobs, tombstones)
def CleanupLeftoverProcesses(): """Clean up the test environment, restarting fresh adb and HTTP daemons.""" _KillWebServers() did_restart_host_adb = False for device_serial in android_commands.GetAttachedDevices(): device = device_utils.DeviceUtils(device_serial) # Make sure we restart the host adb server only once. if not did_restart_host_adb: device_utils.RestartServer() did_restart_host_adb = True device.old_interface.RestartAdbdOnDevice() try: device.EnableRoot() except device_errors.CommandFailedError as e: # TODO(jbudorick) Handle this exception appropriately after interface # conversions are finished. logging.error(str(e)) device.old_interface.WaitForDevicePm()
def __init__(self, device_serial, tool): """ Args: device: Tests will run on the device of this ID. tool: Name of the Valgrind tool. """ self.device_serial = device_serial self.device = device_utils.DeviceUtils(device_serial) self.tool = CreateTool(tool, self.device) self._http_server = None self._forwarder_device_port = 8000 self.forwarder_base_url = ('http://localhost:%d' % self._forwarder_device_port) # We will allocate port for test server spawner when calling method # LaunchChromeTestServerSpawner and allocate port for test server when # starting it in TestServerThread. self.test_server_spawner_port = 0 self.test_server_port = 0
def testBlockingReboot(self): a = self._getTestAdbWrapper() d = device_utils.DeviceUtils(a) old_boot_time = a.Shell('getprop ro.runtime.firstboot').strip() if old_boot_time and len(old_boot_time): d.Reboot(block=True, timeout=120) self.assertNotEquals( old_boot_time, a.Shell('getprop ro.runtime.firstboot').strip()) self.assertEquals( '1', a.Shell('getprop sys.boot_completed').splitlines()[0]) self.assertTrue( a.Shell('pm path android').splitlines()[0].startswith( 'package:')) self.assertTrue(a.Shell('ls $EXTERNAL_STORAGE')) else: self.skipTest("No 'ro.runtime.firstboot' property on %s." % str(a))
def main(argv): option_parser = optparse.OptionParser() option_parser.add_option('--enable_asserts', dest='set_asserts', action='store_true', default=None, help='Sets the dalvik.vm.enableassertions property to "all"') option_parser.add_option('--disable_asserts', dest='set_asserts', action='store_false', default=None, help='Removes the dalvik.vm.enableassertions property') options, _ = option_parser.parse_args(argv) # TODO(jbudorick): Accept optional serial number and run only for the # specified device when present. devices = android_commands.GetAttachedDevices() for device in [device_utils.DeviceUtils(serial) for serial in devices]: if options.set_asserts != None: if device.SetJavaAsserts(options.set_asserts): # TODO(jbudorick) How to best do shell restarts after the # android_commands refactor? device.RunShellCommand('stop') device.RunShellCommand('start')
def _KillAllEmulators(): """Kill all running emulators that look like ones we started. There are odd 'sticky' cases where there can be no emulator process running but a device slot is taken. A little bot trouble and we're out of room forever. """ emulators = [ device_utils.DeviceUtils(a) for a in adb_wrapper.AdbWrapper.Devices() if a.is_emulator ] if not emulators: return for e in emulators: e.adb.Emu(['kill']) logging.info( 'Emulator killing is async; give a few seconds for all to die.') for _ in range(5): if not any(a.is_emulator for a in adb_wrapper.AdbWrapper.Devices()): return time.sleep(1)
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) device = device_utils.DeviceUtils(options.device) 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 GetConfigurationForDevice(device_id): device = device_utils.DeviceUtils(device_id) configuration = None has_root = False is_online = device.old_interface.IsOnline() if is_online: cmd = 'ls -l /data/app; getprop ro.build.description' cmd_output = device.old_interface.RunShellCommand(cmd) has_root = not 'Permission denied' in cmd_output[0] if not has_root: # Disable warning log messages from EnableAdbRoot() logging.getLogger().disabled = True has_root = device.old_interface.EnableAdbRoot() logging.getLogger().disabled = False cmd_output = device.old_interface.RunShellCommand(cmd) configuration = { 'id': device_id, 'description': cmd_output[-1], 'install_metadata': cmd_output[:-1], } return configuration, is_online, has_root
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) try: (device_utils.DeviceUtils.parallel(devices).old_interface.Reboot( True).pFinish(None)) except errors.DeviceUnresponsiveError: pass else: ProvisionDevices(options)
def ProvisionDevice(device_serial, is_perf, disable_location): device = device_utils.DeviceUtils(device_serial) device.old_interface.EnableAdbRoot() _ConfigureLocalProperties(device, is_perf) device_settings_map = device_settings.DETERMINISTIC_DEVICE_SETTINGS if disable_location: device_settings_map.update(device_settings.DISABLE_LOCATION_SETTING) else: device_settings_map.update(device_settings.ENABLE_LOCATION_SETTING) device_settings.ConfigureContentSettingsDict(device, device_settings_map) device_settings.SetLockScreenSettings(device) if is_perf: # TODO(tonyg): We eventually want network on. However, currently radios # can cause perfbots to drain faster than they charge. device_settings.ConfigureContentSettingsDict( device, device_settings.NETWORK_DISABLED_SETTINGS) # 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. try: battery_info = device.old_interface.GetBatteryInfo() except Exception as e: battery_info = {} logging.error('Unable to obtain battery info for %s, %s', device_serial, e) while int(battery_info.get('level', 100)) < 95: if not device.old_interface.IsDeviceCharging(): if device.old_interface.CanControlUsbCharging(): device.old_interface.EnableUsbCharging() else: logging.error('Device is not charging') break logging.info('Waiting for device to charge. Current level=%s', battery_info.get('level', 0)) time.sleep(60) battery_info = device.old_interface.GetBatteryInfo() device.RunShellCommand('date -u %f' % time.time(), as_root=True)
def main(): parser = optparse.OptionParser() parser.add_option('--device', help='The serial number of the device. If not specified ' 'will use all devices.') parser.add_option( '-a', '--all-tombstones', action='store_true', help="""Resolve symbols for all tombstones, rather than just the most recent""") parser.add_option('-s', '--stack', action='store_true', help='Also include symbols for stack data') parser.add_option('-w', '--wipe-tombstones', action='store_true', help='Erase all tombstones from device after processing') parser.add_option('-j', '--jobs', type='int', default=4, help='Number of jobs to use when processing multiple ' 'crash stacks.') options, _ = parser.parse_args() if options.device: devices = [options.device] else: devices = android_commands.GetAttachedDevices() tombstones = [] for device_serial in devices: device = device_utils.DeviceUtils(device_serial) tombstones += _GetTombstonesForDevice(device, options) _ResolveTombstones(options.jobs, tombstones)
def main(argv): option_parser = optparse.OptionParser() option_parser.add_option( '--enable_asserts', dest='set_asserts', action='store_true', default=None, help='Sets the dalvik.vm.enableassertions property to "all"') option_parser.add_option( '--disable_asserts', dest='set_asserts', action='store_false', default=None, help='Removes the dalvik.vm.enableassertions property') options, _ = option_parser.parse_args(argv) # TODO(jbudorick): Accept optional serial number and run only for the # specified device when present. devices = android_commands.GetAttachedDevices() for device in [device_utils.DeviceUtils(serial) for serial in devices]: if options.set_asserts != None: if device.old_interface.SetJavaAssertsEnabled(options.set_asserts): device.old_interface.Reboot(full_reboot=False)
def ConfirmLaunch(self, wait_for_boot=False): """Confirm the emulator launched properly. Loop on a wait-for-device with a very small timeout. On each timeout, check the emulator process is still alive. After confirming a wait-for-device can be successful, make sure it returns the right answer. """ seconds_waited = 0 number_of_waits = 2 # Make sure we can wfd twice # TODO(jbudorick) Un-handroll this in the implementation switch. adb_cmd = "adb -s %s %s" % (self.device_serial, 'wait-for-device') while seconds_waited < self._LAUNCH_TIMEOUT: try: run_command.RunCommand(adb_cmd, timeout_time=self._WAITFORDEVICE_TIMEOUT, retry_count=1) number_of_waits -= 1 if not number_of_waits: break except errors.WaitForResponseTimedOutError: seconds_waited += self._WAITFORDEVICE_TIMEOUT adb_cmd = "adb -s %s %s" % (self.device_serial, 'kill-server') run_command.RunCommand(adb_cmd) self.popen.poll() if self.popen.returncode != None: raise EmulatorLaunchException('EMULATOR DIED') if seconds_waited >= self._LAUNCH_TIMEOUT: raise EmulatorLaunchException('TIMEOUT with wait-for-device') logging.info('Seconds waited on wait-for-device: %d', seconds_waited) if wait_for_boot: # Now that we checked for obvious problems, wait for a boot complete. # Waiting for the package manager is sometimes problematic. # TODO(jbudorick) Convert this once waiting for the package manager and # the external storage is no longer problematic. d = device_utils.DeviceUtils(self.device_serial) d.old_interface.WaitForSystemBootCompleted(self._WAITFORBOOT_TIMEOUT)
def PushAndLaunchAdbReboot(devices, target): """Pushes and launches the adb_reboot binary on the device. Arguments: devices: The list of serial numbers of the device to which the adb_reboot binary should be pushed. target : The build target (example, Debug or Release) which helps in locating the adb_reboot binary. """ for device_serial in devices: print 'Will push and launch adb_reboot on %s' % device_serial device = device_utils.DeviceUtils(device_serial) # Kill if adb_reboot is already running. device.old_interface.KillAllBlocking('adb_reboot', 2) # Push adb_reboot print ' Pushing adb_reboot ...' adb_reboot = os.path.join(constants.DIR_SOURCE_ROOT, 'out/%s/adb_reboot' % target) device.old_interface.PushIfNeeded(adb_reboot, '/data/local/tmp/') # Launch adb_reboot print ' Launching adb_reboot ...' device.old_interface.GetAndroidToolStatusAndOutput( '/data/local/tmp/adb_reboot') LaunchHostHeartbeat()
def testInitWithDeviceUtil(self): serial = '0fedcba987654321' d = device_utils.DeviceUtils(serial) b = battery_utils.BatteryUtils(d) self.assertEqual(d, b._device)
def __init__(self, configuration): self.id = configuration['id'] self.description = configuration['description'] self.install_metadata = configuration['install_metadata'] self.device = device_utils.DeviceUtils(self.id)
def main(): parser = optparse.OptionParser() parser.add_option('', '--out-dir', help='Directory where the device path is stored', default=os.path.join(constants.DIR_SOURCE_ROOT, 'out')) parser.add_option( '--no-provisioning-check', action='store_true', help='Will not check if devices are provisioned properly.') parser.add_option('--device-status-dashboard', action='store_true', help='Output device status data for dashboard.') parser.add_option('--restart-usb', action='store_true', help='Restart USB ports before running device check.') parser.add_option('--json-output', help='Output JSON information into a specified file.') parser.add_option('-v', '--verbose', action='count', default=1, help='Log more information.') options, args = parser.parse_args() if args: parser.error('Unknown options %s' % args) run_tests_helper.SetLogLevel(options.verbose) # Remove the last build's "bad devices" before checking device statuses. device_blacklist.ResetBlacklist() try: expected_devices = device_list.GetPersistentDeviceList( os.path.join(options.out_dir, device_list.LAST_DEVICES_FILENAME)) except IOError: expected_devices = [] devices = device_utils.DeviceUtils.HealthyDevices() device_serials = [d.adb.GetDeviceSerial() for d in devices] # Only restart usb if devices are missing. if set(expected_devices) != set(device_serials): logging.warning('expected_devices: %s', expected_devices) logging.warning('devices: %s', device_serials) KillAllAdb() retries = 5 usb_restarted = True if options.restart_usb: if not RestartUsb(): usb_restarted = False bb_annotations.PrintWarning() logging.error('USB reset stage failed, ' 'wait for any device to come back.') while retries: logging.info('retry adb devices...') time.sleep(1) devices = device_utils.DeviceUtils.HealthyDevices() device_serials = [d.adb.GetDeviceSerial() for d in devices] if set(expected_devices) == set(device_serials): # All devices are online, keep going. break if not usb_restarted and devices: # The USB wasn't restarted, but there's at least one device online. # No point in trying to wait for all devices. break retries -= 1 types, builds, batteries, errors, devices_ok, json_data = ([], [], [], [], [], []) if devices: types, builds, batteries, errors, devices_ok, json_data = (zip( *[DeviceInfo(dev, options) for dev in devices])) # Write device info to file for buildbot info display. if os.path.exists('/home/chrome-bot'): with open('/home/chrome-bot/.adb_device_info', 'w') as f: for device in json_data: try: f.write('%s %s %s %.1fC %s%%\n' % (device['serial'], device['type'], device['build'], float(device['battery']['temperature']) / 10, device['battery']['level'])) except Exception: pass err_msg = CheckForMissingDevices(options, devices) or [] unique_types = list(set(types)) unique_builds = list(set(builds)) bb_annotations.PrintMsg('Online devices: %d. Device types %s, builds %s' % (len(devices), unique_types, unique_builds)) for j in json_data: logging.info('Device %s (%s)', j.get('serial'), j.get('type')) logging.info(' Build: %s (%s)', j.get('build'), j.get('build_detail')) logging.info(' Current Battery Service state:') for k, v in j.get('battery', {}).iteritems(): logging.info(' %s: %s', k, v) logging.info(' IMEI slice: %s', j.get('imei_slice')) logging.info(' WiFi IP: %s', j.get('wifi_ip')) for dev, dev_errors in zip(devices, errors): if dev_errors: err_msg += ['%s errors:' % str(dev)] err_msg += [' %s' % error for error in dev_errors] if err_msg: bb_annotations.PrintWarning() for e in err_msg: logging.error(e) from_address = '*****@*****.**' to_addresses = ['*****@*****.**'] bot_name = os.environ.get('BUILDBOT_BUILDERNAME') slave_name = os.environ.get('BUILDBOT_SLAVENAME') subject = 'Device status check errors on %s, %s.' % (slave_name, bot_name) SendEmail(from_address, to_addresses, [], subject, '\n'.join(err_msg)) if options.device_status_dashboard: offline_devices = [ device_utils.DeviceUtils(a) for a in adb_wrapper.AdbWrapper.Devices(is_ready=False) if a.GetState() == 'offline' ] perf_tests_results_helper.PrintPerfResult('BotDevices', 'OnlineDevices', [len(devices)], 'devices') perf_tests_results_helper.PrintPerfResult('BotDevices', 'OfflineDevices', [len(offline_devices)], 'devices', 'unimportant') for dev, battery in zip(devices, batteries): perf_tests_results_helper.PrintPerfResult('DeviceBattery', str(dev), [battery], '%', 'unimportant') if options.json_output: with open(options.json_output, 'wb') as f: f.write(json.dumps(json_data, indent=4)) num_failed_devs = 0 for device_ok, device in zip(devices_ok, devices): if not device_ok: logging.warning('Blacklisting %s', str(device)) device_blacklist.ExtendBlacklist([str(device)]) num_failed_devs += 1 if num_failed_devs == len(devices): return 2 if not devices: return 1
def DeviceInfo(serial, options): """Gathers info on a device via various adb calls. Args: serial: The serial of the attached device to construct info about. Returns: Tuple of device type, build id, report as a string, error messages, and boolean indicating whether or not device can be used for testing. """ device_adb = device_utils.DeviceUtils(serial) device_type = device_adb.GetProp('ro.build.product') device_build = device_adb.GetProp('ro.build.id') device_build_type = device_adb.GetProp('ro.build.type') device_product_name = device_adb.GetProp('ro.product.name') try: battery_info = device_adb.old_interface.GetBatteryInfo() except Exception as e: battery_info = {} logging.error('Unable to obtain battery info for %s, %s', serial, e) def _GetData(re_expression, line, lambda_function=lambda x: x): if not line: return 'Unknown' found = re.findall(re_expression, line) if found and len(found): return lambda_function(found[0]) return 'Unknown' battery_level = int(battery_info.get('level', 100)) imei_slice = _GetData('Device ID = (\d+)', device_adb.old_interface.GetSubscriberInfo(), lambda x: x[-6:]) report = [ 'Device %s (%s)' % (serial, device_type), ' Build: %s (%s)' % (device_build, device_adb.GetProp('ro.build.fingerprint')), ' Current Battery Service state: ', '\n'.join([' %s: %s' % (k, v) for k, v in battery_info.iteritems()]), ' IMEI slice: %s' % imei_slice, ' Wifi IP: %s' % device_adb.GetProp('dhcp.wlan0.ipaddress'), '' ] errors = [] dev_good = True if battery_level < 15: errors += ['Device critically low in battery. Turning off device.'] dev_good = False if not options.no_provisioning_check: setup_wizard_disabled = ( device_adb.GetProp('ro.setupwizard.mode') == 'DISABLED') if not setup_wizard_disabled and device_build_type != 'user': errors += [ 'Setup wizard not disabled. Was it provisioned correctly?' ] if (device_product_name == 'mantaray' and battery_info.get('AC powered', None) != 'true'): errors += ['Mantaray device not connected to AC power.'] # Turn off devices with low battery. if battery_level < 15: try: device_adb.EnableRoot() except device_errors.CommandFailedError as e: # Attempt shutdown anyway. # TODO(jbudorick) Handle this exception appropriately after interface # conversions are finished. logging.error(str(e)) device_adb.old_interface.Shutdown() full_report = '\n'.join(report) return device_type, device_build, battery_level, full_report, errors, dev_good
def __init__(self, device): self._device = device_utils.DeviceUtils(device) self._device_serial = device
def main(): parser = _CreateOptionParser() options, _args = parser.parse_args() if options.trace_cc: parser.parse_error("""--trace-cc is deprecated. For basic jank busting uses, use --trace-frame-viewer For detailed study of ubercompositor, pass --trace-ubercompositor. When in doubt, just try out --trace-frame-viewer. """) if options.verbose: logging.getLogger().setLevel(logging.DEBUG) devices = android_commands.GetAttachedDevices() if len(devices) != 1: parser.error('Exactly 1 device must be attached.') device = device_utils.DeviceUtils(devices[0]) package_info = profiler.GetSupportedBrowsers()[options.browser] if options.chrome_categories in ['list', 'help']: ui.PrintMessage('Collecting record categories list...', eol='') record_categories = [] disabled_by_default_categories = [] record_categories, disabled_by_default_categories = \ chrome_controller.ChromeTracingController.GetCategories( device, package_info) ui.PrintMessage('done') ui.PrintMessage('Record Categories:') ui.PrintMessage('\n'.join('\t%s' % item \ for item in sorted(record_categories))) ui.PrintMessage('\nDisabled by Default Categories:') ui.PrintMessage('\n'.join('\t%s' % item \ for item in sorted(disabled_by_default_categories))) return 0 if options.systrace_categories in ['list', 'help']: ui.PrintMessage('\n'.join( systrace_controller.SystraceController.GetCategories(device))) return 0 if (perf_controller.PerfProfilerController.IsSupported() and options.perf_categories in ['list', 'help']): ui.PrintMessage('\n'.join( perf_controller.PerfProfilerController.GetCategories(device))) return 0 if not options.time and not options.continuous: ui.PrintMessage( 'Time interval or continuous tracing should be specified.') return 1 chrome_categories = _ComputeChromeCategories(options) systrace_categories = _ComputeSystraceCategories(options) perf_categories = _ComputePerfCategories(options) if chrome_categories and 'webview' in systrace_categories: logging.warning( 'Using the "webview" category in systrace together with ' 'Chrome tracing results in duplicate trace events.') enabled_controllers = [] if chrome_categories: enabled_controllers.append( chrome_controller.ChromeTracingController(device, package_info, chrome_categories, options.ring_buffer, options.trace_memory)) if systrace_categories: enabled_controllers.append( systrace_controller.SystraceController(device, systrace_categories, options.ring_buffer)) if perf_categories: enabled_controllers.append( perf_controller.PerfProfilerController(device, perf_categories)) if not enabled_controllers: ui.PrintMessage('No trace categories enabled.') return 1 if options.output: options.output = os.path.expanduser(options.output) result = profiler.CaptureProfile( enabled_controllers, options.time if not options.continuous else 0, output=options.output, compress=options.compress, write_json=options.json) if options.view: if sys.platform == 'darwin': os.system('/usr/bin/open %s' % os.path.abspath(result)) else: webbrowser.open(result)
def _InstallApk(args): apk_path, apk_package, keep_data, device = args device_utils.DeviceUtils(device=device).old_interface.ManagedInstall( apk_path, keep_data, apk_package) print '----- Installed on %s -----' % device
def main(argv): parser = argparse.ArgumentParser() parser.add_argument('--process', dest='procname', help="A (sub)string to match against process names.") parser.add_argument('-p', '--pid', dest='pid', type=Validator.ValidateNonNegativeNumber, help='Which pid to scan for.') parser.add_argument('-d', '--device', dest='device', help='Device serial to scan.') parser.add_argument('-t', '--timelimit', dest='timelimit', type=Validator.ValidateNonNegativeNumber, help='How long to track memory in seconds.') parser.add_argument('-f', '--frequency', dest='frequency', default=0, type=Validator.ValidateNonNegativeNumber, help='How often to poll in seconds.') parser.add_argument('-s', '--diff-against-start', dest='diff_against_start', action='store_true', help='Whether or not to always compare against the' ' original memory values for deltas.') parser.add_argument('-b', '--boring-output', dest='dull_output', action='store_true', help='Whether or not to dull down the output.') parser.add_argument('-k', '--keep-results', dest='no_overwrite', action='store_true', help='Keeps printing the results in a list instead of' ' overwriting the previous values.') parser.add_argument('-g', '--graph-file', dest='graph_file', type=Validator.ValidatePdfPath, help='PDF file to save graph of memory stats to.') parser.add_argument('-o', '--text-file', dest='text_file', type=Validator.ValidatePath, help='File to save memory tracking stats to.') parser.add_argument('-m', '--memory', dest='show_mem', action='store_true', help='Whether or not to show memory stats. True by' ' default unless --n is specified.') parser.add_argument('-n', '--net', dest='show_net', action='store_true', help='Whether or not to show network stats. False by' ' default.') args = parser.parse_args() # Add a basic filter to make sure we search for something. if not args.procname and not args.pid: args.procname = 'chrome' # Make sure we show memory stats if nothing was specifically requested. if not args.show_net and not args.show_mem: args.show_mem = True curses.setupterm() printer = OutputBeautifier(not args.dull_output, not args.no_overwrite) sys.stdout.write("Running... Hold CTRL-C to stop (or specify timeout).\n") try: last_time = time.time() adb = None old_snapshot = None snapshots = [] while not args.timelimit or Timer.GetTimestamp() < float( args.timelimit): # Check if we need to track another device device = DeviceHelper.GetDeviceToTrack(args.device) if not device: adb = None elif not adb or device != str(adb): #adb = adb_wrapper.AdbWrapper(device) adb = device_utils.DeviceUtils(device) old_snapshot = None snapshots = [] try: adb.EnableRoot() except device_errors.CommandFailedError: sys.stderr.write('Unable to run adb as root.\n') sys.exit(1) # Grab a snapshot if we have a device snapshot = None if adb: pids = DeviceHelper.GetPidsToTrack(adb, args.pid, args.procname) snapshot = None if pids: snapshot = DeviceSnapshot(adb, pids, args.show_mem, args.show_net) if snapshot and snapshot.HasResults(): snapshots.append(snapshot) printer.PrettyPrint(snapshot, old_snapshot, args.show_mem, args.show_net) # Transfer state for the next iteration and sleep delay = max(1, args.frequency) if snapshot: delay = max(0, args.frequency - (time.time() - last_time)) time.sleep(delay) last_time = time.time() if not old_snapshot or not args.diff_against_start: old_snapshot = snapshot except KeyboardInterrupt: pass if args.graph_file: printer.PrettyGraph(args.graph_file, snapshots) if args.text_file: printer.PrettyFile(args.text_file, snapshots, args.diff_against_start, args.show_mem, args.show_net)
def DeviceInfo(serial, options): """Gathers info on a device via various adb calls. Args: serial: The serial of the attached device to construct info about. Returns: Tuple of device type, build id, report as a string, error messages, and boolean indicating whether or not device can be used for testing. """ device_adb = device_utils.DeviceUtils(serial) device_type = device_adb.build_product device_build = device_adb.build_id device_build_type = device_adb.build_type device_product_name = device_adb.product_name try: battery_info = device_adb.old_interface.GetBatteryInfo() except Exception as e: battery_info = {} logging.error('Unable to obtain battery info for %s, %s', serial, e) def _GetData(re_expression, line, lambda_function=lambda x: x): if not line: return 'Unknown' found = re.findall(re_expression, line) if found and len(found): return lambda_function(found[0]) return 'Unknown' battery_level = int(battery_info.get('level', 100)) imei_slice = _GetData(r'Device ID = (\d+)', device_adb.old_interface.GetSubscriberInfo(), lambda x: x[-6:]) json_data = { 'serial': serial, 'type': device_type, 'build': device_build, 'build_detail': device_adb.GetProp('ro.build.fingerprint'), 'battery': battery_info, 'imei_slice': imei_slice, 'wifi_ip': device_adb.GetProp('dhcp.wlan0.ipaddress'), } report = ['Device %s (%s)' % (serial, device_type), ' Build: %s (%s)' % (device_build, json_data['build_detail']), ' Current Battery Service state: ', '\n'.join([' %s: %s' % (k, v) for k, v in battery_info.iteritems()]), ' IMEI slice: %s' % imei_slice, ' Wifi IP: %s' % json_data['wifi_ip'], ''] errors = [] dev_good = True if battery_level < 15: errors += ['Device critically low in battery. Will add to blacklist.'] dev_good = False if not device_adb.old_interface.IsDeviceCharging(): if device_adb.old_interface.CanControlUsbCharging(): device_adb.old_interface.EnableUsbCharging() else: logging.error('Device %s is not charging' % serial) if not options.no_provisioning_check: setup_wizard_disabled = ( device_adb.GetProp('ro.setupwizard.mode') == 'DISABLED') if not setup_wizard_disabled and device_build_type != 'user': errors += ['Setup wizard not disabled. Was it provisioned correctly?'] if (device_product_name == 'mantaray' and battery_info.get('AC powered', None) != 'true'): errors += ['Mantaray device not connected to AC power.'] full_report = '\n'.join(report) return (device_type, device_build, battery_level, full_report, errors, dev_good, json_data)
def main(): parser = argparse.ArgumentParser() parser.add_argument('--out-dir', help='Directory where the device path is stored', default=os.path.join(constants.DIR_SOURCE_ROOT, 'out')) parser.add_argument('--no-provisioning-check', action='store_true', help='Will not check if devices are provisioned ' 'properly.') parser.add_argument('--device-status-dashboard', action='store_true', help='Output device status data for dashboard.') parser.add_argument('--restart-usb', action='store_true', help='DEPRECATED. ' 'This script now always tries to reset USB.') parser.add_argument('--json-output', help='Output JSON information into a specified file.') parser.add_argument('--blacklist-file', help='Device blacklist JSON file.') parser.add_argument('-v', '--verbose', action='count', default=1, help='Log more information.') args = parser.parse_args() run_tests_helper.SetLogLevel(args.verbose) if args.blacklist_file: blacklist = device_blacklist.Blacklist(args.blacklist_file) else: # TODO(jbudorick): Remove this once bots pass the blacklist file. blacklist = device_blacklist.Blacklist(device_blacklist.BLACKLIST_JSON) devices = RecoverDevices(blacklist, args.out_dir) types, builds, batteries, errors, devices_ok, json_data = ([], [], [], [], [], []) if devices: types, builds, batteries, errors, devices_ok, json_data = (zip( *[DeviceInfo(dev, args) for dev in devices])) # Write device info to file for buildbot info display. if os.path.exists('/home/chrome-bot'): with open('/home/chrome-bot/.adb_device_info', 'w') as f: for device in json_data: try: f.write('%s %s %s %.1fC %s%%\n' % (device['serial'], device['type'], device['build'], float(device['battery']['temperature']) / 10, device['battery']['level'])) except Exception: pass err_msg = CheckForMissingDevices(args, devices) or [] unique_types = list(set(types)) unique_builds = list(set(builds)) bb_annotations.PrintMsg('Online devices: %d. Device types %s, builds %s' % (len(devices), unique_types, unique_builds)) for j in json_data: logging.info('Device %s (%s)', j.get('serial'), j.get('type')) logging.info(' Build: %s (%s)', j.get('build'), j.get('build_detail')) logging.info(' Current Battery Service state:') for k, v in j.get('battery', {}).iteritems(): logging.info(' %s: %s', k, v) logging.info(' IMEI slice: %s', j.get('imei_slice')) logging.info(' WiFi IP: %s', j.get('wifi_ip')) for dev, dev_errors in zip(devices, errors): if dev_errors: err_msg += ['%s errors:' % str(dev)] err_msg += [' %s' % error for error in dev_errors] if err_msg: bb_annotations.PrintWarning() for e in err_msg: logging.error(e) from_address = '*****@*****.**' to_addresses = ['*****@*****.**'] bot_name = os.environ.get('BUILDBOT_BUILDERNAME') slave_name = os.environ.get('BUILDBOT_SLAVENAME') subject = 'Device status check errors on %s, %s.' % (slave_name, bot_name) SendEmail(from_address, to_addresses, [], subject, '\n'.join(err_msg)) if args.device_status_dashboard: offline_devices = [ device_utils.DeviceUtils(a) for a in adb_wrapper.AdbWrapper.Devices(desired_state=None) if a.GetState() == 'offline' ] perf_tests_results_helper.PrintPerfResult('BotDevices', 'OnlineDevices', [len(devices)], 'devices') perf_tests_results_helper.PrintPerfResult('BotDevices', 'OfflineDevices', [len(offline_devices)], 'devices', 'unimportant') for dev, battery in zip(devices, batteries): perf_tests_results_helper.PrintPerfResult('DeviceBattery', str(dev), [battery], '%', 'unimportant') if args.json_output: with open(args.json_output, 'wb') as f: f.write(json.dumps(json_data, indent=4)) num_failed_devs = 0 for device_ok, device in zip(devices_ok, devices): if not device_ok: logging.warning('Blacklisting %s', str(device)) blacklist.Extend([str(device)]) num_failed_devs += 1 if num_failed_devs == len(devices): return 2 if not devices: return 1
def DeviceInfo(serial, options): """Gathers info on a device via various adb calls. Args: serial: The serial of the attached device to construct info about. Returns: Tuple of device type, build id, report as a string, error messages, and boolean indicating whether or not device can be used for testing. """ device_adb = device_utils.DeviceUtils(serial) device_type = device_adb.old_interface.GetBuildProduct() device_build = device_adb.old_interface.GetBuildId() device_build_type = device_adb.old_interface.GetBuildType() device_product_name = device_adb.old_interface.GetProductName() try: battery = device_adb.old_interface.GetBatteryInfo() except Exception as e: battery = None logging.error('Unable to obtain battery info for %s, %s', serial, e) def _GetData(re_expression, line, lambda_function=lambda x: x): if not line: return 'Unknown' found = re.findall(re_expression, line) if found and len(found): return lambda_function(found[0]) return 'Unknown' def _GetBatteryInfo(battery): if not battery: return 'No battery info.' battery_info = battery.split('\n') return battery_info[0] + '\n '.join(battery_info[1:]) ac_power = _GetData('AC powered: (\w+)', battery) battery_level = _GetData('level: (\d+)', battery) imei_slice = _GetData('Device ID = (\d+)', device_adb.old_interface.GetSubscriberInfo(), lambda x: x[-6:]) report = [ 'Device %s (%s)' % (serial, device_type), ' Build: %s (%s)' % (device_build, device_adb.old_interface.GetBuildFingerprint()), ' %s' % _GetBatteryInfo(battery), ' IMEI slice: %s' % imei_slice, ' Wifi IP: %s' % device_adb.old_interface.GetWifiIP(), '' ] errors = [] if battery_level < 15: errors += ['Device critically low in battery. Turning off device.'] if not options.no_provisioning_check: setup_wizard_disabled = ( device_adb.old_interface.GetSetupWizardStatus() == 'DISABLED') if not setup_wizard_disabled and device_build_type != 'user': errors += [ 'Setup wizard not disabled. Was it provisioned correctly?' ] if device_product_name == 'mantaray' and ac_power != 'true': errors += ['Mantaray device not connected to AC power.'] # Turn off devices with low battery. if battery_level < 15: try: device_adb.EnableRoot() except device_errors.CommandFailedError as e: # Attempt shutdown anyway. # TODO(jbudorick) Handle this exception appropriately after interface # conversions are finished. logging.error(str(e)) device_adb.old_interface.Shutdown() full_report = '\n'.join(report) return device_type, device_build, battery_level, full_report, errors, True