All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] tst_test.sh: achieve TST_RETRY_FUNC function in shell
Date: Wed, 2 May 2018 18:36:52 +0200	[thread overview]
Message-ID: <20180502163652.a7py5fv6yf4iceut@dell5510> (raw)
In-Reply-To: <20180502132902.16065-1-liwang@redhat.com>

Hi Li,

nice feature, thanks for adding it.
1 bashism to be fixed + minor issues bellow.


> Signed-off-by: Li Wang <liwang@redhat.com>
Tested-by: Petr Vorel <pvorel@suse.cz>

> ---
>  doc/test-writing-guidelines.txt | 20 ++++++++++++++++++++
>  testcases/lib/tst_test.sh       | 30 ++++++++++++++++++++++++++++++
>  2 files changed, 50 insertions(+)

> diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt
> index cbbfe6c..318eca6 100644
> --- a/doc/test-writing-guidelines.txt
> +++ b/doc/test-writing-guidelines.txt
> @@ -1640,6 +1640,26 @@ that can sleep for defined amount of seconds, milliseconds or microseconds.
>  tst_sleep 100ms
>  -------------------------------------------------------------------------------

> +Retry a function in limited time
> +++++++++++++++++++++++++++++++++
> +
> +Sometimes LTP test needs retrying a function for many times to get success.
> +This achievement makes that possible via keeping it retrying if the return
> +value of the function is NOT as we expected. After exceeding one second, the
> +test will break from the retries immediately.
> +
> +[source,c]
> +-------------------------------------------------------------------------------
> +# retry function in 1 second
> +TST_RETRY_FUNC(FUNC, ERET)
C docs should have been added in c2ce4df67d. Maybe you could just mention this in commit
message.

> +-------------------------------------------------------------------------------
> +
> +[source,sh]
> +-------------------------------------------------------------------------------
> +# retry function in 1 second
> +TST_RETRY_FUNC "FUNC arg1 arg2" "ERET"
Maybe EXPECTED_RET to be clearer?

> +-------------------------------------------------------------------------------
> +
>  Checking for integers
>  +++++++++++++++++++++

> +TST_RETRY_FN_EXP_BACKOFF()
> +{
> +	local tst_fun=$1
> +	local tst_exp=$2
I'd check number of params ($#) and tst_brk to warn user about improper usage.
And mention TST_RETRY_FN_EXP_BACKOFF() in docs?

> +	local tst_sec=$(expr $3 \* 1000000)
> +	local tst_delay=1
> +
> +	while true; do
> +		$tst_fun
> +		if [ "$?" == "$tst_exp" ]; then
                  ^
This is bashism, it's broken in dash. Please use single equal sign:
		if [ "$?" = "$tst_exp" ]; then


> +			break
> +		fi
> +
> +		if [ $tst_delay -lt $tst_sec ]; then
> +			tst_sleep ${tst_delay}us
> +			tst_delay=$((tst_delay*2))
> +		else
> +			tst_brk TBROK "$tst_fun failed"
> +		fi
> +	done
> +
> +	return $tst_exp
> +}
> +
> +TST_RETRY_FUNC()
> +{
> +	TST_RETRY_FN_EXP_BACKOFF "$1" "$2" 1
> +	return $2
> +}
> +
>  tst_umount()
>  {
>  	local device="$1"


Kind regards,
Petr

  reply	other threads:[~2018-05-02 16:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-02 13:29 [LTP] [PATCH] tst_test.sh: achieve TST_RETRY_FUNC function in shell Li Wang
2018-05-02 16:36 ` Petr Vorel [this message]
2018-05-03  2:56   ` Li Wang

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=20180502163652.a7py5fv6yf4iceut@dell5510 \
    --to=pvorel@suse.cz \
    --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.