diff mbox series

[v2,1/2] tst_test_macros: add TST_EXP_FAIL_SILENT

Message ID b10d44db50b76cf5332cff491b5f22500b2b88c6.1643980361.git.jstancek@redhat.com
State Accepted, archived
Headers show
Series mkdir09: rewrite in new LTP API | expand

Commit Message

Jan Stancek Feb. 4, 2022, 1:14 p.m. UTC
This variant does not print TPASS messages when
SCALL fails as expected.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 doc/c-test-api.txt        |  3 +++
 include/tst_test_macros.h | 15 ++++++++++-----
 2 files changed, 13 insertions(+), 5 deletions(-)

Comments

Li Wang Feb. 5, 2022, 3:07 a.m. UTC | #1
On Fri, Feb 4, 2022 at 9:14 PM Jan Stancek <jstancek@redhat.com> wrote:

> This variant does not print TPASS messages when
> SCALL fails as expected.
>
> Signed-off-by: Jan Stancek <jstancek@redhat.com>
> ---
>  doc/c-test-api.txt        |  3 +++
>  include/tst_test_macros.h | 15 ++++++++++-----
>  2 files changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/doc/c-test-api.txt b/doc/c-test-api.txt
> index 6f4de3f80f95..9119e094dbfd 100644
> --- a/doc/c-test-api.txt
> +++ b/doc/c-test-api.txt
> @@ -298,6 +298,9 @@ The 'TST_EXP_FAIL2()' is the same as 'TST_EXP_FAIL()'
> except the return value is
>  expected to be non-negative integer if call passes. These macros build
> upon the
>  +TEST()+ macro and associated variables.
>
> +'TST_EXP_FAIL_SILENT()' and 'TST_EXP_FAIL2_SILENT()' variants are less
> verbose
> +and do not print TPASS messages when SCALL fails as expected.
> +
>  [source,c]
>
>  -------------------------------------------------------------------------------
>  TEST(socket(AF_INET, SOCK_RAW, 1));
> diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
> index ec8c38523344..f7de8d00a666 100644
> --- a/include/tst_test_macros.h
> +++ b/include/tst_test_macros.h
> @@ -163,7 +163,7 @@ extern void *TST_RET_PTR;
>                         TST_MSG_(TPASS, " passed", #SCALL,
> ##__VA_ARGS__);     \
>         } while (0)
>     \
>
> -#define TST_EXP_FAIL_(PASS_COND, SCALL, SSCALL, ERRNO, ...)
>       \
> +#define TST_EXP_FAIL_(SILENT, PASS_COND, SCALL, SSCALL, ERRNO, ...)
>       \
>

I think maybe the better way is to define TST_EXP_FAIL_SILENT_
but not add a new SILENT parameter. So that it keeps consistent with
the existing TST_EXP_PASS_SILENT_ macros.

How about this:
(changed base on your patch)

--- a/include/tst_test_macros.h
+++ b/include/tst_test_macros.h
@@ -163,7 +163,7 @@ extern void *TST_RET_PTR;
                        TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__);
    \
        } while (0)
   \

-#define TST_EXP_FAIL_(SILENT, PASS_COND, SCALL, SSCALL, ERRNO, ...)
     \
+#define TST_EXP_FAIL_SILENT_(PASS_COND, SCALL, SSCALL, ERRNO, ...)
    \
        do {
    \
                TEST(SCALL);
    \

   \
@@ -181,9 +181,6 @@ extern void *TST_RET_PTR;
                }
   \

   \
                if (TST_ERR == (ERRNO)) {
   \
-                       if (!SILENT)
    \
-                               TST_MSG_(TPASS | TTERRNO, " ",
    \
-                                       SSCALL, ##__VA_ARGS__);
   \
                        TST_PASS = 1;
   \
                } else {
    \
                        TST_MSGP_(TFAIL | TTERRNO, " expected %s",
    \
@@ -192,13 +189,23 @@ extern void *TST_RET_PTR;
                }
   \
        } while (0)

-#define TST_EXP_FAIL(SCALL, ERRNO, ...) TST_EXP_FAIL_(0, TST_RET == 0,
SCALL, #SCALL, ERRNO, ##__VA_ARGS__)
+#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)

-#define TST_EXP_FAIL2(SCALL, ERRNO, ...) TST_EXP_FAIL_(0, TST_RET >= 0,
SCALL, #SCALL, ERRNO, ##__VA_ARGS__)
+#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)

-#define TST_EXP_FAIL_SILENT(SCALL, ERRNO, ...) TST_EXP_FAIL_(1, TST_RET ==
0, SCALL, #SCALL, ERRNO, ##__VA_ARGS__)
+#define TST_EXP_FAIL_SILENT(SCALL, ERRNO, ...)
TST_EXP_FAIL_SILENT_(TST_RET == 0, SCALL, #SCALL, ERRNO, ##__VA_ARGS__) \

-#define TST_EXP_FAIL2_SILENT(SCALL, ERRNO, ...) TST_EXP_FAIL_(1, TST_RET
>= 0, SCALL, #SCALL, ERRNO, ##__VA_ARGS__)
+#define TST_EXP_FAIL2_SILENT(SCALL, ERRNO, ...)
TST_EXP_FAIL_SILENT_(TST_RET >= 0, SCALL, #SCALL, ERRNO, ##__VA_ARGS__) \

 #define TST_EXP_EXPR(EXPR, FMT, ...)
    \
        tst_res_(__FILE__, __LINE__, (EXPR) ? TPASS : TFAIL, "Expect: "
FMT, ##__VA_ARGS__);
Jan Stancek Feb. 7, 2022, 9:17 a.m. UTC | #2
On Sat, Feb 5, 2022 at 4:07 AM Li Wang <liwang@redhat.com> wrote:
>
>
>
> On Fri, Feb 4, 2022 at 9:14 PM Jan Stancek <jstancek@redhat.com> wrote:
>>
>> This variant does not print TPASS messages when
>> SCALL fails as expected.
>>
>> Signed-off-by: Jan Stancek <jstancek@redhat.com>
>> ---
>>  doc/c-test-api.txt        |  3 +++
>>  include/tst_test_macros.h | 15 ++++++++++-----
>>  2 files changed, 13 insertions(+), 5 deletions(-)
>>
>> diff --git a/doc/c-test-api.txt b/doc/c-test-api.txt
>> index 6f4de3f80f95..9119e094dbfd 100644
>> --- a/doc/c-test-api.txt
>> +++ b/doc/c-test-api.txt
>> @@ -298,6 +298,9 @@ The 'TST_EXP_FAIL2()' is the same as 'TST_EXP_FAIL()' except the return value is
>>  expected to be non-negative integer if call passes. These macros build upon the
>>  +TEST()+ macro and associated variables.
>>
>> +'TST_EXP_FAIL_SILENT()' and 'TST_EXP_FAIL2_SILENT()' variants are less verbose
>> +and do not print TPASS messages when SCALL fails as expected.
>> +
>>  [source,c]
>>  -------------------------------------------------------------------------------
>>  TEST(socket(AF_INET, SOCK_RAW, 1));
>> diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
>> index ec8c38523344..f7de8d00a666 100644
>> --- a/include/tst_test_macros.h
>> +++ b/include/tst_test_macros.h
>> @@ -163,7 +163,7 @@ extern void *TST_RET_PTR;
>>                         TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__);     \
>>         } while (0)                                                            \
>>
>> -#define TST_EXP_FAIL_(PASS_COND, SCALL, SSCALL, ERRNO, ...)                    \
>> +#define TST_EXP_FAIL_(SILENT, PASS_COND, SCALL, SSCALL, ERRNO, ...)            \
>
>
> I think maybe the better way is to define TST_EXP_FAIL_SILENT_
> but not add a new SILENT parameter. So that it keeps consistent with
> the existing TST_EXP_PASS_SILENT_ macros.

It looked like smaller change, but I can update it (Along with the
suggestion to create/delete more directories)
diff mbox series

Patch

diff --git a/doc/c-test-api.txt b/doc/c-test-api.txt
index 6f4de3f80f95..9119e094dbfd 100644
--- a/doc/c-test-api.txt
+++ b/doc/c-test-api.txt
@@ -298,6 +298,9 @@  The 'TST_EXP_FAIL2()' is the same as 'TST_EXP_FAIL()' except the return value is
 expected to be non-negative integer if call passes. These macros build upon the
 +TEST()+ macro and associated variables.
 
+'TST_EXP_FAIL_SILENT()' and 'TST_EXP_FAIL2_SILENT()' variants are less verbose
+and do not print TPASS messages when SCALL fails as expected.
+
 [source,c]
 -------------------------------------------------------------------------------
 TEST(socket(AF_INET, SOCK_RAW, 1));
diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
index ec8c38523344..f7de8d00a666 100644
--- a/include/tst_test_macros.h
+++ b/include/tst_test_macros.h
@@ -163,7 +163,7 @@  extern void *TST_RET_PTR;
 			TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__);     \
 	} while (0)                                                            \
 
-#define TST_EXP_FAIL_(PASS_COND, SCALL, SSCALL, ERRNO, ...)                    \
+#define TST_EXP_FAIL_(SILENT, PASS_COND, SCALL, SSCALL, ERRNO, ...)            \
 	do {                                                                   \
 		TEST(SCALL);                                                   \
 		                                                               \
@@ -181,8 +181,9 @@  extern void *TST_RET_PTR;
 		}                                                              \
 		                                                               \
 		if (TST_ERR == (ERRNO)) {                                      \
-			TST_MSG_(TPASS | TTERRNO, " ",                         \
-				 SSCALL, ##__VA_ARGS__);                       \
+			if (!SILENT)                                           \
+				TST_MSG_(TPASS | TTERRNO, " ",                 \
+				        SSCALL, ##__VA_ARGS__);                \
 			TST_PASS = 1;                                          \
 		} else {                                                       \
 			TST_MSGP_(TFAIL | TTERRNO, " expected %s",             \
@@ -191,9 +192,13 @@  extern void *TST_RET_PTR;
 		}                                                              \
 	} while (0)
 
-#define TST_EXP_FAIL(SCALL, ERRNO, ...) TST_EXP_FAIL_(TST_RET == 0, SCALL, #SCALL, ERRNO, ##__VA_ARGS__)
+#define TST_EXP_FAIL(SCALL, ERRNO, ...) TST_EXP_FAIL_(0, TST_RET == 0, SCALL, #SCALL, ERRNO, ##__VA_ARGS__)
 
-#define TST_EXP_FAIL2(SCALL, ERRNO, ...) TST_EXP_FAIL_(TST_RET >= 0, SCALL, #SCALL, ERRNO, ##__VA_ARGS__)
+#define TST_EXP_FAIL2(SCALL, ERRNO, ...) TST_EXP_FAIL_(0, TST_RET >= 0, SCALL, #SCALL, ERRNO, ##__VA_ARGS__)
+
+#define TST_EXP_FAIL_SILENT(SCALL, ERRNO, ...) TST_EXP_FAIL_(1, TST_RET == 0, SCALL, #SCALL, ERRNO, ##__VA_ARGS__)
+
+#define TST_EXP_FAIL2_SILENT(SCALL, ERRNO, ...) TST_EXP_FAIL_(1, TST_RET >= 0, SCALL, #SCALL, ERRNO, ##__VA_ARGS__)
 
 #define TST_EXP_EXPR(EXPR, FMT, ...)						\
 	tst_res_(__FILE__, __LINE__, (EXPR) ? TPASS : TFAIL, "Expect: " FMT, ##__VA_ARGS__);