[PATCH xorg-gtest 06/16] xserver: move Terminate and Kill handling here

Peter Hutterer peter.hutterer at who-t.net
Mon Jul 2 23:44:47 PDT 2012


Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 include/xorg/gtest/xorg-gtest-xserver.h |   13 ++++++++++++
 src/environment.cpp                     |   31 +++-------------------------
 src/xserver.cpp                         |   34 +++++++++++++++++++++++++++++++
 3 files changed, 50 insertions(+), 28 deletions(-)

diff --git a/include/xorg/gtest/xorg-gtest-xserver.h b/include/xorg/gtest/xorg-gtest-xserver.h
index 52a2fd0..821b01f 100644
--- a/include/xorg/gtest/xorg-gtest-xserver.h
+++ b/include/xorg/gtest/xorg-gtest-xserver.h
@@ -53,6 +53,19 @@ class XServer : public xorg::testing::Process {
     void Start(std::string &program);
 
     /**
+     * Terminates this server process. Will signal the server to terminate
+     * multiple times before giving up.
+     *
+     * @return false if the server did not terminate, true otherwise
+     */
+    bool Terminate(void);
+
+    /**
+     * Kills the server. With a vengeance.
+     */
+    bool Kill(void);
+
+    /**
      * Waits until this server is ready to take connections.
      */
     void WaitForConnections(void);
diff --git a/src/environment.cpp b/src/environment.cpp
index 69972a4..b041236 100644
--- a/src/environment.cpp
+++ b/src/environment.cpp
@@ -116,35 +116,10 @@ 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())
+    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();
 }
diff --git a/src/xserver.cpp b/src/xserver.cpp
index 1a46dbb..bd1e2f9 100644
--- a/src/xserver.cpp
+++ b/src/xserver.cpp
@@ -298,3 +298,37 @@ void xorg::testing::XServer::Start(std::string &program) {
                  "-config", d_->path_to_conf.c_str(),
                  NULL);
 }
+
+bool xorg::testing::XServer::Terminate(void) {
+  if (Process::Terminate()) {
+    for (int i = 0; i < 10; i++) {
+      int status;
+      int pid = waitpid(Pid(), &status, WNOHANG);
+
+      if (pid == Pid())
+        return true;
+
+      sleep(1); /* Give the dummy X server more time to shut down */
+    }
+  }
+  return false;
+}
+
+bool xorg::testing::XServer::Kill(void) {
+  if (!Process::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(Pid(), &status, WNOHANG);
+
+    if (pid == Pid())
+      return true;
+
+      sleep(1); /* Give the dummy X server more time to shut down */
+  }
+
+  std::cerr << "Warning: Dummy X server did not shut down\n";
+  return false;
+}
-- 
1.7.10.4



More information about the xorg-devel mailing list