def CreateEnvironment(args, output_manager, error_func):

    if args.environment == 'local':
        if args.command not in constants.LOCAL_MACHINE_TESTS:
            if args.avd_name:
                return local_emulator_environment.LocalEmulatorEnvironment(
                    args, output_manager, error_func)
            return local_device_environment.LocalDeviceEnvironment(
                args, output_manager, error_func)
        else:
            return local_machine_environment.LocalMachineEnvironment(
                args, output_manager, error_func)

    error_func('Unable to create %s environment.' % args.environment)
Exemplo n.º 2
0
def CreateEnvironment(args, output_manager, error_func):

  if args.environment == 'local':
    if args.command not in constants.LOCAL_MACHINE_TESTS:
      if args.avd_config:
        if not local_emulator_environment:
          error_func('emulator environment requested but not available.')
          raise RuntimeError('error_func must call exit inside.')
        return local_emulator_environment.LocalEmulatorEnvironment(
            args, output_manager, error_func)
      return local_device_environment.LocalDeviceEnvironment(
          args, output_manager, error_func)
    return local_machine_environment.LocalMachineEnvironment(
        args, output_manager, error_func)

  error_func('Unable to create %s environment.' % args.environment)
  raise RuntimeError('error_func must call exit inside.')
Exemplo n.º 3
0
    def ParseAndroidEmulatorOptions(self):
        """Parses Android emulator args, and if necessary, starts an emulator.

    No-ops if --avd-config is not specified or if an emulator is already
    started.

    Performing this setup during argument parsing isn't ideal, but we need to
    set up the emulator sometime between arg parsing and browser finding.
    """
        if not self.avd_config:
            return
        if BrowserFinderOptions.emulator_environment:
            return
        build_android_dir = os.path.join(util.GetChromiumSrcDir(), 'build',
                                         'android')
        if not os.path.exists(build_android_dir):
            raise RuntimeError(
                '--avd-config specified, but Chromium //build/android directory not '
                'available')
        # Everything after this point only works if //build/android is actually
        # available, which we can't rely on, so use this to exit early in unittests.
        self._NoOpFunctionForTesting()
        sys.path.append(build_android_dir)
        # pylint: disable=import-error
        from pylib import constants as pylib_constants
        from pylib.local.emulator import local_emulator_environment
        # pylint: enable=import-error

        # We need to call this so that the Chromium output directory is set if it
        # is not explicitly specified via the command line argument/environment
        # variable.
        pylib_constants.CheckOutputDirectory()

        class AvdArgs(object):
            """A class to stand in for the AVD argparse.ArgumentParser object.

      Chromium's Android emulator code expects quite a few arguments from
      //build/android/test_runner.py, but the only one we actually care about
      here is avd_config. So, use a stand-in class with some sane defaults.
      """
            def __init__(self, avd_config):
                self.avd_config = avd_config
                self.emulator_count = 1
                self.emulator_window = False
                self.use_webview_provider = False
                self.replace_system_package = False
                self.denylist_file = None
                self.test_devices = []
                self.enable_concurrent_adb = False
                self.logcat_output_dir = None
                self.logcat_output_file = None
                self.num_retries = 1
                self.recover_devices = False
                self.skip_clear_data = True
                self.tool = None
                self.adb_path = None
                self.enable_device_cache = True

        avd_args = AvdArgs(self.avd_config)
        BrowserFinderOptions.emulator_environment =\
            local_emulator_environment.LocalEmulatorEnvironment(
                avd_args, None, None)
        BrowserFinderOptions.emulator_environment.SetUp()
        atexit.register(BrowserFinderOptions.emulator_environment.TearDown)