From: "André Almeida" <andrealmeid@collabora.com>
To: linux-kernel@vger.kernel.org, tglx@linutronix.de, peterz@infradead.org
Cc: krisman@collabora.com, kernel@collabora.com,
andrealmeid@collabora.com, dvhart@infradead.org,
mingo@redhat.com, pgriffais@valvesoftware.com,
fweimer@redhat.com, libc-alpha@sourceware.org,
malteskarupke@web.de, linux-api@vger.kernel.org
Subject: [RFC 4/4] selftests: futex: Add futex2 wouldblock test
Date: Fri, 12 Jun 2020 15:51:22 -0300 [thread overview]
Message-ID: <20200612185122.327860-5-andrealmeid@collabora.com> (raw)
In-Reply-To: <20200612185122.327860-1-andrealmeid@collabora.com>
Adapt existing futex wait wouldblock file to test the same mechanism for
futex2.
Signed-off-by: André Almeida <andrealmeid@collabora.com>
---
.../futex/functional/futex_wait_wouldblock.c | 34 ++++++++++++++++---
1 file changed, 29 insertions(+), 5 deletions(-)
diff --git a/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c b/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c
index 0ae390ff8164..67374d9db70c 100644
--- a/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c
+++ b/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c
@@ -12,6 +12,7 @@
*
* HISTORY
* 2009-Nov-14: Initial version by Gowrishankar <gowrishankar.m@in.ibm.com>
+ * 2020-Jun-11: Add futex2 test by André <andrealmeid@collabora.com>
*
*****************************************************************************/
@@ -21,7 +22,7 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
-#include "futextest.h"
+#include "futex2test.h"
#include "logging.h"
#define TEST_NAME "futex-wait-wouldblock"
@@ -38,7 +39,8 @@ void usage(char *prog)
int main(int argc, char *argv[])
{
- struct timespec to = {.tv_sec = 0, .tv_nsec = timeout_ns};
+ time_t abs_to;
+ struct timespec to;
futex_t f1 = FUTEX_INITIALIZER;
int res, ret = RET_PASS;
int c;
@@ -61,18 +63,40 @@ int main(int argc, char *argv[])
}
ksft_print_header();
- ksft_set_plan(1);
+ ksft_set_plan(2);
ksft_print_msg("%s: Test the unexpected futex value in FUTEX_WAIT\n",
basename(argv[0]));
+ /* setting absolute timeout for futex2 */
+ if (clock_gettime(CLOCK_MONOTONIC, &to))
+ error("clock_gettime failed\n", errno);
+
+ abs_to = (NSEC_PER_SEC * to.tv_sec) + to.tv_nsec + timeout_ns;
+
+ /* initialize timeout */
+ to.tv_sec = 0;
+ to.tv_nsec = timeout_ns;
+
info("Calling futex_wait on f1: %u @ %p with val=%u\n", f1, &f1, f1+1);
res = futex_wait(&f1, f1+1, &to, FUTEX_PRIVATE_FLAG);
if (!res || errno != EWOULDBLOCK) {
- fail("futex_wait returned: %d %s\n",
+ ksft_test_result_fail("futex_wait returned: %d %s\n",
+ res ? errno : res, res ? strerror(errno) : "");
+ ret = RET_FAIL;
+ } else {
+ ksft_test_result_pass("futex_wait wouldblock succeeds\n");
+ }
+
+ info("Calling futex2_wait on f1: %u @ %p with val=%u\n", f1, &f1, f1+1);
+ res = futex2_wait(&f1, f1+1, FUTEX_PRIVATE_FLAG | FUTEX_32, &abs_to);
+ if (!res || errno != EWOULDBLOCK) {
+ ksft_test_result_fail("futex2_wait returned: %d %s\n",
res ? errno : res, res ? strerror(errno) : "");
ret = RET_FAIL;
+ } else {
+ ksft_test_result_pass("futex2_wait wouldblock succeeds\n");
}
- print_result(TEST_NAME, ret);
+ ksft_print_cnts();
return ret;
}
--
2.27.0
next prev parent reply other threads:[~2020-06-12 18:51 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-12 18:51 [RFC 0/4] futex2: Add new futex interface André Almeida
2020-06-12 18:51 ` [RFC 1/4] " André Almeida
2020-06-12 18:51 ` [RFC 2/4] selftests: futex: Add futex2 wake/wait test André Almeida
2020-06-12 18:51 ` [RFC 3/4] selftests: futex: Add futex2 timeout test André Almeida
2020-06-12 18:51 ` André Almeida [this message]
2020-06-12 19:35 ` [RFC 0/4] futex2: Add new futex interface H.J. Lu
2020-06-13 19:25 ` André Almeida
2020-06-25 6:48 ` Arnd Bergmann
2020-06-25 14:38 ` André Almeida
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=20200612185122.327860-5-andrealmeid@collabora.com \
--to=andrealmeid@collabora.com \
--cc=dvhart@infradead.org \
--cc=fweimer@redhat.com \
--cc=kernel@collabora.com \
--cc=krisman@collabora.com \
--cc=libc-alpha@sourceware.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=malteskarupke@web.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=pgriffais@valvesoftware.com \
--cc=tglx@linutronix.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).