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

Li Wang liwang@redhat.com
Mon Apr 23 12:53:24 CEST 2018


Cyril Hrubis wrote:

> 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.

Good catch.

> 
> > +		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...

Yes, we should. I will do that when I'm free. Thanks for reviewing.

Li Wang


More information about the ltp mailing list