All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: Li Wang <liwang@redhat.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH 0/2] lib: Add TINFO_WARN
Date: Fri, 21 Jun 2024 15:39:11 +0200	[thread overview]
Message-ID: <20240621133911.GA694629@pevik> (raw)
In-Reply-To: <CAEemH2dVaMfNPP2m8_nEb235=9Q5bo4H1WtQbpFgrcmyyVESfw@mail.gmail.com>

Hi Li,

> Hi All,

> I come up with a way to define simple macros for all LTP print, especially
> for TFAIL
> we could make use of the GET_MACRO to select a specific macro implementation
> based on the number of arguments provided to a variadic macro.

> Something partly like:

> --- a/include/tst_test_macros.h
> +++ b/include/tst_test_macros.h
> @@ -368,4 +368,28 @@ const char *tst_errno_names(char *buf, const int
> *exp_errs, int exp_errs_cnt);
>  #define TST_EXP_EQ_SSZ(VAL_A, VAL_B) \
>                 TST_EXP_EQ_(VAL_A, #VAL_A, VAL_B, #VAL_B, ssize_t, "%zi")

> +/*TST_RES*/
> +#define TST_RES_TINFO(MESSAGE) \
> +       tst_res(TINFO, MESSAGE);
> +
> +#define TST_RES_TWARN(MESSAGE) \
> +       tst_res(TINFO, "WARNING "MESSAGE);
> +
> +#define TST_RES_TCONF(MESSAGE) \
> +       tst_res(TCONF, MESSAGE);
> +
> +#define TST_RES_TPASS(MESSAGE) \
> +       tst_res(TPASS, MESSAGE);
> +
> +#define TST_RES_TFAIL(...) \
> +           GET_MACRO(__VA_ARGS__, TST_RES_FAIL2,
> TST_RES_FAIL1)(__VA_ARGS__)
> +
> +#define GET_MACRO(_1, _2, NAME, ...) NAME
> +
> +#define TST_RES_FAIL1(MESSAGE) \
> +           tst_res(TFAIL, MESSAGE)
> +
> +#define TST_RES_FAIL2(flag, MESSAGE) \
> +           tst_res(TFAIL | flag, MESSAGE)
> +
>  #endif /* TST_TEST_MACROS_H__ */
> diff --git a/lib/newlib_tests/tst_res_macros.c
> b/lib/newlib_tests/tst_res_macros.c
> new file mode 100644
> index 000000000..e16f3cbba
> --- /dev/null
> +++ b/lib/newlib_tests/tst_res_macros.c
> @@ -0,0 +1,22 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2024 Li Wang <liwang@redhat.com>
> + */
> +
> +#include "tst_test.h"
> +#include "tst_res_flags.h"
> +#include "tst_test_macros.h"
> +
> +static void do_test(unsigned int i)
> +{
> +       TST_RES_TINFO("message");
> +       TST_RES_TPASS("message");
> +       TST_RES_TWARN("message");
> +       TST_RES_TFAIL("message");
> +       TST_RES_TFAIL(TERRNO, "message");
> +       TST_RES_TFAIL(TTERRNO, "message");
> +}
> +
> +static struct tst_test test = {
> +       .test_all = do_test,
> +};

Reviewed-by: Petr Vorel <pvorel@suse.cz>
Thanks!

Kind regards,
Petr

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

  reply	other threads:[~2024-06-21 13:39 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-27 22:29 [LTP] [PATCH 0/2] lib: Add TINFO_WARN Petr Vorel
2024-05-27 22:29 ` [LTP] [PATCH 1/2] " Petr Vorel
2024-05-27 22:29 ` [LTP] [PATCH 2/2] tree: Use TINFO_WARN Petr Vorel
2024-05-28  6:04 ` [LTP] [PATCH 0/2] lib: Add TINFO_WARN Andrea Cervesato via ltp
2024-05-29 15:10   ` Cyril Hrubis
2024-06-20  5:36     ` Petr Vorel
2024-06-20  8:05       ` Li Wang
2024-06-20 11:25         ` Petr Vorel
2024-06-21 13:22         ` Li Wang
2024-06-21 13:39           ` Petr Vorel [this message]
2024-06-21 13:47             ` Li Wang
2024-06-21 13:53               ` Petr Vorel
  -- strict thread matches above, loose matches on Subject: below --
2024-05-28 12:05 Petr Vorel

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=20240621133911.GA694629@pevik \
    --to=pvorel@suse.cz \
    --cc=liwang@redhat.com \
    --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 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.