[PATCH xorg-gtest v2 6/8] xserver: move Terminate and Kill handling here
Peter Hutterer
peter.hutterer at who-t.net
Tue Jul 10 20:28:46 PDT 2012
Rename to TerminateAndCheck/KillAndCheck to signal that we're waiting for
the process to shut down instead of just sending the respective signals
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
Changes to v1:
- rename to *AndCheck
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 f31ce8a..5eb402e 100644
--- a/include/xorg/gtest/xorg-gtest-xserver.h
+++ b/include/xorg/gtest/xorg-gtest-xserver.h
@@ -55,6 +55,19 @@ class XServer : public xorg::testing::Process {
void Start(std::string program = std::string());
/**
+ * 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 TerminateAndCheck(void);
+
+ /**
+ * Kills the server. With a vengeance.
+ */
+ bool KillAndCheck(void);
+
+ /**
* Waits until this server is ready to take connections.
*/
void WaitForConnections(void);
diff --git a/src/environment.cpp b/src/environment.cpp
index 608abaf..64907e5 100644
--- a/src/environment.cpp
+++ b/src/environment.cpp
@@ -116,37 +116,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.TerminateAndCheck())
+ 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.KillAndCheck();
}
diff --git a/src/xserver.cpp b/src/xserver.cpp
index f263c63..4d98c10 100644
--- a/src/xserver.cpp
+++ b/src/xserver.cpp
@@ -313,6 +313,40 @@ void xorg::testing::XServer::Start(std::string program) {
Process::Start(program, args);
}
+bool xorg::testing::XServer::TerminateAndCheck(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::KillAndCheck(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;
+}
+
void xorg::testing::XServer::SetOption(std::string key, std::string value) {
d_->options[key] = value;
}
--
1.7.10.4
More information about the xorg-devel
mailing list