From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 67EE5A0548; Tue, 17 Aug 2021 05:30:32 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A035141183; Tue, 17 Aug 2021 05:30:30 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 8448441183 for ; Tue, 17 Aug 2021 05:30:28 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.1.2/8.16.0.43) with SMTP id 17H2ldqW006753; Mon, 16 Aug 2021 20:30:24 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=+0R8VA+/m87ziXmnSG3F+7vKnk60Jn58q3DUijI7iHM=; b=LHYb/0vf8Lvhx0bMFTiDSAkEnOMpMT71V1xLly0idl4PV7Pg8i8FYPTO8mBTxnvVy2/f joNw06OESFEqJaHuJKKNWcRmLDGWIA7Hb2OHFrJij+VHl8pGhnduuOboc1tsL9DmotCw P25VSxSSvsChzGc5HdLvRQoqFVo+/znJ2PlzMPuoF7+n+M/G7Nrs5BW4vfOzWLwPxtEp VubP4KC3l5FSET/HXfRutHM99BXMzgBbQCcrUta7UVQy8BZ+SVBN/DGzEIqpq6tstbAZ 8LSwXUk1F2nBv+OrESIjKJhj+T01LlZJH7NamtCjjObsgNtYTfLbv2wu1a0QVDKH8nHs nw== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com with ESMTP id 3ag4n0r3vw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 16 Aug 2021 20:30:24 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 16 Aug 2021 20:30:23 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Mon, 16 Aug 2021 20:30:23 -0700 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id 1E2D03F70AC; Mon, 16 Aug 2021 20:30:18 -0700 (PDT) From: To: CC: , , , , , , , , , , , Jerin Jacob Date: Tue, 17 Aug 2021 08:57:23 +0530 Message-ID: <20210817032723.3997054-7-jerinj@marvell.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210817032723.3997054-1-jerinj@marvell.com> References: <20210730084938.2426128-2-jerinj@marvell.com> <20210817032723.3997054-1-jerinj@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-GUID: buJzccEWNr1E85oC_smlpSw4ibvdB6Ne X-Proofpoint-ORIG-GUID: buJzccEWNr1E85oC_smlpSw4ibvdB6Ne X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.391,FMLib:17.0.607.475 definitions=2021-08-17_01,2021-08-16_02,2020-04-07_01 Subject: [dpdk-dev] [PATCH v2 6/6] test/oops: support unit test case for oops handling APIs X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Jerin Jacob Added unit test cases for all the oops handling APIs. Signed-off-by: Jerin Jacob --- app/test/meson.build | 2 + app/test/test_oops.c | 121 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 app/test/test_oops.c diff --git a/app/test/meson.build b/app/test/meson.build index a7611686ad..1e471ab351 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -97,6 +97,7 @@ test_sources = files( 'test_metrics.c', 'test_mcslock.c', 'test_mp_secondary.c', + 'test_oops.c', 'test_per_lcore.c', 'test_pflock.c', 'test_pmd_perf.c', @@ -236,6 +237,7 @@ fast_tests = [ ['memzone_autotest', false], ['meter_autotest', true], ['multiprocess_autotest', false], + ['oops_autotest', true], ['per_lcore_autotest', true], ['pflock_autotest', true], ['prefetch_autotest', true], diff --git a/app/test/test_oops.c b/app/test/test_oops.c new file mode 100644 index 0000000000..60a7f259c7 --- /dev/null +++ b/app/test/test_oops.c @@ -0,0 +1,121 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2021 Marvell + */ + +#include +#include + +#include +#include + +#include "test.h" + +static jmp_buf pc; +static bool detected_segfault; + +static void +segv_handler(int sig, siginfo_t *info, void *ctx) +{ + detected_segfault = true; + rte_oops_decode(sig, info, (ucontext_t *)ctx); + longjmp(pc, 1); +} + +/* OS specific way install the signal segfault handler*/ +static int +segv_handler_install(void) +{ + struct sigaction sa; + + sigemptyset(&sa.sa_mask); + sa.sa_sigaction = &segv_handler; + sa.sa_flags = SA_SIGINFO; + + return sigaction(SIGSEGV, &sa, NULL); +} + +static int +test_oops_generate(void) +{ + int rc; + + rc = segv_handler_install(); + TEST_ASSERT_EQUAL(rc, 0, "rc=%d\n", rc); + + detected_segfault = false; + rc = setjmp(pc); /* Save the execution state */ + if (rc == 0) { + /* Generate a segfault */ + *(volatile int *)0x05 = 0; + } else { /* logjump from segv_handler */ + if (detected_segfault) + return TEST_SUCCESS; + + } + return TEST_FAILED; +} + +static int +test_signal_handler_installed(int count, int *signals) +{ + int i, rc, verified = 0; + struct sigaction sa; + + for (i = 0; i < count; i++) { + rc = sigaction(signals[i], NULL, &sa); + if (rc) { + printf("Failed to get sigaction for %d", signals[i]); + continue; + } + if (sa.sa_handler != SIG_DFL) + verified++; + } + TEST_ASSERT_EQUAL(count, verified, "count=%d verified=%d\n", count, + verified); + return TEST_SUCCESS; +} + +static int +test_oops_signals_enabled(void) +{ + int *signals = NULL; + int i, rc; + + rc = rte_oops_signals_enabled(signals); + TEST_ASSERT_NOT_EQUAL(rc, 0, "rc=%d\n", rc); + + signals = malloc(sizeof(int) * rc); + rc = rte_oops_signals_enabled(signals); + TEST_ASSERT_NOT_EQUAL(rc, 0, "rc=%d\n", rc); + free(signals); + + signals = malloc(sizeof(int) * RTE_OOPS_SIGNALS_MAX); + rc = rte_oops_signals_enabled(signals); + TEST_ASSERT_NOT_EQUAL(rc, 0, "rc=%d\n", rc); + + for (i = 0; i < rc; i++) + TEST_ASSERT_NOT_EQUAL(signals[i], 0, "idx=%d val=%d\n", i, + signals[i]); + + rc = test_signal_handler_installed(rc, signals); + free(signals); + + return rc; +} + +static struct unit_test_suite oops_tests = { + .suite_name = "oops autotest", + .setup = NULL, + .teardown = NULL, + .unit_test_cases = { + TEST_CASE(test_oops_signals_enabled), + TEST_CASE(test_oops_generate), + TEST_CASES_END()}}; + +static int +test_oops(void) +{ + return unit_test_suite_runner(&oops_tests); +} + +REGISTER_TEST_COMMAND(oops_autotest, test_oops); -- 2.32.0