From: Clemens Famulla-Conrad <cfamullaconrad@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v3 1/4] tst_test.sh: Use LTP_TIMEOUT_MUL in TST_RETRY_FN()
Date: Thu, 17 Oct 2019 14:23:19 +0200 [thread overview]
Message-ID: <1571314999.4128.3.camel@suse.de> (raw)
In-Reply-To: <20191017083935.GA21011@dell5510>
On Thu, 2019-10-17 at 10:39 +0200, Petr Vorel wrote:
> Hi Clemens,
>
> ...
> > -_tst_setup_timer()
> > +tst_multiply_timeout()
>
> Private function, it should have underscore prefix.
> > {
> > - TST_TIMEOUT=${TST_TIMEOUT:-300}
> > - LTP_TIMEOUT_MUL=${LTP_TIMEOUT_MUL:-1}
> > + # first parameter is used as return value
> > + local timeout="${!1}"
>
> Bashism, this will not work on dash, busybox shell ('busybox sh'),
> etc.
>
> checkbashisms.pl is your friend :).
> https://salsa.debian.org/debian/devscripts/raw/master/scripts/checkba
> shisms.pl
> https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guideline
> s#132-shell-coding-style
>
> Variable variable is possible to do portable way with eval.
> eval timeout=\$$1
Ok, I will take bashisms into acount. Thx for pointing me to that
script.
>
> > + [ $# -gt 1 ] && timeout="$2"
> > - if [ "$TST_TIMEOUT" = -1 ]; then
> > - tst_res TINFO "Timeout per run is disabled"
> > - return
> > - fi
> > + LTP_TIMEOUT_MUL=${LTP_TIMEOUT_MUL:-1}
> > local err="LTP_TIMEOUT_MUL must be number >= 1!"
> > @@ -396,13 +395,29 @@ _tst_setup_timer()
> > LTP_TIMEOUT_MUL=$((LTP_TIMEOUT_MUL+1))
> > tst_res TINFO "ceiling LTP_TIMEOUT_MUL to
> > $LTP_TIMEOUT_MUL"
> > fi
> > +
> > [ "$LTP_TIMEOUT_MUL" -ge 1 ] || tst_brk TBROK "$err
> > ($LTP_TIMEOUT_MUL)"
> > + [ "$timeout" -ge 1 ] || tst_brk TBROK "timeout need to be
> > >= 1 ($timeout)"
> > +
> > + eval "$1='$(( timeout * LTP_TIMEOUT_MUL))'"
>
> Eval on input, eval on output :).
>
> > + return 0
>
> You don't use return value anywhere. + There is no return 1.
> > +}
>
> Passing timeout variable name and optionally timeout value works and
> allows
> TBROK messages not to be mangled/hidden (which would be if function
> echo the
> result, which is then read the usual way:
> timeout=$(tst_multiply_timeout 100) ),
> but I'm not sure if all this is worth of just error handling.
> Having 2x eval, $2 optionally used (but only in tests) makes code a
> bit complex.
In the end, I never called the function with the optional second
parameter. So we could remove it and with it, the first eval.
Would you be ok with just one eval ?
> How about just simply save the result into global variable
> $TST_TIMEOUT?
Will not work, as this function is also used in
TST_RETRY_FN_EXP_BACKOFF() where we do not use TST_TIMEOUT.
thanks
Clemens
next prev parent reply other threads:[~2019-10-17 12:23 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-11 8:55 [LTP] [PATCH] Use LTP_TIMEOUT_MUL in TST_RETRY_FN() Clemens Famulla-Conrad
2019-09-11 9:12 ` Petr Vorel
2019-09-11 9:17 ` Clemens Famulla-Conrad
2019-09-11 16:52 ` [LTP] [PATCH v2 1/3] tst_test.sh: " Clemens Famulla-Conrad
2019-09-11 16:52 ` [LTP] [PATCH v2 2/3] tst_test.c: Add tst_adjust_timeout() Clemens Famulla-Conrad
2019-09-11 16:52 ` [LTP] [PATCH v2 3/3] tst_common.h: Use tst_adjust_timeout in TST_RETRY_FN() Clemens Famulla-Conrad
2019-09-12 5:42 ` [LTP] [PATCH v2 1/3] tst_test.sh: Use LTP_TIMEOUT_MUL " Li Wang
2019-09-12 8:52 ` Clemens Famulla-Conrad
2019-09-12 14:55 ` Petr Vorel
2019-09-12 16:49 ` Clemens Famulla-Conrad
2019-09-12 19:46 ` Clemens Famulla-Conrad
2019-09-12 21:51 ` Petr Vorel
2019-10-11 12:02 ` Petr Vorel
2019-10-11 12:53 ` Cyril Hrubis
2019-10-12 2:46 ` Li Wang
2019-10-16 11:25 ` Clemens Famulla-Conrad
2019-10-16 16:15 ` [LTP] [PATCH v3 1/4] " Clemens Famulla-Conrad
2019-10-16 16:15 ` [LTP] [PATCH v3 2/4] tst_test.c: Add tst_multiply_timeout() Clemens Famulla-Conrad
2019-10-17 8:47 ` Petr Vorel
2019-10-16 16:15 ` [LTP] [PATCH v3 3/4] tst_common.h: Use tst_multiply_timeout in TST_RETRY_FN() Clemens Famulla-Conrad
2019-10-17 8:48 ` Petr Vorel
2019-10-16 16:15 ` [LTP] [PATCH v3 4/4] Add newlib shell test for tst_multiply_timeout() Clemens Famulla-Conrad
2019-10-17 9:00 ` Petr Vorel
2019-10-17 8:39 ` [LTP] [PATCH v3 1/4] tst_test.sh: Use LTP_TIMEOUT_MUL in TST_RETRY_FN() Petr Vorel
2019-10-17 12:23 ` Clemens Famulla-Conrad [this message]
2019-10-18 7:46 ` Petr Vorel
2019-10-18 8:29 ` Petr Vorel
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=1571314999.4128.3.camel@suse.de \
--to=cfamullaconrad@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 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.