summaryrefslogtreecommitdiffstats
path: root/staging_vespalib/src/tests
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2018-12-06 21:04:05 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2018-12-06 21:04:05 +0000
commitc6011003d7866f62488a638a99c501b90efe7170 (patch)
treebbe94a51b61f9d8370696ebfc407a2d8051fff78 /staging_vespalib/src/tests
parentdfe58ec7ebb45281e994c54bced22c7add9c47de (diff)
Allow asserts that rember if they have been triggered before.
Diffstat (limited to 'staging_vespalib/src/tests')
-rw-r--r--staging_vespalib/src/tests/assert/.gitignore1
-rw-r--r--staging_vespalib/src/tests/assert/CMakeLists.txt16
-rw-r--r--staging_vespalib/src/tests/assert/assert_test.cpp30
-rw-r--r--staging_vespalib/src/tests/assert/asserter.cpp16
4 files changed, 63 insertions, 0 deletions
diff --git a/staging_vespalib/src/tests/assert/.gitignore b/staging_vespalib/src/tests/assert/.gitignore
new file mode 100644
index 00000000000..d0e23fcd846
--- /dev/null
+++ b/staging_vespalib/src/tests/assert/.gitignore
@@ -0,0 +1 @@
+staging_vespalib_asserter_app
diff --git a/staging_vespalib/src/tests/assert/CMakeLists.txt b/staging_vespalib/src/tests/assert/CMakeLists.txt
new file mode 100644
index 00000000000..88030680cfb
--- /dev/null
+++ b/staging_vespalib/src/tests/assert/CMakeLists.txt
@@ -0,0 +1,16 @@
+# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+vespa_add_executable(staging_vespalib_assert_test_app TEST
+ SOURCES
+ assert_test.cpp
+ DEPENDS
+ staging_vespalib
+)
+vespa_add_test(NAME staging_vespalib_assert_test_app COMMAND staging_vespalib_assert_test_app)
+
+vespa_add_executable(staging_vespalib_asserter_app TEST
+ SOURCES
+ asserter.cpp
+ DEPENDS
+ staging_vespalib
+)
diff --git a/staging_vespalib/src/tests/assert/assert_test.cpp b/staging_vespalib/src/tests/assert/assert_test.cpp
new file mode 100644
index 00000000000..d1a27fbf73c
--- /dev/null
+++ b/staging_vespalib/src/tests/assert/assert_test.cpp
@@ -0,0 +1,30 @@
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespa/vespalib/testkit/test_kit.h>
+#include <vespa/vespalib/util/slaveproc.h>
+#include <vespa/vespalib/util/stringfmt.h>
+#include <vespa/fastos/file.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <vespa/defaults.h>
+
+using namespace vespalib;
+
+TEST("that it borks the first time.") {
+ vespalib::string assertName = make_string("tmp/myassert.assert.%s", vespa::Defaults::vespaUser());
+ FastOS_File::EmptyAndRemoveDirectory("tmp");
+ ASSERT_EQUAL(0, mkdir("tmp", 0755));
+ {
+ SlaveProc proc("ulimit -c 0 && exec env VESPA_HOME=./ ./staging_vespalib_asserter_app myassert 10000");
+ proc.wait();
+ ASSERT_EQUAL(proc.getExitCode() & 0x7f, 6);
+ }
+ {
+ SlaveProc proc("ulimit -c 0 && exec env VESPA_HOME=./ ./staging_vespalib_asserter_app myassert 10000");
+ proc.wait();
+ ASSERT_EQUAL(proc.getExitCode() & 0x7f, 0);
+ }
+ ASSERT_EQUAL(0, unlink(assertName.c_str()));
+ ASSERT_EQUAL(0, rmdir("tmp"));
+}
+
+TEST_MAIN_WITH_PROCESS_PROXY() { TEST_RUN_ALL(); }
diff --git a/staging_vespalib/src/tests/assert/asserter.cpp b/staging_vespalib/src/tests/assert/asserter.cpp
new file mode 100644
index 00000000000..f1be7531575
--- /dev/null
+++ b/staging_vespalib/src/tests/assert/asserter.cpp
@@ -0,0 +1,16 @@
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespa/vespalib/util/assert.h>
+#include <cassert>
+#include <cstdlib>
+
+int main(int argc, char *argv[]) {
+ assert(argc == 3);
+ const char * assertKey = argv[1];
+ size_t assertCount = strtoul(argv[2], nullptr, 0);
+ for (size_t i(0); i < assertCount; i++) {
+ ASSERT_ONCE_OR_LOG(true, assertKey, 100);
+ ASSERT_ONCE_OR_LOG(false, assertKey, 100);
+ }
+ assert(assertCount == vespalib::assert::getNumAsserts(assertKey));
+ return 0;
+}