示例#1
0
def before_iterations(kw):
    global build_generator

    if "fenix_nightlysim_multicommit" not in kw.get("android_install_apk")[0]:
        return

    # Get the builds to test
    build_url = get_multi_tasks_url(NIGHTLY_SIM_ROUTE, day=kw["test_date"])
    tmpfile = pathlib.Path(tempfile.mkdtemp(), "alltasks.json")
    download_file(build_url, tmpfile)

    # Set the number of test-iterations to the number of builds
    with tmpfile.open() as f:
        tasks = json.load(f)["tasks"]
    kw["test_iterations"] = len(tasks)

    # Finally, make an iterator for the builds (used in `before_runs`)
    route_suffix = G5_SUFFIX
    if "arm64_v8a" in kw.get("android_install_apk"):
        route_suffix = P2_SUFFIX

    def _build_iterator(route_suffix):
        for task in tasks:
            route = task["namespace"]
            revision = route.split(".")[-1]
            print("Testing revision %s" % revision)
            download_url = "%s%s/%s" % (_ROOT_URL, route, route_suffix)
            yield revision, [download_url]

    build_generator = _build_iterator(route_suffix)

    return kw
def _fetch_json(get_url_function, *args, **kwargs):
    build_url = get_url_function(*args, **kwargs)
    tmpfile = pathlib.Path(tempfile.mkdtemp(), "temp.json")
    download_file(build_url, tmpfile)

    with tmpfile.open() as f:
        return json.load(f)
示例#3
0
def _fetch_json(get_url_function, *args, **kwargs):
    build_url = get_url_function(*args, **kwargs)
    tmpfile = pathlib.Path(tempfile.mkdtemp(), "temp.json")
    download_file(build_url, tmpfile)

    # Set the number of test-iterations to the number of builds
    with tmpfile.open() as f:
        return json.load(f)
示例#4
0
    def run(self, metadata):
        self.metadata = metadata

        replay_file = self.get_arg("replay")
        if replay_file is not None and replay_file.startswith("http"):
            self.tmpdir = tempfile.TemporaryDirectory()
            target = os.path.join(self.tmpdir.name, "recording.zip")
            self.info("Downloading %s" % replay_file)
            download_file(replay_file, target)
            replay_file = target

        self.info("Setting up the proxy")
        command = [
            self.mach_cmd.virtualenv_manager.python_path,
            "-m",
            "mozproxy.driver",
            "--local",
            "--binary=" + self.mach_cmd.get_binary_path(),
            "--topsrcdir=" + self.mach_cmd.topsrcdir,
            "--objdir=" + self.mach_cmd.topobjdir,
        ]
        if self.get_arg("record"):
            command.extend(["--record", self.get_arg("record")])
        elif replay_file:
            command.append(replay_file)
        else:
            command.append(os.path.join(HERE, "example.zip"))
        print(" ".join(command))
        self.output_handler = OutputHandler()
        self.proxy = ProcessHandler(
            command,
            processOutputLine=self.output_handler,
            onFinish=self.output_handler.finished,
        )
        self.output_handler.proc = self.proxy
        self.proxy.run()

        # Wait until we've retrieved the proxy server's port number so we can
        # configure the browser properly.
        port = self.output_handler.wait_for_port()
        if port is None:
            raise ValueError(
                "Unable to retrieve the port number from mozproxy")
        self.info("Received port number %s from mozproxy" % port)

        prefs = {
            "network.proxy.type": 1,
            "network.proxy.http": "localhost",
            "network.proxy.http_port": port,
            "network.proxy.ssl": "localhost",
            "network.proxy.ssl_port": port,
            "network.proxy.no_proxies_on": "localhost",
        }
        browser_prefs = metadata.get_options("browser_prefs")
        browser_prefs.update(prefs)
        return metadata
示例#5
0
    def __init__(self, mach_cmd, hook_module=None):
        MachLogger.__init__(self, mach_cmd)
        self.tmp_dir = tempfile.mkdtemp()

        if hook_module is None:
            self._hooks = None
            return

        if not isinstance(hook_module, Path):
            if hook_module.startswith("http"):
                target = Path(self.tmp_dir, hook_module.split("/")[-1])
                hook_module = download_file(hook_module, target)
            else:
                hook_module = Path(hook_module)

        if hook_module.exists():
            path = str(hook_module)
            if path not in _LOADED_MODULES:
                spec = importlib.util.spec_from_file_location("hooks", path)
                hook_module = importlib.util.module_from_spec(spec)
                spec.loader.exec_module(hook_module)
                _LOADED_MODULES[path] = hook_module
            self._hooks = _LOADED_MODULES[path]
        else:
            raise IOError(str(hook_module))
示例#6
0
    def __call__(self, metadata):
        self.app_name = self.get_arg("android-app-name")
        self.android_activity = self.get_arg("android-activity")
        self.metadata = metadata
        try:
            self.device = ADBDevice(verbose=True, timeout=30)
        except (ADBError, AttributeError) as e:
            self.error("Could not connect to the phone. Is it connected?")
            raise DeviceError(str(e))

        # install APKs
        for apk in self.get_arg("android-install-apk"):
            self.info("Installing %s" % apk)
            if apk in _PERMALINKS:
                apk = _PERMALINKS[apk]
            if apk.startswith("http"):
                with tempfile.TemporaryDirectory() as tmpdirname:
                    target = Path(tmpdirname, "target.apk")
                    self.info("Downloading %s" % apk)
                    download_file(apk, target)
                    self.info("Installing downloaded APK")
                    self.device.install_app(str(target), replace=True)
            else:
                self.device.install_app(apk, replace=True)
            self.info("Done.")

        # checking that the app is installed
        if not self.device.is_app_installed(self.app_name):
            raise Exception("%s is not installed" % self.app_name)

        # set up default activity with the app name if none given
        if self.android_activity is None:
            # guess the activity, given the app
            if "fenix" in self.app_name:
                self.android_activity = "org.mozilla.fenix.IntentReceiverActivity"
            elif "geckoview_example" in self.app_name:
                self.android_activity = (
                    "org.mozilla.geckoview_example.GeckoViewActivity")
            self.set_arg("android_activity", self.android_activity)

        self.info("Android environment:")
        self.info("- Application name: %s" % self.app_name)
        self.info("- Activity: %s" % self.android_activity)
        self.info("- Intent: %s" % self.get_arg("android_intent"))
        return metadata
示例#7
0
    def _load_hooks(self):
        self._hooks = None
        hooks = self.get_arg("hooks")
        if hooks is None:
            return

        if hooks.startswith("http"):
            target = Path(self.tmp_dir, hooks.split("/")[-1])
            hooks = download_file(hooks, target)
        else:
            hooks = Path(hooks)

        if hooks.exists():
            spec = importlib.util.spec_from_file_location("hooks", str(hooks))
            hooks = importlib.util.module_from_spec(spec)
            spec.loader.exec_module(hooks)
            self._hooks = hooks
        else:
            raise IOError(str(hooks))
示例#8
0
def test_download_file_success():
    with temp_file() as target:
        download_file("http://content", Path(target), retry_sleep=0.1)
        with open(target) as f:
            assert f.read() == "some content"
示例#9
0
def test_download_file_fails():
    with temp_file() as target, silence(), pytest.raises(Exception):
        download_file("http://I don't exist", Path(target), retry_sleep=0.1)
示例#10
0
    def run(self, metadata):
        self.app_name = self.get_arg("android-app-name")
        self.android_activity = self.get_arg("android-activity")
        self.clear_logcat = self.get_arg("clear-logcat")
        self.metadata = metadata
        self.verbose = self.get_arg("verbose")
        self.capture_adb = self._set_output_path(self.get_arg("capture-adb"))
        self.capture_logcat = self._set_output_path(
            self.get_arg("capture-logcat"))

        # capture the logs produced by ADBDevice
        logger_name = "mozperftest-adb"
        logger = mozlog.structuredlog.StructuredLogger(logger_name)
        if self.capture_adb == "stdout":
            stream = sys.stdout
            disable_colors = False
        else:
            stream = self.capture_file = self.capture_adb.open("w")
            disable_colors = True

        handler = mozlog.handlers.StreamHandler(
            stream=stream,
            formatter=mozlog.formatters.MachFormatter(
                verbose=self.verbose, disable_colors=disable_colors),
        )
        logger.add_handler(handler)
        try:
            self.device = ADBLoggedDevice(verbose=self.verbose,
                                          timeout=self.get_arg("timeout"),
                                          logger=logger)
        except (ADBError, AttributeError) as e:
            self.error("Could not connect to the phone. Is it connected?")
            raise DeviceError(str(e))

        if self.clear_logcat:
            self.device.clear_logcat()

        # Install APKs
        for apk in self.get_arg("android-install-apk"):
            self.info("Uninstalling old version")
            self.device.uninstall_app(self.get_arg("android-app-name"))
            self.info("Installing %s" % apk)
            if apk in _PERMALINKS:
                apk = _PERMALINKS[apk]
            if apk.startswith("http"):
                with tempfile.TemporaryDirectory() as tmpdirname:
                    target = Path(tmpdirname, "target.apk")
                    self.info("Downloading %s" % apk)
                    download_file(apk, target)
                    self.info("Installing downloaded APK")
                    self.device.install_app(str(target))
            else:
                self.device.install_app(apk, replace=True)
            self.info("Done.")

        # checking that the app is installed
        if not self.device.is_app_installed(self.app_name):
            raise Exception("%s is not installed" % self.app_name)

        if self.get_arg("android-perf-tuning", False):
            tune_performance(self.device)

        # set up default activity with the app name if none given
        if self.android_activity is None:
            # guess the activity, given the app
            if "fenix" in self.app_name:
                self.android_activity = "org.mozilla.fenix.IntentReceiverActivity"
            elif "geckoview_example" in self.app_name:
                self.android_activity = (
                    "org.mozilla.geckoview_example.GeckoViewActivity")
            self.set_arg("android_activity", self.android_activity)

        self.info("Android environment:")
        self.info("- Application name: %s" % self.app_name)
        self.info("- Activity: %s" % self.android_activity)
        self.info("- Intent: %s" % self.get_arg("android_intent"))
        return metadata
示例#11
0
    def run(self, metadata):
        self.metadata = metadata
        replay_file = self.get_arg("file")

        # Check if we have a replay file
        if replay_file is None:
            raise ValueError("Proxy file not provided!!")

        if replay_file is not None and replay_file.startswith("http"):
            self.tmpdir = tempfile.TemporaryDirectory()
            target = pathlib.Path(self.tmpdir.name, "recording.zip")
            self.info("Downloading %s" % replay_file)
            download_file(replay_file, target)
            replay_file = target

        self.info("Setting up the proxy")

        command = [
            self.mach_cmd.virtualenv_manager.python_path,
            "-m",
            "mozproxy.driver",
            "--local",
            "--topsrcdir=" + self.mach_cmd.topsrcdir,
            "--objdir=" + self.mach_cmd.topobjdir,
            "--profiledir=" + self.get_arg("profile-directory"),
        ]

        if metadata.flavor == "mobile-browser":
            command.extend(["--tool=%s" % "mitmproxy-android"])
            command.extend(["--binary=android"])
        else:
            command.extend(["--tool=%s" % "mitmproxy"])
            # XXX See bug 1712337, we need a single point where we can get the binary used from
            command.extend(
                ["--binary=%s" % self.get_arg("browsertime-binary")])

        if self.get_arg("mode") == "record":
            output = self.get_arg("output")
            if output is None:
                output = pathlib.Path(self.mach_cmd.topsrcdir, "artifacts")
            results_dir = get_output_dir(output)

            command.extend(["--mode", "record"])
            command.append(str(pathlib.Path(results_dir, replay_file)))
        elif self.get_arg("mode") == "playback":
            command.extend(["--mode", "playback"])
            command.append(str(replay_file))
        else:
            raise ValueError(
                "Proxy mode not provided please provide proxy mode")

        print(" ".join(command))
        self.output_handler = OutputHandler()
        self.proxy = ProcessHandler(
            command,
            processOutputLine=self.output_handler,
            onFinish=self.output_handler.finished,
        )
        self.output_handler.proc = self.proxy
        self.proxy.run()

        # Wait until we've retrieved the proxy server's port number so we can
        # configure the browser properly.
        port = self.output_handler.wait_for_port()
        if port is None:
            raise ValueError(
                "Unable to retrieve the port number from mozproxy")
        self.info("Received port number %s from mozproxy" % port)

        prefs = {
            "network.proxy.type": 1,
            "network.proxy.http": "127.0.0.1",
            "network.proxy.http_port": port,
            "network.proxy.ssl": "127.0.0.1",
            "network.proxy.ssl_port": port,
            "network.proxy.no_proxies_on": "127.0.0.1",
        }
        browser_prefs = metadata.get_options("browser_prefs")
        browser_prefs.update(prefs)

        if metadata.flavor == "mobile-browser":
            self.info("Setting reverse port fw for android device")
            device = ADBDevice()
            device.create_socket_connection("reverse", "tcp:%s" % port,
                                            "tcp:%s" % port)

        return metadata