mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: linux-kernel@vger.kernel.org
Cc: "André Almeida" <andrealmeid@igalia.com>,
	"Darren Hart" <dvhart@infradead.org>,
	"Davidlohr Bueso" <dave@stgolabs.net>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Juri Lelli" <juri.lelli@redhat.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Valentin Schneider" <vschneid@redhat.com>,
	"Waiman Long" <longman@redhat.com>,
	"Sebastian Andrzej Siewior" <bigeasy@linutronix.de>
Subject: [PATCH v2 2/5] selftests/futex: Use TAP output in futex_numa_mpol
Date: Sat, 17 May 2025 17:14:52 +0200	[thread overview]
Message-ID: <20250517151455.1065363-3-bigeasy@linutronix.de> (raw)
In-Reply-To: <20250517151455.1065363-1-bigeasy@linutronix.de>

Use TAP output for easier automated testing.

Suggested-by: André Almeida <andrealmeid@igalia.com>
Reviewed-by: André Almeida <andrealmeid@igalia.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 .../futex/functional/futex_numa_mpol.c        | 65 +++++++++----------
 1 file changed, 32 insertions(+), 33 deletions(-)

diff --git a/tools/testing/selftests/futex/functional/futex_numa_mpol.c b/tools/testing/selftests/futex/functional/futex_numa_mpol.c
index dd70532f293ec..d18949ea915aa 100644
--- a/tools/testing/selftests/futex/functional/futex_numa_mpol.c
+++ b/tools/testing/selftests/futex/functional/futex_numa_mpol.c
@@ -61,10 +61,8 @@ static void create_max_threads(void *futex_ptr)
 		thread_args[i].flags = FUTEX2_SIZE_U32 | FUTEX_PRIVATE_FLAG | FUTEX2_NUMA;
 		thread_args[i].result = 0;
 		ret = pthread_create(&threads[i], NULL, thread_lock_fn, &thread_args[i]);
-		if (ret) {
-			error("pthread_create failed\n", errno);
-			exit(1);
-		}
+		if (ret)
+			ksft_exit_fail_msg("pthread_create failed\n");
 	}
 }
 
@@ -74,10 +72,8 @@ static void join_max_threads(void)
 
 	for (i = 0; i < MAX_THREADS; i++) {
 		ret = pthread_join(threads[i], NULL);
-		if (ret) {
-			error("pthread_join failed for thread %d\n", errno, i);
-			exit(1);
-		}
+		if (ret)
+			ksft_exit_fail_msg("pthread_join failed for thread %d\n", i);
 	}
 }
 
@@ -95,12 +91,12 @@ static void __test_futex(void *futex_ptr, int must_fail, unsigned int futex_flag
 		if (must_fail) {
 			if (ret < 0)
 				break;
-			fail("Should fail, but didn't\n");
-			exit(1);
+			ksft_exit_fail_msg("futex2_wake(%d, 0x%x) should fail, but didn't\n",
+					   to_wake, futex_flags);
 		}
 		if (ret < 0) {
-			error("Failed futex2_wake(%d)\n", errno, to_wake);
-			exit(1);
+			ksft_exit_fail_msg("Failed futex2_wake(%d, 0x%x): %m\n",
+					   to_wake, futex_flags);
 		}
 		if (!ret)
 			usleep(50);
@@ -111,16 +107,17 @@ static void __test_futex(void *futex_ptr, int must_fail, unsigned int futex_flag
 
 	for (i = 0; i < MAX_THREADS; i++) {
 		if (must_fail && thread_args[i].result != -1) {
-			fail("Thread %d should fail but succeeded (%d)\n", i, thread_args[i].result);
+			ksft_print_msg("Thread %d should fail but succeeded (%d)\n",
+				       i, thread_args[i].result);
 			need_exit = 1;
 		}
 		if (!must_fail && thread_args[i].result != 0) {
-			fail("Thread %d failed (%d)\n", i, thread_args[i].result);
+			ksft_print_msg("Thread %d failed (%d)\n", i, thread_args[i].result);
 			need_exit = 1;
 		}
 	}
 	if (need_exit)
-		exit(1);
+		ksft_exit_fail_msg("Aborting due to earlier errors.\n");
 }
 
 static void test_futex(void *futex_ptr, int must_fail)
@@ -167,41 +164,41 @@ int main(int argc, char *argv[])
 		}
 	}
 
+	ksft_print_header();
+	ksft_set_plan(1);
+
 	mem_size = sysconf(_SC_PAGE_SIZE);
 	futex_ptr = mmap(NULL, mem_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
-	if (futex_ptr == MAP_FAILED) {
-		error("mmap() for %d bytes failed\n", errno, mem_size);
-		return 1;
-	}
+	if (futex_ptr == MAP_FAILED)
+		ksft_exit_fail_msg("mmap() for %d bytes failed\n", mem_size);
+
 	futex_numa = futex_ptr;
 
-	info("Regular test\n");
+	ksft_print_msg("Regular test\n");
 	futex_numa->futex = 0;
 	futex_numa->numa = FUTEX_NO_NODE;
 	test_futex(futex_ptr, 0);
 
-	if (futex_numa->numa == FUTEX_NO_NODE) {
-		fail("NUMA node is left unitiliazed\n");
-		return 1;
-	}
+	if (futex_numa->numa == FUTEX_NO_NODE)
+		ksft_exit_fail_msg("NUMA node is left unitiliazed\n");
 
-	info("Memory too small\n");
+	ksft_print_msg("Memory too small\n");
 	test_futex(futex_ptr + mem_size - 4, 1);
 
-	info("Memory out of range\n");
+	ksft_print_msg("Memory out of range\n");
 	test_futex(futex_ptr + mem_size, 1);
 
 	futex_numa->numa = FUTEX_NO_NODE;
 	mprotect(futex_ptr, mem_size, PROT_READ);
-	info("Memory, RO\n");
+	ksft_print_msg("Memory, RO\n");
 	test_futex(futex_ptr, 1);
 
 	mprotect(futex_ptr, mem_size, PROT_NONE);
-	info("Memory, no access\n");
+	ksft_print_msg("Memory, no access\n");
 	test_futex(futex_ptr, 1);
 
 	mprotect(futex_ptr, mem_size, PROT_READ | PROT_WRITE);
-	info("Memory back to RW\n");
+	ksft_print_msg("Memory back to RW\n");
 	test_futex(futex_ptr, 0);
 
 	/* MPOL test. Does not work as expected */
@@ -213,20 +210,22 @@ int main(int argc, char *argv[])
 		ret = mbind(futex_ptr, mem_size, MPOL_BIND, &nodemask,
 			    sizeof(nodemask) * 8, 0);
 		if (ret == 0) {
-			info("Node %d test\n", i);
+			ksft_print_msg("Node %d test\n", i);
 			futex_numa->futex = 0;
 			futex_numa->numa = FUTEX_NO_NODE;
 
 			ret = futex2_wake(futex_ptr, 0, FUTEX2_SIZE_U32 | FUTEX_PRIVATE_FLAG | FUTEX2_NUMA | FUTEX2_MPOL);
 			if (ret < 0)
-				error("Failed to wake 0 with MPOL.\n", errno);
+				ksft_test_result_fail("Failed to wake 0 with MPOL: %m\n");
 			if (0)
 				test_futex_mpol(futex_numa, 0);
 			if (futex_numa->numa != i) {
-				fail("Returned NUMA node is %d expected %d\n",
-				     futex_numa->numa, i);
+				ksft_test_result_fail("Returned NUMA node is %d expected %d\n",
+						      futex_numa->numa, i);
 			}
 		}
 	}
+	ksft_test_result_pass("NUMA MPOL tests passed\n");
+	ksft_finished();
 	return 0;
 }
-- 
2.49.0


  parent reply	other threads:[~2025-05-17 15:15 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-17 15:14 [PATCH v2 0/5] futex: Random fixes after the private-hash series Sebastian Andrzej Siewior
2025-05-17 15:14 ` [PATCH v2 1/5] selftests/futex: Use TAP output in futex_priv_hash Sebastian Andrzej Siewior
2025-05-21 12:06   ` [tip: locking/futex] " tip-bot2 for Sebastian Andrzej Siewior
2025-05-17 15:14 ` Sebastian Andrzej Siewior [this message]
2025-05-21 12:06   ` [tip: locking/futex] selftests/futex: Use TAP output in futex_numa_mpol tip-bot2 for Sebastian Andrzej Siewior
2025-05-17 15:14 ` [PATCH v2 3/5] futex: Use RCU_INIT_POINTER() in futex_mm_init() Sebastian Andrzej Siewior
2025-05-21 12:06   ` [tip: locking/futex] " tip-bot2 for Sebastian Andrzej Siewior
2025-05-17 15:14 ` [PATCH v2 4/5] tools headers: Synchronize prctl.h ABI header Sebastian Andrzej Siewior
2025-05-21 12:06   ` [tip: locking/futex] " tip-bot2 for Sebastian Andrzej Siewior
2025-05-17 15:14 ` [PATCH v2 5/5] futex: Correct the kernedoc return value for futex_wait_setup() Sebastian Andrzej Siewior
2025-05-21 12:06   ` [tip: locking/futex] " tip-bot2 for Sebastian Andrzej Siewior

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=20250517151455.1065363-3-bigeasy@linutronix.de \
    --to=bigeasy@linutronix.de \
    --cc=andrealmeid@igalia.com \
    --cc=dave@stgolabs.net \
    --cc=dvhart@infradead.org \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=vschneid@redhat.com \
    /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

all inboxes | Powered by JetHome®