summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2012-09-26 14:43:08 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2012-10-08 11:38:17 +1000
commitcb076239a970f4b19994a22567f3ff799abf9d8f (patch)
tree35925724518fa29ed1adf0aa09855a5375061709
parentd7290f99c10b6bb27ed5f29c3875d6097afe367b (diff)
test: add helper program for process termination issueprocess-kill
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r--test/Makefile.am12
-rw-r--r--test/process-test-helper.cpp16
-rw-r--r--test/process-test.cpp30
3 files changed, 56 insertions, 2 deletions
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);