[LTP] [PATCH v2 1/2] tst_test_macros: add TST_EXP_FAIL_SILENT
Li Wang
liwang@redhat.com
Sat Feb 5 04:07:14 CET 2022
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__);
--
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20220205/040fdfcd/attachment.htm>
More information about the ltp
mailing list