Commit 04d9fd13 authored by Peter Hutterer's avatar Peter Hutterer Committed by Chase Douglas
Browse files

xserver: move Terminate and Kill handling here



Same behaviour as Process, but with some more error messages
Signed-off-by: Peter Hutterer's avatarPeter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: default avatarChase Douglas <chase.douglas@canonical.com>
Signed-off-by: default avatarChase Douglas <chase.douglas@canonical.com>
parent cf9c6a9f
......@@ -152,7 +152,7 @@ class Process {
* @post If successful: Child process terminated.
* @post If successful: Subsequent calls to Pid() return -1.
*/
bool Terminate(unsigned int timeout = 0);
virtual bool Terminate(unsigned int timeout = 0);
/**
* Kills (SIGKILL) this child process and waits a given timeout for the
......@@ -170,7 +170,7 @@ class Process {
* @post If successful: Child process killed.
* @post If successful: Subsequent calls to Pid() return -1.
*/
bool Kill(unsigned int timeout = 0);
virtual bool Kill(unsigned int timeout = 0);
/**
* Accesses the pid of the child process.
......
......@@ -54,6 +54,31 @@ class XServer : public xorg::testing::Process {
*/
void Start(const std::string &program = "");
/**
* Terminates this server process. Will signal the server to terminate
* multiple times before giving up.
*
* @param [in] timeout The timeout in millis to wait for the process to
* terminate. A timeout of 0 implies not to wait but
* return immediately.
*
* @returns true if termination succeeded and, if a timout is given, the
* process shut down within that timeout. false otherwise.
*/
virtual bool Terminate(unsigned int timeout = 0);
/**
* Kills the server. With a vengeance.
*
* @param [in] timeout The timeout in millis to wait for the process to
* terminate. A timeout of 0 implies not to wait but
* return immediately.
*
* @returns true if kill succeeded and, if a timout is given, the
* process shut down within that timeout. false otherwise.
*/
virtual bool Kill(unsigned int timeout = 0);
/**
* Waits until this server is ready to take connections.
*/
......
......@@ -115,37 +115,12 @@ void xorg::testing::Environment::SetUp() {
}
void xorg::testing::Environment::TearDown() {
if (d_->server.Terminate()) {
for (int i = 0; i < 10; i++) {
int status;
int pid = waitpid(d_->server.Pid(), &status, WNOHANG);
if (pid == d_->server.Pid())
return;
sleep(1); /* Give the dummy X server more time to shut down */
}
}
Kill();
if (!d_->server.Terminate(1000))
Kill();
}
void xorg::testing::Environment::Kill() {
if (!d_->server.Kill())
std::cerr << "Warning: Failed to kill dummy Xorg server: "
<< std::strerror(errno) << "\n";
for (int i = 0; i < 10; i++) {
int status;
int pid = waitpid(d_->server.Pid(), &status, WNOHANG);
if (pid == d_->server.Pid())
return;
sleep(1); /* Give the dummy X server more time to shut down */
}
std::cerr << "Warning: Dummy X server did not shut down\n";
d_->server.Kill(1000);
}
......
......@@ -304,6 +304,24 @@ void xorg::testing::XServer::Start(const std::string &program) {
Process::Start(program.empty() ? d_->path_to_server : program, args);
}
bool xorg::testing::XServer::Terminate(unsigned int timeout) {
if (!Process::Terminate(timeout)) {
std::cerr << "Warning: Failed to terminate dummy Xorg server: "
<< std::strerror(errno) << "\n";
return false;
} else
return true;
}
bool xorg::testing::XServer::Kill(unsigned int timeout) {
if (!Process::Kill(timeout)) {
std::cerr << "Warning: Failed to kill dummy Xorg server: "
<< std::strerror(errno) << "\n";
return false;
} else
return true;
}
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