Skip to content

Commit

Permalink
selftests: futex: Test sys_futex_waitv() timeout
Browse files Browse the repository at this point in the history
Test if the futex_waitv timeout is working as expected, using the
supported clockid options.

Signed-off-by: André Almeida <andrealmeid@collabora.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20210923171111.300673-21-andrealmeid@collabora.com
  • Loading branch information
André Almeida authored and Peter Zijlstra committed Oct 7, 2021
1 parent 5e59c1d commit 02e56cc
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion tools/testing/selftests/futex/functional/futex_wait_timeout.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <pthread.h>
#include "futextest.h"
#include "futex2test.h"
#include "logging.h"

#define TEST_NAME "futex-wait-timeout"
Expand Down Expand Up @@ -96,6 +97,12 @@ int main(int argc, char *argv[])
struct timespec to;
pthread_t thread;
int c;
struct futex_waitv waitv = {
.uaddr = (uintptr_t)&f1,
.val = f1,
.flags = FUTEX_32,
.__reserved = 0
};

while ((c = getopt(argc, argv, "cht:v:")) != -1) {
switch (c) {
Expand All @@ -118,7 +125,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);
Expand Down Expand Up @@ -175,6 +182,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);

/* futex_waitv with CLOCK_MONOTONIC */
if (futex_get_abs_timeout(CLOCK_MONOTONIC, &to, timeout_ns))
return RET_FAIL;
res = futex_waitv(&waitv, 1, 0, &to, CLOCK_MONOTONIC);
test_timeout(res, &ret, "futex_waitv monotonic", ETIMEDOUT);

/* futex_waitv with CLOCK_REALTIME */
if (futex_get_abs_timeout(CLOCK_REALTIME, &to, timeout_ns))
return RET_FAIL;
res = futex_waitv(&waitv, 1, 0, &to, CLOCK_REALTIME);
test_timeout(res, &ret, "futex_waitv realtime", ETIMEDOUT);

ksft_print_cnts();
return ret;
}

0 comments on commit 02e56cc

Please sign in to comment.