* [LTP] [PATCH v2] Refactor timer_getoverrun test using new LTP API
@ 2023-09-04 11:19 Andrea Cervesato
2023-10-02 10:43 ` Richard Palethorpe
2023-10-30 13:56 ` Cyril Hrubis
0 siblings, 2 replies; 5+ messages in thread
From: Andrea Cervesato @ 2023-09-04 11:19 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
Added glibc variant
.../kernel/syscalls/timer_getoverrun/Makefile | 2 +
.../timer_getoverrun/timer_getoverrun01.c | 117 ++++++------------
2 files changed, 43 insertions(+), 76 deletions(-)
diff --git a/testcases/kernel/syscalls/timer_getoverrun/Makefile b/testcases/kernel/syscalls/timer_getoverrun/Makefile
index 1273a4e9c..58376e379 100644
--- a/testcases/kernel/syscalls/timer_getoverrun/Makefile
+++ b/testcases/kernel/syscalls/timer_getoverrun/Makefile
@@ -5,4 +5,6 @@ top_srcdir ?= ../../../..
include $(top_srcdir)/include/mk/testcases.mk
+LDLIBS := -lrt $(LDLIBS)
+
include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/timer_getoverrun/timer_getoverrun01.c b/testcases/kernel/syscalls/timer_getoverrun/timer_getoverrun01.c
index aa9881f27..28cba8214 100644
--- a/testcases/kernel/syscalls/timer_getoverrun/timer_getoverrun01.c
+++ b/testcases/kernel/syscalls/timer_getoverrun/timer_getoverrun01.c
@@ -1,88 +1,53 @@
-/******************************************************************************
- * Copyright (c) Crackerjack Project., 2007 *
- * Porting from Crackerjack to LTP is done by: *
- * Manas Kumar Nayak <maknayak@in.ibm.com> *
- * Copyright (c) 2013 Cyril Hrubis <chrubis@suse.cz> *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See *
- * the GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software Foundation, *
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
- * *
- ******************************************************************************/
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) International Business Machines Corp., 2001
+ * Porting from Crackerjack to LTP is done by:
+ * Manas Kumar Nayak <maknayak@in.ibm.com>
+ *
+ * Copyright (c) Linux Test Project, 2009-2023
+ * Copyright (c) 2013 Cyril Hrubis <chrubis@suse.cz>
+ * Copyright (C) 2023 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test checks base timer_getoverrun() functionality.
+ */
-#include <stdio.h>
-#include <errno.h>
-#include <time.h>
#include <signal.h>
-#include <sys/syscall.h>
-
-#include "test.h"
+#include "tst_test.h"
+#include "tst_safe_clocks.h"
#include "lapi/syscalls.h"
-char *TCID = "timer_getoverrun01";
-int TST_TOTAL = 1;
-
-static void cleanup(void)
-{
-
- tst_rmdir();
-}
-
-static void setup(void)
-{
- TEST_PAUSE;
- tst_tmpdir();
-}
-
-int main(int ac, char **av)
+static void run(void)
{
- int lc;
- int timer;
+ timer_t timer;
struct sigevent ev;
- tst_parse_opts(ac, av, NULL, NULL);
-
- setup();
-
ev.sigev_value = (union sigval) 0;
- ev.sigev_signo = SIGALRM;
ev.sigev_notify = SIGEV_SIGNAL;
- TEST(tst_syscall(__NR_timer_create, CLOCK_REALTIME, &ev, &timer));
-
- if (TEST_RETURN != 0)
- tst_brkm(TBROK | TTERRNO, cleanup, "Failed to create timer");
-
- for (lc = 0; TEST_LOOPING(lc); ++lc) {
- tst_count = 0;
-
- TEST(tst_syscall(__NR_timer_getoverrun, timer));
- if (TEST_RETURN == 0) {
- tst_resm(TPASS,
- "timer_getoverrun(CLOCK_REALTIME) Passed");
- } else {
- tst_resm(TFAIL | TTERRNO,
- "timer_getoverrun(CLOCK_REALTIME) Failed");
- }
+ ev.sigev_signo = SIGALRM;
- TEST(tst_syscall(__NR_timer_getoverrun, -1));
- if (TEST_RETURN == -1 && TEST_ERRNO == EINVAL) {
- tst_resm(TPASS, "timer_gettime(-1) Failed: EINVAL");
- } else {
- tst_resm(TFAIL | TTERRNO,
- "timer_gettime(-1) = %li", TEST_RETURN);
- }
+ switch (tst_variant) {
+ case 0:
+ SAFE_TIMER_CREATE(CLOCK_REALTIME, &ev, &timer);
+ TST_EXP_POSITIVE(timer_getoverrun(timer));
+
+ /* glibc causes SIGSEGV where timer_getoverrun() fails with EINVAL */
+#ifndef __GLIBC__
+ TST_EXP_FAIL(timer_getoverrun((timer_t)-1), EINVAL);
+#endif
+ break;
+ case 1:
+ tst_syscall(__NR_timer_create, CLOCK_REALTIME, &ev, &timer);
+ TST_EXP_POSITIVE(tst_syscall(__NR_timer_getoverrun, timer));
+ TST_EXP_FAIL(tst_syscall(__NR_timer_getoverrun, -1), EINVAL);
+ break;
}
-
- cleanup();
- tst_exit();
}
+
+static struct tst_test test = {
+ .test_all = run,
+ .test_variants = 2,
+};
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [LTP] [PATCH v2] Refactor timer_getoverrun test using new LTP API
2023-09-04 11:19 [LTP] [PATCH v2] Refactor timer_getoverrun test using new LTP API Andrea Cervesato
@ 2023-10-02 10:43 ` Richard Palethorpe
2023-10-30 13:34 ` Cyril Hrubis
2023-10-30 13:56 ` Cyril Hrubis
1 sibling, 1 reply; 5+ messages in thread
From: Richard Palethorpe @ 2023-10-02 10:43 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hello,
Test looks fine apart from the issues I have with any test which fails
if a different error number is returned. I already started that
discussion here:
https://patchwork.ozlabs.org/project/ltp/patch/20230901144433.2526-1-chrubis@suse.cz/#3191079
Andrea Cervesato <andrea.cervesato@suse.de> writes:
> From: Andrea Cervesato <andrea.cervesato@suse.com>
>
> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
> ---
> Added glibc variant
>
> .../kernel/syscalls/timer_getoverrun/Makefile | 2 +
> .../timer_getoverrun/timer_getoverrun01.c | 117 ++++++------------
> 2 files changed, 43 insertions(+), 76 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/timer_getoverrun/Makefile b/testcases/kernel/syscalls/timer_getoverrun/Makefile
> index 1273a4e9c..58376e379 100644
> --- a/testcases/kernel/syscalls/timer_getoverrun/Makefile
> +++ b/testcases/kernel/syscalls/timer_getoverrun/Makefile
> @@ -5,4 +5,6 @@ top_srcdir ?= ../../../..
>
> include $(top_srcdir)/include/mk/testcases.mk
>
> +LDLIBS := -lrt $(LDLIBS)
> +
> include $(top_srcdir)/include/mk/generic_leaf_target.mk
> diff --git a/testcases/kernel/syscalls/timer_getoverrun/timer_getoverrun01.c b/testcases/kernel/syscalls/timer_getoverrun/timer_getoverrun01.c
> index aa9881f27..28cba8214 100644
> --- a/testcases/kernel/syscalls/timer_getoverrun/timer_getoverrun01.c
> +++ b/testcases/kernel/syscalls/timer_getoverrun/timer_getoverrun01.c
> @@ -1,88 +1,53 @@
> -/******************************************************************************
> - * Copyright (c) Crackerjack Project., 2007 *
> - * Porting from Crackerjack to LTP is done by: *
> - * Manas Kumar Nayak <maknayak@in.ibm.com> *
> - * Copyright (c) 2013 Cyril Hrubis <chrubis@suse.cz> *
> - * *
> - * This program is free software; you can redistribute it and/or modify *
> - * it under the terms of the GNU General Public License as published by *
> - * the Free Software Foundation; either version 2 of the License, or *
> - * (at your option) any later version. *
> - * *
> - * This program is distributed in the hope that it will be useful, *
> - * but WITHOUT ANY WARRANTY; without even the implied warranty of *
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See *
> - * the GNU General Public License for more details. *
> - * *
> - * You should have received a copy of the GNU General Public License *
> - * along with this program; if not, write to the Free Software Foundation, *
> - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
> - * *
> - ******************************************************************************/
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) International Business Machines Corp., 2001
> + * Porting from Crackerjack to LTP is done by:
> + * Manas Kumar Nayak <maknayak@in.ibm.com>
> + *
> + * Copyright (c) Linux Test Project, 2009-2023
> + * Copyright (c) 2013 Cyril Hrubis <chrubis@suse.cz>
> + * Copyright (C) 2023 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
> + */
> +
> +/*\
> + * [Description]
> + *
> + * This test checks base timer_getoverrun() functionality.
> + */
>
> -#include <stdio.h>
> -#include <errno.h>
> -#include <time.h>
> #include <signal.h>
> -#include <sys/syscall.h>
> -
> -#include "test.h"
> +#include "tst_test.h"
> +#include "tst_safe_clocks.h"
> #include "lapi/syscalls.h"
>
> -char *TCID = "timer_getoverrun01";
> -int TST_TOTAL = 1;
> -
> -static void cleanup(void)
> -{
> -
> - tst_rmdir();
> -}
> -
> -static void setup(void)
> -{
> - TEST_PAUSE;
> - tst_tmpdir();
> -}
> -
> -int main(int ac, char **av)
> +static void run(void)
> {
> - int lc;
> - int timer;
> + timer_t timer;
> struct sigevent ev;
>
> - tst_parse_opts(ac, av, NULL, NULL);
> -
> - setup();
> -
> ev.sigev_value = (union sigval) 0;
> - ev.sigev_signo = SIGALRM;
> ev.sigev_notify = SIGEV_SIGNAL;
> - TEST(tst_syscall(__NR_timer_create, CLOCK_REALTIME, &ev, &timer));
> -
> - if (TEST_RETURN != 0)
> - tst_brkm(TBROK | TTERRNO, cleanup, "Failed to create timer");
> -
> - for (lc = 0; TEST_LOOPING(lc); ++lc) {
> - tst_count = 0;
> -
> - TEST(tst_syscall(__NR_timer_getoverrun, timer));
> - if (TEST_RETURN == 0) {
> - tst_resm(TPASS,
> - "timer_getoverrun(CLOCK_REALTIME) Passed");
> - } else {
> - tst_resm(TFAIL | TTERRNO,
> - "timer_getoverrun(CLOCK_REALTIME) Failed");
> - }
> + ev.sigev_signo = SIGALRM;
>
> - TEST(tst_syscall(__NR_timer_getoverrun, -1));
> - if (TEST_RETURN == -1 && TEST_ERRNO == EINVAL) {
> - tst_resm(TPASS, "timer_gettime(-1) Failed: EINVAL");
> - } else {
> - tst_resm(TFAIL | TTERRNO,
> - "timer_gettime(-1) = %li", TEST_RETURN);
> - }
> + switch (tst_variant) {
> + case 0:
> + SAFE_TIMER_CREATE(CLOCK_REALTIME, &ev, &timer);
> + TST_EXP_POSITIVE(timer_getoverrun(timer));
> +
> + /* glibc causes SIGSEGV where timer_getoverrun() fails with EINVAL */
> +#ifndef __GLIBC__
> + TST_EXP_FAIL(timer_getoverrun((timer_t)-1), EINVAL);
> +#endif
> + break;
> + case 1:
> + tst_syscall(__NR_timer_create, CLOCK_REALTIME, &ev, &timer);
> + TST_EXP_POSITIVE(tst_syscall(__NR_timer_getoverrun, timer));
> + TST_EXP_FAIL(tst_syscall(__NR_timer_getoverrun, -1), EINVAL);
> + break;
> }
> -
> - cleanup();
> - tst_exit();
> }
> +
> +static struct tst_test test = {
> + .test_all = run,
> + .test_variants = 2,
> +};
> --
> 2.35.3
--
Thank you,
Richard.
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [LTP] [PATCH v2] Refactor timer_getoverrun test using new LTP API
2023-09-04 11:19 [LTP] [PATCH v2] Refactor timer_getoverrun test using new LTP API Andrea Cervesato
2023-10-02 10:43 ` Richard Palethorpe
@ 2023-10-30 13:56 ` Cyril Hrubis
2023-11-16 15:13 ` Andrea Cervesato via ltp
1 sibling, 1 reply; 5+ messages in thread
From: Cyril Hrubis @ 2023-10-30 13:56 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi!
> + switch (tst_variant) {
> + case 0:
> + SAFE_TIMER_CREATE(CLOCK_REALTIME, &ev, &timer);
> + TST_EXP_POSITIVE(timer_getoverrun(timer));
> +
> + /* glibc causes SIGSEGV where timer_getoverrun() fails with EINVAL */
> +#ifndef __GLIBC__
> + TST_EXP_FAIL(timer_getoverrun((timer_t)-1), EINVAL);
> +#endif
I wonder if we should even keep it here, the most likely end result is
that we will have to add to this ifdef once other libc implementations
attempt to interpret the id before passing it to kernel. Maybe we should
just remove it and save our future time.
> + break;
> + case 1:
> + tst_syscall(__NR_timer_create, CLOCK_REALTIME, &ev, &timer);
> + TST_EXP_POSITIVE(tst_syscall(__NR_timer_getoverrun, timer));
> + TST_EXP_FAIL(tst_syscall(__NR_timer_getoverrun, -1), EINVAL);
There are actually two different cases that can cause EINVAL in the
kernel, first obvious case is that we id > INT_MAX, the second case is
failed lookup. I suppose that the -1 gets casted to unsigned long long
in kernel and ends up > INT_MAX.
I guess to trigger the second case we can call timer_delete(timer); and
then test it as:
TST_EXP_FAIL(tst_syscall(__NR_timer_getoverrun, timer), EINVAL);
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [LTP] [PATCH v2] Refactor timer_getoverrun test using new LTP API
2023-10-30 13:56 ` Cyril Hrubis
@ 2023-11-16 15:13 ` Andrea Cervesato via ltp
0 siblings, 0 replies; 5+ messages in thread
From: Andrea Cervesato via ltp @ 2023-11-16 15:13 UTC (permalink / raw)
To: Cyril Hrubis, Andrea Cervesato; +Cc: ltp
Hi!
On 10/30/23 14:56, Cyril Hrubis wrote:
> Hi!
>> + switch (tst_variant) {
>> + case 0:
>> + SAFE_TIMER_CREATE(CLOCK_REALTIME, &ev, &timer);
>> + TST_EXP_POSITIVE(timer_getoverrun(timer));
>> +
>> + /* glibc causes SIGSEGV where timer_getoverrun() fails with EINVAL */
>> +#ifndef __GLIBC__
>> + TST_EXP_FAIL(timer_getoverrun((timer_t)-1), EINVAL);
>> +#endif
> I wonder if we should even keep it here, the most likely end result is
> that we will have to add to this ifdef once other libc implementations
> attempt to interpret the id before passing it to kernel. Maybe we should
> just remove it and save our future time.
>
>> + break;
>> + case 1:
>> + tst_syscall(__NR_timer_create, CLOCK_REALTIME, &ev, &timer);
>> + TST_EXP_POSITIVE(tst_syscall(__NR_timer_getoverrun, timer));
>> + TST_EXP_FAIL(tst_syscall(__NR_timer_getoverrun, -1), EINVAL);
> There are actually two different cases that can cause EINVAL in the
> kernel, first obvious case is that we id > INT_MAX, the second case is
> failed lookup. I suppose that the -1 gets casted to unsigned long long
> in kernel and ends up > INT_MAX.
>
> I guess to trigger the second case we can call timer_delete(timer); and
> then test it as:
> TST_EXP_FAIL(tst_syscall(__NR_timer_getoverrun, timer), EINVAL);
>
In this case we can just get rid of variant and go for timer_delete.
That will also work.
Andrea
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-11-16 15:13 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-04 11:19 [LTP] [PATCH v2] Refactor timer_getoverrun test using new LTP API Andrea Cervesato
2023-10-02 10:43 ` Richard Palethorpe
2023-10-30 13:34 ` Cyril Hrubis
2023-10-30 13:56 ` Cyril Hrubis
2023-11-16 15:13 ` Andrea Cervesato via ltp
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox