diff mbox series

futex_waitv04: Add test for futex_waitv syscall

Message ID 20220413114014.51577-1-zhaogongyi@huawei.com
State Changes Requested
Headers show
Series futex_waitv04: Add test for futex_waitv syscall | expand

Commit Message

Zhao Gongyi April 13, 2022, 11:40 a.m. UTC
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

--
2.17.1

Comments

Cyril Hrubis April 14, 2022, 1:46 p.m. UTC | #1
Hi!
> 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.
                         ^
                         EAGAIN

Is there a reason why can't we add these two testcases into
futex_waitv01.c?
diff mbox series

Patch

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) },
+			{},
+		},
+};