From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-f193.google.com (mail-lj1-f193.google.com [209.85.208.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id A443C4696C4 for ; Tue, 4 Feb 2020 17:32:35 +0300 (MSK) Received: by mail-lj1-f193.google.com with SMTP id h23so18845480ljc.8 for ; Tue, 04 Feb 2020 06:32:35 -0800 (PST) From: Cyrill Gorcunov Date: Tue, 4 Feb 2020 17:31:47 +0300 Message-Id: <20200204143147.20791-5-gorcunov@gmail.com> In-Reply-To: <20200204143147.20791-1-gorcunov@gmail.com> References: <20200204143147.20791-1-gorcunov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v3 4/4] test: unit/fiber -- add madvise, mprotect tests List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tml Co-developed-by: Alexander Turenko Signed-off-by: Cyrill Gorcunov --- 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