From d6a390e44e0caffbb19d96dfd0d6c0c83b27e602 Mon Sep 17 00:00:00 2001 From: Hangbin Liu Date: Thu, 16 Jul 2015 22:47:53 +0800 Subject: testcases/lib/test.sh: add tst_retry() The function allows you to retry running command a few times until it succeeds or until given amount of retries has been reached. Signed-off-by: Hangbin Liu Signed-off-by: Cyril Hrubis --- doc/test-writing-guidelines.txt | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'doc') diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt index edd59051d..de06dc9b5 100644 --- a/doc/test-writing-guidelines.txt +++ b/doc/test-writing-guidelines.txt @@ -1247,11 +1247,34 @@ fi ... ------------------------------------------------------------------------------- -The tst_fs_has_free shell interface returns 0 if the specified free space is +The 'tst_fs_has_free' shell interface returns 0 if the specified free space is satisfied, 1 if not, and 2 on error. The second argument supports suffixes kB, MB and GB, the default unit is Byte. +.tst_retry +[source,sh] +------------------------------------------------------------------------------- +#!/bin/sh + +... + +# Retry ping command three times +tst_retry "ping -c 1 127.0.0.1" + +if [ $? -ne 0 ]; then + tst_resm TFAIL "Failed to ping 127.0.0.1" +else + tst_resm TPASS "Successfully pinged 127.0.0.1" +fi + +... +------------------------------------------------------------------------------- + +The 'tst_retry' function allows you to retry a command after waiting small +amount of time until it succeeds or until given amount of retries has been +reached (default is three attempts). + 2.3.3 Cleanup ^^^^^^^^^^^^^ -- cgit v1.2.3