All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] test_macros: TST_EXP_EXPR() add auto stringification
@ 2022-02-17 14:27 Cyril Hrubis
  2022-02-17 16:39 ` Petr Vorel
  0 siblings, 1 reply; 5+ messages in thread
From: Cyril Hrubis @ 2022-02-17 14:27 UTC (permalink / raw)
  To: ltp

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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH] test_macros: TST_EXP_EXPR() add auto stringification
  2022-02-17 14:27 [LTP] [PATCH] test_macros: TST_EXP_EXPR() add auto stringification Cyril Hrubis
@ 2022-02-17 16:39 ` Petr Vorel
  2022-02-18  9:54   ` Cyril Hrubis
  0 siblings, 1 reply; 5+ messages in thread
From: Petr Vorel @ 2022-02-17 16:39 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hi Cyril,

Reviewed-by: Petr Vorel <pvorel@suse.cz>
Good idea.

BTW I'm thinking to add some comments to "top level" macros.
because it's getting hard to read these macros.

Kind regards,
Petr

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH] test_macros: TST_EXP_EXPR() add auto stringification
  2022-02-17 16:39 ` Petr Vorel
@ 2022-02-18  9:54   ` Cyril Hrubis
  2022-02-18 10:31     ` Petr Vorel
  0 siblings, 1 reply; 5+ messages in thread
From: Cyril Hrubis @ 2022-02-18  9:54 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

Hi!
> Reviewed-by: Petr Vorel <pvorel@suse.cz>
> Good idea.

It occured to me that this is probably not the best result though, since
in the case of the failure it does not print the expected and actual
value. So maybe it would be better to add TST_EXP_EQ() macro instead. I
will send a patch later on.

> BTW I'm thinking to add some comments to "top level" macros.
> because it's getting hard to read these macros.

Well yes, it's getting a bit hard to read indeed.

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH] test_macros: TST_EXP_EXPR() add auto stringification
  2022-02-18  9:54   ` Cyril Hrubis
@ 2022-02-18 10:31     ` Petr Vorel
  2022-02-18 10:35       ` Cyril Hrubis
  0 siblings, 1 reply; 5+ messages in thread
From: Petr Vorel @ 2022-02-18 10:31 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hi Cyril,

> Hi!
> > Reviewed-by: Petr Vorel <pvorel@suse.cz>
> > Good idea.

> It occured to me that this is probably not the best result though, since
> in the case of the failure it does not print the expected and actual
> value. So maybe it would be better to add TST_EXP_EQ() macro instead. I
> will send a patch later on.

I wonder can't we have both - print stringified parameters and also their
values? Would it be too confusing?

> > BTW I'm thinking to add some comments to "top level" macros.
> > because it's getting hard to read these macros.

> Well yes, it's getting a bit hard to read indeed.
I mean it's good to have documented in our wiki. But even we document all
macros most of us will endup reading the header, thus why useful to document
at least end user ("top level") macros.

Kind regards,
Petr

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH] test_macros: TST_EXP_EXPR() add auto stringification
  2022-02-18 10:31     ` Petr Vorel
@ 2022-02-18 10:35       ` Cyril Hrubis
  0 siblings, 0 replies; 5+ messages in thread
From: Cyril Hrubis @ 2022-02-18 10:35 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

Hi!
> > It occured to me that this is probably not the best result though, since
> > in the case of the failure it does not print the expected and actual
> > value. So maybe it would be better to add TST_EXP_EQ() macro instead. I
> > will send a patch later on.
> 
> I wonder can't we have both - print stringified parameters and also their
> values? Would it be too confusing?

Couldn't be done unless you know the types beforehand. I've send another
patch that adds TST_EXP_EQ_*() macros please have a look at that one
instead.

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-02-18 10:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-17 14:27 [LTP] [PATCH] test_macros: TST_EXP_EXPR() add auto stringification Cyril Hrubis
2022-02-17 16:39 ` Petr Vorel
2022-02-18  9:54   ` Cyril Hrubis
2022-02-18 10:31     ` Petr Vorel
2022-02-18 10:35       ` Cyril Hrubis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.