* [LTP] [PATCH v2] futex_waitv01: Add test verifies EAGIN/ETIMEDOUT
@ 2022-06-07 2:54 Zhao Gongyi via ltp
2022-06-07 13:12 ` Cyril Hrubis
0 siblings, 1 reply; 3+ messages in thread
From: Zhao Gongyi via ltp @ 2022-06-07 2:54 UTC (permalink / raw)
To: ltp
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>
---
v1->v1: move test code to futex_waitv01.c
.../kernel/syscalls/futex/futex_waitv01.c | 30 +++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/testcases/kernel/syscalls/futex/futex_waitv01.c b/testcases/kernel/syscalls/futex/futex_waitv01.c
index f2c19b748..2d905fa5f 100644
--- a/testcases/kernel/syscalls/futex/futex_waitv01.c
+++ b/testcases/kernel/syscalls/futex/futex_waitv01.c
@@ -113,6 +113,34 @@ static void test_invalid_nr_futexes(void)
"futex_waitv invalid nr_futexes");
}
+static void test_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)
{
free(futex);
@@ -126,6 +154,8 @@ static void run(void)
test_null_waiters();
test_invalid_clockid();
test_invalid_nr_futexes();
+ test_mismatch_between_uaddr_and_val();
+ test_timeout();
}
static struct tst_test test = {
--
2.17.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [LTP] [PATCH v2] futex_waitv01: Add test verifies EAGIN/ETIMEDOUT
2022-06-07 2:54 [LTP] [PATCH v2] futex_waitv01: Add test verifies EAGIN/ETIMEDOUT Zhao Gongyi via ltp
@ 2022-06-07 13:12 ` Cyril Hrubis
0 siblings, 0 replies; 3+ messages in thread
From: Cyril Hrubis @ 2022-06-07 13:12 UTC (permalink / raw)
To: Zhao Gongyi; +Cc: ltp
Hi!
> +static void test_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");
The init_timeout(&to) inits the timeout with CLOCK_REALTIME time, so we
should pass CLOCK_REALTIME to the futex_waitv() as well.
> +}
> +
> +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);
I guess that we can as well just do:
SAFE_CLOCK_GETTIME(CLOCK_REALTIME, &to);
Which would make the test much faster as we will not have to wait for
one second for the timeout.
Eventually we can as well add a few miliseconds to the timeout, we do
have a nice functions to work with different time structures in this
case we can just do:
to = tst_timespec_add_us(to, 10000);
To add 10ms to the timeout.
> + TST_EXP_FAIL(futex_waitv(waitv, 1, 0, &to, CLOCK_REALTIME), ETIMEDOUT,
> + "futex_waitv timeout");
> +
> +}
> +
> static void cleanup(void)
> {
> free(futex);
> @@ -126,6 +154,8 @@ static void run(void)
> test_null_waiters();
> test_invalid_clockid();
> test_invalid_nr_futexes();
> + test_mismatch_between_uaddr_and_val();
> + test_timeout();
> }
>
> static struct tst_test test = {
> --
> 2.17.1
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [LTP] [PATCH v2] futex_waitv01: Add test verifies EAGIN/ETIMEDOUT
@ 2022-06-08 3:24 zhaogongyi via ltp
0 siblings, 0 replies; 3+ messages in thread
From: zhaogongyi via ltp @ 2022-06-08 3:24 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp@lists.linux.it
Hi Cyril,
I have submit a new patch according your review, please see: https://patchwork.ozlabs.org/project/ltp/patch/20220608031953.152525-1-zhaogongyi@huawei.com/
Thanks for your review!
Best wishes,
Gongyi
>
> Hi!
> > +static void test_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");
>
> The init_timeout(&to) inits the timeout with CLOCK_REALTIME time, so we
> should pass CLOCK_REALTIME to the futex_waitv() as well.
>
> > +}
> > +
> > +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);
>
> I guess that we can as well just do:
>
> SAFE_CLOCK_GETTIME(CLOCK_REALTIME, &to);
>
> Which would make the test much faster as we will not have to wait for one
> second for the timeout.
>
> Eventually we can as well add a few miliseconds to the timeout, we do
> have a nice functions to work with different time structures in this case we
> can just do:
>
> to = tst_timespec_add_us(to, 10000);
>
> To add 10ms to the timeout.
>
> > + TST_EXP_FAIL(futex_waitv(waitv, 1, 0, &to, CLOCK_REALTIME),
> ETIMEDOUT,
> > + "futex_waitv timeout");
> > +
> > +}
> > +
> > static void cleanup(void)
> > {
> > free(futex);
> > @@ -126,6 +154,8 @@ static void run(void)
> > test_null_waiters();
> > test_invalid_clockid();
> > test_invalid_nr_futexes();
> > + test_mismatch_between_uaddr_and_val();
> > + test_timeout();
> > }
> >
> > static struct tst_test test = {
> > --
> > 2.17.1
> >
> >
> > --
> > Mailing list info: https://lists.linux.it/listinfo/ltp
>
> --
> Cyril Hrubis
> chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-06-08 3:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-07 2:54 [LTP] [PATCH v2] futex_waitv01: Add test verifies EAGIN/ETIMEDOUT Zhao Gongyi via ltp
2022-06-07 13:12 ` Cyril Hrubis
-- strict thread matches above, loose matches on Subject: below --
2022-06-08 3:24 zhaogongyi via ltp
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox