[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <f94a179b-be0f-4758-8eea-2a307db87f36@igalia.com>
Date: Fri, 9 May 2025 18:22:18 -0300
From: André Almeida <andrealmeid@...lia.com>
To: Sebastian Andrzej Siewior <bigeasy@...utronix.de>,
linux-kernel@...r.kernel.org
Cc: Darren Hart <dvhart@...radead.org>, Davidlohr Bueso <dave@...olabs.net>,
Ingo Molnar <mingo@...hat.com>, Juri Lelli <juri.lelli@...hat.com>,
Peter Zijlstra <peterz@...radead.org>, Thomas Gleixner <tglx@...utronix.de>,
Valentin Schneider <vschneid@...hat.com>, Waiman Long <longman@...hat.com>
Subject: Re: [PATCH v12 20/21] selftests/futex: Add futex_priv_hash
Hi Sebastian,
Thank you for adding a selftest for the new uAPI. The recent futex
selftests accepted uses the kselftest helpers in a different way than
the way you have used. I've attached a diff to exemplify how I would
write this selftest. The advantage is to have a TAP output that can be
easier used with automated testing, and that would not stop when the
first test fails.
Em 16/04/2025 13:29, Sebastian Andrzej Siewior escreveu:
> Test the basic functionality of the private hash:
> - Upon start, with no threads there is no private hash.
> - The first thread initializes the private hash.
> - More than four threads will increase the size of the private hash if
> the system has more than 16 CPUs online.
> - Once the user sets the size of private hash, auto scaling is disabled.
> - The user is only allowed to use numbers to the power of two.
> - The user may request the global or make the hash immutable.
> - Once the global hash has been set or the hash has been made immutable,
> further changes are not allowed.
> - Futex operations should work the whole time. It must be possible to
> hold a lock, such a PI initialised mutex, during the resize operation.
>
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@...utronix.de>
> ---
-- >8 --
---
.../futex/functional/futex_priv_hash.c | 31 ++++++++++++-------
1 file changed, 19 insertions(+), 12 deletions(-)
diff --git a/tools/testing/selftests/futex/functional/futex_priv_hash.c
b/tools/testing/selftests/futex/functional/futex_priv_hash.c
index 4d37650baa19..33fa9ad11d69 100644
--- a/tools/testing/selftests/futex/functional/futex_priv_hash.c
+++ b/tools/testing/selftests/futex/functional/futex_priv_hash.c
@@ -51,15 +51,17 @@ static void futex_hash_slots_set_verify(int slots)
ret = futex_hash_slots_set(slots, 0);
if (ret != 0) {
- error("Failed to set slots to %d\n", errno, slots);
- exit(1);
+ ksft_test_result_fail("Failed to set slots to %d: %s\n", slots,
strerror(errno));
+ return;
}
ret = futex_hash_slots_get();
if (ret != slots) {
- error("Set %d slots but PR_FUTEX_HASH_GET_SLOTS returns: %d\n",
- errno, slots, ret);
- exit(1);
+ ksft_test_result_fail("Set %d slots but PR_FUTEX_HASH_GET_SLOTS
returns: %d\n",
+ slots, ret);
+ return;
}
+
+ ksft_test_result_pass("futex_hash_slots_set() and get() succeeded (%d
slots)\n", slots);
}
static void futex_hash_slots_set_must_fail(int slots, int immutable)
@@ -67,12 +69,14 @@ static void futex_hash_slots_set_must_fail(int
slots, int immutable)
int ret;
ret = futex_hash_slots_set(slots, immutable);
- if (ret < 0)
+ if (ret < 0) {
+ ksft_test_result_pass("invalid futex_hash_slots_set(%d, %d)
succeeded.\n",
+ slots, immutable);
return;
+ }
- fail("futex_hash_slots_set(%d, %d) expected to fail but succeeded.\n",
+ ksft_test_result_fail("futex_hash_slots_set(%d, %d) expected to fail
but succeeded.\n",
slots, immutable);
- exit(1);
}
static void *thread_return_fn(void *arg)
@@ -156,6 +160,8 @@ int main(int argc, char *argv[])
}
}
+ ksft_print_header();
+ ksft_set_plan(13);
ret = pthread_mutexattr_init(&mutex_attr_pi);
ret |= pthread_mutexattr_setprotocol(&mutex_attr_pi,
PTHREAD_PRIO_INHERIT);
@@ -235,13 +241,13 @@ int main(int argc, char *argv[])
ret = futex_hash_slots_set(15, 0);
if (ret >= 0) {
- fail("Expected to fail with 15 slots but succeeded: %d.\n", ret);
+ ksft_test_result_fail("Expected to fail with 15 slots but succeeded:
%d.\n", ret);
return 1;
}
futex_hash_slots_set_verify(2);
join_max_threads();
if (counter != MAX_THREADS) {
- fail("Expected thread counter at %d but is %d\n",
+ ksft_test_result_fail("Expected thread counter at %d but is %d\n",
MAX_THREADS, counter);
return 1;
}
@@ -254,8 +260,7 @@ int main(int argc, char *argv[])
ret = futex_hash_slots_get();
if (ret != 2) {
- printf("Expected 2 slots, no auto-resize, got %d\n", ret);
- return 1;
+ ksft_test_result_fail("Expected 2 slots, no auto-resize, got %d\n", ret);
}
futex_hash_slots_set_must_fail(1 << 29, 0);
@@ -311,5 +316,7 @@ int main(int argc, char *argv[])
fail("Expected immutable private hash, got %d\n", ret);
return 1;
}
+
+ ksft_print_cnts();
return 0;
}
--
2.49.0
Powered by blists - more mailing lists