summaryrefslogtreecommitdiffstats
path: root/vespalib/src/tests/exception_classes
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2016-09-05 07:41:34 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2016-09-05 07:41:34 +0000
commitffe0351586b3d50f477e59d6a9947cd1d1dedc44 (patch)
treee6c1cd4d9a5a10625da1f3a7d5e90b19db822b45 /vespalib/src/tests/exception_classes
parent848e0d73a13607cdb6265337157c1b6edd4837d1 (diff)
Only reinstate termination handler if exception is caught.
Diffstat (limited to 'vespalib/src/tests/exception_classes')
-rw-r--r--vespalib/src/tests/exception_classes/.gitignore1
-rw-r--r--vespalib/src/tests/exception_classes/CMakeLists.txt6
-rw-r--r--vespalib/src/tests/exception_classes/mmap.cpp22
-rw-r--r--vespalib/src/tests/exception_classes/silenceuncaught_test.cpp20
4 files changed, 48 insertions, 1 deletions
diff --git a/vespalib/src/tests/exception_classes/.gitignore b/vespalib/src/tests/exception_classes/.gitignore
index fe7001def80..c3805a2ff55 100644
--- a/vespalib/src/tests/exception_classes/.gitignore
+++ b/vespalib/src/tests/exception_classes/.gitignore
@@ -1,2 +1,3 @@
vespalib_exception_classes_test_app
vespalib_caught_uncaught_app
+vespalib_mmap_app
diff --git a/vespalib/src/tests/exception_classes/CMakeLists.txt b/vespalib/src/tests/exception_classes/CMakeLists.txt
index 134634252ff..94c6855fb78 100644
--- a/vespalib/src/tests/exception_classes/CMakeLists.txt
+++ b/vespalib/src/tests/exception_classes/CMakeLists.txt
@@ -19,3 +19,9 @@ vespa_add_executable(vespalib_caught_uncaught_app TEST
DEPENDS
vespalib
)
+vespa_add_executable(vespalib_mmap_app TEST
+ SOURCES
+ mmap.cpp
+ DEPENDS
+ vespalib
+)
diff --git a/vespalib/src/tests/exception_classes/mmap.cpp b/vespalib/src/tests/exception_classes/mmap.cpp
new file mode 100644
index 00000000000..56c2b5d8d67
--- /dev/null
+++ b/vespalib/src/tests/exception_classes/mmap.cpp
@@ -0,0 +1,22 @@
+#include <vespa/vespalib/util/alloc.h>
+
+using vespalib::MMapAlloc;
+
+int main(int argc, char *argv[]) {
+ if (argc != 4) {
+ return 77;
+ }
+ size_t virt = strtoul(argv[1], nullptr, 0);
+ size_t blockSize = strtoul(argv[2], nullptr, 0);
+ size_t numBlocks = strtoul(argv[3], nullptr, 0);
+ rlimit virtualLimit;
+ virtualLimit.rlim_cur = virt;
+ virtualLimit.rlim_max = virt;
+ assert(setrlimit(RLIMIT_AS, &virtualLimit) == 0);
+ std::vector<MMapAlloc> mappings;
+ for (size_t i(0); i < numBlocks; i++) {
+ mappings.emplace_back(blockSize);
+ memset(mappings.back().get(), 0xa5, mappings.back().size());
+ }
+ return 0;
+}
diff --git a/vespalib/src/tests/exception_classes/silenceuncaught_test.cpp b/vespalib/src/tests/exception_classes/silenceuncaught_test.cpp
index 7f6ae20ded9..3b1ba49de5c 100644
--- a/vespalib/src/tests/exception_classes/silenceuncaught_test.cpp
+++ b/vespalib/src/tests/exception_classes/silenceuncaught_test.cpp
@@ -5,7 +5,7 @@
using namespace vespalib;
-TEST("that uncaught exception causes exitcode 1") {
+TEST("that uncaught exception causes negative exitcode.") {
SlaveProc proc("./vespalib_caught_uncaught_app uncaught");
proc.wait();
EXPECT_LESS(proc.getExitCode(), 0);
@@ -23,4 +23,22 @@ TEST("that caught silenced exception causes exitcode 0") {
EXPECT_EQUAL(proc.getExitCode(), 0);
}
+TEST("that mmap within limits are fine cause exitcode 0") {
+ SlaveProc proc("./vespalib_mmap_app 100000000 10485760 1");
+ proc.wait();
+ EXPECT_EQUAL(proc.getExitCode(), 0);
+}
+
+TEST("that mmap beyond limits cause negative exitcode.") {
+ SlaveProc proc("./vespalib_mmap_app 100000000 10485760 10");
+ proc.wait();
+ EXPECT_LESS(proc.getExitCode(), 0);
+}
+
+TEST("that mmap beyond limits with set VESPA_SILENCE_CORE_ON_OOM cause exitcode 66.") {
+ SlaveProc proc("VESPA_SILENCE_CORE_ON_OOM=1 ./vespalib_mmap_app 100000000 10485760 10");
+ proc.wait();
+ EXPECT_EQUAL(proc.getExitCode(), 66);
+}
+
TEST_MAIN_WITH_PROCESS_PROXY() { TEST_RUN_ALL(); }