[LTP] [PATCH v1] Support return value in TST_* macros

Andrea Cervesato andrea.cervesato@suse.com
Wed Apr 26 10:31:01 CEST 2023


Hi Cyril,

On 4/26/23 10:26, Cyril Hrubis wrote:
> Hi!
>>   include/tst_test_macros.h | 69 +++++++++++++++++++++++++++------------
>>   1 file changed, 48 insertions(+), 21 deletions(-)
>>
>> diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
>> index 231c04951..acc2d1bff 100644
>> --- a/include/tst_test_macros.h
>> +++ b/include/tst_test_macros.h
>> @@ -74,45 +74,60 @@ extern void *TST_RET_PTR;
>>   	} while (0)
>>   
>>   #define TST_EXP_POSITIVE(SCALL, ...)                                           \
>> -	do {                                                                   \
>> +	({                                                                     \
>>   		TST_EXP_POSITIVE_(SCALL, #SCALL, ##__VA_ARGS__);               \
>>   		                                                               \
>>   		if (TST_PASS) {                                                \
>>   			TST_MSGP_(TPASS, " returned %ld",                      \
>>   			          TST_RET, #SCALL, ##__VA_ARGS__);             \
>>   		}                                                              \
>> -	} while (0)
>> +		                                                               \
>> +		TST_RET;                                                       \
>> +	})
>>   
>> -#define TST_EXP_FD_SILENT(SCALL, ...)	TST_EXP_POSITIVE_(SCALL, #SCALL, ##__VA_ARGS__)
>> +#define TST_EXP_FD_SILENT(SCALL, ...)                                          \
>> +	({                                                                     \
>> +		TST_EXP_POSITIVE_(SCALL, #SCALL, ##__VA_ARGS__);               \
>> +		TST_RET;                                                       \
>> +	})
> It would prbably be easier to change the TST_EXP_POSITIVE_ to return a
> value instead of changing all the macros that expand to
> TST_EXP_POSITIVE_.
The reason is that I didn't want to handle every "break". To return 
TST_RET after TST_EXP_POSITIVE_ seemed like a cleaner option.
>
>>   #define TST_EXP_FD(SCALL, ...)                                                 \
>> -	do {                                                                   \
>> +	({                                                                     \
>>   		TST_EXP_POSITIVE_(SCALL, #SCALL, ##__VA_ARGS__);               \
>>   		                                                               \
>>   		if (TST_PASS)                                                  \
>>   			TST_MSGP_(TPASS, " returned fd %ld", TST_RET,          \
>>   				#SCALL, ##__VA_ARGS__);                        \
>> -	} while (0)
>> +		                                                               \
>> +		TST_RET;                                                       \
>> +	})
>>   
>> -#define TST_EXP_FD_OR_FAIL(SCALL, ERRNO, ...)                                    \
>> -	do {                                                                   \
>> +#define TST_EXP_FD_OR_FAIL(SCALL, ERRNO, ...)                                  \
>> +	({                                                                     \
>>   		if (ERRNO)                                                     \
>>   			TST_EXP_FAIL(SCALL, ERRNO, ##__VA_ARGS__);             \
>>   		else                                                           \
>>   			TST_EXP_FD(SCALL, ##__VA_ARGS__);                      \
>>   		                                                               \
>> -	} while (0)
>> +		TST_RET;                                                       \
>> +	})
>>   
>> -#define TST_EXP_PID_SILENT(SCALL, ...)	TST_EXP_POSITIVE_(SCALL, #SCALL, ##__VA_ARGS__)
>> +#define TST_EXP_PID_SILENT(SCALL, ...)                                         \
>> +	({                                                                     \
>> +		TST_EXP_POSITIVE_(SCALL, #SCALL, ##__VA_ARGS__);               \
>> +		TST_RET;                                                       \
>> +	})
>>   
>>   #define TST_EXP_PID(SCALL, ...)                                                \
>> -	do {                                                                   \
>> +	({                                                                     \
>>   		TST_EXP_POSITIVE_(SCALL, #SCALL, ##__VA_ARGS__);               \
>>   									       \
>>   		if (TST_PASS)                                                  \
>>   			TST_MSGP_(TPASS, " returned pid %ld", TST_RET,         \
>>   				#SCALL, ##__VA_ARGS__);                        \
>> -	} while (0)
>> +		                                                               \
>> +		TST_RET;                                                       \
>> +	})
>>   
>>   #define TST_EXP_VAL_SILENT_(SCALL, VAL, SSCALL, ...)                           \
>>   	do {                                                                   \
>> @@ -128,18 +143,20 @@ extern void *TST_RET_PTR;
>>   		                                                               \
>>   		TST_PASS = 1;                                                  \
>>   		                                                               \
>> +		TST_RET;                                                       \
>>   	} while (0)
>>   
>>   #define TST_EXP_VAL_SILENT(SCALL, VAL, ...) TST_EXP_VAL_SILENT_(SCALL, VAL, #SCALL, ##__VA_ARGS__)
>>   
>>   #define TST_EXP_VAL(SCALL, VAL, ...)                                           \
>> -	do {                                                                   \
>> +	({                                                                     \
>>   		TST_EXP_VAL_SILENT_(SCALL, VAL, #SCALL, ##__VA_ARGS__);        \
>>   		                                                               \
>>   		if (TST_PASS)                                                  \
>>   			TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__);     \
>> -			                                                       \
>> -	} while(0)
>> +		                                                               \
>> +		TST_RET;                                                       \
>> +	})
>>   
>>   #define TST_EXP_PASS_SILENT_(SCALL, SSCALL, ...)                               \
>>   	do {                                                                   \
>> @@ -163,15 +180,21 @@ extern void *TST_RET_PTR;
>>                                                                                  \
>>   	} while (0)
>>   
>> -#define TST_EXP_PASS_SILENT(SCALL, ...) TST_EXP_PASS_SILENT_(SCALL, #SCALL, ##__VA_ARGS__)
>> +#define TST_EXP_PASS_SILENT(SCALL, ...)                                        \
>> +	({                                                                     \
>> +		TST_EXP_PASS_SILENT_(SCALL, #SCALL, ##__VA_ARGS__);            \
>> +		TST_RET;                                                       \
>> +	})
> Do we really need an return value from EXP_PASS and EXP_FAIL?
>
> If TST_EXP_PASS_* does not break the test the return value was 0, if
> TST_EXP_FAIL_* does not break the test, the return value was -1
Makes sense.
>>   #define TST_EXP_PASS(SCALL, ...)                                               \
>> -	do {                                                                   \
>> +	({                                                                     \
>>   		TST_EXP_PASS_SILENT_(SCALL, #SCALL, ##__VA_ARGS__);            \
>>   		                                                               \
>>   		if (TST_PASS)                                                  \
>>   			TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__);     \
>> -	} while (0)                                                            \
>> +		                                                               \
>> +		TST_RET;                                                       \
>> +	})
>>   
>>   #define TST_EXP_FAIL_SILENT_(PASS_COND, SCALL, SSCALL, ERRNO, ...)             \
>>   	do {                                                                   \
>> @@ -200,20 +223,24 @@ extern void *TST_RET_PTR;
>>   	} while (0)
>>   
>>   #define TST_EXP_FAIL(SCALL, ERRNO, ...)                                        \
>> -	do {                                                                   \
>> +	({                                                                     \
>>   		TST_EXP_FAIL_SILENT_(TST_RET == 0, SCALL, #SCALL,              \
>>   			ERRNO, ##__VA_ARGS__);                                 \
>>   		if (TST_PASS)                                                  \
>>   			TST_MSG_(TPASS | TTERRNO, " ", #SCALL, ##__VA_ARGS__); \
>> -	} while (0)
>> +		                                                               \
>> +		TST_RET;                                                       \
>> +	})
>>   
>>   #define TST_EXP_FAIL2(SCALL, ERRNO, ...)                                       \
>> -	do {                                                                   \
>> +	({                                                                     \
>>   		TST_EXP_FAIL_SILENT_(TST_RET >= 0, SCALL, #SCALL,              \
>>   			ERRNO, ##__VA_ARGS__);                                 \
>>   		if (TST_PASS)                                                  \
>>   			TST_MSG_(TPASS | TTERRNO, " ", #SCALL, ##__VA_ARGS__); \
>> -	} while (0)
>> +		                                                               \
>> +		TST_RET;                                                       \
>> +	})
>>   
>>   #define TST_EXP_FAIL_SILENT(SCALL, ERRNO, ...) \
>>   	TST_EXP_FAIL_SILENT_(TST_RET == 0, SCALL, #SCALL, ERRNO, ##__VA_ARGS__)
>> -- 
>> 2.35.3
>>
>>
>> -- 
>> Mailing list info: https://lists.linux.it/listinfo/ltp

Andrea



More information about the ltp mailing list