diff mbox series

[v5,1/2] Add silent macros for TST_EXP_EQ_*

Message ID 20240911-fcntl4_refactoring-v5-1-948401e7131c@suse.com
State Accepted
Headers show
Series fcntl14 refactoring | expand

Commit Message

Andrea Cervesato Sept. 11, 2024, 8:06 a.m. UTC
From: Andrea Cervesato <andrea.cervesato@suse.com>

This patch adds the following macros:

TST_EXP_EQ_LI_SILENT
TST_EXP_EQ_LU_SILENT
TST_EXP_EQ_SZ_SILENT
TST_EXP_EQ_SSI_SILENT

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 include/tst_test_macros.h | 81 ++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 62 insertions(+), 19 deletions(-)

Comments

Cyril Hrubis Sept. 11, 2024, 1:44 p.m. UTC | #1
Hi!
> TST_EXP_EQ_LI_SILENT
> TST_EXP_EQ_LU_SILENT
> TST_EXP_EQ_SZ_SILENT
> TST_EXP_EQ_SSI_SILENT
> 
> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
> ---
>  include/tst_test_macros.h | 81 ++++++++++++++++++++++++++++++++++++-----------
>  1 file changed, 62 insertions(+), 19 deletions(-)
> 
> diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
> index 7a443c803..4217700f3 100644
> --- a/include/tst_test_macros.h
> +++ b/include/tst_test_macros.h
> @@ -344,29 +344,72 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
>         tst_res_(__FILE__, __LINE__, (EXPR) ? TPASS : TFAIL, "Expect: "       \
>                  TST_FMT_(TST_2_(dummy, ##__VA_ARGS__, #EXPR), __VA_ARGS__));
>  
> -#define TST_EXP_EQ_(VAL_A, SVAL_A, VAL_B, SVAL_B, TYPE, PFS) do {\
> -	TYPE tst_tmp_a__ = VAL_A; \
> -	TYPE tst_tmp_b__ = VAL_B; \
> -	if (tst_tmp_a__ == tst_tmp_b__) { \
> -		tst_res_(__FILE__, __LINE__, TPASS, \
> -			SVAL_A " == " SVAL_B " (" PFS ")", tst_tmp_a__); \
> -	} else { \
> -		tst_res_(__FILE__, __LINE__, TFAIL, \
> -			SVAL_A " (" PFS ") != " SVAL_B " (" PFS ")", \
> -			tst_tmp_a__, tst_tmp_b__); \
> -	} \
> +#define TST_EXP_EQ_SILENT_(VAL_A, SVAL_A, VAL_B, SVAL_B, TYPE, PFS) do {       \
> +	TYPE tst_tmp_a__ = VAL_A;                                              \
> +	TYPE tst_tmp_b__ = VAL_B;                                              \
> +                                                                               \
> +	TST_PASS = 0;                                                          \
> +                                                                               \
> +	if (tst_tmp_a__ != tst_tmp_b__) {                                      \
> +		tst_res_(__FILE__, __LINE__, TFAIL,                            \
> +			SVAL_A " (" PFS ") != " SVAL_B " (" PFS ")",           \
> +			tst_tmp_a__, tst_tmp_b__);                             \
> +		break;                                                         \

No need for the break here now.

Otherwise: Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Andrea Cervesato Sept. 11, 2024, 2:42 p.m. UTC | #2
Hi!

Pushed without the break.

Thanks,
Andrea

On 9/11/24 15:44, Cyril Hrubis wrote:
> Hi!
>> TST_EXP_EQ_LI_SILENT
>> TST_EXP_EQ_LU_SILENT
>> TST_EXP_EQ_SZ_SILENT
>> TST_EXP_EQ_SSI_SILENT
>>
>> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
>> ---
>>   include/tst_test_macros.h | 81 ++++++++++++++++++++++++++++++++++++-----------
>>   1 file changed, 62 insertions(+), 19 deletions(-)
>>
>> diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
>> index 7a443c803..4217700f3 100644
>> --- a/include/tst_test_macros.h
>> +++ b/include/tst_test_macros.h
>> @@ -344,29 +344,72 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
>>          tst_res_(__FILE__, __LINE__, (EXPR) ? TPASS : TFAIL, "Expect: "       \
>>                   TST_FMT_(TST_2_(dummy, ##__VA_ARGS__, #EXPR), __VA_ARGS__));
>>   
>> -#define TST_EXP_EQ_(VAL_A, SVAL_A, VAL_B, SVAL_B, TYPE, PFS) do {\
>> -	TYPE tst_tmp_a__ = VAL_A; \
>> -	TYPE tst_tmp_b__ = VAL_B; \
>> -	if (tst_tmp_a__ == tst_tmp_b__) { \
>> -		tst_res_(__FILE__, __LINE__, TPASS, \
>> -			SVAL_A " == " SVAL_B " (" PFS ")", tst_tmp_a__); \
>> -	} else { \
>> -		tst_res_(__FILE__, __LINE__, TFAIL, \
>> -			SVAL_A " (" PFS ") != " SVAL_B " (" PFS ")", \
>> -			tst_tmp_a__, tst_tmp_b__); \
>> -	} \
>> +#define TST_EXP_EQ_SILENT_(VAL_A, SVAL_A, VAL_B, SVAL_B, TYPE, PFS) do {       \
>> +	TYPE tst_tmp_a__ = VAL_A;                                              \
>> +	TYPE tst_tmp_b__ = VAL_B;                                              \
>> +                                                                               \
>> +	TST_PASS = 0;                                                          \
>> +                                                                               \
>> +	if (tst_tmp_a__ != tst_tmp_b__) {                                      \
>> +		tst_res_(__FILE__, __LINE__, TFAIL,                            \
>> +			SVAL_A " (" PFS ") != " SVAL_B " (" PFS ")",           \
>> +			tst_tmp_a__, tst_tmp_b__);                             \
>> +		break;                                                         \
> No need for the break here now.
>
> Otherwise: Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
>
diff mbox series

Patch

diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
index 7a443c803..4217700f3 100644
--- a/include/tst_test_macros.h
+++ b/include/tst_test_macros.h
@@ -344,29 +344,72 @@  const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
        tst_res_(__FILE__, __LINE__, (EXPR) ? TPASS : TFAIL, "Expect: "       \
                 TST_FMT_(TST_2_(dummy, ##__VA_ARGS__, #EXPR), __VA_ARGS__));
 
-#define TST_EXP_EQ_(VAL_A, SVAL_A, VAL_B, SVAL_B, TYPE, PFS) do {\
-	TYPE tst_tmp_a__ = VAL_A; \
-	TYPE tst_tmp_b__ = VAL_B; \
-	if (tst_tmp_a__ == tst_tmp_b__) { \
-		tst_res_(__FILE__, __LINE__, TPASS, \
-			SVAL_A " == " SVAL_B " (" PFS ")", tst_tmp_a__); \
-	} else { \
-		tst_res_(__FILE__, __LINE__, TFAIL, \
-			SVAL_A " (" PFS ") != " SVAL_B " (" PFS ")", \
-			tst_tmp_a__, tst_tmp_b__); \
-	} \
+#define TST_EXP_EQ_SILENT_(VAL_A, SVAL_A, VAL_B, SVAL_B, TYPE, PFS) do {       \
+	TYPE tst_tmp_a__ = VAL_A;                                              \
+	TYPE tst_tmp_b__ = VAL_B;                                              \
+                                                                               \
+	TST_PASS = 0;                                                          \
+                                                                               \
+	if (tst_tmp_a__ != tst_tmp_b__) {                                      \
+		tst_res_(__FILE__, __LINE__, TFAIL,                            \
+			SVAL_A " (" PFS ") != " SVAL_B " (" PFS ")",           \
+			tst_tmp_a__, tst_tmp_b__);                             \
+		break;                                                         \
+	} else {                                                               \
+		TST_PASS = 1;                                                  \
+	}                                                                      \
+} while (0)
+
+#define TST_EXP_EQ_LI(VAL_A, VAL_B) do {                                       \
+	TST_EXP_EQ_SILENT_(VAL_A, #VAL_A, VAL_B, #VAL_B, long long, "%lli");   \
+								               \
+	if (TST_PASS) {                                                        \
+		tst_res_(__FILE__, __LINE__, TPASS,                            \
+			#VAL_A " == " #VAL_B " (%lli)",                        \
+			(long long)VAL_A);                                     \
+	}                                                                      \
 } while (0)
 
-#define TST_EXP_EQ_LI(VAL_A, VAL_B) \
-		TST_EXP_EQ_(VAL_A, #VAL_A, VAL_B, #VAL_B, long long, "%lli")
+#define TST_EXP_EQ_LI_SILENT(VAL_A, VAL_B) \
+	TST_EXP_EQ_SILENT_(VAL_A, #VAL_A, VAL_B, #VAL_B, long long, "%lli")
+
+#define TST_EXP_EQ_LU(VAL_A, VAL_B) do {                                       \
+	TST_EXP_EQ_SILENT_(VAL_A, #VAL_A, VAL_B, #VAL_B, unsigned long long, "%llu"); \
+								               \
+	if (TST_PASS) {                                                        \
+		tst_res_(__FILE__, __LINE__, TPASS,                            \
+			#VAL_A " == " #VAL_B " (%llu)",                        \
+			(unsigned long long)VAL_A);                            \
+	}                                                                      \
+} while (0)
 
-#define TST_EXP_EQ_LU(VAL_A, VAL_B) \
-		TST_EXP_EQ_(VAL_A, #VAL_A, VAL_B, #VAL_B, unsigned long long, "%llu")
+#define TST_EXP_EQ_LU_SILENT(VAL_A, VAL_B) \
+	TST_EXP_EQ_SILENT_(VAL_A, #VAL_A, VAL_B, #VAL_B, unsigned long long, "%llu")
+
+#define TST_EXP_EQ_SZ(VAL_A, VAL_B) do {                                       \
+	TST_EXP_EQ_SILENT_(VAL_A, #VAL_A, VAL_B, #VAL_B, size_t, "%zu");       \
+								               \
+	if (TST_PASS) {                                                        \
+		tst_res_(__FILE__, __LINE__, TPASS,                            \
+			#VAL_A " == " #VAL_B " (%zu)",                         \
+			(size_t)VAL_A);                                        \
+	}                                                                      \
+} while (0)
 
-#define TST_EXP_EQ_SZ(VAL_A, VAL_B) \
-		TST_EXP_EQ_(VAL_A, #VAL_A, VAL_B, #VAL_B, size_t, "%zu")
+#define TST_EXP_EQ_SZ_SILENT(VAL_A, VAL_B) \
+	TST_EXP_EQ_SILENT_(VAL_A, #VAL_A, VAL_B, #VAL_B, size_t, "%zu")
+
+#define TST_EXP_EQ_SSZ(VAL_A, VAL_B) do {                                      \
+	TST_EXP_EQ_SILENT_(VAL_A, #VAL_A, VAL_B, #VAL_B, size_t, "%zi");       \
+								               \
+	if (TST_PASS) {                                                        \
+		tst_res_(__FILE__, __LINE__, TPASS,                            \
+			#VAL_A " == " #VAL_B " (%zi)",                         \
+			(ssize_t)VAL_A);                                        \
+	}                                                                      \
+} while (0)
 
-#define TST_EXP_EQ_SSZ(VAL_A, VAL_B) \
-		TST_EXP_EQ_(VAL_A, #VAL_A, VAL_B, #VAL_B, ssize_t, "%zi")
+#define TST_EXP_EQ_SSZ_SILENT(VAL_A, VAL_B) \
+	TST_EXP_EQ_SILENT_(VAL_A, #VAL_A, VAL_B, #VAL_B, ssize_t, "%zi")
 
 #endif	/* TST_TEST_MACROS_H__ */