[2/2] misc: tst-futex: Create futex test
Checks
| Context |
Check |
Description |
| redhat-pt-bot/TryBot-apply_patch |
success
|
Patch applied to master at the time it was sent
|
| linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_glibc_build--master-arm |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_glibc_check--master-arm |
fail
|
Test failed
|
| redhat-pt-bot/TryBot-32bit |
success
|
Build for i686
|
| linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 |
fail
|
Test failed
|
Commit Message
Create test for the futex syscall wrappers.
Signed-off-by: André Almeida <andrealmeid@igalia.com>
---
sysdeps/unix/sysv/linux/Makefile | 1 +
sysdeps/unix/sysv/linux/tst-futex.c | 93 +++++++++++++++++++++++++++++
2 files changed, 94 insertions(+)
create mode 100644 sysdeps/unix/sysv/linux/tst-futex.c
@@ -201,6 +201,7 @@ tests += \
tst-epoll-ioctls \
tst-fanotify \
tst-fdopendir-o_path \
+ tst-futex \
tst-getauxval \
tst-gettid \
tst-gettid-kill \
new file mode 100644
@@ -0,0 +1,93 @@
+/* Basic tests for Linux futex_* wrappers.
+ Copyright (C) 2022-2026 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <intprops.h>
+#include <support/check.h>
+#include <support/support.h>
+#include <support/timespec.h>
+#include <support/xunistd.h>
+#include <support/xthread.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <sys/futex.h>
+#include <sys/syscall.h>
+
+#define FUTEX_WAKE 1
+
+#define NR_WAITERS 5
+
+static uint32_t futex[NR_WAITERS];
+
+static int
+futex_wake (uint32_t *futex, int val)
+{
+ return syscall (__NR_futex, futex, FUTEX_WAKE, val);
+}
+
+static void *
+thread_waiter (void *arg)
+{
+ struct futex_waitv waiters[NR_WAITERS];
+ struct timespec timeout;
+ int i, ret;
+
+ clock_gettime(CLOCK_MONOTONIC, &timeout);
+ timeout.tv_sec += 5;
+
+ for (i = 0; i < NR_WAITERS; i++) {
+ waiters[i].uaddr = (uintptr_t) &futex[i];
+ waiters[i].val = 0;
+ waiters[i].flags = FUTEX2_SIZE_U32;
+ waiters[i].__reserved = 0;
+ }
+
+ ret = futex_waitv(waiters, NR_WAITERS, 0, &timeout, CLOCK_MONOTONIC);
+
+ if (ret == -1)
+ FAIL_EXIT1 ("futex_waitv failed");
+
+ return NULL;
+}
+
+static void
+test_futex_waitv_basic (void)
+{
+ int i;
+
+ for (i = 0; i < NR_WAITERS; i++)
+ futex[i] = 0;
+
+ xpthread_create (NULL, thread_waiter, NULL);
+
+ usleep(1000);
+
+ futex_wake (&futex[3], 0);
+
+}
+
+static int
+do_test (void)
+{
+ test_futex_waitv_basic ();
+
+
+ return 0;
+}
+
+#include <support/test-driver.c>