DPDK patches and discussions
 help / color / mirror / Atom feed
From: <jerinj@marvell.com>
To: <dev@dpdk.org>
Cc: <thomas@monjalon.net>, <david.marchand@redhat.com>,
	<bruce.richardson@intel.com>, <dmitry.kozliuk@gmail.com>,
	<navasile@linux.microsoft.com>, <dmitrym@microsoft.com>,
	<pallavi.kadam@intel.com>, <konstantin.ananyev@intel.com>,
	<ruifeng.wang@arm.com>, <drc@linux.vnet.ibm.com>,
	<stephen@networkplumber.org>, Jerin Jacob <jerinj@marvell.com>
Subject: [dpdk-dev] [PATCH v3 6/6] test/oops: support unit test case for oops handling APIs
Date: Mon, 6 Sep 2021 09:47:32 +0530	[thread overview]
Message-ID: <20210906041732.1019743-7-jerinj@marvell.com> (raw)
In-Reply-To: <20210906041732.1019743-1-jerinj@marvell.com>

From: Jerin Jacob <jerinj@marvell.com>

Added unit test cases for all the oops handling APIs.

Signed-off-by: Jerin Jacob <jerinj@marvell.com>
---
 app/test/meson.build |   2 +
 app/test/test_oops.c | 122 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 124 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..288761822c
--- /dev/null
+++ b/app/test/test_oops.c
@@ -0,0 +1,122 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2021 Marvell
+ */
+
+#include <setjmp.h>
+#include <signal.h>
+
+#include <rte_config.h>
+#include <rte_oops.h>
+
+#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);
+	if (rc == 0)
+		return TEST_SUCCESS;
+
+	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.33.0


  parent reply	other threads:[~2021-09-06  4:20 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-30  8:49 [dpdk-dev] 0/6] support oops handling jerinj
2021-07-30  8:49 ` [dpdk-dev] 1/6] eal: introduce oops handling API jerinj
2021-08-17  3:27   ` [dpdk-dev] [PATCH v2 0/6] support oops handling jerinj
2021-08-17  3:27     ` [dpdk-dev] [PATCH v2 1/6] eal: introduce oops handling API jerinj
2021-08-17  3:53       ` Stephen Hemminger
2021-08-17  7:38         ` Jerin Jacob
2021-08-17 15:09           ` Stephen Hemminger
2021-08-17 15:27             ` Jerin Jacob
2021-08-17 15:52               ` Stephen Hemminger
2021-08-18  9:37                 ` Jerin Jacob
2021-08-18 16:46                   ` Stephen Hemminger
2021-08-18 18:04                     ` Jerin Jacob
2021-08-17  3:27     ` [dpdk-dev] [PATCH v2 2/6] eal: oops handling API implementation jerinj
2021-08-17  3:52       ` Stephen Hemminger
2021-08-17 10:24         ` Jerin Jacob
2021-08-17  3:27     ` [dpdk-dev] [PATCH v2 3/6] eal: support libunwind based backtrace jerinj
2021-08-17  3:27     ` [dpdk-dev] [PATCH v2 4/6] eal/x86: support register dump for oops jerinj
2021-08-17  3:27     ` [dpdk-dev] [PATCH v2 5/6] eal/arm64: " jerinj
2021-08-17  3:27     ` [dpdk-dev] [PATCH v2 6/6] test/oops: support unit test case for oops handling APIs jerinj
2021-09-06  4:17     ` [dpdk-dev] [PATCH v3 0/6] support oops handling jerinj
2021-09-06  4:17       ` [dpdk-dev] [PATCH v3 1/6] eal: introduce oops handling API jerinj
2021-09-06  4:17       ` [dpdk-dev] [PATCH v3 2/6] eal: oops handling API implementation jerinj
2021-09-06  4:17       ` [dpdk-dev] [PATCH v3 3/6] eal: support libunwind based backtrace jerinj
2022-01-27 20:47         ` Stephen Hemminger
2022-01-28  4:33           ` Jerin Jacob
2022-01-28  8:41             ` Thomas Monjalon
2022-01-28 14:27               ` Jerin Jacob
2022-01-28 17:05                 ` Stephen Hemminger
2021-09-06  4:17       ` [dpdk-dev] [PATCH v3 4/6] eal/x86: support register dump for oops jerinj
2021-09-06  4:17       ` [dpdk-dev] [PATCH v3 5/6] eal/arm64: " jerinj
2021-09-06  4:17       ` jerinj [this message]
2021-09-21 17:30       ` [dpdk-dev] [PATCH v3 0/6] support oops handling Thomas Monjalon
2021-09-21 17:54         ` Jerin Jacob
2021-09-22  7:34           ` Thomas Monjalon
2021-09-22  8:03             ` Jerin Jacob
2021-09-22  8:33               ` Thomas Monjalon
2021-09-22  8:49                 ` Jerin Jacob
2021-07-30  8:49 ` [dpdk-dev] 2/6] eal: oops handling API implementation jerinj
2021-08-02 22:46   ` David Christensen
2021-07-30  8:49 ` [dpdk-dev] 3/6] eal: support libunwind based backtrace jerinj
2021-07-30  8:49 ` [dpdk-dev] 4/6] eal/x86: support register dump for oops jerinj
2021-07-30  8:49 ` [dpdk-dev] 5/6] eal/arm64: " jerinj
2021-08-02 22:49   ` David Christensen
2021-08-16 16:24     ` Jerin Jacob
2021-07-30  8:49 ` [dpdk-dev] 6/6] test/oops: support unit test case for oops handling APIs jerinj

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=20210906041732.1019743-7-jerinj@marvell.com \
    --to=jerinj@marvell.com \
    --cc=bruce.richardson@intel.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=dmitry.kozliuk@gmail.com \
    --cc=dmitrym@microsoft.com \
    --cc=drc@linux.vnet.ibm.com \
    --cc=konstantin.ananyev@intel.com \
    --cc=navasile@linux.microsoft.com \
    --cc=pallavi.kadam@intel.com \
    --cc=ruifeng.wang@arm.com \
    --cc=stephen@networkplumber.org \
    --cc=thomas@monjalon.net \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).