summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2012-10-25 13:17:35 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2012-10-29 08:53:42 +1000
commit2e70aa20844a877c9148c7ba29c25710b2bd4624 (patch)
tree1b30927e101046de068fd9f78a208fc7a4daca39 /test
parent55eaaec2383fa67eb42e06cf094327481b77a8d9 (diff)
xserver: add XORG_GTEST_XSERVER_KEEPALIVE environment variable
If set, XServer will ignore Terminate() and Kill() requests, and will not die if the parent process dies. This enables a user to hook up gdb to a server, wait for the test case to trigger some code in the server and continue debugging from there, without the test case terminating the server. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Chase Douglas <chase.douglas@ubuntu.com>
Diffstat (limited to 'test')
-rw-r--r--test/xserver-test.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/test/xserver-test.cpp b/test/xserver-test.cpp
index 4088baa..ccbc2e9 100644
--- a/test/xserver-test.cpp
+++ b/test/xserver-test.cpp
@@ -207,6 +207,73 @@ TEST(XServer, IOErrorException)
}, XIOError);
}
+TEST(XServer, KeepAlive)
+{
+ XORG_TESTCASE("If XORG_GTEST_XSERVER_KEEPALIVE is set,\n"
+ "XServer::Terminate() and XServer::Kill() have no "
+ "effect");
+
+ int pipefd[2];
+ ASSERT_NE(pipe(pipefd), -1);
+
+ if (fork() == 0) {
+ close(pipefd[0]);
+
+ ASSERT_EQ(setenv("XORG_GTEST_XSERVER_KEEPALIVE", "1", 1), 0);
+ ASSERT_TRUE(getenv("XORG_GTEST_XSERVER_KEEPALIVE") != NULL);
+
+ XServer server;
+ server.SetOption("-logfile", "/tmp/Xorg-keepalive.log");
+ server.SetOption("-noreset", "");
+ server.Start();
+ ASSERT_EQ(server.GetState(), Process::RUNNING);
+ ::Display *dpy = XOpenDisplay(server.GetDisplayString().c_str());
+ ASSERT_TRUE(dpy != NULL);
+
+ server.Terminate();
+ ASSERT_EQ(server.GetState(), Process::RUNNING);
+ server.Kill();
+ ASSERT_EQ(server.GetState(), Process::RUNNING);
+
+ char *buffer;
+ ASSERT_GT(asprintf(&buffer, "%d", server.Pid()), 0);
+ ASSERT_EQ(write(pipefd[1], buffer, strlen(buffer)), (int)strlen(buffer));
+ close(pipefd[1]);
+ free(buffer);
+ return;
+ }
+
+ sigset_t sig_mask;
+ sigemptyset(&sig_mask);
+ sigaddset(&sig_mask, SIGCHLD);
+ struct timespec tv = { 1, 0 };
+ sigprocmask(SIG_BLOCK, &sig_mask, NULL);
+
+ /* parent */
+ close(pipefd[1]);
+
+ char buffer[20] = {0};
+ ASSERT_GT(read(pipefd[0], buffer, sizeof(buffer)), 0);
+ close(pipefd[0]);
+
+ /* wait for forked child to die */
+ ASSERT_EQ(sigtimedwait(&sig_mask, NULL, &tv), SIGCHLD);
+
+ pid_t server_pid = atoi(buffer);
+
+ /* server must still be running, kill it */
+ ASSERT_EQ(kill(server_pid, 0), 0);
+ kill(server_pid, SIGTERM);
+
+ int i = 0;
+
+ while(kill(server_pid, 0) == 0 && i++ < 10)
+ usleep(50000);
+
+ ASSERT_EQ(kill(server_pid, 0), -1);
+ ASSERT_EQ(errno, ESRCH);
+}
+
int main(int argc, char *argv[]) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();