public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Richard Palethorpe <rpalethorpe@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 1/2] Add TST_SPIN_TEST() macro
Date: Wed, 05 Feb 2020 12:51:11 +0100	[thread overview]
Message-ID: <87o8udgsls.fsf@our.domain.is.not.set> (raw)
In-Reply-To: <20200203113956.13176-1-mdoucha@suse.cz>

Hi,

Martin Doucha <mdoucha@suse.cz> writes:

> The TST_RETRY_FUNC() macro requires a single return value that'll be considered
> success. This cannot be used with system calls that e.g. return a new file
> descriptor because the success value is somewhat unpredictable.
>
> Add a new macro TST_SPIN_TEST that'll work mostly like TST_RETRY_FUNC(), except:
> - Any negative return value means failure, any non-negative return value means
>   success.
> - The loop will fall through on timeout instead of callid tst_brk(). TST_RET
>   and TST_ERR will be set to the values returned by the last FUNC call.
>
> Signed-off-by: Martin Doucha <mdoucha@suse.cz>
> ---
>  include/tst_common.h | 28 ++++++++++++++++++++++++++++
>  1 file changed, 28 insertions(+)
>
> diff --git a/include/tst_common.h b/include/tst_common.h
> index a0c06a3f7..72e00ca81 100644
> --- a/include/tst_common.h
> +++ b/include/tst_common.h
> @@ -55,6 +55,34 @@
>  	ERET;								\
>  })
>
> +/**
> + * TST_SPIN_TEST() - Repeatedly retry a function with an increasing delay.
> + * @FUNC - The function which will be retried
> + *
> + * Same as TST_RETRY_FUNC() but any non-negative return value is accepted
> + * as success and tst_brk() will not be called on timeout.
> + */
> +#define TST_SPIN_TEST(FUNC) \
> +	TST_SPIN_TEST_EXP_BACKOFF(FUNC, 1, -1)

Ah, so this is actually always exponential. Ignore my comment on other
patch.

> +
> +#define TST_SPIN_TEST_EXP_BACKOFF(FUNC, MAX_DELAY, GOOD_ERRNO)	\
> +({	unsigned int tst_delay_, tst_max_delay_;			\
> +	tst_delay_ = 1;							\
> +	tst_max_delay_ = tst_multiply_timeout(MAX_DELAY * 1000000);	\
> +	for (;;) {							\
> +		TEST(FUNC);						\
> +		if (TST_RET >= 0 || (GOOD_ERRNO >= 0 && TST_ERR == GOOD_ERRNO))	\
> +			break;						\
> +		if (tst_delay_ < tst_max_delay_) {			\
> +			usleep(tst_delay_);				\
> +			tst_delay_ *= 2;				\
> +		} else {						\
> +			break;						\
> +		}							\
> +	}								\
> +	TST_RET;							\
> +})
> +
>  #define TST_BRK_SUPPORTS_ONLY_TCONF_TBROK(condition) \
>  	do { ((void)sizeof(char[1 - 2 * !!(condition)])); } while (0)
>
> --
> 2.24.1


--
Thank you,
Richard.

  parent reply	other threads:[~2020-02-05 11:51 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-03 11:39 [LTP] [PATCH 1/2] Add TST_SPIN_TEST() macro Martin Doucha
2020-02-03 11:39 ` [LTP] [PATCH 2/2] Fix BPF test program loading issues Martin Doucha
2020-02-05 11:48   ` Richard Palethorpe
2020-02-05 14:31   ` Cyril Hrubis
2020-02-05 15:25     ` Martin Doucha
2020-02-05 15:50       ` Cyril Hrubis
2020-02-05 16:17         ` Martin Doucha
2020-02-05 19:10           ` Cyril Hrubis
2020-02-06 11:02             ` Richard Palethorpe
2020-02-06 11:53               ` Martin Doucha
2020-02-06 12:10                 ` Richard Palethorpe
2020-02-06 12:36                   ` Richard Palethorpe
2020-02-06 13:08                     ` Martin Doucha
2020-02-05 11:51 ` Richard Palethorpe [this message]
2020-02-05 14:25 ` [LTP] [PATCH 1/2] Add TST_SPIN_TEST() macro Cyril Hrubis

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=87o8udgsls.fsf@our.domain.is.not.set \
    --to=rpalethorpe@suse.de \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox