[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210709001328.329716-7-andrealmeid@collabora.com>
Date: Thu, 8 Jul 2021 21:13:23 -0300
From: André Almeida <andrealmeid@...labora.com>
To: Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>,
Peter Zijlstra <peterz@...radead.org>,
Darren Hart <dvhart@...radead.org>,
linux-kernel@...r.kernel.org, Steven Rostedt <rostedt@...dmis.org>,
Sebastian Andrzej Siewior <bigeasy@...utronix.de>
Cc: kernel@...labora.com, krisman@...labora.com,
pgriffais@...vesoftware.com, z.figura12@...il.com,
joel@...lfernandes.org, malteskarupke@...tmail.fm,
linux-api@...r.kernel.org, fweimer@...hat.com,
libc-alpha@...rceware.org, linux-kselftest@...r.kernel.org,
shuah@...nel.org, acme@...nel.org, corbet@....net,
Peter Oskolkov <posk@...k.io>,
Andrey Semashev <andrey.semashev@...il.com>,
Davidlohr Bueso <dave@...olabs.net>,
Nicholas Piggin <npiggin@...il.com>,
Adhemerval Zanella <adhemerval.zanella@...aro.org>,
André Almeida <andrealmeid@...labora.com>
Subject: [PATCH v5 06/11] selftests: futex2: Add timeout test
Adapt existing futex wait timeout file to test the same mechanism for
futex2. futex2 accepts only absolute 64bit timers, but supports both
monotonic and realtime clocks.
Signed-off-by: André Almeida <andrealmeid@...labora.com>
---
.../futex/functional/futex_wait_timeout.c | 24 +++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/futex/functional/futex_wait_timeout.c b/tools/testing/selftests/futex/functional/futex_wait_timeout.c
index 1f8f6daaf1e7..d20f54745c2e 100644
--- a/tools/testing/selftests/futex/functional/futex_wait_timeout.c
+++ b/tools/testing/selftests/futex/functional/futex_wait_timeout.c
@@ -17,6 +17,14 @@
#include <pthread.h>
#include "futextest.h"
+
+#include <errno.h>
+#include <getopt.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include "futex2test.h"
#include "logging.h"
#define TEST_NAME "futex-wait-timeout"
@@ -92,8 +100,8 @@ static int futex_get_abs_timeout(clockid_t clockid, struct timespec *to,
int main(int argc, char *argv[])
{
futex_t f1 = FUTEX_INITIALIZER;
+ struct timespec to = {.tv_sec = 0, .tv_nsec = timeout_ns};
int res, ret = RET_PASS;
- struct timespec to;
pthread_t thread;
int c;
@@ -118,7 +126,7 @@ int main(int argc, char *argv[])
}
ksft_print_header();
- ksft_set_plan(7);
+ ksft_set_plan(9);
ksft_print_msg("%s: Block on a futex and wait for timeout\n",
basename(argv[0]));
ksft_print_msg("\tArguments: timeout=%ldns\n", timeout_ns);
@@ -175,6 +183,18 @@ int main(int argc, char *argv[])
res = futex_lock_pi(&futex_pi, NULL, 0, FUTEX_CLOCK_REALTIME);
test_timeout(res, &ret, "futex_lock_pi invalid timeout flag", ENOSYS);
+ /* setting absolute monotonic timeout for futex2 */
+ if (futex_get_abs_timeout(CLOCK_MONOTONIC, &to, timeout_ns))
+ return RET_FAIL;
+ res = futex2_wait(&f1, f1, FUTEX_32, &to);
+ test_timeout(res, &ret, "futex2_wait monotonic", ETIMEDOUT);
+
+ /* setting absolute realtime timeout for futex2 */
+ if (futex_get_abs_timeout(CLOCK_REALTIME, &to, timeout_ns))
+ return RET_FAIL;
+ res = futex2_wait(&f1, f1, FUTEX_32 | FUTEX_CLOCK_REALTIME, &to);
+ test_timeout(res, &ret, "futex2_wait realtime", ETIMEDOUT);
+
ksft_print_cnts();
return ret;
}
--
2.32.0
Powered by blists - more mailing lists