Beispiel #1
0
    def emulator(self, version, wait=False, force_update=False, verbose=False):
        from mozrunner.devices.android_device import AndroidEmulator

        emulator = AndroidEmulator(version, verbose, substs=self.substs,
                                   device_serial='emulator-5554')
        if emulator.is_running():
            # It is possible to run multiple emulators simultaneously, but:
            #  - if more than one emulator is using the same avd, errors may
            #    occur due to locked resources;
            #  - additional parameters must be specified when running tests,
            #    to select a specific device.
            # To avoid these complications, allow just one emulator at a time.
            self.log(logging.ERROR, "emulator", {},
                     "An Android emulator is already running.\n"
                     "Close the existing emulator and re-run this command.")
            return 1

        if not emulator.is_available():
            self.log(logging.WARN, "emulator", {},
                     "Emulator binary not found.\n"
                     "Install the Android SDK and make sure 'emulator' is in your PATH.")
            return 2

        if not emulator.check_avd(force_update):
            self.log(logging.INFO, "emulator", {},
                     "Fetching and installing AVD. This may take a few minutes...")
            emulator.update_avd(force_update)

        self.log(logging.INFO, "emulator", {},
                 "Starting Android emulator running %s..." %
                 emulator.get_avd_description())
        emulator.start()
        if emulator.wait_for_start():
            self.log(logging.INFO, "emulator", {},
                     "Android emulator is running.")
        else:
            # This is unusual but the emulator may still function.
            self.log(logging.WARN, "emulator", {},
                     "Unable to verify that emulator is running.")

        if conditions.is_android(self):
            self.log(logging.INFO, "emulator", {},
                     "Use 'mach install' to install or update Firefox on your emulator.")
        else:
            self.log(logging.WARN, "emulator", {},
                     "No Firefox for Android build detected.\n"
                     "Switch to a Firefox for Android build context or use 'mach bootstrap'\n"
                     "to setup an Android build environment.")

        if wait:
            self.log(logging.INFO, "emulator", {},
                     "Waiting for Android emulator to close...")
            rc = emulator.wait()
            if rc is not None:
                self.log(logging.INFO, "emulator", {},
                         "Android emulator completed with return code %d." % rc)
            else:
                self.log(logging.WARN, "emulator", {},
                         "Unable to retrieve Android emulator return code.")
        return 0
    def emulator(self, version, wait=False, force_update=False, verbose=False):
        from mozrunner.devices.android_device import AndroidEmulator

        emulator = AndroidEmulator(version, verbose, substs=self.substs, device_serial='emulator-5554')
        if emulator.is_running():
            # It is possible to run multiple emulators simultaneously, but:
            #  - if more than one emulator is using the same avd, errors may
            #    occur due to locked resources;
            #  - additional parameters must be specified when running tests,
            #    to select a specific device.
            # To avoid these complications, allow just one emulator at a time.
            self.log(logging.ERROR, "emulator", {},
                     "An Android emulator is already running.\n"
                     "Close the existing emulator and re-run this command.")
            return 1

        if not emulator.is_available():
            self.log(logging.WARN, "emulator", {},
                     "Emulator binary not found.\n"
                     "Install the Android SDK and make sure 'emulator' is in your PATH.")
            return 2

        if not emulator.check_avd(force_update):
            self.log(logging.INFO, "emulator", {},
                     "Fetching and installing AVD. This may take a few minutes...")
            emulator.update_avd(force_update)

        self.log(logging.INFO, "emulator", {},
                 "Starting Android emulator running %s..." %
                 emulator.get_avd_description())
        emulator.start()
        if emulator.wait_for_start():
            self.log(logging.INFO, "emulator", {},
                     "Android emulator is running.")
        else:
            # This is unusual but the emulator may still function.
            self.log(logging.WARN, "emulator", {},
                     "Unable to verify that emulator is running.")

        if conditions.is_android(self):
            self.log(logging.INFO, "emulator", {},
                     "Use 'mach install' to install or update Firefox on your emulator.")
        else:
            self.log(logging.WARN, "emulator", {},
                     "No Firefox for Android build detected.\n"
                     "Switch to a Firefox for Android build context or use 'mach bootstrap'\n"
                     "to setup an Android build environment.")

        if wait:
            self.log(logging.INFO, "emulator", {},
                     "Waiting for Android emulator to close...")
            rc = emulator.wait()
            if rc is not None:
                self.log(logging.INFO, "emulator", {},
                         "Android emulator completed with return code %d." % rc)
            else:
                self.log(logging.WARN, "emulator", {},
                         "Unable to retrieve Android emulator return code.")
        return 0
Beispiel #3
0
def emulator(
    command_context,
    version,
    wait=False,
    gpu=None,
    verbose=False,
):
    """
    Run the Android emulator with one of the AVDs used in the Mozilla
    automated test environment. If necessary, the AVD is fetched from
    the taskcluster server and installed.
    """
    from mozrunner.devices.android_device import AndroidEmulator

    emulator = AndroidEmulator(
        version,
        verbose,
        substs=command_context.substs,
        device_serial="emulator-5554",
    )
    if emulator.is_running():
        # It is possible to run multiple emulators simultaneously, but:
        #  - if more than one emulator is using the same avd, errors may
        #    occur due to locked resources;
        #  - additional parameters must be specified when running tests,
        #    to select a specific device.
        # To avoid these complications, allow just one emulator at a time.
        command_context.log(
            logging.ERROR,
            "emulator",
            {},
            "An Android emulator is already running.\n"
            "Close the existing emulator and re-run this command.",
        )
        return 1

    if not emulator.check_avd():
        command_context.log(
            logging.WARN,
            "emulator",
            {},
            "AVD not found. Please run |mach bootstrap|.",
        )
        return 2

    if not emulator.is_available():
        command_context.log(
            logging.WARN,
            "emulator",
            {},
            "Emulator binary not found.\n"
            "Install the Android SDK and make sure 'emulator' is in your PATH.",
        )
        return 2

    command_context.log(
        logging.INFO,
        "emulator",
        {},
        "Starting Android emulator running %s..." %
        emulator.get_avd_description(),
    )
    emulator.start(gpu)
    if emulator.wait_for_start():
        command_context.log(logging.INFO, "emulator", {},
                            "Android emulator is running.")
    else:
        # This is unusual but the emulator may still function.
        command_context.log(
            logging.WARN,
            "emulator",
            {},
            "Unable to verify that emulator is running.",
        )

    if conditions.is_android(command_context):
        command_context.log(
            logging.INFO,
            "emulator",
            {},
            "Use 'mach install' to install or update Firefox on your emulator.",
        )
    else:
        command_context.log(
            logging.WARN,
            "emulator",
            {},
            "No Firefox for Android build detected.\n"
            "Switch to a Firefox for Android build context or use 'mach bootstrap'\n"
            "to setup an Android build environment.",
        )

    if wait:
        command_context.log(logging.INFO, "emulator", {},
                            "Waiting for Android emulator to close...")
        rc = emulator.wait()
        if rc is not None:
            command_context.log(
                logging.INFO,
                "emulator",
                {},
                "Android emulator completed with return code %d." % rc,
            )
        else:
            command_context.log(
                logging.WARN,
                "emulator",
                {},
                "Unable to retrieve Android emulator return code.",
            )
    return 0