[LTP] [PATCH v3 1/2] include: add an exponential backoff macro for function repeat

Cyril Hrubis chrubis@suse.cz
Mon Apr 23 11:58:55 CEST 2018


Hi!
> +#define TST_RETRY_FN_EXP_BACKOFF(FUNC, ERET, MAX_DELAY)	\
> +({	int tst_delay = 1;					\
> +	for (;;) {						\
> +		typeof(FUNC) ret = FUNC;			\
                              ^
		I prefixed this variable with tst_ and even added _
		suffix to make sure that it will not alias either.

> +		if (ret == ERET)				\
> +			break;					\
> +		if (tst_delay < MAX_DELAY * 1000000) {		\
> +			tst_res(TINFO,				\
> +				#FUNC" returned %i, retrying"	\
> +				" in %ius", ret, tst_delay);	\
> +			usleep(tst_delay);			\
> +			tst_delay *= 2;				\
> +		} else {					\
> +			tst_brk(TBROK, #FUNC" failed");		\
> +		}						\
> +	}							\
> +	ERET;							\
> +})

And pushed, thanks.

I know that the documentation is there in the comment but we should
probably add a note about the macro into the test-writing-guidelines.txt
as well...

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list