From patchwork Fri Jul 30 08:49:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerin Jacob Kollanukkaran X-Patchwork-Id: 96455 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D6211A0C45; Fri, 30 Jul 2021 10:51:53 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 02DD4410DA; Fri, 30 Jul 2021 10:51:48 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 2318E40040 for ; Fri, 30 Jul 2021 10:51:45 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 16U8kE3g016339; Fri, 30 Jul 2021 01:51:43 -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=PBRRkXRvfbtgtLTYZl79AEkVNxSsRExVgnTAadcqFBO8wcd0Cq59enJfeGc6npnSRHp2 v1yiDUecMyinM3fSb0zKd/mVOOJzeMgyN99+UvF79ekzU7ZYwDzo2kAiVsOi5WhCHmNa 8VqKCsbcWR3QlRzviJ2Wxg3LiC6xPIyquMCIokOnOSzjhTDqvL8pzeju6xgmXAG+LEpq Nhc5Vr0/13MBfp2QlumOnq1Che3BV5FdLvas3CZcD1mVBQJ7ZVkfifhcv3Ge9jwClfGh xIv6dpfdbrCa4HNr/8kzlMZah8g1cfkCsNzf5DAOUh3O+rJD9uO+SWVaGBO/Clyf5ORw LA== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com with ESMTP id 3a4866sacy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 30 Jul 2021 01:51:43 -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; Fri, 30 Jul 2021 01:51:41 -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; Fri, 30 Jul 2021 01:51:41 -0700 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id BE5863F7061; Fri, 30 Jul 2021 01:51:37 -0700 (PDT) From: To: CC: , , , , , , , , , , , Jerin Jacob Date: Fri, 30 Jul 2021 14:19:38 +0530 Message-ID: <20210730084938.2426128-7-jerinj@marvell.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210730084938.2426128-1-jerinj@marvell.com> References: <20210730084938.2426128-1-jerinj@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: Ixj6sEp68KHPu9zSQLR4an352ZjEDiYk X-Proofpoint-ORIG-GUID: Ixj6sEp68KHPu9zSQLR4an352ZjEDiYk X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-07-30_05:2021-07-29, 2021-07-30 signatures=0 Subject: [dpdk-dev] 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);