Tarantool development patches archive
 help / color / mirror / Atom feed
From: Cyrill Gorcunov <gorcunov@gmail.com>
To: tml <tarantool-patches@dev.tarantool.org>
Subject: [Tarantool-patches] [PATCH v4 4/4] test: unit/fiber -- add madvise, mprotect tests
Date: Tue, 4 Feb 2020 18:43:08 +0300	[thread overview]
Message-ID: <20200204154308.GE12445@uranus> (raw)
In-Reply-To: <20200204143147.20791-5-gorcunov@gmail.com>

Co-developed-by: Alexander Turenko <alexander.turenko@tarantool.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@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

      parent reply	other threads:[~2020-02-04 15:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-04 14:31 [Tarantool-patches] [PATCH v3 0/4] fiber: Handle stack madvise/mprotect errors Cyrill Gorcunov
2020-02-04 14:31 ` [Tarantool-patches] [PATCH v3 1/4] fiber: use diag_ logger in fiber_madvise/mprotect failures Cyrill Gorcunov
2020-02-04 14:31 ` [Tarantool-patches] [PATCH v3 2/4] fiber: leak stack if we unable to revert guard page Cyrill Gorcunov
2020-02-04 14:31 ` [Tarantool-patches] [PATCH v3 3/4] errinj: add ERRINJ_FIBER_MADVISE and ERRINJ_FIBER_MPROTECT Cyrill Gorcunov
2020-02-04 14:31 ` [Tarantool-patches] [PATCH v3 4/4] test: unit/fiber -- add madvise, mprotect tests Cyrill Gorcunov
2020-02-04 14:37   ` Cyrill Gorcunov
2020-02-04 15:43   ` Cyrill Gorcunov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200204154308.GE12445@uranus \
    --to=gorcunov@gmail.com \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v4 4/4] test: unit/fiber -- add madvise, mprotect tests' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox