Example #1
0
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)
Example #2
0
def _GetAttachedDevices(blacklist_file, test_device):
    """Get all attached devices.

  Args:
    test_device: Name of a specific device to use.

  Returns:
    A list of attached devices.
  """
    if not blacklist_file:
        # TODO(jbudorick): Remove this once bots pass the blacklist file.
        blacklist_file = device_blacklist.BLACKLIST_JSON
        logging.warning('Using default device blacklist %s',
                        device_blacklist.BLACKLIST_JSON)

    blacklist = device_blacklist.Blacklist(blacklist_file)
    attached_devices = device_utils.DeviceUtils.HealthyDevices(blacklist)
    if test_device:
        test_device = [d for d in attached_devices if d == test_device]
        if not test_device:
            raise device_errors.DeviceUnreachableError(
                'Did not find device %s among attached device. Attached devices: %s'
                % (test_device, ', '.join(attached_devices)))
        return test_device

    else:
        if not attached_devices:
            raise device_errors.NoDevicesError()
        return sorted(attached_devices)
 def __init__(self, args, _error_func):
     super(LocalDeviceEnvironment, self).__init__()
     self._blacklist = device_blacklist.Blacklist(
         args.blacklist_file or device_blacklist.BLACKLIST_JSON)
     self._device_serial = args.test_device
     self._devices = []
     self._max_tries = 1 + args.num_retries
     self._tool_name = args.tool
Example #4
0
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('--blacklist-file', help='Device blacklist JSON file.')
    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.blacklist_file:
        blacklist = device_blacklist.Blacklist(options.blacklist_file)
    else:
        blacklist = None

    if options.device:
        devices = [device_utils.DeviceUtils(options.device)]
    else:
        devices = device_utils.DeviceUtils.HealthyDevices(blacklist)

    # 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 in devices:
        tombstones += _GetTombstonesForDevice(device, options)

    _ResolveTombstones(options.jobs, tombstones)
Example #5
0
def main():
  parser = argparse.ArgumentParser(
      description="Script to do semi-automated upgrade testing.")
  parser.add_argument('-v', '--verbose', action='count',
                      help='Print verbose log information.')
  parser.add_argument('--blacklist-file', help='Device blacklist JSON file.')
  command_parsers = parser.add_subparsers(dest='command')

  subparser = command_parsers.add_parser('create_app_data')
  subparser.add_argument('--old-apk', required=True,
                         help='Path to apk to update from.')
  subparser.add_argument('--app-data', required=True,
                         help='Path to where the app data backup should be '
                           'saved to.')
  subparser.add_argument('--package-name',
                         help='Chrome apk package name.')

  subparser = command_parsers.add_parser('test_update')
  subparser.add_argument('--old-apk', required=True,
                         help='Path to apk to update from.')
  subparser.add_argument('--new-apk', required=True,
                         help='Path to apk to update to.')
  subparser.add_argument('--app-data', required=True,
                         help='Path to where the app data backup is saved.')
  subparser.add_argument('--package-name',
                         help='Chrome apk package name.')

  args = parser.parse_args()
  run_tests_helper.SetLogLevel(args.verbose)

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

  devices = device_utils.DeviceUtils.HealthyDevices(blacklist)
  if not devices:
    raise device_errors.NoDevicesError()
  device = devices[0]
  logging.info('Using device %s for testing.' % str(device))

  package_name = (args.package_name if args.package_name
                  else apk_helper.GetPackageName(args.old_apk))
  if args.command == 'create_app_data':
    CreateAppData(device, args.old_apk, args.app_data, package_name)
  elif args.command == 'test_update':
    TestUpdate(
        device, args.old_apk, args.new_apk, args.app_data, package_name)
  else:
    raise Exception('Unknown test command: %s' % args.command)
Example #6
0
def ProvisionDevices(args):
    if args.blacklist_file:
        blacklist = device_blacklist.Blacklist(args.blacklist_file)
    else:
        # TODO(jbudorick): Remove once the bots have switched over.
        blacklist = device_blacklist.Blacklist(device_blacklist.BLACKLIST_JSON)

    devices = device_utils.DeviceUtils.HealthyDevices(blacklist)
    if args.device:
        devices = [d for d in devices if d == args.device]
        if not devices:
            raise device_errors.DeviceUnreachableError(args.device)

    parallel_devices = device_utils.DeviceUtils.parallel(devices)
    parallel_devices.pMap(ProvisionDevice, blacklist, args)
    if args.auto_reconnect:
        _LaunchHostHeartbeat()
    blacklisted_devices = blacklist.Read()
    if args.output_device_blacklist:
        with open(args.output_device_blacklist, 'w') as f:
            json.dump(blacklisted_devices, f)
    if all(d in blacklisted_devices for d in devices):
        raise device_errors.NoDevicesError
    return 0
Example #7
0
def main():
    parser = argparse.ArgumentParser()

    parser.add_argument('--blacklist-file', help='Device blacklist JSON file.')

    set_asserts_group = parser.add_mutually_exclusive_group(required=True)
    set_asserts_group.add_argument(
        '--enable_asserts',
        dest='set_asserts',
        action='store_true',
        help='Sets the dalvik.vm.enableassertions property to "all"')
    set_asserts_group.add_argument(
        '--disable_asserts',
        dest='set_asserts',
        action='store_false',
        help='Removes the dalvik.vm.enableassertions property')

    args = parser.parse_args()

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

    # TODO(jbudorick): Accept optional serial number and run only for the
    # specified device when present.
    devices = device_utils.DeviceUtils.parallel(
        device_utils.DeviceUtils.HealthyDevices(blacklist))

    def set_java_asserts_and_restart(device):
        if device.SetJavaAsserts(args.set_asserts):
            device.RunShellCommand('stop')
            device.RunShellCommand('start')

    devices.pMap(set_java_asserts_and_restart)
    return 0
Example #8
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('--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
Example #9
0
def main():
    # Parse options.
    parser = optparse.OptionParser(description=__doc__,
                                   usage='screenshot.py [options] [filename]')
    parser.add_option('-d',
                      '--device',
                      metavar='ANDROID_DEVICE',
                      help='Serial '
                      'number of Android device to use.',
                      default=None)
    parser.add_option('--blacklist-file', help='Device blacklist JSON file.')
    parser.add_option('-f',
                      '--file',
                      help='Save result to file instead of '
                      'generating a timestamped file name.',
                      metavar='FILE')
    parser.add_option('-v',
                      '--verbose',
                      help='Verbose logging.',
                      action='store_true')
    video_options = optparse.OptionGroup(parser, 'Video capture')
    video_options.add_option('--video',
                             help='Enable video capturing. Requires '
                             'Android KitKat or later',
                             action='store_true')
    video_options.add_option('-b',
                             '--bitrate',
                             help='Bitrate in megabits/s, '
                             'from 0.1 to 100 mbps, %default mbps by default.',
                             default=4,
                             type='float')
    video_options.add_option('-r',
                             '--rotate',
                             help='Rotate video by 90 degrees.',
                             default=False,
                             action='store_true')
    video_options.add_option('-s',
                             '--size',
                             metavar='WIDTHxHEIGHT',
                             help='Frame size to use instead of the device '
                             'screen size.',
                             default=None)
    parser.add_option_group(video_options)

    (options, args) = parser.parse_args()

    if len(args) > 1:
        parser.error('Too many positional arguments.')
    host_file = args[0] if args else options.file

    if options.verbose:
        logging.getLogger().setLevel(logging.DEBUG)

    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)
    else:
        if len(devices) > 1:
            parser.error('Multiple devices are attached. '
                         'Please specify device serial number with --device.')
        elif len(devices) == 1:
            device = devices[0]
        else:
            raise device_errors.NoDevicesError()

    if options.video:
        _CaptureVideo(device, host_file, options)
    else:
        _CaptureScreenshot(device, host_file)
    return 0
Example #10
0
def main():
    parser = argparse.ArgumentParser()

    apk_group = parser.add_mutually_exclusive_group(required=True)
    apk_group.add_argument('--apk',
                           dest='apk_name',
                           help='DEPRECATED The name of the apk containing the'
                           ' application (with the .apk extension).')
    apk_group.add_argument('apk_path',
                           nargs='?',
                           help='The path to the APK to install.')

    # TODO(jbudorick): Remove once no clients pass --apk_package
    parser.add_argument('--apk_package', help='DEPRECATED unused')
    parser.add_argument('--split',
                        action='append',
                        dest='splits',
                        help='A glob matching the apk splits. '
                        'Can be specified multiple times.')
    parser.add_argument('--keep_data',
                        action='store_true',
                        default=False,
                        help='Keep the package data when installing '
                        'the application.')
    parser.add_argument('--debug',
                        action='store_const',
                        const='Debug',
                        dest='build_type',
                        default=os.environ.get('BUILDTYPE', 'Debug'),
                        help='If set, run test suites under out/Debug. '
                        'Default is env var BUILDTYPE or Debug')
    parser.add_argument('--release',
                        action='store_const',
                        const='Release',
                        dest='build_type',
                        help='If set, run test suites under out/Release. '
                        'Default is env var BUILDTYPE or Debug.')
    parser.add_argument('-d',
                        '--device',
                        dest='device',
                        help='Target device for apk to install on.')
    parser.add_argument('--blacklist-file', help='Device blacklist JSON file.')
    parser.add_argument('-v',
                        '--verbose',
                        action='count',
                        help='Enable verbose logging.')

    args = parser.parse_args()

    run_tests_helper.SetLogLevel(args.verbose)
    constants.SetBuildType(args.build_type)

    apk = args.apk_path or args.apk_name
    if not apk.endswith('.apk'):
        apk += '.apk'
    if not os.path.exists(apk):
        apk = os.path.join(constants.GetOutDirectory(), 'apks', apk)
        if not os.path.exists(apk):
            parser.error('%s not found.' % apk)

    if args.splits:
        splits = []
        base_apk_package = apk_helper.ApkHelper(apk).GetPackageName()
        for split_glob in args.splits:
            apks = [f for f in glob.glob(split_glob) if f.endswith('.apk')]
            if not apks:
                logging.warning('No apks matched for %s.' % split_glob)
            for f in apks:
                helper = apk_helper.ApkHelper(f)
                if (helper.GetPackageName() == base_apk_package
                        and helper.GetSplitName()):
                    splits.append(f)

    if args.blacklist_file:
        blacklist = device_blacklist.Blacklist(args.blacklist_file)
    else:
        # TODO(jbudorick): Remove this once the bots are converted.
        blacklist = device_blacklist.Blacklist(device_blacklist.BLACKLIST_JSON)

    devices = device_utils.DeviceUtils.HealthyDevices(blacklist)

    if args.device:
        devices = [d for d in devices if d == args.device]
        if not devices:
            raise device_errors.DeviceUnreachableError(args.device)
    elif not devices:
        raise device_errors.NoDevicesError()

    def blacklisting_install(device):
        try:
            if args.splits:
                device.InstallSplitApk(apk, splits, reinstall=args.keep_data)
            else:
                device.Install(apk, reinstall=args.keep_data)
        except device_errors.CommandFailedError:
            logging.exception('Failed to install %s', args.apk_name)
            if blacklist:
                blacklist.Extend([str(device)])
                logging.warning('Blacklisting %s', str(device))
        except device_errors.CommandTimeoutError:
            logging.exception('Timed out while installing %s', args.apk_name)
            if blacklist:
                blacklist.Extend([str(device)])
                logging.warning('Blacklisting %s', str(device))

    device_utils.DeviceUtils.parallel(devices).pMap(blacklisting_install)