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

Cyrill Gorcunov gorcunov at gmail.com
Tue Feb 4 18:43:08 MSK 2020


Co-developed-by: Alexander Turenko <alexander.turenko at tarantool.org>
Signed-off-by: Cyrill Gorcunov <gorcunov at gmail.com>
---

Pushed into gorcunov/gh-4722-mprotect-diag-error-4

 test/unit/fiber.cc | 59 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/test/unit/fiber.cc b/test/unit/fiber.cc
index 91f7d43f9..ed0d9d7a3 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,70 @@ fiber_name_test()
 	footer();
 }
 
+static void
+fiber_stack_fail_test(void)
+{
+	struct errinj *inj;
+	struct fiber *fiber;
+
+	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.
+	 */
+	inj = errinj(ERRINJ_FIBER_MPROTECT, ERRINJ_INT);
+	if (inj != NULL) {
+		inj->iparam = PROT_NONE;
+		fiber = fiber_new_ex("test_mprotect", fiber_attr, noop_f);
+		inj->iparam = -1;
+
+		ok(fiber == NULL, "mprotect: failed to setup fiber guard page");
+		ok(diag_get() != NULL, "mprotect: diag is armed after error");
+	} else {
+		ok(true, "skip mprotect");
+	}
+
+	/*
+	 * Check madvise. We can't test the fiber destroy
+	 * path since it is cleaning error.
+	 */
+	diag_clear(diag_get());
+	inj = errinj(ERRINJ_FIBER_MADVISE, ERRINJ_BOOL);
+	if (inj != NULL) {
+		inj->bparam = true;
+		fiber = fiber_new_ex("test_madvise", fiber_attr, noop_f);
+		inj->bparam = false;
+
+		ok(fiber != NULL, "madvise: non critical error on madvise hint");
+		ok(diag_get() != NULL, "madvise: diag is armed after error");
+	} else {
+		ok(true, "skip madvise");
+	}
+
+	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