[PATCH xorg-gtest 4/4] test: add helper program for process termination issue

Peter Hutterer peter.hutterer at who-t.net
Sun Oct 7 19:47:35 PDT 2012


Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 test/Makefile.am             | 12 ++++++++++--
 test/process-test-helper.cpp | 16 ++++++++++++++++
 test/process-test.cpp        | 30 ++++++++++++++++++++++++++++++
 3 files changed, 56 insertions(+), 2 deletions(-)
 create mode 100644 test/process-test-helper.cpp

diff --git a/test/Makefile.am b/test/Makefile.am
index 4f847b3..12c9c6a 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -25,7 +25,12 @@
 # SOFTWARE.
 #
 
-noinst_PROGRAMS = process-test xserver-test device-test
+test_programs = process-test \
+		xserver-test \
+		device-test
+
+noinst_PROGRAMS = $(test_programs) \
+		  process-test-helper
 noinst_DATA = PIXART-USB-OPTICAL-MOUSE.desc
 
 AM_CPPFLAGS = $(GTEST_CPPFLAGS)
@@ -43,6 +48,9 @@ process_test_SOURCES = process-test.cpp
 process_test_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/include
 process_test_LDADD =  $(tests_libraries)
 
+process_test_helper_SOURCES = process-test-helper.cpp
+process_test_helper_CPPFLAGS = $(AM_CPPFLAGS)
+
 xserver_test_SOURCES = xserver-test.cpp
 xserver_test_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/include
 xserver_test_LDADD =  $(tests_libraries)
@@ -68,5 +76,5 @@ libxorg_gtest_a_CPPFLAGS = \
 libxorg_gtest_a_CXXFLAGS = $(GTEST_CXXFLAGS) $(AM_CXXFLAGS)
 
 if ENABLE_XORG_GTEST_TESTS
-TESTS = $(noinst_PROGRAMS)
+TESTS = $(test_programs)
 endif
diff --git a/test/process-test-helper.cpp b/test/process-test-helper.cpp
new file mode 100644
index 0000000..aa1b3da
--- /dev/null
+++ b/test/process-test-helper.cpp
@@ -0,0 +1,16 @@
+/**
+ * Helper program for Process::Terminate() failure.
+ * Program ignores SIGTERM and goes to sleep. Sends SIGUSR1 to caller to
+ * signal that it's ready.
+ */
+#include <signal.h>
+#include <unistd.h>
+#include <stdio.h>
+
+int main(void) {
+  signal(SIGTERM, SIG_IGN);
+  kill(getppid(), SIGUSR1);
+  sleep(100);
+
+  return 0;
+}
diff --git a/test/process-test.cpp b/test/process-test.cpp
index 8646c12..06f3bd9 100644
--- a/test/process-test.cpp
+++ b/test/process-test.cpp
@@ -2,6 +2,7 @@
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <string.h>
 
 #include <gtest/gtest.h>
 #include <xorg/gtest/xorg-gtest.h>
@@ -108,6 +109,35 @@ TEST(Process, ChildTearDown)
   }
 }
 
+TEST(Process, TerminationFailure)
+{
+  SCOPED_TRACE("TESTCASE: if Process::Terminate() fails to terminate the \n"
+               "child process, kill must terminate it it instead");
+
+  sigset_t sig_mask;
+  sigset_t old_mask;
+  struct timespec sig_timeout = {0, 5000000L};
+
+  sigemptyset(&sig_mask);
+  sigaddset(&sig_mask, SIGUSR1);
+
+  sigprocmask(SIG_BLOCK, &sig_mask, &old_mask);
+
+  Process p;
+  p.Start(TEST_ROOT_DIR "process-test-helper", NULL);
+  if (sigtimedwait(&sig_mask, NULL, &sig_timeout) != SIGUSR1)
+    FAIL() << "Failed to wait for SIGUSR1: " << strerror(errno);
+
+  if (sigismember(&old_mask, SIGUSR1))
+      sigprocmask(SIG_UNBLOCK, &sig_mask, NULL);
+
+  ASSERT_GT(p.Pid(), 0);
+  kill(p.Pid(), SIGSTOP);
+
+  ASSERT_FALSE(p.Terminate(100));
+  ASSERT_EQ(p.GetState(), Process::RUNNING);
+  ASSERT_TRUE(p.Kill(100));
+}
 
 int main(int argc, char *argv[]) {
   testing::InitGoogleTest(&argc, argv);
-- 
1.7.11.4



More information about the xorg-devel mailing list