Beispiel #1
0
 def _test_connect(self, server_args=(), auth="none", client_args=(), password=None, uri_prefix=DISPLAY_PREFIX, exit_code=0):
     display_no = self.find_free_display_no()
     display = ":%s" % display_no
     log("starting test server on %s", display)
     server = self.start_server(display, "--auth=%s" % auth, "--printing=no", *server_args)
     #we should always be able to get the version:
     uri = uri_prefix + str(display_no)
     start = monotonic()
     while True:
         client = self.run_xpra(["version", uri] + list(server_args or ()))
         r = pollwait(client, CONNECT_WAIT)
         if r==0:
             break
         if r is None:
             client.terminate()
         if monotonic()-start>SUBPROCESS_WAIT:
             raise Exception("version client failed to connect, returned %s" % estr(r))
     #try to connect
     cmd = ["connect-test", uri] + [x.replace("$DISPLAY_NO", str(display_no)) for x in client_args]
     f = None
     if password:
         f = self._temp_file(password)
         cmd += ["--password-file=%s" % f.name]
         cmd += ["--challenge-handlers=file:filename=%s" % f.name]
     client = self.run_xpra(cmd)
     r = pollwait(client, SUBPROCESS_WAIT)
     if f:
         f.close()
     if r is None:
         client.terminate()
     server.terminate()
     if r!=exit_code:
         log.error("Exit code mismatch")
         log.error(" expected %s (%s)", estr(exit_code), exit_code)
         log.error(" got %s (%s)", estr(r), r)
         log.error(" server args=%s", server_args)
         log.error(" client args=%s", client_args)
         if r is None:
             raise Exception("expected info client to return %s but it is still running" % (estr(exit_code),))
         raise Exception("expected info client to return %s but got %s" % (estr(exit_code), estr(r)))
     pollwait(server, 10)
Beispiel #2
0
    def _test(self, subcommand, options):
        log("starting test server with options=%s", options)
        args = ["--%s=%s" % (k, v) for k, v in options.items()]
        tcp_port = None
        xvfb = None
        if WIN32 or OSX:
            display = ""
            connect_args = []
        elif self.display:
            display = self.display
            connect_args = [display]
            args.append("--use-display=yes")
        else:
            display = self.find_free_display()
            connect_args = [display]
            if subcommand == "shadow":
                xvfb = self.start_Xvfb(display)
        if TEST_RFB or WIN32:
            tcp_port = get_free_tcp_port()
            args += ["--bind-tcp=0.0.0.0:%i" % tcp_port]
            if WIN32:
                connect_args = ["tcp://127.0.0.1:%i" % tcp_port]
        server = None
        client = None
        rfb_client = None
        gui_client = None
        try:
            log("args=%s", " ".join("'%s'" % x for x in args))
            server = self.check_server(subcommand, display, *args)
            #we should always be able to get the version:
            client = self.run_xpra(["version"] + connect_args)
            assert pollwait(
                client, 5
            ) == 0, "version client failed to connect to server with args=%s" % args
            #run info query:
            cmd = ["info"] + connect_args
            client = self.run_xpra(cmd)
            r = pollwait(client, 20)
            assert r==0, "info client failed and returned %s: '%s' for server with args=%s" % \
                (r, EXIT_STR.get(r, r), args)

            client_kwargs = {}
            if not (WIN32 or OSX):
                env = self.get_run_env()
                env["DISPLAY"] = self.client_display
                client_kwargs = {"env": env}

            if subcommand in ("shadow",
                              "start-desktop") and TEST_RFB and options.get(
                                  "windows", True):
                vncviewer = which("vncviewer")
                log("testing RFB clients with vncviewer '%s'", vncviewer)
                if vncviewer:
                    rfb_cmd = [vncviewer, "localhost::%i" % tcp_port]
                    rfb_client = self.run_command(rfb_cmd, **client_kwargs)
                    r = pollwait(rfb_client, 10)
                    if r is not None:
                        self.show_proc_error(
                            rfb_client,
                            "rfb client terminated early and returned %i for server with args=%s"
                            % (r, args))

            #connect a gui client:
            if WIN32 or (self.client_display and self.client_xvfb):
                xpra_args = [
                    "attach",
                    "--clipboard=no",  #could create loops
                    "--notifications=no",  #may get sent to the desktop session running the tests!
                ] + connect_args
                gui_client = self.run_xpra(xpra_args, **client_kwargs)
                r = pollwait(gui_client, 10)
                if r is not None:
                    self.show_proc_error(
                        gui_client,
                        "gui client terminated early and returned %i : '%s' for server with args=%s"
                        % (r, EXIT_STR.get(r, r), args))

            if self.display:
                self.stop_server(server, "exit", *connect_args)
            else:
                self.stop_server(server, "stop", *connect_args)
            if display:
                if display in self.dotxpra.displays():
                    log.warn(
                        "server socket for display %s should have been removed",
                        display)

            if gui_client:
                r = pollwait(gui_client, 20)
                if r is None:
                    log.warn("client still connected!")
                    self.show_proc_pipes(server)
                    raise Exception("gui client should have been disconnected")
        except Exception:
            log.error("test error for '%s' subcommand with options=%s",
                      subcommand, options)
            raise
        finally:
            for x in (xvfb, rfb_client, gui_client, server, client):
                try:
                    if x and x.poll() is None:
                        x.terminate()
                except OSError:
                    log("%s.terminate()", exc_info=True)