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-10 08:24:38 +1000
commitf6849f693afd68f1041f58da15fced61fbe14c73 (patch)
tree8868642a06571c96260b5b2c323b40a9b01070f5
parent32cb0cf72dfb6396ba34c6921745743827f08b5d (diff)
test: add helper program for process termination issue
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Chase Douglas <chase.douglas@ubuntu.com>
-rw-r--r--test/Makefile.am12
-rw-r--r--test/process-test-helper.cpp10
-rw-r--r--test/process-test.cpp24
3 files changed, 44 insertions, 2 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index df671a4..487c534 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
GTEST_CPPFLAGS=-I$(top_srcdir)/gtest/include -I$(top_srcdir)/gtest
@@ -45,6 +50,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)
@@ -70,5 +78,5 @@ libxorg_gtest_a_CPPFLAGS = \
libxorg_gtest_a_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..6332950
--- /dev/null
+++ b/test/process-test-helper.cpp
@@ -0,0 +1,10 @@
+#include <signal.h>
+#include <unistd.h>
+
+int main(void) {
+
+ signal(SIGTERM, SIG_IGN);
+ sleep(100);
+
+ return 0;
+}
diff --git a/test/process-test.cpp b/test/process-test.cpp
index 8646c12..964a97d 100644
--- a/test/process-test.cpp
+++ b/test/process-test.cpp
@@ -108,6 +108,30 @@ 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;
+ struct timespec sig_timeout = {0, 5000000L};
+
+ sigemptyset(&sig_mask);
+ sigaddset(&sig_mask, SIGUSR1);
+
+ Process p;
+ p.Start(TEST_ROOT_DIR "process-test-helper", NULL);
+ /* don't check error here, the helper may have sent the signal before we
+ get here */
+ sigtimedwait(&sig_mask, NULL, &sig_timeout);
+
+ 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);