Exemplo n.º 1
0
def main():
    parser = argparse.ArgumentParser()
    AddArguments(parser)
    args = parser.parse_args()

    run_tests_helper.SetLogLevel(args.verbose)

    devil_dynamic_config = devil_env.EmptyConfig()

    if args.adb_path:
        devil_dynamic_config['dependencies'].update(
            devil_env.LocalConfigItem('adb', devil_env.GetPlatform(),
                                      args.adb_path))
    devil_env.config.Initialize(configs=[devil_dynamic_config])

    blacklist = (device_blacklist.Blacklist(args.blacklist_file)
                 if args.blacklist_file else None)

    expected_devices = GetExpectedDevices(args.known_devices_files)
    usb_devices = set(lsusb.get_android_devices())
    devices = [
        device_utils.DeviceUtils(s)
        for s in expected_devices.union(usb_devices)
    ]

    statuses = DeviceStatus(devices, blacklist)

    # Log the state of all devices.
    _LogStatuses(statuses)

    # Update the last devices file(s).
    if args.overwrite_known_devices_files:
        for path in args.known_devices_files:
            device_list.WritePersistentDeviceList(
                path, [status['serial'] for status in statuses])

    # Write device info to file for buildbot info display.
    _WriteBuildbotFile(args.buildbot_path, statuses)

    # Dump the device statuses to JSON.
    if args.json_output:
        with open(args.json_output, 'wb') as f:
            f.write(
                json.dumps(statuses,
                           indent=4,
                           sort_keys=True,
                           separators=(',', ': ')))

    live_devices = [
        status['serial'] for status in statuses
        if (status['adb_status'] == 'device'
            and not IsBlacklisted(status['serial'], blacklist))
    ]

    # If all devices failed, or if there are no devices, it's an infra error.
    if not live_devices:
        logger.error('No available devices.')
    return 0 if live_devices else exit_codes.INFRA
Exemplo n.º 2
0
def main():
    parser = argparse.ArgumentParser()
    logging_common.AddLoggingArguments(parser)
    script_common.AddEnvironmentArguments(parser)
    AddArguments(parser)
    args = parser.parse_args()

    logging_common.InitializeLogging(args)
    script_common.InitializeEnvironment(args)

    denylist = (device_denylist.Denylist(args.denylist_file)
                if args.denylist_file else None)

    expected_devices = GetExpectedDevices(args.known_devices_files)
    usb_devices = set(lsusb.get_android_devices())
    devices = [
        device_utils.DeviceUtils(s)
        for s in expected_devices.union(usb_devices)
    ]

    statuses = DeviceStatus(devices, denylist)

    # Log the state of all devices.
    _LogStatuses(statuses)

    # Update the last devices file(s).
    if args.overwrite_known_devices_files:
        for path in args.known_devices_files:
            device_list.WritePersistentDeviceList(
                path, [status['serial'] for status in statuses])

    # Write device info to file for buildbot info display.
    _WriteBuildbotFile(args.buildbot_path, statuses)

    # Dump the device statuses to JSON.
    if args.json_output:
        with open(args.json_output, 'wb') as f:
            f.write(
                json.dumps(statuses,
                           indent=4,
                           sort_keys=True,
                           separators=(',', ': ')))

    live_devices = [
        status['serial'] for status in statuses
        if (status['adb_status'] == 'device'
            and not IsDenylisted(status['serial'], denylist))
    ]

    # If all devices failed, or if there are no devices, it's an infra error.
    if not live_devices:
        logger.error('No available devices.')
    return 0 if live_devices else exit_codes.INFRA
Exemplo n.º 3
0
def main():
    parser = argparse.ArgumentParser()
    AddArguments(parser)
    args = parser.parse_args()

    run_tests_helper.SetLogLevel(args.verbose)

    devil_custom_deps = None
    if args.adb_path:
        devil_custom_deps = {
            'adb': {
                devil_env.GetPlatform(): [args.adb_path],
            },
        }
    devil_env.config.Initialize(configs=devil_custom_deps)

    blacklist = (device_blacklist.Blacklist(args.blacklist_file)
                 if args.blacklist_file else None)

    expected_devices = GetExpectedDevices(args.known_devices_files)
    usb_devices = set(lsusb.get_android_devices())
    devices = [
        device_utils.DeviceUtils(s)
        for s in expected_devices.union(usb_devices)
    ]

    statuses = DeviceStatus(devices, blacklist)

    # Log the state of all devices.
    _LogStatuses(statuses)

    # Update the last devices file(s).
    if args.overwrite_known_devices_files:
        for path in args.known_devices_files:
            device_list.WritePersistentDeviceList(
                path, [status['serial'] for status in statuses])

    # Write device info to file for buildbot info display.
    _WriteBuildbotFile(args.buildbot_path, statuses)

    # Dump the device statuses to JSON.
    if args.json_output:
        with open(args.json_output, 'wb') as f:
            f.write(json.dumps(statuses, indent=4))

    live_devices = [
        status['serial'] for status in statuses
        if (status['adb_status'] == 'device'
            and not IsBlacklisted(status['serial'], blacklist))
    ]

    # If all devices failed, or if there are no devices, it's an infra error.
    return 0 if live_devices else exit_codes.INFRA
Exemplo n.º 4
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--out-dir',
                        help='Directory where the device path is stored',
                        default=os.path.join(host_paths.DIR_SOURCE_ROOT,
                                             'out'))
    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('--adb-path',
                        type=os.path.abspath,
                        help='Absolute path to the adb binary to use.')
    parser.add_argument('--blacklist-file', help='Device blacklist JSON file.')
    parser.add_argument('--known-devices-file',
                        action='append',
                        default=[],
                        dest='known_devices_files',
                        help='Path to known device lists.')
    parser.add_argument('-v',
                        '--verbose',
                        action='count',
                        default=1,
                        help='Log more information.')

    args = parser.parse_args()

    run_tests_helper.SetLogLevel(args.verbose)

    devil_chromium.Initialize(adb_path=args.adb_path)

    blacklist = (device_blacklist.Blacklist(args.blacklist_file)
                 if args.blacklist_file else None)

    expected_devices = set()
    try:
        for path in args.known_devices_files:
            if os.path.exists(path):
                expected_devices.update(
                    device_list.GetPersistentDeviceList(path))
    except IOError:
        logging.warning('Problem reading %s, skipping.', path)

    logging.info('Expected devices:')
    for device in expected_devices:
        logging.info('  %s', device)

    usb_devices = set(lsusb.get_android_devices())
    devices = [
        device_utils.DeviceUtils(s)
        for s in expected_devices.union(usb_devices)
    ]

    RecoverDevices(devices, blacklist)
    statuses = DeviceStatus(devices, blacklist)

    # Log the state of all devices.
    for status in statuses:
        logging.info(status['serial'])
        adb_status = status.get('adb_status')
        blacklisted = status.get('blacklisted')
        logging.info('  USB status: %s',
                     'online' if status.get('usb_status') else 'offline')
        logging.info('  ADB status: %s', adb_status)
        logging.info('  Blacklisted: %s', str(blacklisted))
        if adb_status == 'device' and not blacklisted:
            logging.info('  Device type: %s', status.get('ro.build.product'))
            logging.info('  OS build: %s', status.get('ro.build.id'))
            logging.info('  OS build fingerprint: %s',
                         status.get('ro.build.fingerprint'))
            logging.info('  Battery state:')
            for k, v in status.get('battery', {}).iteritems():
                logging.info('    %s: %s', k, v)
            logging.info('  IMEI slice: %s', status.get('imei_slice'))
            logging.info('  WiFi IP: %s', status.get('wifi_ip'))

    # Update the last devices file(s).
    for path in args.known_devices_files:
        device_list.WritePersistentDeviceList(
            path, [status['serial'] for status in statuses])

    # 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 status in statuses:
                try:
                    if status['adb_status'] == 'device':
                        f.write(
                            '{serial} {adb_status} {build_product} {build_id} '
                            '{temperature:.1f}C {level}%\n'.format(
                                serial=status['serial'],
                                adb_status=status['adb_status'],
                                build_product=status['type'],
                                build_id=status['build'],
                                temperature=float(
                                    status['battery']['temperature']) / 10,
                                level=status['battery']['level']))
                    elif status.get('usb_status', False):
                        f.write('{serial} {adb_status}\n'.format(
                            serial=status['serial'],
                            adb_status=status['adb_status']))
                    else:
                        f.write('{serial} offline\n'.format(
                            serial=status['serial']))
                except Exception:  # pylint: disable=broad-except
                    pass

    # Dump the device statuses to JSON.
    if args.json_output:
        with open(args.json_output, 'wb') as f:
            f.write(json.dumps(statuses, indent=4))

    live_devices = [
        status['serial'] for status in statuses
        if (status['adb_status'] == 'device'
            and not _IsBlacklisted(status['serial'], blacklist))
    ]

    # If all devices failed, or if there are no devices, it's an infra error.
    if not live_devices:
        logging.error('No available devices.')
    return 0 if live_devices else exit_codes.INFRA
Exemplo n.º 5
0
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('--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)

  blacklist = (device_blacklist.Blacklist(args.blacklist_file)
               if args.blacklist_file
               else None)

  last_devices_path = os.path.join(
      args.out_dir, device_list.LAST_DEVICES_FILENAME)
  try:
    expected_devices = set(
        device_list.GetPersistentDeviceList(last_devices_path))
  except IOError:
    expected_devices = set()

  usb_devices = set(lsusb.get_android_devices())
  devices = [device_utils.DeviceUtils(s)
             for s in expected_devices.union(usb_devices)]

  RecoverDevices(devices, blacklist)
  statuses = DeviceStatus(devices, blacklist)

  # Log the state of all devices.
  for status in statuses:
    logging.info(status['serial'])
    adb_status = status.get('adb_status')
    blacklisted = status.get('blacklisted')
    logging.info('  USB status: %s',
                 'online' if status.get('usb_status') else 'offline')
    logging.info('  ADB status: %s', adb_status)
    logging.info('  Blacklisted: %s', str(blacklisted))
    if adb_status == 'device' and not blacklisted:
      logging.info('  Device type: %s', status.get('ro.build.product'))
      logging.info('  OS build: %s', status.get('ro.build.id'))
      logging.info('  OS build fingerprint: %s',
                   status.get('ro.build.fingerprint'))
      logging.info('  Battery state:')
      for k, v in status.get('battery', {}).iteritems():
        logging.info('    %s: %s', k, v)
      logging.info('  IMEI slice: %s', status.get('imei_slice'))
      logging.info('  WiFi IP: %s', status.get('wifi_ip'))

  # Update the last devices file.
  device_list.WritePersistentDeviceList(
      last_devices_path,
      [status['serial'] for status in statuses])

  # 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 status in statuses:
        try:
          if status['adb_status'] == 'device':
            f.write('{serial} {adb_status} {build_product} {build_id} '
                    '{temperature:.1f}C {level}%\n'.format(
                serial=status['serial'],
                adb_status=status['adb_status'],
                build_product=status['type'],
                build_id=status['build'],
                temperature=float(status['battery']['temperature']) / 10,
                level=status['battery']['level']
            ))
          else:
            f.write('{serial} {adb_status}'.format(
                serial=status['serial'],
                adb_status=status['adb_status']
            ))
        except Exception: # pylint: disable=broad-except
          pass

  # Dump the device statuses to JSON.
  if args.json_output:
    with open(args.json_output, 'wb') as f:
      f.write(json.dumps(statuses, indent=4))

  live_devices = [status['serial'] for status in statuses
                  if (status['adb_status'] == 'device'
                      and not _IsBlacklisted(status['serial'], blacklist))]

  # If all devices failed, or if there are no devices, it's an infra error.
  return 0 if live_devices else constants.INFRA_EXIT_CODE
Exemplo n.º 6
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--json-output',
                        help='Output JSON information into a specified file.')
    parser.add_argument('--adb-path',
                        help='Absolute path to the adb binary to use.')
    parser.add_argument('--blacklist-file', help='Device blacklist JSON file.')
    parser.add_argument('--known-devices-file',
                        action='append',
                        default=[],
                        dest='known_devices_files',
                        help='Path to known device lists.')
    parser.add_argument('--buildbot-path',
                        '-b',
                        default='/home/chrome-bot/.adb_device_info',
                        help='Absolute path to buildbot file location')
    parser.add_argument('-v',
                        '--verbose',
                        action='count',
                        default=1,
                        help='Log more information.')
    parser.add_argument('-w',
                        '--overwrite-known-devices-files',
                        action='store_true',
                        help='If set, overwrites known devices files wiht new '
                        'values.')

    args = parser.parse_args()

    run_tests_helper.SetLogLevel(args.verbose)

    devil_custom_deps = None
    if args.adb_path:
        devil_custom_deps = {
            'adb': {
                devil_env.GetPlatform(): [args.adb_path],
            },
        }
    devil_env.config.Initialize(configs=devil_custom_deps)

    blacklist = (device_blacklist.Blacklist(args.blacklist_file)
                 if args.blacklist_file else None)

    expected_devices = GetExpectedDevices(args.known_devices_files)
    usb_devices = set(lsusb.get_android_devices())
    devices = [
        device_utils.DeviceUtils(s)
        for s in expected_devices.union(usb_devices)
    ]

    statuses = DeviceStatus(devices, blacklist)

    # Log the state of all devices.
    _LogStatuses(statuses)

    # Update the last devices file(s).
    if args.overwrite_known_devices_files:
        for path in args.known_devices_files:
            device_list.WritePersistentDeviceList(
                path, [status['serial'] for status in statuses])

    # Write device info to file for buildbot info display.
    _WriteBuildbotFile(args.buildbot_path, statuses)

    # Dump the device statuses to JSON.
    if args.json_output:
        with open(args.json_output, 'wb') as f:
            f.write(json.dumps(statuses, indent=4))

    live_devices = [
        status['serial'] for status in statuses
        if (status['adb_status'] == 'device'
            and not IsBlacklisted(status['serial'], blacklist))
    ]

    # If all devices failed, or if there are no devices, it's an infra error.
    return 0 if live_devices else exit_codes.INFRA
               else None)

  expected_devices = GetExpectedDevices(args.known_devices_files)
  usb_devices = set(lsusb.get_android_devices())
  devices = [device_utils.DeviceUtils(s)
             for s in expected_devices.union(usb_devices)]

  statuses = DeviceStatus(devices, blacklist)

  # Log the state of all devices.
  _LogStatuses(statuses)

  # Update the last devices file(s).
  if args.overwrite_known_devices_files:
    for path in args.known_devices_files:
      device_list.WritePersistentDeviceList(
          path, [status['serial'] for status in statuses])

  # Write presentation.device info to file for buildbot info display.
  _WriteBuildbotFile(args.buildbot_path, statuses)

  # Dump the presentation.device statuses to JSON.
  if args.json_output:
    with open(args.json_output, 'wb') as f:
      f.write(json.dumps(
          statuses, indent=4, sort_keys=True, separators=(',', ': ')))

  live_devices = [status['serial'] for status in statuses
                  if (status['adb_status'] == 'presentation.device'
                      and not IsBlacklisted(status['serial'], blacklist))]

  # If all devices failed, or if there are no devices, it's an infra error.