From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) (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 7B79546970E for ; Tue, 4 Feb 2020 18:43:11 +0300 (MSK) Received: by mail-lj1-f175.google.com with SMTP id r19so19121954ljg.3 for ; Tue, 04 Feb 2020 07:43:11 -0800 (PST) Date: Tue, 4 Feb 2020 18:43:08 +0300 From: Cyrill Gorcunov Message-ID: <20200204154308.GE12445@uranus> References: <20200204143147.20791-1-gorcunov@gmail.com> <20200204143147.20791-5-gorcunov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200204143147.20791-5-gorcunov@gmail.com> Subject: [Tarantool-patches] [PATCH v4 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 --- 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