[LTP] [PATCH] futex_waitv04: Add test for futex_waitv syscall

Zhao Gongyi zhaogongyi@huawei.com
Wed Apr 13 13:40:14 CEST 2022


Add test verifies EAGIN/ETIMEDOUT for futex_waitv according to
https://www.kernel.org/doc/html/latest/userspace-api/futex2.html.

Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
---
 testcases/kernel/syscalls/futex/.gitignore    |  1 +
 .../kernel/syscalls/futex/futex_waitv04.c     | 83 +++++++++++++++++++
 2 files changed, 84 insertions(+)
 create mode 100644 testcases/kernel/syscalls/futex/futex_waitv04.c

diff --git a/testcases/kernel/syscalls/futex/.gitignore b/testcases/kernel/syscalls/futex/.gitignore
index 9d08ba7d3..13fd202f4 100644
--- a/testcases/kernel/syscalls/futex/.gitignore
+++ b/testcases/kernel/syscalls/futex/.gitignore
@@ -13,3 +13,4 @@
 /futex_waitv01
 /futex_waitv02
 /futex_waitv03
+/futex_waitv04
diff --git a/testcases/kernel/syscalls/futex/futex_waitv04.c b/testcases/kernel/syscalls/futex/futex_waitv04.c
new file mode 100644
index 000000000..783d481e9
--- /dev/null
+++ b/testcases/kernel/syscalls/futex/futex_waitv04.c
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2022 Zhao Gongyi <zhaogongyi@huawei.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies EAGIN and ETIMEDOUT for futex_waitv syscall.
+ */
+
+#include <time.h>
+#include "tst_test.h"
+#include "lapi/futex.h"
+#include "futex2test.h"
+#include "tst_safe_clocks.h"
+
+static uint32_t *futex;
+static struct futex_waitv *waitv;
+
+static void setup(void)
+{
+	futex = SAFE_MALLOC(sizeof(uint32_t));
+	*futex = FUTEX_INITIALIZER;
+}
+
+static void init_timeout(struct timespec *to)
+{
+	SAFE_CLOCK_GETTIME(CLOCK_MONOTONIC, to);
+	to->tv_sec++;
+}
+
+static void mismatch_between_uaddr_and_val(void)
+{
+	struct timespec to;
+
+	waitv->uaddr = (uintptr_t)futex;
+	waitv->flags = FUTEX_32 | FUTEX_PRIVATE_FLAG;
+	waitv->val = 1;
+
+	init_timeout(&to);
+
+	TST_EXP_FAIL(futex_waitv(waitv, 1, 0, &to, CLOCK_MONOTONIC), EAGAIN,
+		     "futex_waitv mismatch between value of uaddr and val");
+}
+
+static void test_timeout(void)
+{
+        struct timespec to;
+
+	waitv->uaddr = (uintptr_t)futex;
+	waitv->flags = FUTEX_32 | FUTEX_PRIVATE_FLAG;
+	waitv->val = 0;
+
+	init_timeout(&to);
+
+	TST_EXP_FAIL(futex_waitv(waitv, 1, 0, &to, CLOCK_REALTIME), ETIMEDOUT,
+		     "futex_waitv timeout");
+}
+
+static void cleanup(void)
+{
+	if (futex != NULL)
+		free(futex);
+}
+
+static void run(void)
+{
+	mismatch_between_uaddr_and_val();
+	test_timeout();
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.min_kver = "5.16",
+	.bufs =
+		(struct tst_buffers[]){
+			{ &waitv, .size = sizeof(struct futex_waitv) },
+			{},
+		},
+};
--
2.17.1



More information about the ltp mailing list