tst_test.sh: achieve TST_RETRY_FUNC function in shell
PATCH v3 1/1 tst_test.sh: achieve TST_RETRY_FUNC function in shell
The commit c2ce4df67d(include: add an exponential backoff macro for function retry) involves a new MACRO for function retry in C code, here achieve it in shell lib and gives a introduction in LTP documents.
--- doc/test-writing-guidelines.txt | 26 +++++++++++++++++++++++++ testcases/lib/tst_test.sh | 43 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+)
doc/test-writing-guidelines.txt +26 -0
@@ -1640,6 +1640,32 @@ 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 a limited time, +test will break from the retries immediately. + +[source,c] +------------------------------------------------------------------------------- +# retry function in 1 second +TST_RETRY_FUNC(FUNC, EXPECTED_RET) + +# retry function in N second +TST_RETRY_FN_EXP_BACKOFF(FUNC, EXPECTED_RET, N) +------------------------------------------------------------------------------- + +[source,sh] +------------------------------------------------------------------------------- +# retry function in 1 second +TST_RETRY_FUNC "FUNC arg1 arg2 ..." "EXPECTED_RET" + +# retry function in N second +TST_RETRY_FN_EXP_BACKOFF "FUNC arg1 arg2 ..." "EXPECTED_RET" "N" +------------------------------------------------------------------------------- + Checking for integers +++++++++++++++++++++
testcases/lib/tst_test.sh +43 -0
55 lines not on this page · raw message
Signature · 1 line
2.9.5
PATCH v3 1/1 tst_test.sh: achieve TST_RETRY_FUNC function in shell
Hi Li,
Quoted 7 lines
The commit c2ce4df67d(include: add an exponential backoff macro for function retry) involves a new MACRO for function retry in C code, here achieve it in shell lib and gives a introduction in LTP documents.
Signed-off-by Li Wang <[email protected]>Tested-by Petr Vorel <[email protected]>---
Thanks for your patch. Pushed with minor fix bellow + updated wiki.
Kind regards,
Petr
+++ testcases/lib/tst_test.sh
@@ -189,7 +189,7 @@ TST_RETRY_FN_EXP_BACKOFF()
TST_RETRY_FUNC()
{
if [ $# -ne 2 ]; then
- tst_brk TBROK "TST_RETRY_FN_EXP_BACKOFF expects 2 parameters"
+ tst_brk TBROK "TST_RETRY_FUNC expects 2 parameters"
fi
TST_RETRY_FN_EXP_BACKOFF "$1" "$2" 1