Commit 23bd952b authored by Peter Hutterer's avatar Peter Hutterer
Browse files

xserver: add WaitForConnections()



Moved from Environment to XServer class
Signed-off-by: Peter Hutterer's avatarPeter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: default avatarChase Douglas <chase.douglas@canonical.com>
parent b0417d54
......@@ -46,6 +46,11 @@ class XServer : public xorg::testing::Process {
public:
XServer();
/**
* Waits until this server is ready to take connections.
*/
void WaitForConnections(void);
/**
* Set the display number for this server. This number must be set
* before the server is started to have any effect.
......
......@@ -150,40 +150,9 @@ void xorg::testing::Environment::SetUp() {
"-logfile", d_->path_to_log_file.c_str(),
"-config", d_->path_to_conf.c_str(),
NULL);
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() {
......
......@@ -43,6 +43,7 @@
#include <vector>
#include <map>
#include <X11/Xlib.h>
#include <X11/extensions/XInput2.h>
struct xorg::testing::XServer::Private {
......@@ -212,6 +213,40 @@ 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().c_str());
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_->options["-logfile"];
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::XServer::SetOption(const std::string &key, const std::string &value) {
d_->options[key] = value;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment