From: "André Almeida" <andrealmeid@collabora.com>
To: linux-kernel@vger.kernel.org, tglx@linutronix.de
Cc: kernel@collabora.com, krisman@collabora.com, shuah@kernel.org,
linux-kselftest@vger.kernel.org, rostedt@goodmis.org,
ryao@gentoo.org, peterz@infradead.org, dvhart@infradead.org,
mingo@redhat.com, z.figura12@gmail.com, steven@valvesoftware.com,
pgriffais@valvesoftware.com, steven@liquorix.net,
"André Almeida" <andrealmeid@collabora.com>
Subject: [PATCH v3 4/4] selftests: futex: Add FUTEX_WAIT_MULTIPLE wake up test
Date: Thu, 13 Feb 2020 18:45:25 -0300 [thread overview]
Message-ID: <20200213214525.183689-5-andrealmeid@collabora.com> (raw)
In-Reply-To: <20200213214525.183689-1-andrealmeid@collabora.com>
From: Gabriel Krisman Bertazi <krisman@collabora.com>
Add test for wait at multiple futexes mechanism. Skip the test if it's a
x32 application and the kernel returned the approtiaded error, since this
ABI is not supported for this operation.
Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Co-developed-by: André Almeida <andrealmeid@collabora.com>
Signed-off-by: André Almeida <andrealmeid@collabora.com>
---
Changes since v2: none
---
.../selftests/futex/functional/.gitignore | 1 +
.../selftests/futex/functional/Makefile | 3 +-
.../futex/functional/futex_wait_multiple.c | 173 ++++++++++++++++++
.../testing/selftests/futex/functional/run.sh | 3 +
4 files changed, 179 insertions(+), 1 deletion(-)
create mode 100644 tools/testing/selftests/futex/functional/futex_wait_multiple.c
diff --git a/tools/testing/selftests/futex/functional/.gitignore b/tools/testing/selftests/futex/functional/.gitignore
index a09f57061902..4660128a545e 100644
--- a/tools/testing/selftests/futex/functional/.gitignore
+++ b/tools/testing/selftests/futex/functional/.gitignore
@@ -5,3 +5,4 @@ futex_wait_private_mapped_file
futex_wait_timeout
futex_wait_uninitialized_heap
futex_wait_wouldblock
+futex_wait_multiple
diff --git a/tools/testing/selftests/futex/functional/Makefile b/tools/testing/selftests/futex/functional/Makefile
index 30996306cabc..75f9fface11f 100644
--- a/tools/testing/selftests/futex/functional/Makefile
+++ b/tools/testing/selftests/futex/functional/Makefile
@@ -14,7 +14,8 @@ TEST_GEN_FILES := \
futex_requeue_pi_signal_restart \
futex_requeue_pi_mismatched_ops \
futex_wait_uninitialized_heap \
- futex_wait_private_mapped_file
+ futex_wait_private_mapped_file \
+ futex_wait_multiple
TEST_PROGS := run.sh
diff --git a/tools/testing/selftests/futex/functional/futex_wait_multiple.c b/tools/testing/selftests/futex/functional/futex_wait_multiple.c
new file mode 100644
index 000000000000..b48422e79f42
--- /dev/null
+++ b/tools/testing/selftests/futex/functional/futex_wait_multiple.c
@@ -0,0 +1,173 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/******************************************************************************
+ *
+ * Copyright © Collabora, Ltd., 2019
+ *
+ * DESCRIPTION
+ * Test basic semantics of FUTEX_WAIT_MULTIPLE
+ *
+ * AUTHOR
+ * Gabriel Krisman Bertazi <krisman@collabora.com>
+ *
+ * HISTORY
+ * 2019-Dec-13: Initial version by Krisman <krisman@collabora.com>
+ *
+ *****************************************************************************/
+
+#include <errno.h>
+#include <getopt.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <pthread.h>
+#include "futextest.h"
+#include "logging.h"
+
+#define TEST_NAME "futex-wait-multiple"
+#define timeout_ns 100000
+#define MAX_COUNT 128
+#define WAKE_WAIT_US 3000000
+
+int ret = RET_PASS;
+char *progname;
+futex_t f[MAX_COUNT] = {0};
+struct futex_wait_block fwb[MAX_COUNT];
+
+void usage(char *prog)
+{
+ printf("Usage: %s\n", prog);
+ printf(" -c Use color\n");
+ printf(" -h Display this help message\n");
+ printf(" -v L Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n",
+ VQUIET, VCRITICAL, VINFO);
+}
+
+void test_count_overflow(void)
+{
+ futex_t f = FUTEX_INITIALIZER;
+ struct futex_wait_block fwb[MAX_COUNT+1];
+ int res, i;
+
+ ksft_print_msg("%s: Test a too big number of futexes\n", progname);
+
+ for (i = 0; i < MAX_COUNT+1; i++) {
+ fwb[i].uaddr = &f;
+ fwb[i].val = f;
+ fwb[i].bitset = 0;
+ }
+
+ res = futex_wait_multiple(fwb, MAX_COUNT+1, NULL, FUTEX_PRIVATE_FLAG);
+
+#ifdef __ILP32__
+ if (res != -1 || errno != ENOSYS) {
+ ksft_test_result_fail("futex_wait_multiple returned %d\n",
+ res < 0 ? errno : res);
+ ret = RET_FAIL;
+ } else {
+ ksft_test_result_skip("futex_wait_multiple not supported at x32\n");
+ }
+#else
+ if (res != -1 || errno != EINVAL) {
+ ksft_test_result_fail("futex_wait_multiple returned %d\n",
+ res < 0 ? errno : res);
+ ret = RET_FAIL;
+ } else {
+ ksft_test_result_pass("futex_wait_multiple count overflow succeed\n");
+ }
+
+#endif /* __ILP32__ */
+}
+
+void *waiterfn(void *arg)
+{
+ int res;
+
+ res = futex_wait_multiple(fwb, MAX_COUNT, NULL, FUTEX_PRIVATE_FLAG);
+
+#ifdef __ILP32__
+ if (res != -1 || errno != ENOSYS) {
+ ksft_test_result_fail("futex_wait_multiple returned %d\n",
+ res < 0 ? errno : res);
+ ret = RET_FAIL;
+ } else {
+ ksft_test_result_skip("futex_wait_multiple not supported at x32\n");
+ }
+#else
+ if (res < 0)
+ ksft_print_msg("waiter failed %d\n", res);
+
+ info("futex_wait_multiple: Got hint futex %d was freed\n", res);
+#endif /* __ILP32__ */
+
+ return NULL;
+}
+
+void test_fwb_wakeup(void)
+{
+ int res, i;
+ pthread_t waiter;
+
+ ksft_print_msg("%s: Test wake up in a list of futex\n", progname);
+
+ for (i = 0; i < MAX_COUNT; i++) {
+ fwb[i].uaddr = &f[i];
+ fwb[i].val = f[i];
+ fwb[i].bitset = 0xffffffff;
+ }
+
+ res = pthread_create(&waiter, NULL, waiterfn, NULL);
+ if (res) {
+ ksft_test_result_fail("Creating waiting thread failed");
+ ksft_exit_fail();
+ }
+
+ usleep(WAKE_WAIT_US);
+ res = futex_wake(&(f[MAX_COUNT-1]), 1, FUTEX_PRIVATE_FLAG);
+ if (res != 1) {
+ ksft_test_result_fail("Failed to wake thread res=%d\n", res);
+ ksft_exit_fail();
+ }
+
+ pthread_join(waiter, NULL);
+ ksft_test_result_pass("%s succeed\n", __func__);
+}
+
+int main(int argc, char *argv[])
+{
+ int c;
+
+ while ((c = getopt(argc, argv, "cht:v:")) != -1) {
+ switch (c) {
+ case 'c':
+ log_color(1);
+ break;
+ case 'h':
+ usage(basename(argv[0]));
+ exit(0);
+ case 'v':
+ log_verbosity(atoi(optarg));
+ break;
+ default:
+ usage(basename(argv[0]));
+ exit(1);
+ }
+ }
+
+ progname = basename(argv[0]);
+
+ ksft_print_header();
+ ksft_set_plan(2);
+
+ test_count_overflow();
+
+#ifdef __ILP32__
+ // if it's a 32x binary, there's no futex to wakeup
+ ksft_test_result_skip("futex_wait_multiple not supported at x32\n");
+#else
+ test_fwb_wakeup();
+#endif /* __ILP32__ */
+
+ ksft_print_cnts();
+ return ret;
+}
diff --git a/tools/testing/selftests/futex/functional/run.sh b/tools/testing/selftests/futex/functional/run.sh
index 1acb6ace1680..a8be94f28ff7 100755
--- a/tools/testing/selftests/futex/functional/run.sh
+++ b/tools/testing/selftests/futex/functional/run.sh
@@ -73,3 +73,6 @@ echo
echo
./futex_wait_uninitialized_heap $COLOR
./futex_wait_private_mapped_file $COLOR
+
+echo
+./futex_wait_multiple $COLOR
--
2.25.0
next prev parent reply other threads:[~2020-02-13 21:48 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-13 21:45 [PATCH v3 0/4] Implement FUTEX_WAIT_MULTIPLE operation André Almeida
2020-02-13 21:45 ` [PATCH v3 1/4] futex: Implement mechanism to wait on any of several futexes André Almeida
2020-02-28 19:07 ` Peter Zijlstra
2020-02-28 19:49 ` Peter Zijlstra
2020-02-28 21:25 ` Thomas Gleixner
2020-02-29 0:29 ` Pierre-Loup A. Griffais
2020-02-29 10:27 ` Thomas Gleixner
2020-03-03 2:47 ` Pierre-Loup A. Griffais
2020-03-03 12:00 ` 'simple' futex interface [Was: [PATCH v3 1/4] futex: Implement mechanism to wait on any of several futexes] Peter Zijlstra
2020-03-03 13:00 ` Florian Weimer
2020-03-03 13:21 ` Peter Zijlstra
2020-03-03 13:47 ` Florian Weimer
2020-03-03 15:01 ` Peter Zijlstra
2020-03-05 16:14 ` André Almeida
2020-03-05 16:25 ` Florian Weimer
2020-03-05 18:51 ` Peter Zijlstra
2020-03-06 16:57 ` David Laight
2020-02-13 21:45 ` [PATCH v3 2/4] selftests: futex: Add FUTEX_WAIT_MULTIPLE timeout test André Almeida
2020-02-13 21:45 ` [PATCH v3 3/4] selftests: futex: Add FUTEX_WAIT_MULTIPLE wouldblock test André Almeida
2020-02-13 21:45 ` André Almeida [this message]
2020-02-19 16:27 ` [PATCH v3 0/4] Implement FUTEX_WAIT_MULTIPLE operation shuah
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200213214525.183689-5-andrealmeid@collabora.com \
--to=andrealmeid@collabora.com \
--cc=dvhart@infradead.org \
--cc=kernel@collabora.com \
--cc=krisman@collabora.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=pgriffais@valvesoftware.com \
--cc=rostedt@goodmis.org \
--cc=ryao@gentoo.org \
--cc=shuah@kernel.org \
--cc=steven@liquorix.net \
--cc=steven@valvesoftware.com \
--cc=tglx@linutronix.de \
--cc=z.figura12@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.