Ejemplo n.º 1
0
def _tooltool_fetch():
    def outputHandler(line):
        _log_debug(line)

    _download_file(TOOLTOOL_URL, 'tooltool.py', EMULATOR_HOME_DIR)
    command = [
        sys.executable, 'tooltool.py', 'fetch', '-o', '-m', 'releng.manifest'
    ]
    proc = ProcessHandler(command,
                          processOutputLine=outputHandler,
                          storeOutput=False,
                          cwd=EMULATOR_HOME_DIR)
    proc.run()
    try:
        proc.wait()
    except Exception:
        if proc.poll() is None:
            proc.kill(signal.SIGTERM)
Ejemplo n.º 2
0
    def test_options(self):
        absdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
        testdir = os.path.join(absdir, 'js-modules')

        process = ProcessHandler(
            [
                'mozmill', '-b', os.environ['BROWSER_PATH'], '-t',
                os.path.join(testdir, 'useMozmill', 'testTestPass.js'), '-m',
                os.path.join(testdir, 'manifest-empty.ini')
            ],
            # stop mozmill from printing output to console
            processOutputLine=[lambda line: None])
        process.run()
        process.wait()

        self.assertNotEqual(
            process.proc.poll(), 0,
            'Parser error due to -t and -m are mutually exclusive')
Ejemplo n.º 3
0
    def run(self):
        self.reset()

        # Update the environment variables
        env = os.environ.copy()

        process_args = {
            "cmd": self.command,
            "cwd": self.path,
            "onFinish": self.collect_results,
            "processOutputLine": self.process_line,
            "stream": sys.stdout,
            "env": env,
            "universal_newlines": True,
        }
        proc = ProcessHandler(**process_args)
        proc.run()
        return proc.wait()
Ejemplo n.º 4
0
    def start_mitmproxy_playback(
        self,
        mitmdump_path,
        browser_path,
    ):
        """Startup mitmproxy and replay the specified flow file"""

        LOG.info("mitmdump path: %s" % mitmdump_path)
        LOG.info("browser path: %s" % browser_path)

        # mitmproxy needs some DLL's that are a part of Firefox itself, so add to path
        env = os.environ.copy()
        env["PATH"] = os.path.dirname(browser_path) + ";" + env["PATH"]
        command = [mitmdump_path, "-k"]

        if "playback_tool_args" in self.config:
            command.extend(self.config["playback_tool_args"])

        LOG.info("Starting mitmproxy playback using env path: %s" %
                 env["PATH"])
        LOG.info("Starting mitmproxy playback using command: %s" %
                 " ".join(command))
        # to turn off mitmproxy log output, use these params for Popen:
        # Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env)
        mitmproxy_proc = ProcessHandler(command,
                                        logfile=os.path.join(
                                            self.upload_dir, "mitmproxy.log"),
                                        env=env)
        mitmproxy_proc.run()

        # XXX replace the code below with a loop with a connection attempt
        # Bug 1532557
        time.sleep(MITMDUMP_SLEEP)
        data = mitmproxy_proc.poll()
        if data is None:  # None value indicates process hasn't terminated
            LOG.info("Mitmproxy playback successfully started as pid %d" %
                     mitmproxy_proc.pid)
            return mitmproxy_proc
        # cannot continue as we won't be able to playback the pages
        LOG.error(
            "Aborting: mitmproxy playback process failed to start, poll returned: %s"
            % data)
        # XXX here we might end up with a ghost mitmproxy
        sys.exit()
Ejemplo n.º 5
0
    def _run_python_test(self, test_path):
        from mozprocess import ProcessHandler

        output = []

        def _log(line):
            # Buffer messages if more than one worker to avoid interleaving
            if self.jobs > 1:
                output.append(line)
            else:
                self.log(logging.INFO, 'python-test', {'line': line.rstrip()}, '{line}')

        file_displayed_test = []  # used as boolean

        def _line_handler(line):
            if not file_displayed_test:
                output = ('Ran' in line or 'collected' in line or
                          line.startswith('TEST-'))
                if output:
                    file_displayed_test.append(True)

            _log(line)

        _log(test_path)
        cmd = [self.virtualenv_manager.python_path, test_path]
        env = os.environ.copy()
        env[b'PYTHONDONTWRITEBYTECODE'] = b'1'

        proc = ProcessHandler(cmd, env=env, processOutputLine=_line_handler, storeOutput=False)
        proc.run()

        return_code = proc.wait()

        if not file_displayed_test:
            _log('TEST-UNEXPECTED-FAIL | No test output (missing mozunit.main() '
                 'call?): {}'.format(test_path))

        if self.verbose:
            if return_code != 0:
                _log('Test failed: {}'.format(test_path))
            else:
                _log('Test passed: {}'.format(test_path))

        return output, return_code
Ejemplo n.º 6
0
def lint(files, config, **kwargs):
    log = kwargs['log']
    tests_dir = os.path.join(kwargs['root'], 'testing', 'web-platform',
                             'tests')

    def process_line(line):
        try:
            data = json.loads(line)
        except ValueError:
            return

        data["level"] = "error"
        data["path"] = os.path.relpath(os.path.join(tests_dir, data["path"]),
                                       kwargs['root'])
        data.setdefault("lineno", 0)
        results.append(result.from_config(config, **data))

    if files == [tests_dir]:
        print(
            "No specific files specified, running the full wpt lint"
            " (this is slow)",
            file=sys.stderr)
        files = ["--all"]
    cmd = ['python2', os.path.join(tests_dir, 'wpt'), 'lint', '--json'] + files
    log.debug("Command: {}".format(' '.join(cmd)))

    proc = ProcessHandler(cmd,
                          env=os.environ,
                          processOutputLine=process_line,
                          universal_newlines=True)
    proc.run()
    try:
        proc.wait()
        if proc.returncode != 0:
            results.append(
                result.from_config(
                    config,
                    message="Lint process exited with return code %s" %
                    proc.returncode))
    except KeyboardInterrupt:
        proc.kill()

    return results
Ejemplo n.º 7
0
def _tooltool_fetch():
    def outputHandler(line):
        _log_debug(line)

    tooltool_full_path = os.path.abspath(TOOLTOOL_PATH)
    command = [
        sys.executable, tooltool_full_path, 'fetch', '-o', '-m',
        'releng.manifest'
    ]
    proc = ProcessHandler(command,
                          processOutputLine=outputHandler,
                          storeOutput=False,
                          cwd=EMULATOR_HOME_DIR)
    proc.run()
    try:
        proc.wait()
    except Exception:
        if proc.poll() is None:
            proc.kill(signal.SIGTERM)
Ejemplo n.º 8
0
 def pushDir(self, localDir, remoteDir, retryLimit=None, timeout=None):
     # adb "push" accepts a directory as an argument, but if the directory
     # contains symbolic links, the links are pushed, rather than the linked
     # files; we either zip/unzip or re-copy the directory into a temporary
     # one to get around this limitation
     retryLimit = retryLimit or self.retryLimit
     if self._useZip:
         self.removeDir(remoteDir)
         self.mkDirs(remoteDir+"/x")
         try:
             localZip = tempfile.mktemp() + ".zip"
             remoteZip = remoteDir + "/adbdmtmp.zip"
             proc = ProcessHandler(["zip", "-r", localZip, '.'], cwd=localDir,
                           processOutputLine=self._log)
             proc.run()
             proc.wait()
             self.pushFile(localZip, remoteZip, retryLimit=retryLimit, createDir=False)
             mozfile.remove(localZip)
             data = self._runCmd(["shell", "unzip", "-o", remoteZip,
                                  "-d", remoteDir]).output[0]
             self._checkCmd(["shell", "rm", remoteZip],
                            retryLimit=retryLimit, timeout=self.short_timeout)
             if re.search("unzip: exiting", data) or re.search("Operation not permitted", data):
                 raise Exception("unzip failed, or permissions error")
         except:
             self._logger.warning(traceback.format_exc())
             self._logger.warning("zip/unzip failure: falling back to normal push")
             self._useZip = False
             self.pushDir(localDir, remoteDir, retryLimit=retryLimit, timeout=timeout)
     else:
         # If the remote directory exists, newer implementations of
         # "adb push" will create a sub-directory, while older versions
         # will not! Bug 1285040
         self.mkDirs(remoteDir+"/x")
         self.removeDir(remoteDir)
         tmpDir = tempfile.mkdtemp()
         # copytree's target dir must not already exist, so create a subdir
         tmpDirTarget = os.path.join(tmpDir, "tmp")
         shutil.copytree(localDir, tmpDirTarget)
         self._checkCmd(["push", tmpDirTarget, remoteDir],
                        retryLimit=retryLimit, timeout=timeout)
         mozfile.remove(tmpDir)
Ejemplo n.º 9
0
    def start(self):
        """
           Launch the emulator.
        """
        if self.avd_info.x86 and 'linux' in _get_host_platform():
            _verify_kvm(self.substs)
        if os.path.exists(EMULATOR_AUTH_FILE):
            os.remove(EMULATOR_AUTH_FILE)
            _log_debug("deleted %s" % EMULATOR_AUTH_FILE)
        # create an empty auth file to disable emulator authentication
        auth_file = open(EMULATOR_AUTH_FILE, 'w')
        auth_file.close()

        def outputHandler(line):
            self.emulator_log.write("<%s>\n" % line)
            if "Invalid value for -gpu" in line or "Invalid GPU mode" in line:
                self.gpu = False

        env = os.environ
        env['ANDROID_AVD_HOME'] = os.path.join(EMULATOR_HOME_DIR, "avd")
        command = [self.emulator_path, "-avd", self.avd_info.name]
        if self.gpu:
            command += ['-gpu', 'swiftshader_indirect']
        if self.avd_info.extra_args:
            # -enable-kvm option is not valid on OSX
            if _get_host_platform(
            ) == 'macosx64' and '-enable-kvm' in self.avd_info.extra_args:
                self.avd_info.extra_args.remove('-enable-kvm')
            command += self.avd_info.extra_args
        log_path = os.path.join(EMULATOR_HOME_DIR, 'emulator.log')
        self.emulator_log = open(log_path, 'w')
        _log_debug("Starting the emulator with this command: %s" %
                   ' '.join(command))
        _log_debug("Emulator output will be written to '%s'" % log_path)
        self.proc = ProcessHandler(command,
                                   storeOutput=False,
                                   processOutputLine=outputHandler,
                                   stdin=subprocess.PIPE,
                                   env=env,
                                   ignore_children=True)
        self.proc.run()
        _log_debug("Emulator started with pid %d" % int(self.proc.proc.pid))
Ejemplo n.º 10
0
    def setup_avds(self):
        '''
        If tooltool cache mechanism is enabled, the cached version is used by
        the fetch command. If the manifest includes an "unpack" field, tooltool
        will unpack all compressed archives mentioned in the manifest.
        '''
        c = self.config
        dirs = self.query_abs_dirs()

        # FIXME
        # Clobbering and re-unpacking would not be needed if we had a way to
        # check whether the unpacked content already present match the
        # contents of the tar ball
        self.rmtree(dirs['abs_avds_dir'])
        self.mkdir_p(dirs['abs_avds_dir'])
        if not self.buildbot_config:
            # XXX until we figure out how to determine the repo_path, revision
            url = 'https://hg.mozilla.org/%s/raw-file/%s/%s' % (
                "try", "default", c["tooltool_manifest_path"])
            self._tooltool_fetch(url)
        elif self.buildbot_config and 'properties' in self.buildbot_config:
            url = 'https://hg.mozilla.org/%s/raw-file/%s/%s' % (
                self.buildbot_config['properties']['repo_path'],
                self.buildbot_config['properties']['revision'],
                c["tooltool_manifest_path"])
            self._tooltool_fetch(url)
        else:
            self.fatal("properties in self.buildbot_config are required to "
                       "retrieve tooltool manifest to be used for avds setup")

        if self.config.get("developer_mode"):
            # For developer mode we have to modify the downloaded avds to
            # point to the right directory.
            avd_home_dir = self.abs_dirs['abs_avds_dir']
            cmd = [
                'bash', '-c',
                'sed -i "s|/home/cltbld/.android|%s|" %s/test-*.ini' %
                (avd_home_dir, os.path.join(avd_home_dir, 'avd'))
            ]
            proc = ProcessHandler(cmd)
            proc.run()
            proc.wait()
Ejemplo n.º 11
0
    def _checkCmd(self, args, timeout=None, retryLimit=None):
        """
        Runs a command using adb and waits for the command to finish.
        If timeout is specified, the process is killed after <timeout> seconds.

        returns: returncode from process
        """
        retryLimit = retryLimit or self.retryLimit
        finalArgs = [self._adbPath]
        if self._serverHost is not None:
            finalArgs.extend(['-H', self._serverHost])
        if self._serverPort is not None:
            finalArgs.extend(['-P', str(self._serverPort)])
        if self._deviceSerial:
            finalArgs.extend(['-s', self._deviceSerial])
        finalArgs.extend(args)
        self._logger.debug("_checkCmd - command: %s" % ' '.join(finalArgs))
        if not timeout:
            # We are asserting that all commands will complete in this
            # time unless otherwise specified
            timeout = self.default_timeout

        def _timeout():
            self._logger.error("Timeout exceeded for _checkCmd call '%s'" %
                               ' '.join(finalArgs))

        timeout = int(timeout)
        retries = 0
        while retries < retryLimit:
            proc = ProcessHandler(finalArgs,
                                  processOutputLine=self._log,
                                  onTimeout=_timeout)
            proc.run(timeout=timeout)
            ret_code = proc.wait()
            if ret_code == None:
                proc.kill()
                retries += 1
            else:
                return ret_code

        raise DMError("Timeout exceeded for _checkCmd call after %d retries." %
                      retries)
Ejemplo n.º 12
0
    def start(self, **kwargs):
        with ServoWebDriverBrowser.used_ports_lock:
            self.webdriver_port = get_free_port(4444, exclude=self.used_ports)
            self.used_ports.add(self.webdriver_port)

        env = os.environ.copy()
        env["HOST_FILE"] = self.hosts_path
        env["RUST_BACKTRACE"] = "1"
        env["EMULATOR_REVERSE_FORWARD_PORTS"] = ",".join(
            str(port) for _protocol, ports in self.server_ports.items()
            for port in ports if port)

        debug_args, command = browser_command(
            self.binary, self.binary_args + [
                "--hard-fail",
                "--webdriver=%s" % self.webdriver_port,
                "about:blank",
            ], self.debug_info)

        if self.headless:
            command += ["--headless"]

        if self.ca_certificate_path:
            command += ["--certificate-path", self.ca_certificate_path]

        for stylesheet in self.user_stylesheets:
            command += ["--user-stylesheet", stylesheet]

        self.command = command

        self.command = debug_args + self.command

        if not self.debug_info or not self.debug_info.interactive:
            self.proc = ProcessHandler(self.command,
                                       processOutputLine=[self.on_output],
                                       env=env,
                                       storeOutput=False)
            self.proc.run()
        else:
            self.proc = subprocess.Popen(self.command, env=env)

        self.logger.debug("Servo Started")
Ejemplo n.º 13
0
def tooltool_download(manifest, run_local, raptor_dir):
    """Download a file from tooltool using the provided tooltool manifest"""
    def outputHandler(line):
        LOG.info(line)

    if run_local:
        command = [
            sys.executable, TOOLTOOL_PATH, "fetch", "-o", "-m", manifest
        ]
    else:
        # we want to use the tooltool cache in production
        if os.environ.get("TOOLTOOLCACHE") is not None:
            _cache = os.environ["TOOLTOOLCACHE"]
        else:
            # XXX top level dir? really?
            # that gets run locally on any platform
            # when you call ./mach python-test
            _cache = "/builds/tooltool_cache"

        command = [
            sys.executable,
            TOOLTOOL_PATH,
            "fetch",
            "-o",
            "-m",
            manifest,
            "-c",
            _cache,
        ]

    proc = ProcessHandler(command,
                          processOutputLine=outputHandler,
                          storeOutput=False,
                          cwd=raptor_dir)

    proc.run()

    try:
        proc.wait()
    except Exception:
        if proc.poll() is None:
            proc.kill(signal.SIGTERM)
Ejemplo n.º 14
0
    def _runCmd(self, args, timeout=None, retryLimit=None):
        """
        Runs a command using adb
        If timeout is specified, the process is killed after <timeout> seconds.

        returns: instance of ProcessHandler
        """
        retryLimit = retryLimit or self.retryLimit
        finalArgs = [self._adbPath]
        if self._serverHost is not None:
            finalArgs.extend(['-H', self._serverHost])
        if self._serverPort is not None:
            finalArgs.extend(['-P', str(self._serverPort)])
        if self._deviceSerial:
            finalArgs.extend(['-s', self._deviceSerial])
        finalArgs.extend(args)
        self._logger.debug("_runCmd - command: %s" % ' '.join(finalArgs))
        if not timeout:
            timeout = self.default_timeout

        def _timeout():
            self._logger.error("Timeout exceeded for _runCmd call '%s'" %
                               ' '.join(finalArgs))

        retries = 0
        proc = None
        while retries < retryLimit:
            proc = ProcessHandler(finalArgs,
                                  storeOutput=True,
                                  processOutputLine=self._log,
                                  onTimeout=_timeout)
            proc.run(timeout=timeout)
            proc.returncode = proc.wait()
            if proc.returncode is not None:
                break
            proc.kill()
            self._logger.warning("_runCmd failed for '%s'" %
                                 ' '.join(finalArgs))
            retries += 1
        if retries >= retryLimit:
            self._logger.warning("_runCmd exceeded all retries")
        return proc
Ejemplo n.º 15
0
    def _tooltool_fetch(self, manifest):
        def outputHandler(line):
            LOG.info(line)

        command = [
            sys.executable, TOOLTOOL_PATH, 'fetch', '-o', '-m', manifest
        ]

        proc = ProcessHandler(command,
                              processOutputLine=outputHandler,
                              storeOutput=False,
                              cwd=self.bindir)

        proc.run()

        try:
            proc.wait()
        except Exception:
            if proc.poll() is None:
                proc.kill(signal.SIGTERM)
Ejemplo n.º 16
0
    def run(self):
        self.reset()

        # Update the environment variables
        env = os.environ.copy()

        # disable "GC poisoning" Bug# 1499043
        env['JSGC_DISABLE_POISONING'] = '1'

        process_args = {
            'cmd': self.command,
            'cwd': self.path,
            'onFinish': self.collect_results,
            'processOutputLine': self.process_line,
            'stream': sys.stdout,
            'env': env,
        }
        proc = ProcessHandler(**process_args)
        proc.run()
        return proc.wait()
Ejemplo n.º 17
0
def _verify_kvm(substs):
    # 'emulator -accel-check' should produce output like:
    # accel:
    # 0
    # KVM (version 12) is installed and usable
    # accel
    emulator_path = _find_sdk_exe(substs, 'emulator', True)
    if not emulator_path:
        emulator_path = 'emulator'
    command = [emulator_path, '-accel-check']
    try:
        p = ProcessHandler(command, storeOutput=True)
        p.run()
        p.wait()
        out = p.output
        if 'is installed and usable' in ''.join(out):
            return
    except Exception as e:
        _log_warning(str(e))
    _log_warning("Unable to verify kvm acceleration!")
    _log_warning("The x86 emulator may fail to start without kvm.")
Ejemplo n.º 18
0
    def run(self):
        self.reset()

        # Update the environment variables
        env = os.environ.copy()

        # disable "GC poisoning" Bug# 1499043
        env["JSGC_DISABLE_POISONING"] = "1"

        process_args = {
            "cmd": self.command,
            "cwd": self.path,
            "onFinish": self.collect_results,
            "processOutputLine": self.process_line,
            "stream": sys.stdout,
            "env": env,
            "universal_newlines": True,
        }
        proc = ProcessHandler(**process_args)
        proc.run()
        return proc.wait()
Ejemplo n.º 19
0
    def start_mitmproxy_playback(self, mitmdump_path, browser_path):
        """Startup mitmproxy and replay the specified flow file"""
        if self.mitmproxy_proc is not None:
            raise Exception("Proxy already started.")
        LOG.info("mitmdump path: %s" % mitmdump_path)
        LOG.info("browser path: %s" % browser_path)

        # mitmproxy needs some DLL's that are a part of Firefox itself, so add to path
        env = os.environ.copy()
        env["PATH"] = os.path.dirname(browser_path) + os.pathsep + env["PATH"]
        command = [mitmdump_path]

        if "playback_tool_args" in self.config:
            command.extend(self.config["playback_tool_args"])

        LOG.info("Starting mitmproxy playback using env path: %s" %
                 env["PATH"])
        LOG.info("Starting mitmproxy playback using command: %s" %
                 " ".join(command))
        # to turn off mitmproxy log output, use these params for Popen:
        # Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env)
        self.mitmproxy_proc = ProcessHandler(command,
                                             logfile=os.path.join(
                                                 self.upload_dir,
                                                 "mitmproxy.log"),
                                             env=env)
        self.mitmproxy_proc.run()
        end_time = time.time() + MITMDUMP_COMMAND_TIMEOUT
        ready = False
        while time.time() < end_time:
            ready = self.check_proxy()
            if ready:
                LOG.info("Mitmproxy playback successfully started as pid %d" %
                         self.mitmproxy_proc.pid)
                return
            time.sleep(0.25)
        # cannot continue as we won't be able to playback the pages
        LOG.error("Aborting: Mitmproxy process did not startup")
        self.stop_mitmproxy_playback()
        sys.exit()  # XXX why do we need to do that? a raise is not enough?
Ejemplo n.º 20
0
def lint(files, config, **kwargs):
    tests_dir = os.path.join(kwargs['root'], 'testing', 'web-platform',
                             'tests')

    def process_line(line):
        try:
            data = json.loads(line)
        except ValueError:
            return

        data["level"] = "error"
        data["path"] = os.path.relpath(os.path.join(tests_dir, data["path"]),
                                       kwargs['root'])
        data.setdefault("lineno", 0)
        results.append(result.from_config(config, **data))

    if files == [tests_dir]:
        print(
            "No specific files specified, running the full wpt lint"
            " (this is slow)",
            file=sys.stderr)
        files = ["--all"]
    cmd = [os.path.join(tests_dir, 'wpt'), 'lint', '--json'] + files
    if platform.system() == 'Windows':
        cmd.insert(0, sys.executable)

    proc = ProcessHandler(cmd, env=os.environ, processOutputLine=process_line)
    proc.run()
    try:
        proc.wait()
        if proc.returncode != 0:
            results.append(
                result.from_config(
                    config,
                    message="Lint process exited with return code %s" %
                    proc.returncode))
    except KeyboardInterrupt:
        proc.kill()

    return results
Ejemplo n.º 21
0
    def start(self):
        """
        Starts a new emulator.
        """
        if self.proc:
            return

        original_devices = set(self._get_online_devices())

        # QEMU relies on atexit() to remove temporary files, which does not
        # work since mozprocess uses SIGKILL to kill the emulator process.
        # Use a customized temporary directory so we can clean it up.
        os.environ['ANDROID_TMP'] = self.tmpdir

        qemu_log = None
        qemu_proc_args = {}
        if self.logdir:
            # save output from qemu to logfile
            qemu_log = os.path.join(self.logdir, 'qemu.log')
            if os.path.isfile(qemu_log):
                self._rotate_log(qemu_log)
            qemu_proc_args['logfile'] = qemu_log
        else:
            qemu_proc_args['processOutputLine'] = lambda line: None
        self.proc = ProcessHandler(self.args, **qemu_proc_args)
        self.proc.run()

        devices = set(self._get_online_devices())
        now = datetime.datetime.now()
        while (devices - original_devices) == set([]):
            time.sleep(1)
            # Sometimes it takes more than 60s to launch emulator, so we
            # increase timeout value to 180s. Please see bug 1143380.
            if datetime.datetime.now() - now > datetime.timedelta(seconds=180):
                raise TimeoutException(
                    'timed out waiting for emulator to start')
            devices = set(self._get_online_devices())
        devices = devices - original_devices
        self.serial = devices.pop()
        self.connect()
Ejemplo n.º 22
0
    def run(self, metadata):
        self.metadata = metadata

        self.info("Setting up the proxy")
        # replace with artifacts
        self.output_handler = OutputHandler()
        self.proxy = ProcessHandler(
            [
                "mozproxy",
                "--local",
                "--binary=" + self.mach_cmd.get_binary_path(),
                "--topsrcdir=" + self.mach_cmd.topsrcdir,
                "--objdir=" + self.mach_cmd.topobjdir,
                os.path.join(HERE, "example.dump"),
            ],
            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
Ejemplo n.º 23
0
    def run_process(self, cmd, cwd=None, dump=False):
        def _processOutput(line):
            if self.verbose or dump:
                print(line)

        if self.verbose:
            self.build_obj.log(logging.INFO, "autophone", {},
                               "Running '%s' in '%s'" % (cmd, cwd))
        proc = ProcessHandler(cmd, cwd=cwd, processOutputLine=_processOutput,
                              processStderrLine=_processOutput)
        proc.run()
        proc_complete = False
        try:
            proc.wait()
            if proc.proc.returncode == 0:
                proc_complete = True
        except Exception:
            if proc.poll() is None:
                proc.kill(signal.SIGTERM)
        if not proc_complete:
            if not self.verbose:
                print(proc.output)
        return proc_complete
Ejemplo n.º 24
0
    def _runCmd(self, args, retryLimit=None):
        """
        Runs a command using adb

        returns: instance of ProcessHandler
        """
        retryLimit = retryLimit or self.retryLimit
        finalArgs = [self._adbPath]
        if self._deviceSerial:
            finalArgs.extend(['-s', self._deviceSerial])
        finalArgs.extend(args)
        self._logger.debug("_runCmd - command: %s" % ' '.join(finalArgs))
        retries = 0
        while retries < retryLimit:
            proc = ProcessHandler(finalArgs, storeOutput=True,
                    processOutputLine=self._log)
            proc.run()
            proc.returncode = proc.wait()
            if proc.returncode == None:
                proc.kill()
                retries += 1
            else:
                return proc
Ejemplo n.º 25
0
def test_all_js(tests, options):
    print "Running JS Tests"
    # We run each test in its own instance since these are harness tests.
    # That just seems safer, no opportunity for cross-talk since
    # we are sorta using the framework to test itself
    results = JSResults()

    for t in tests:

        # write a temporary manifest
        manifest = TestManifest()
        manifest.tests = [t]
        fd, filename = tempfile.mkstemp(suffix='.ini')
        os.close(fd)
        fp = file(filename, 'w')
        manifest.write(fp=fp)
        fp.close()

        # get CLI arguments to mozmill
        args = []
        if options.binary:
            args.extend(['-b', options.binary])
        args.append('--console-level=DEBUG')        
        args.append('-m')
        args.append(filename)

        # run the test
        proc = ProcessHandler("mozmill", args=args)
        proc.run()
        status = proc.waitForFinish(timeout=300)
        command = proc.commandline
        results.acquire(t['name'], proc.output, status, command)

        # remove the temporary manifest
        os.remove(filename)
        
    return results
Ejemplo n.º 26
0
def lint(files, config, **kwargs):
    tests_dir = os.path.join(kwargs['root'], 'testing', 'web-platform', 'tests')

    def process_line(line):
        try:
            data = json.loads(line)
        except ValueError:
            return
        data["level"] = "error"
        data["path"] = os.path.relpath(os.path.join(tests_dir, data["path"]), kwargs['root'])
        results.append(result.from_config(config, **data))

    cmd = [os.path.join(tests_dir, 'wpt'), 'lint', '--json'] + files
    if platform.system() == 'Windows':
        cmd.insert(0, sys.executable)

    proc = ProcessHandler(cmd, env=os.environ, processOutputLine=process_line)
    proc.run()
    try:
        proc.wait()
    except KeyboardInterrupt:
        proc.kill()

    return results
Ejemplo n.º 27
0
    def start(self):
        """
           Launch the emulator.
        """
        if os.path.exists(EMULATOR_AUTH_FILE):
            os.remove(EMULATOR_AUTH_FILE)
            _log_debug("deleted %s" % EMULATOR_AUTH_FILE)
        # create an empty auth file to disable emulator authentication
        auth_file = open(EMULATOR_AUTH_FILE, 'w')
        auth_file.close()

        def outputHandler(line):
            self.emulator_log.write("<%s>\n" % line)

        env = os.environ
        env['ANDROID_AVD_HOME'] = os.path.join(EMULATOR_HOME_DIR, "avd")
        command = [
            self.emulator_path, "-avd", self.avd_info.name, "-port", "5554"
        ]
        if self.avd_info.extra_args:
            # -enable-kvm option is not valid on OSX
            if _get_host_platform(
            ) == 'macosx64' and '-enable-kvm' in self.avd_info.extra_args:
                self.avd_info.extra_args.remove('-enable-kvm')
            command += self.avd_info.extra_args
        log_path = os.path.join(EMULATOR_HOME_DIR, 'emulator.log')
        self.emulator_log = open(log_path, 'w')
        _log_debug("Starting the emulator with this command: %s" %
                   ' '.join(command))
        _log_debug("Emulator output will be written to '%s'" % log_path)
        self.proc = ProcessHandler(command,
                                   storeOutput=False,
                                   processOutputLine=outputHandler,
                                   env=env)
        self.proc.run()
        _log_debug("Emulator started with pid %d" % int(self.proc.proc.pid))
Ejemplo n.º 28
0
    def screenshot(self, test):
        full_url = self.test_url(test)

        with TempFilename(self.tempdir) as output_path:
            self.command = [
                self.binary, "--cpu", "--hard-fail", "--exit",
                "--output=%s" % output_path, full_url
            ]

            self.proc = ProcessHandler(self.command,
                                       processOutputLine=[self.on_output])
            self.proc.run()
            rv = self.proc.wait(timeout=test.timeout)
            if rv is None:
                self.proc.kill()
                return False, ("EXTERNAL-TIMEOUT", None)

            if rv != 0 or not os.path.exists(output_path):
                return False, ("CRASH", None)

            with open(output_path) as f:
                # Might need to strip variable headers or something here
                data = f.read()
                return True, data
Ejemplo n.º 29
0
def test_run(install_mozproxy):
    build = install_mozproxy
    output_handler = OutputHandler()
    p = ProcessHandler(
        ["mozproxy",
         "--local",
         "--binary=firefox",
         "--topsrcdir=" + build.topsrcdir,
         "--objdir=" + build.topobjdir,
         os.path.join(here, "example.dump")],
        processOutputLine=output_handler,
        onFinish=output_handler.finished,
    )
    p.run()
    # The first time we run mozproxy, we need to fetch mitmproxy, which can
    # take a while...
    assert output_handler.port_event.wait(120) is True
    # Give mitmproxy a bit of time to start up so we can verify that it's
    # actually running before we kill mozproxy.
    time.sleep(5)
    _kill_mozproxy(p.pid)

    assert p.wait(10) == 0
    assert output_handler.port is not None
Ejemplo n.º 30
0
    def screenshot(self, test):
        full_url = self.test_url(test)

        with TempFilename(self.tempdir) as output_path:
            self.command = [
                self.binary, "--cpu", "--hard-fail", "--exit", "-u",
                "Servo/wptrunner", "-Z", "disable-text-aa",
                "--output=%s" % output_path, full_url
            ]

            env = os.environ.copy()
            env["HOST_FILE"] = self.hosts_path

            self.proc = ProcessHandler(self.command,
                                       processOutputLine=[self.on_output],
                                       env=env)

            try:
                self.proc.run()
                timeout = test.timeout * self.timeout_multiplier + 5
                rv = self.proc.wait(timeout=timeout)
            except KeyboardInterrupt:
                self.proc.kill()
                raise

            if rv is None:
                self.proc.kill()
                return False, ("EXTERNAL-TIMEOUT", None)

            if rv != 0 or not os.path.exists(output_path):
                return False, ("CRASH", None)

            with open(output_path) as f:
                # Might need to strip variable headers or something here
                data = f.read()
                return True, base64.b64encode(data)