mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/9] test: self: setjmp: add simple initial testcase
Date: Mon, 25 Nov 2024 16:35:16 +0100	[thread overview]
Message-ID: <20241125153523.1411849-3-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20241125153523.1411849-1-a.fatoum@pengutronix.de>

Instead of having a single complicate test, let's first have a simple
test than the existing two tests to make debugging easier.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 test/self/setjmp.c | 75 +++++++++++++++++++++++++++++++++-------------
 1 file changed, 54 insertions(+), 21 deletions(-)

diff --git a/test/self/setjmp.c b/test/self/setjmp.c
index 1cbb44bdf941..deac584d736d 100644
--- a/test/self/setjmp.c
+++ b/test/self/setjmp.c
@@ -14,6 +14,29 @@
 
 BSELFTEST_GLOBALS();
 
+static jmp_buf jbuf;
+
+static void test_setjmp_simple(void)
+{
+	total_tests++;
+
+	pr_debug("%s: saving jmp_buf\n", __func__);
+
+	switch (setjmp(jbuf)) {
+	case 0:
+		break;
+	case 42:
+		pr_debug("%s: returned from longjmp\n", __func__);
+		return;
+	default:
+		printf("%s: unexpected value from setjmp\n", __func__);
+		failed_tests++;
+	}
+
+	pr_debug("%s: attempting longjmp\n", __func__);
+	longjmp(jbuf, 42);
+}
+
 static __noreturn void raise_longjmp(jmp_buf jbuf, int i, int n)
 {
 	while (i < n)
@@ -22,28 +45,8 @@ static __noreturn void raise_longjmp(jmp_buf jbuf, int i, int n)
 	longjmp(jbuf, n);
 }
 
-static jmp_buf jbuf;
-
-static void __noreturn initjmp_entry(void)
+static void test_setjmp_loop(void)
 {
-	volatile u32 arr[256];
-	int i;
-
-	for (i = 0; i < ARRAY_SIZE(arr); i++)
-		writel(i, &arr[i]);
-
-	/* ensure arr[] is allocated on stack */
-	OPTIMIZER_HIDE_VAR(i);
-	if (i == 0)
-		initjmp_entry();
-
-	longjmp(jbuf, 0x1337);
-}
-
-static void test_setjmp(void)
-{
-	void *stack;
-	jmp_buf ijbuf;
 	volatile int i;
 	int ret;
 
@@ -71,6 +74,29 @@ static void test_setjmp(void)
 		failed_tests++;
 	}
 
+}
+
+static void __noreturn initjmp_entry(void)
+{
+	volatile u32 arr[256];
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(arr); i++)
+		writel(i, &arr[i]);
+
+	/* ensure arr[] is allocated on stack */
+	OPTIMIZER_HIDE_VAR(i);
+	if (i == 0)
+		initjmp_entry();
+
+	longjmp(jbuf, 0x1337);
+}
+
+static void test_initjmp(void)
+{
+	void *stack;
+	jmp_buf ijbuf;
+
 	stack = memalign(16, CONFIG_STACK_SIZE);
 	if (WARN_ON(!stack)) {
 		skipped_tests++;
@@ -95,4 +121,11 @@ static void test_setjmp(void)
 
 	free(stack);
 }
+
+static void test_setjmp(void)
+{
+	test_setjmp_simple();
+	test_setjmp_loop();
+	test_initjmp();
+}
 bselftest(core, test_setjmp);
-- 
2.39.5




  parent reply	other threads:[~2024-11-25 15:35 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-25 15:35 [PATCH 0/9] sandbox: use native setjmp/longjmp/initjmp implementation by default Ahmad Fatoum
2024-11-25 15:35 ` [PATCH 1/9] sandbox: asm: support inclusion from sandbox os support code Ahmad Fatoum
2024-11-25 15:35 ` Ahmad Fatoum [this message]
2024-11-25 15:35 ` [PATCH 3/9] sandbox: source/invoke um Makefiles provided by host architecture Ahmad Fatoum
2024-11-25 15:35 ` [PATCH 4/9] sandbox: setjmp: mark C version as __weak Ahmad Fatoum
2024-11-25 15:35 ` [PATCH 5/9] sandbox: use native setjmp/longjmp/initjmp implementation by default Ahmad Fatoum
2024-11-25 15:35 ` [PATCH 6/9] sandbox: retire HAVE_ARCH_ASAN Ahmad Fatoum
2024-11-25 15:35 ` [PATCH 7/9] bthread: move asan fiber API into header Ahmad Fatoum
2024-11-25 15:35 ` [PATCH 8/9] test: self: setjmp: make compatible with ASAN Ahmad Fatoum
2024-11-25 15:35 ` [PATCH 9/9] bthread: fix use of ASAN fiber stack switch API Ahmad Fatoum

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=20241125153523.1411849-3-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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