[LTP] [PATCH v2] Refactor timer_getoverrun test using new LTP API

Richard Palethorpe rpalethorpe@suse.de
Mon Oct 2 12:43:33 CEST 2023


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.


More information about the ltp mailing list