Exemplo n.º 1
0
def ProcessInstrumentationOptions(args):
    """Processes options/arguments and populate |options| with defaults.

  Args:
    args: argparse.Namespace object.

  Returns:
    An InstrumentationOptions named tuple which contains all options relevant to
    instrumentation tests.
  """

    ProcessJavaTestOptions(args)

    if not args.host_driven_root:
        args.run_python_tests = False

    args.test_apk_path = os.path.join(constants.GetOutDirectory(),
                                      constants.SDK_BUILD_APKS_DIR,
                                      '%s.apk' % args.test_apk)
    args.test_apk_jar_path = os.path.join(constants.GetOutDirectory(),
                                          constants.SDK_BUILD_TEST_JAVALIB_DIR,
                                          '%s.jar' % args.test_apk)
    args.test_support_apk_path = '%sSupport%s' % (os.path.splitext(
        args.test_apk_path))

    args.test_runner = apk_helper.GetInstrumentationName(args.test_apk_path)

    # TODO(jbudorick): Get rid of InstrumentationOptions.
    return instrumentation_test_options.InstrumentationOptions(
        args.tool, args.annotations, args.exclude_annotations,
        args.test_filter, args.test_data, args.save_perf_json,
        args.screenshot_failures, args.wait_for_debugger, args.coverage_dir,
        args.test_apk, args.test_apk_path, args.test_apk_jar_path,
        args.test_runner, args.test_support_apk_path, args.device_flags,
        args.isolate_file_path, args.set_asserts, args.delete_stale_data)
Exemplo n.º 2
0
    def __init__(self, test_options, device, shard_index, test_pkg,
                 ports_to_forward):
        """Create a new TestRunner.

    Args:
      test_options: A UIAutomatorOptions object.
      device: Attached android device.
      shard_index: Shard index.
      test_pkg: A TestPackage object.
      ports_to_forward: A list of port numbers for which to set up forwarders.
          Can be optionally requested by a test case.
    """
        # Create an InstrumentationOptions object to pass to the super class
        instrumentation_options = instr_test_options.InstrumentationOptions(
            test_options.tool,
            test_options.cleanup_test_files,
            test_options.push_deps,
            test_options.annotations,
            test_options.exclude_annotations,
            test_options.test_filter,
            test_options.test_data,
            test_options.save_perf_json,
            test_options.screenshot_failures,
            wait_for_debugger=False,
            coverage_dir=None,
            test_apk=None,
            test_apk_path=None,
            test_apk_jar_path=None)
        super(TestRunner,
              self).__init__(instrumentation_options, device, shard_index,
                             test_pkg, ports_to_forward)

        self._package = constants.PACKAGE_INFO[test_options.package].package
        self._activity = constants.PACKAGE_INFO[test_options.package].activity
Exemplo n.º 3
0
    def __init__(self, test_options, device, shard_index, test_pkg):
        """Create a new TestRunner.

    Args:
      test_options: A UIAutomatorOptions object.
      device: Attached android device.
      shard_index: Shard index.
      test_pkg: A TestPackage object.
    """
        # Create an InstrumentationOptions object to pass to the super class
        instrumentation_options = instr_test_options.InstrumentationOptions(
            test_options.tool,
            test_options.cleanup_test_files,
            test_options.push_deps,
            test_options.annotations,
            test_options.exclude_annotations,
            test_options.test_filter,
            test_options.test_data,
            test_options.save_perf_json,
            test_options.screenshot_failures,
            wait_for_debugger=False,
            coverage_dir=None,
            test_apk=None,
            test_apk_path=None,
            test_apk_jar_path=None)
        super(TestRunner, self).__init__(instrumentation_options, device,
                                         shard_index, test_pkg)

        cmdline_file = constants.PACKAGE_INFO[
            test_options.package].cmdline_file
        self.flags = None
        if cmdline_file:
            self.flags = flag_changer.FlagChanger(self.adb, cmdline_file)
        self._package = constants.PACKAGE_INFO[test_options.package].package
        self._activity = constants.PACKAGE_INFO[test_options.package].activity
Exemplo n.º 4
0
    def _RunJavaTest(self, fname, suite, test):
        """Runs a single Java test with a Java TestRunner.

    Args:
      fname: filename for the test (e.g. foo/bar/baz/tests/FooTest.py)
      suite: name of the Java test suite (e.g. FooTest)
      test: name of the test method to run (e.g. testFooBar)

    Returns:
      TestRunResults object with a single test result.
    """
        test = self._ComposeFullTestName(fname, suite, test)
        test_pkg = test_package.TestPackage(self.options.test_apk_path,
                                            self.options.test_apk_jar_path)
        instrumentation_options = test_options.InstrumentationOptions(
            self.options.build_type, self.options.tool,
            self.options.cleanup_test_files, self.options.push_deps,
            self.options.annotations, self.options.exclude_annotations,
            self.options.test_filter, self.options.test_data,
            self.options.save_perf_json, self.options.screenshot_failures,
            self.options.disable_assertions, self.options.wait_for_debugger,
            self.options.test_apk, self.options.test_apk_path,
            self.options.test_apk_jar_path)
        java_test_runner = test_runner.TestRunner(instrumentation_options,
                                                  self.device_id,
                                                  self.shard_index, test_pkg,
                                                  self.ports_to_forward)
        try:
            java_test_runner.SetUp()
            return java_test_runner.RunTest(test)[0]
        finally:
            java_test_runner.TearDown()
Exemplo n.º 5
0
def ProcessInstrumentationOptions(options, error_func):
  """Processes options/arguments and populate |options| with defaults.

  Args:
    options: optparse.Options object.
    error_func: Function to call with the error message in case of an error.

  Returns:
    An InstrumentationOptions named tuple which contains all options relevant to
    instrumentation tests.
  """

  ProcessJavaTestOptions(options, error_func)

  if options.java_only and options.python_only:
    error_func('Options java_only (-j) and python_only (-p) '
               'are mutually exclusive.')
  options.run_java_tests = True
  options.run_python_tests = True
  if options.java_only:
    options.run_python_tests = False
  elif options.python_only:
    options.run_java_tests = False

  if not options.host_driven_root:
    options.run_python_tests = False

  if not options.test_apk:
    error_func('--test-apk must be specified.')


  options.test_apk_path = os.path.join(constants.GetOutDirectory(),
                                       constants.SDK_BUILD_APKS_DIR,
                                       '%s.apk' % options.test_apk)
  options.test_apk_jar_path = os.path.join(
      constants.GetOutDirectory(),
      constants.SDK_BUILD_TEST_JAVALIB_DIR,
      '%s.jar' %  options.test_apk)

  return instrumentation_test_options.InstrumentationOptions(
      options.tool,
      options.cleanup_test_files,
      options.push_deps,
      options.annotations,
      options.exclude_annotations,
      options.test_filter,
      options.test_data,
      options.save_perf_json,
      options.screenshot_failures,
      options.wait_for_debugger,
      options.coverage_dir,
      options.test_apk,
      options.test_apk_path,
      options.test_apk_jar_path)
Exemplo n.º 6
0
def ProcessInstrumentationOptions(options, error_func):
    """Processes options/arguments and populate |options| with defaults.

  Args:
    options: optparse.Options object.
    error_func: Function to call with the error message in case of an error.

  Returns:
    An InstrumentationOptions named tuple which contains all options relevant to
    instrumentation tests.
  """

    ProcessJavaTestOptions(options, error_func)

    if options.java_only and options.python_only:
        error_func('Options java_only (-j) and python_only (-p) '
                   'are mutually exclusive.')
    options.run_java_tests = True
    options.run_python_tests = True
    if options.java_only:
        options.run_python_tests = False
    elif options.python_only:
        options.run_java_tests = False

    if not options.python_test_root:
        options.run_python_tests = False

    if not options.test_apk:
        error_func('--test-apk must be specified.')

    if os.path.exists(options.test_apk):
        # The APK is fully qualified, assume the JAR lives along side.
        options.test_apk_path = options.test_apk
        options.test_apk_jar_path = (
            os.path.splitext(options.test_apk_path)[0] + '.jar')
    else:
        options.test_apk_path = os.path.join(_SDK_OUT_DIR, options.build_type,
                                             constants.SDK_BUILD_APKS_DIR,
                                             '%s.apk' % options.test_apk)
        options.test_apk_jar_path = os.path.join(
            _SDK_OUT_DIR, options.build_type,
            constants.SDK_BUILD_TEST_JAVALIB_DIR, '%s.jar' % options.test_apk)

    return instrumentation_test_options.InstrumentationOptions(
        options.build_type, options.tool, options.cleanup_test_files,
        options.push_deps, options.annotations, options.exclude_annotations,
        options.test_filter, options.test_data, options.save_perf_json,
        options.screenshot_failures, options.wait_for_debugger,
        options.test_apk, options.test_apk_path, options.test_apk_jar_path)
def ProcessInstrumentationOptions(args):
    """Processes options/arguments and populate |options| with defaults.

  Args:
    args: argparse.Namespace object.

  Returns:
    An InstrumentationOptions named tuple which contains all options relevant to
    instrumentation tests.
  """

    ProcessJavaTestOptions(args)

    if not args.host_driven_root:
        args.run_python_tests = False

    if os.path.exists(args.test_apk):
        args.test_apk_path = args.test_apk
        args.test_apk, _ = os.path.splitext(os.path.basename(args.test_apk))
    else:
        args.test_apk_path = os.path.join(constants.GetOutDirectory(),
                                          constants.SDK_BUILD_APKS_DIR,
                                          '%s.apk' % args.test_apk)

    jar_basename = args.test_apk
    if jar_basename.endswith('_incremental'):
        jar_basename = jar_basename[:-len('_incremental')]

    args.test_apk_jar_path = os.path.join(constants.GetOutDirectory(),
                                          constants.SDK_BUILD_TEST_JAVALIB_DIR,
                                          '%s.jar' % jar_basename)
    args.test_support_apk_path = '%sSupport%s' % (os.path.splitext(
        args.test_apk_path))

    args.test_runner = apk_helper.GetInstrumentationName(args.test_apk_path)

    # TODO(jbudorick): Get rid of InstrumentationOptions.
    return instrumentation_test_options.InstrumentationOptions(
        args.tool, args.annotations, args.exclude_annotations,
        args.test_filter, args.test_data, args.save_perf_json,
        args.screenshot_failures, args.wait_for_debugger, args.coverage_dir,
        args.test_apk, args.test_apk_path, args.test_apk_jar_path,
        args.test_runner, args.test_support_apk_path, args.device_flags,
        args.isolate_file_path, args.set_asserts, args.delete_stale_data,
        args.timeout_scale, args.apk_under_test, args.additional_apks,
        args.strict_mode, args.skip_clear_data,
        args.test_apk_incremental_install_script,
        args.apk_under_test_incremental_install_script)
def DispatchPythonTests(options):
  """Dispatches the Python tests. If there are multiple devices, use sharding.

  Args:
    options: command line options.

  Returns:
    A tuple of (base_test_result.TestRunResults object, exit code)

  Raises:
    Exception: If there are no attached devices.
  """

  attached_devices = android_commands.GetAttachedDevices()
  if not attached_devices:
    raise Exception('You have no devices attached or visible!')
  if options.test_device:
    attached_devices = [options.test_device]

  test_collection = TestInfoCollection()
  all_tests = _GetAllTests(options.python_test_root, options.official_build)
  test_collection.AddTests(all_tests)
  test_names = [t.qualified_name for t in all_tests]
  logging.debug('All available tests: ' + str(test_names))

  available_tests = test_collection.GetAvailableTests(
      options.annotations, options.exclude_annotations, options.test_filter)

  if not available_tests:
    logging.warning('No Python tests to run with current args.')
    return (base_test_result.TestRunResults(), 0)

  test_names = [t.qualified_name for t in available_tests]
  logging.debug('Final list of tests to run: ' + str(test_names))

  # Copy files to each device before running any tests.
  for device_id in attached_devices:
    logging.debug('Pushing files to device %s', device_id)
    test_pkg = test_package.TestPackage(options.test_apk_path,
                                        options.test_apk_jar_path)
    instrumentation_options = test_options.InstrumentationOptions(
        options.build_type,
        options.tool,
        options.cleanup_test_files,
        options.push_deps,
        options.annotations,
        options.exclude_annotations,
        options.test_filter,
        options.test_data,
        options.save_perf_json,
        options.screenshot_failures,
        options.disable_assertions,
        options.wait_for_debugger,
        options.test_apk,
        options.test_apk_path,
        options.test_apk_jar_path)
    test_files_copier = test_runner.TestRunner(instrumentation_options,
                                               device_id, 0, test_pkg, [])
    test_files_copier.InstallTestPackage()
    if options.push_deps:
      logging.info('Pushing data deps to device.')
      test_files_copier.PushDataDeps()
    else:
      logging.warning('Skipping pushing data deps to device.')

  # Actually run the tests.
  if len(attached_devices) > 1 and options.wait_for_debugger:
    logging.warning('Debugger can not be sharded, '
                    'using first available device')
    attached_devices = attached_devices[:1]
  logging.debug('Running Python tests')
  sharder = PythonTestSharder(attached_devices, available_tests, options)
  test_results = sharder.RunShardedTests()

  if not test_results.DidRunPass():
    return (test_results, 1)

  return (test_results, 0)