summaryrefslogtreecommitdiffstats
path: root/vespalib/src/tests/signalhandler
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /vespalib/src/tests/signalhandler
Publish
Diffstat (limited to 'vespalib/src/tests/signalhandler')
-rw-r--r--vespalib/src/tests/signalhandler/.gitignore6
-rw-r--r--vespalib/src/tests/signalhandler/CMakeLists.txt14
-rw-r--r--vespalib/src/tests/signalhandler/DESC1
-rw-r--r--vespalib/src/tests/signalhandler/FILES2
-rw-r--r--vespalib/src/tests/signalhandler/signalhandler_test.cpp35
-rw-r--r--vespalib/src/tests/signalhandler/victim.cpp21
6 files changed, 79 insertions, 0 deletions
diff --git a/vespalib/src/tests/signalhandler/.gitignore b/vespalib/src/tests/signalhandler/.gitignore
new file mode 100644
index 00000000000..a83ef5b3648
--- /dev/null
+++ b/vespalib/src/tests/signalhandler/.gitignore
@@ -0,0 +1,6 @@
+.depend
+Makefile
+signalhandler_test
+victim
+vespalib_signalhandler_test_app
+vespalib_victim_app
diff --git a/vespalib/src/tests/signalhandler/CMakeLists.txt b/vespalib/src/tests/signalhandler/CMakeLists.txt
new file mode 100644
index 00000000000..20339d16ebe
--- /dev/null
+++ b/vespalib/src/tests/signalhandler/CMakeLists.txt
@@ -0,0 +1,14 @@
+# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+vespa_add_executable(vespalib_signalhandler_test_app
+ SOURCES
+ signalhandler_test.cpp
+ DEPENDS
+ vespalib
+)
+vespa_add_test(NAME vespalib_signalhandler_test_app NO_VALGRIND COMMAND vespalib_signalhandler_test_app)
+vespa_add_executable(vespalib_victim_app
+ SOURCES
+ victim.cpp
+ DEPENDS
+ vespalib
+)
diff --git a/vespalib/src/tests/signalhandler/DESC b/vespalib/src/tests/signalhandler/DESC
new file mode 100644
index 00000000000..72cddf8a8f2
--- /dev/null
+++ b/vespalib/src/tests/signalhandler/DESC
@@ -0,0 +1 @@
+signalhandler test. Take a look at signalhandler.cpp for details.
diff --git a/vespalib/src/tests/signalhandler/FILES b/vespalib/src/tests/signalhandler/FILES
new file mode 100644
index 00000000000..85c709cf5ac
--- /dev/null
+++ b/vespalib/src/tests/signalhandler/FILES
@@ -0,0 +1,2 @@
+signalhandler.cpp
+victim.cpp
diff --git a/vespalib/src/tests/signalhandler/signalhandler_test.cpp b/vespalib/src/tests/signalhandler/signalhandler_test.cpp
new file mode 100644
index 00000000000..2aa0445a339
--- /dev/null
+++ b/vespalib/src/tests/signalhandler/signalhandler_test.cpp
@@ -0,0 +1,35 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespa/fastos/fastos.h>
+#include <vespa/log/log.h>
+LOG_SETUP("signalhandler_test");
+#include <vespa/vespalib/testkit/testapp.h>
+#include <vespa/vespalib/util/signalhandler.h>
+
+using namespace vespalib;
+
+TEST_SETUP(Test);
+
+int
+Test::Main()
+{
+ TEST_INIT("signalhandler_test");
+ EXPECT_TRUE(!SignalHandler::INT.check());
+ EXPECT_TRUE(!SignalHandler::TERM.check());
+ SignalHandler::INT.ignore();
+ EXPECT_TRUE(!SignalHandler::INT.check());
+ EXPECT_TRUE(!SignalHandler::TERM.check());
+ SignalHandler::TERM.hook();
+ EXPECT_TRUE(!SignalHandler::INT.check());
+ EXPECT_TRUE(!SignalHandler::TERM.check());
+ kill(getpid(), SIGINT);
+ EXPECT_TRUE(!SignalHandler::INT.check());
+ EXPECT_TRUE(!SignalHandler::TERM.check());
+ kill(getpid(), SIGTERM);
+ EXPECT_TRUE(!SignalHandler::INT.check());
+ EXPECT_TRUE(SignalHandler::TERM.check());
+ SignalHandler::TERM.clear();
+ EXPECT_TRUE(!SignalHandler::INT.check());
+ EXPECT_TRUE(!SignalHandler::TERM.check());
+ EXPECT_EQUAL(0, system("res=`./vespalib_victim_app`; test \"$res\" = \"GOT TERM\""));
+ TEST_DONE();
+}
diff --git a/vespalib/src/tests/signalhandler/victim.cpp b/vespalib/src/tests/signalhandler/victim.cpp
new file mode 100644
index 00000000000..fe42489006c
--- /dev/null
+++ b/vespalib/src/tests/signalhandler/victim.cpp
@@ -0,0 +1,21 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespa/fastos/fastos.h>
+#include <vespa/vespalib/util/signalhandler.h>
+
+using vespalib::SignalHandler;
+
+int main(int argc, char **argv) {
+ (void) argc;
+ (void) argv;
+ SignalHandler::TERM.hook();
+ kill(getpid(), SIGTERM);
+ if (SignalHandler::TERM.check()) {
+ fprintf(stdout, "GOT TERM\n");
+ fflush(stdout);
+ }
+ SignalHandler::TERM.unhook();
+ kill(getpid(), SIGTERM);
+ fprintf(stdout, "SURVIVED TERM\n");
+ fflush(stdout);
+ return 0;
+}