[Tarantool-patches] [PATCH v3 4/4] test: unit/fiber -- add madvise, mprotect tests

Cyrill Gorcunov gorcunov at gmail.com
Tue Feb 4 17:31:47 MSK 2020


Co-developed-by: Alexander Turenko <alexander.turenko at tarantool.org>
Signed-off-by: Cyrill Gorcunov <gorcunov at gmail.com>
---
 test/unit/fiber.cc | 51 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/test/unit/fiber.cc b/test/unit/fiber.cc
index 91f7d43f9..4f6c08123 100644
--- a/test/unit/fiber.cc
+++ b/test/unit/fiber.cc
@@ -2,6 +2,7 @@
 #include "fiber.h"
 #include "unit.h"
 #include "trivia/util.h"
+#include "errinj.h"
 
 static struct fiber_attr default_attr;
 
@@ -181,12 +182,62 @@ fiber_name_test()
 	footer();
 }
 
+static void
+fiber_stack_fail_test(void)
+{
+	struct fiber *fiber;
+	struct errinj *errinj;
+
+	header();
+
+	/*
+        * Set non-default stack size to prevent reusing of an
+        * existing fiber.
+        */
+	struct fiber_attr *fiber_attr = fiber_attr_new();
+	fiber_attr_setstacksize(fiber_attr, default_attr.stack_size * 2);
+
+	/*
+        * Clear the fiber's diagnostics area to check that failed
+        * fiber_new() sets an error.
+        */
+	diag_clear(diag_get());
+
+	/*
+	 * Check guard page setup via mprotect. We can't test the fiber
+	 * destroy path since it clears fiber's diag.
+	 */
+	errinj = &errinjs[ERRINJ_FIBER_MPROTECT];
+	errinj->iparam = PROT_NONE;
+	fiber = fiber_new_ex("test_mprotect", fiber_attr, noop_f);
+	errinj->iparam = -1;
+
+	ok(fiber == NULL, "mprotect: failed to setup fiber guard page");
+	ok(diag_get() != NULL, "mprotect: diag is armed after error");
+
+	/*
+	 * Check madvise. We can't test the fiber destroy
+	 * path since it is cleaning error.
+	 */
+	diag_clear(diag_get());
+	errinj = &errinjs[ERRINJ_FIBER_MADVISE];
+	errinj->bparam = true;
+	fiber = fiber_new_ex("test_madvise", fiber_attr, noop_f);
+	errinj->bparam = false;
+
+	ok(fiber != NULL, "madvise: non critical error on madvise hint");
+	ok(diag_get() != NULL, "madvise: diag is armed after error");
+
+	footer();
+}
+
 static int
 main_f(va_list ap)
 {
 	fiber_name_test();
 	fiber_join_test();
 	fiber_stack_test();
+	fiber_stack_fail_test();
 	ev_break(loop(), EVBREAK_ALL);
 	return 0;
 }
-- 
2.20.1



More information about the Tarantool-patches mailing list