ltp.lists.linux.it archive mirror
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] test_macros: TST_EXP_EXPR() add auto stringification
Date: Thu, 17 Feb 2022 15:27:30 +0100	[thread overview]
Message-ID: <20220217142730.19726-1-chrubis@suse.cz> (raw)

This unifies the behavior with the rest of the TST_EXP_*() macros that
auto-stringify their parameters in case that no format string is
supplied.

It's actually useful in cases where there is clear from the variables
what has been asserted such as:

static void run(void)
{
	siginfo_t infop;

	...

	TST_EXP_EXPR(infop.si_pid == child_pid);

	...
}

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 include/tst_test_macros.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
index 8893dbf0e..3b3b1b17e 100644
--- a/include/tst_test_macros.h
+++ b/include/tst_test_macros.h
@@ -211,7 +211,10 @@ extern void *TST_RET_PTR;
 #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__);
+#define TST_EXP_EXPR_(EXPR, SEXPR, ...) \
+	tst_res_(__FILE__, __LINE__, (EXPR) ? TPASS : TFAIL, \
+		TST_FMT_("Expect: " TST_2_(dummy, ##__VA_ARGS__, SEXPR), __VA_ARGS__))
+
+#define TST_EXP_EXPR(EXPR, ...) TST_EXP_EXPR_(EXPR, #EXPR, ##__VA_ARGS__)
 
 #endif	/* TST_TEST_MACROS_H__ */
-- 
2.34.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

             reply	other threads:[~2022-02-17 14:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-17 14:27 Cyril Hrubis [this message]
2022-02-17 16:39 ` [LTP] [PATCH] test_macros: TST_EXP_EXPR() add auto stringification Petr Vorel
2022-02-18  9:54   ` Cyril Hrubis
2022-02-18 10:31     ` Petr Vorel
2022-02-18 10:35       ` Cyril Hrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220217142730.19726-1-chrubis@suse.cz \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).