All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Palethorpe <rpalethorpe@suse.de>
To: Li Wang <liwang@redhat.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v2 2/2] getitimer01: add checking for nonzero timer
Date: Thu, 17 Nov 2022 09:57:47 +0000	[thread overview]
Message-ID: <87edu1rjh4.fsf@suse.de> (raw)
In-Reply-To: <20221116122646.4085688-2-liwang@redhat.com>

Hello,

Li Wang <liwang@redhat.com> writes:

> By default a new process disabled the timer and getitimer()
> returned zero value. But we also need to check if the timer
> is correct when reset to nonzero.
>
> Signed-off-by: Li Wang <liwang@redhat.com>
> ---
>
> Notes:
>     v1 --> v2
>         * reset itimer value to zero to make parameter '-i' works
>         * print the time at the begining and end of test
>         * sperately compare result for tv_sec elapse or not
>         * print more info when TFAIL

Merged, thanks!

>
>  .../kernel/syscalls/getitimer/getitimer01.c   | 108 ++++++++++++++++--
>  1 file changed, 96 insertions(+), 12 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/getitimer/getitimer01.c b/testcases/kernel/syscalls/getitimer/getitimer01.c
> index 5ecfac55c..6b0cfba1c 100644
> --- a/testcases/kernel/syscalls/getitimer/getitimer01.c
> +++ b/testcases/kernel/syscalls/getitimer/getitimer01.c
> @@ -12,25 +12,109 @@
>   */
>  
>  #include "tst_test.h"
> +#include "tst_safe_clocks.h"
>  
> -static int itimer_name[] = {
> -	ITIMER_REAL,
> -	ITIMER_VIRTUAL,
> -	ITIMER_PROF,
> +#define SEC  100
> +#define USEC 10000
> +
> +static struct timeval tv;
> +static struct itimerval *value;
> +static long jiffy;
> +
> +static struct tcase {
> +	int which;
> +	char *des;
> +} tcases[] = {
> +	{ITIMER_REAL,    "ITIMER_REAL"},
> +	{ITIMER_VIRTUAL, "ITIMER_VIRTUAL"},
> +	{ITIMER_PROF,    "ITIMER_PROF"},
>  };
>  
> -static void run(void)
> +static void set_setitimer_value(int sec, int usec)
> +{
> +	value->it_value.tv_sec = sec;
> +	value->it_value.tv_usec = usec;
> +	value->it_interval.tv_sec = sec;
> +	value->it_interval.tv_usec = usec;
> +}
> +
> +static void verify_getitimer(unsigned int i)
>  {
> -	long unsigned int i;
> -	struct itimerval value;
> +	struct tcase *tc = &tcases[i];
> +
> +	tst_res(TINFO, "tc->which = %s", tc->des);
>  
> -	for (i = 0; i < ARRAY_SIZE(itimer_name); i++) {
> -		TST_EXP_PASS(getitimer(itimer_name[i], &value));
> -		TST_EXP_EQ_LI(value.it_value.tv_sec, 0);
> -		TST_EXP_EQ_LI(value.it_value.tv_usec, 0);
> +	if (tc->which == ITIMER_REAL) {
> +		if (gettimeofday(&tv, NULL) == -1)
> +			tst_brk(TBROK | TERRNO, "gettimeofday(&tv1, NULL) failed");
> +		else
> +			tst_res(TINFO, "Test begin time: %ld.%lds", tv.tv_sec, tv.tv_usec);
>  	}
> +
> +	TST_EXP_PASS(getitimer(tc->which, value));
> +	TST_EXP_EQ_LI(value->it_value.tv_sec, 0);
> +	TST_EXP_EQ_LI(value->it_value.tv_usec, 0);
> +	TST_EXP_EQ_LI(value->it_interval.tv_sec, 0);
> +	TST_EXP_EQ_LI(value->it_interval.tv_usec, 0);
> +
> +	set_setitimer_value(SEC, USEC);
> +	TST_EXP_PASS(setitimer(tc->which, value, NULL));
> +
> +	set_setitimer_value(0, 0);
> +	TST_EXP_PASS(getitimer(tc->which, value));
> +
> +	TST_EXP_EQ_LI(value->it_interval.tv_sec, SEC);
> +	TST_EXP_EQ_LI(value->it_interval.tv_usec, USEC);
> +
> +	tst_res(TINFO, "value->it_value.tv_sec=%ld, value->it_value.tv_usec=%ld",
> +			value->it_value.tv_sec, value->it_value.tv_usec);
> +
> +	/*
> +	 * ITIMER_VIRTUAL and ITIMER_PROF timers always expire a
> +	 * TICK_NSEC (jiffy) afterward the elapsed time to make
> +	 * sure that at least time counters take effect.
> +	 */
> +	long margin = (tc->which == ITIMER_REAL) ? 0 : jiffy;
> +
> +	if (value->it_value.tv_sec == SEC) {
> +		if (value->it_value.tv_usec < 0 ||
> +				value->it_value.tv_usec > USEC + margin)
> +			tst_brk(TFAIL, "value->it_value.tv_usec is out of range: %ld",
> +				value->it_value.tv_usec);
> +	} else {
> +		if (value->it_value.tv_sec < 0 ||
> +				value->it_value.tv_sec > SEC)
> +			tst_brk(TFAIL, "value->it_value.tv_sec is out of range: %ld",
> +				value->it_value.tv_sec);
> +	}
> +
> +	tst_res(TPASS, "timer value is within the expected range");
> +
> +	if (tc->which == ITIMER_REAL) {
> +		if (gettimeofday(&tv, NULL) == -1)
> +			tst_brk(TBROK | TERRNO, "gettimeofday(&tv1, NULL) failed");
> +		else
> +			tst_res(TINFO, "Test end time: %ld.%lds", tv.tv_sec, tv.tv_usec);
> +	}
> +
> +	set_setitimer_value(0, 0);
> +	TST_EXP_PASS_SILENT(setitimer(tc->which, value, NULL));
> +}
> +
> +static void setup(void)
> +{
> +	struct timespec time_res;
> +
> +	SAFE_CLOCK_GETRES(CLOCK_MONOTONIC_COARSE, &time_res);
> +	jiffy = (time_res.tv_nsec + 999) / 1000;
>  }
>  
>  static struct tst_test test = {
> -	.test_all = run
> +	.tcnt = ARRAY_SIZE(tcases),
> +	.setup = setup,
> +	.test = verify_getitimer,
> +	.bufs = (struct tst_buffers[]) {
> +		{&value,  .size = sizeof(struct itimerval)},
> +		{}
> +	}
>  };


-- 
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2022-11-17  9:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-16 12:26 [LTP] [PATCH v2 1/2] setitimer01: add interval timer test Li Wang
2022-11-16 12:26 ` [LTP] [PATCH v2 2/2] getitimer01: add checking for nonzero timer Li Wang
2022-11-17  9:57   ` Richard Palethorpe [this message]
2022-11-17  9:57 ` [LTP] [PATCH v2 1/2] setitimer01: add interval timer test Richard Palethorpe

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=87edu1rjh4.fsf@suse.de \
    --to=rpalethorpe@suse.de \
    --cc=liwang@redhat.com \
    --cc=ltp@lists.linux.it \
    /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.