[PATCH xorg-gtest 02/16] xserver: add WaitForConnections()

Chase Douglas chase.douglas at canonical.com
Tue Jul 3 09:19:02 PDT 2012


On 07/02/2012 11:44 PM, Peter Hutterer wrote:
> Moved from Environment to XServer class
>
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> ---
>   include/xorg/gtest/xorg-gtest-xserver.h |    5 +++++
>   src/environment.cpp                     |   34 +-----------------------------
>   src/xserver.cpp                         |   35 +++++++++++++++++++++++++++++++
>   3 files changed, 41 insertions(+), 33 deletions(-)
>
> diff --git a/include/xorg/gtest/xorg-gtest-xserver.h b/include/xorg/gtest/xorg-gtest-xserver.h
> index 78f72ce..c62970d 100644
> --- a/include/xorg/gtest/xorg-gtest-xserver.h
> +++ b/include/xorg/gtest/xorg-gtest-xserver.h
> @@ -47,6 +47,11 @@ class XServer : public xorg::testing::Process {
>       XServer();
>
>       /**
> +     * Waits until this server is ready to take connections.
> +     */
> +    void WaitForConnections(void);
> +
> +    /**
>        * @param [in] display_number The display number the server runs on
>        */
>       void SetDisplayNumber(unsigned int display_number);
> diff --git a/src/environment.cpp b/src/environment.cpp
> index 43e1e70..5e7a156 100644
> --- a/src/environment.cpp
> +++ b/src/environment.cpp
> @@ -147,42 +147,10 @@ void xorg::testing::Environment::SetUp() {
>                       "-logfile", d_->path_to_log_file.c_str(),
>                       "-config", d_->path_to_conf.c_str(),
>                       NULL);
> -
>     d_->server.SetDisplayNumber(d_->display);
> +  d_->server.WaitForConnections();
>
>     Process::SetEnv("DISPLAY", display_string, true);
> -
> -  for (int i = 0; i < 10; ++i) {
> -    test_display = XOpenDisplay(NULL);
> -
> -    if (test_display) {
> -      XCloseDisplay(test_display);
> -      return;
> -    }
> -
> -    int status;
> -    int pid = waitpid(d_->server.Pid(), &status, WNOHANG);
> -    if (pid == d_->server.Pid()) {
> -      std::string message;
> -      message += "X server failed to start on display ";
> -      message += display_string;
> -      message += ". Ensure that the \"dummy\" video driver is installed.\n"
> -                 "If the X.org server is older than 1.12, "
> -                 "tests will need to be run as root.\nCheck ";
> -      message += d_->path_to_log_file;
> -      message += " for any errors";
> -      throw std::runtime_error(message);
> -    } else if (pid == 0) {
> -      sleep(1); /* Give the dummy X server some time to start */
> -    } else if (pid == -1) {
> -      throw std::runtime_error("Could not get status of dummy X server "
> -                               "process");
> -    } else {
> -      throw std::runtime_error("Invalid child PID returned by Process::Wait()");
> -    }
> -  }
> -
> -  throw std::runtime_error("Unable to open connection to dummy X server");
>   }
>
>   void xorg::testing::Environment::TearDown() {
> diff --git a/src/xserver.cpp b/src/xserver.cpp
> index 28130d7..ba847f1 100644
> --- a/src/xserver.cpp
> +++ b/src/xserver.cpp
> @@ -41,6 +41,7 @@
>   #include <stdexcept>
>   #include <vector>
>
> +#include <X11/Xlib.h>
>   #include <X11/extensions/XInput2.h>
>
>   struct xorg::testing::XServer::Private {
> @@ -190,3 +191,37 @@ bool xorg::testing::XServer::WaitForDevice(::Display *display, const std::string
>
>       return false;
>   }
> +
> +void xorg::testing::XServer::WaitForConnections(void) {
> +  for (int i = 0; i < 10; ++i) {
> +    Display *test_display = XOpenDisplay(GetDisplayString());
> +
> +    if (test_display) {
> +      XCloseDisplay(test_display);
> +      return;
> +    }
> +
> +    int status;
> +    int pid = waitpid(Pid(), &status, WNOHANG);
> +    if (pid == Pid()) {
> +      std::string message;
> +      message += "X server failed to start on display ";
> +      message +=  GetDisplayString();
> +      message += ". Ensure that the \"dummy\" video driver is installed.\n"
> +                 "If the X.org server is older than 1.12, "
> +                 "tests will need to be run as root.\nCheck ";
> +      //message += d_->path_to_log_file;

How do you plan to fix this ^^?

If you get to it later on in the patch set, feel free to disregard :).

> +      message += " for any errors";
> +      throw std::runtime_error(message);
> +    } else if (pid == 0) {
> +      sleep(1); /* Give the dummy X server some time to start */
> +    } else if (pid == -1) {
> +      throw std::runtime_error("Could not get status of dummy X server "
> +                               "process");
> +    } else {
> +      throw std::runtime_error("Invalid child PID returned by Process::Wait()");
> +    }
> +  }
> +
> +  throw std::runtime_error("Unable to open connection to dummy X server");
> +}
>



More information about the xorg-devel mailing list