qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>, qemu-devel@nongnu.org
Cc: Laurent Vivier <lvivier@redhat.com>,
	Thomas Huth <thuth@redhat.com>, Li Qiang <liq3ea@gmail.com>,
	Gerd Hoffmann <kraxel@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH 4/7] tests/fw_cfg: Let the tests use a context
Date: Fri, 4 Oct 2019 20:50:10 +0200	[thread overview]
Message-ID: <081e5bdb-73b3-9bb5-0ded-8a98577763f9@redhat.com> (raw)
In-Reply-To: <20191003225437.16651-5-philmd@redhat.com>

On 10/04/19 00:54, Philippe Mathieu-Daudé wrote:
> Introduce the local QTestCtx structure, and register the tests
> with qtest_add_data_func(ctx).
> For now the context only contains the machine name (which is
> fixed to the 'pc' machine, since this test only runs on the
> x86 architecture).
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>  tests/fw_cfg-test.c | 93 ++++++++++++++++++++++++++++-----------------
>  1 file changed, 59 insertions(+), 34 deletions(-)
> 
> diff --git a/tests/fw_cfg-test.c b/tests/fw_cfg-test.c
> index 53ae82f7c8..77a833d50e 100644
> --- a/tests/fw_cfg-test.c
> +++ b/tests/fw_cfg-test.c
> @@ -23,13 +23,18 @@ static uint16_t max_cpus = 1;
>  static uint64_t nb_nodes = 0;
>  static uint16_t boot_menu = 0;
>  
> -static void test_fw_cfg_signature(void)
> +typedef struct {
> +    const char *machine_name;
> +} QTestCtx;
> +
> +static void test_fw_cfg_signature(const void *opaque)
>  {
> +    QTestCtx *ctx = (QTestCtx *)opaque;

(1) I'd suggest:

    const QTestCtx *ctx = opaque;

(I think that should work fine with the current patch; not sure if it
will work with the rest of the series, when you perhaps introduce more
members to QTestCtx.)

This request applies a few more times to this patch, of course.

Another (different) comment:

>      QFWCFG *fw_cfg;
>      QTestState *s;
>      char buf[5];
>  
> -    s = qtest_init("");
> +    s = qtest_initf("-M %s", ctx->machine_name);
>      fw_cfg = pc_fw_cfg_init(s);
>  
>      qfw_cfg_get(fw_cfg, FW_CFG_SIGNATURE, buf, 4);
> @@ -40,13 +45,14 @@ static void test_fw_cfg_signature(void)
>      qtest_quit(s);
>  }
>  
> -static void test_fw_cfg_id(void)
> +static void test_fw_cfg_id(const void *opaque)
>  {
> +    QTestCtx *ctx = (QTestCtx *)opaque;
>      QFWCFG *fw_cfg;
>      QTestState *s;
>      uint32_t id;
>  
> -    s = qtest_init("");
> +    s = qtest_initf("-M %s", ctx->machine_name);
>      fw_cfg = pc_fw_cfg_init(s);
>  
>      id = qfw_cfg_get_u32(fw_cfg, FW_CFG_ID);
> @@ -56,8 +62,9 @@ static void test_fw_cfg_id(void)
>      qtest_quit(s);
>  }
>  
> -static void test_fw_cfg_uuid(void)
> +static void test_fw_cfg_uuid(const void *opaque)
>  {
> +    QTestCtx *ctx = (QTestCtx *)opaque;
>      QFWCFG *fw_cfg;
>      QTestState *s;
>  
> @@ -67,7 +74,7 @@ static void test_fw_cfg_uuid(void)
>          0x8a, 0xcb, 0x81, 0xc6, 0xea, 0x54, 0xf2, 0xd8,
>      };
>  
> -    s = qtest_init("-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8");
> +    s = qtest_initf("-M %s -uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8", ctx->machine_name);
>      fw_cfg = pc_fw_cfg_init(s);
>  
>      qfw_cfg_get(fw_cfg, FW_CFG_UUID, buf, 16);
> @@ -78,12 +85,13 @@ static void test_fw_cfg_uuid(void)
>  
>  }
>  
> -static void test_fw_cfg_ram_size(void)
> +static void test_fw_cfg_ram_size(const void *opaque)
>  {
> +    QTestCtx *ctx = (QTestCtx *)opaque;
>      QFWCFG *fw_cfg;
>      QTestState *s;
>  
> -    s = qtest_init("");
> +    s = qtest_initf("-M %s", ctx->machine_name);
>      fw_cfg = pc_fw_cfg_init(s);
>  
>      g_assert_cmpint(qfw_cfg_get_u64(fw_cfg, FW_CFG_RAM_SIZE), ==, ram_size);
> @@ -92,12 +100,13 @@ static void test_fw_cfg_ram_size(void)
>      qtest_quit(s);
>  }
>  
> -static void test_fw_cfg_nographic(void)
> +static void test_fw_cfg_nographic(const void *opaque)
>  {
> +    QTestCtx *ctx = (QTestCtx *)opaque;
>      QFWCFG *fw_cfg;
>      QTestState *s;
>  
> -    s = qtest_init("");
> +    s = qtest_initf("-M %s", ctx->machine_name);
>      fw_cfg = pc_fw_cfg_init(s);
>  
>      g_assert_cmpint(qfw_cfg_get_u16(fw_cfg, FW_CFG_NOGRAPHIC), ==, 0);
> @@ -106,12 +115,13 @@ static void test_fw_cfg_nographic(void)
>      qtest_quit(s);
>  }
>  
> -static void test_fw_cfg_nb_cpus(void)
> +static void test_fw_cfg_nb_cpus(const void *opaque)
>  {
> +    QTestCtx *ctx = (QTestCtx *)opaque;
>      QFWCFG *fw_cfg;
>      QTestState *s;
>  
> -    s = qtest_init("");
> +    s = qtest_initf("-M %s", ctx->machine_name);
>      fw_cfg = pc_fw_cfg_init(s);
>  
>      g_assert_cmpint(qfw_cfg_get_u16(fw_cfg, FW_CFG_NB_CPUS), ==, nb_cpus);
> @@ -120,12 +130,13 @@ static void test_fw_cfg_nb_cpus(void)
>      qtest_quit(s);
>  }
>  
> -static void test_fw_cfg_max_cpus(void)
> +static void test_fw_cfg_max_cpus(const void *opaque)
>  {
> +    QTestCtx *ctx = (QTestCtx *)opaque;
>      QFWCFG *fw_cfg;
>      QTestState *s;
>  
> -    s = qtest_init("");
> +    s = qtest_initf("-M %s", ctx->machine_name);
>      fw_cfg = pc_fw_cfg_init(s);
>  
>      g_assert_cmpint(qfw_cfg_get_u16(fw_cfg, FW_CFG_MAX_CPUS), ==, max_cpus);
> @@ -133,14 +144,15 @@ static void test_fw_cfg_max_cpus(void)
>      qtest_quit(s);
>  }
>  
> -static void test_fw_cfg_numa(void)
> +static void test_fw_cfg_numa(const void *opaque)
>  {
> +    QTestCtx *ctx = (QTestCtx *)opaque;
>      QFWCFG *fw_cfg;
>      QTestState *s;
>      uint64_t *cpu_mask;
>      uint64_t *node_mask;
>  
> -    s = qtest_init("");
> +    s = qtest_initf("-M %s", ctx->machine_name);
>      fw_cfg = pc_fw_cfg_init(s);
>  
>      g_assert_cmpint(qfw_cfg_get_u64(fw_cfg, FW_CFG_NUMA), ==, nb_nodes);
> @@ -162,12 +174,13 @@ static void test_fw_cfg_numa(void)
>      qtest_quit(s);
>  }
>  
> -static void test_fw_cfg_boot_menu(void)
> +static void test_fw_cfg_boot_menu(const void *opaque)
>  {
> +    QTestCtx *ctx = (QTestCtx *)opaque;
>      QFWCFG *fw_cfg;
>      QTestState *s;
>  
> -    s = qtest_init("");
> +    s = qtest_initf("-M %s", ctx->machine_name);
>      fw_cfg = pc_fw_cfg_init(s);
>  
>      g_assert_cmpint(qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_MENU), ==, boot_menu);
> @@ -175,14 +188,15 @@ static void test_fw_cfg_boot_menu(void)
>      qtest_quit(s);
>  }
>  
> -static void test_fw_cfg_reboot_timeout(void)
> +static void test_fw_cfg_reboot_timeout(const void *opaque)
>  {
> +    QTestCtx *ctx = (QTestCtx *)opaque;
>      QFWCFG *fw_cfg;
>      QTestState *s;
>      uint32_t reboot_timeout = 0;
>      size_t filesize;
>  
> -    s = qtest_init("-boot reboot-timeout=15");
> +    s = qtest_initf("-M %s -boot reboot-timeout=15", ctx->machine_name);
>      fw_cfg = pc_fw_cfg_init(s);
>  
>      filesize = qfw_cfg_get_file(fw_cfg, "etc/boot-fail-wait",
> @@ -194,14 +208,15 @@ static void test_fw_cfg_reboot_timeout(void)
>      qtest_quit(s);
>  }
>  
> -static void test_fw_cfg_splash_time(void)
> +static void test_fw_cfg_splash_time(const void *opaque)
>  {
> +    QTestCtx *ctx = (QTestCtx *)opaque;
>      QFWCFG *fw_cfg;
>      QTestState *s;
>      uint16_t splash_time = 0;
>      size_t filesize;
>  
> -    s = qtest_init("-boot splash-time=12");
> +    s = qtest_initf("-M %s -boot splash-time=12", ctx->machine_name);
>      fw_cfg = pc_fw_cfg_init(s);
>  
>      filesize = qfw_cfg_get_file(fw_cfg, "etc/boot-menu-wait",
> @@ -215,25 +230,35 @@ static void test_fw_cfg_splash_time(void)
>  
>  int main(int argc, char **argv)
>  {
> +    QTestCtx *ctx = g_new(QTestCtx, 1);
> +    int ret;
> +
>      g_test_init(&argc, &argv, NULL);
>  
> -    qtest_add_func("fw_cfg/signature", test_fw_cfg_signature);
> -    qtest_add_func("fw_cfg/id", test_fw_cfg_id);
> -    qtest_add_func("fw_cfg/uuid", test_fw_cfg_uuid);
> -    qtest_add_func("fw_cfg/ram_size", test_fw_cfg_ram_size);
> -    qtest_add_func("fw_cfg/nographic", test_fw_cfg_nographic);
> -    qtest_add_func("fw_cfg/nb_cpus", test_fw_cfg_nb_cpus);
> +    ctx->machine_name = "pc";
> +
> +    qtest_add_data_func("fw_cfg/signature", ctx, test_fw_cfg_signature);
> +    qtest_add_data_func("fw_cfg/id", ctx, test_fw_cfg_id);
> +    qtest_add_data_func("fw_cfg/uuid", ctx, test_fw_cfg_uuid);
> +    qtest_add_data_func("fw_cfg/ram_size", ctx, test_fw_cfg_ram_size);
> +    qtest_add_data_func("fw_cfg/nographic", ctx, test_fw_cfg_nographic);
> +    qtest_add_data_func("fw_cfg/nb_cpus", ctx, test_fw_cfg_nb_cpus);
>  #if 0
>      qtest_add_func("fw_cfg/machine_id", test_fw_cfg_machine_id);
>      qtest_add_func("fw_cfg/kernel", test_fw_cfg_kernel);
>      qtest_add_func("fw_cfg/initrd", test_fw_cfg_initrd);
>      qtest_add_func("fw_cfg/boot_device", test_fw_cfg_boot_device);
>  #endif
> -    qtest_add_func("fw_cfg/max_cpus", test_fw_cfg_max_cpus);
> -    qtest_add_func("fw_cfg/numa", test_fw_cfg_numa);
> -    qtest_add_func("fw_cfg/boot_menu", test_fw_cfg_boot_menu);
> -    qtest_add_func("fw_cfg/reboot_timeout", test_fw_cfg_reboot_timeout);
> -    qtest_add_func("fw_cfg/splash_time", test_fw_cfg_splash_time);
> +    qtest_add_data_func("fw_cfg/max_cpus", ctx, test_fw_cfg_max_cpus);
> +    qtest_add_data_func("fw_cfg/numa", ctx, test_fw_cfg_numa);
> +    qtest_add_data_func("fw_cfg/boot_menu", ctx, test_fw_cfg_boot_menu);
> +    qtest_add_data_func("fw_cfg/reboot_timeout", ctx,
> +                        test_fw_cfg_reboot_timeout);
> +    qtest_add_data_func("fw_cfg/splash_time", ctx, test_fw_cfg_splash_time);
>  
> -    return g_test_run();
> +    ret = g_test_run();
> +
> +    g_free(ctx);
> +
> +    return ret;
>  }
> 

(2) You don't necessarily have to use g_new / g_free for ctx; I think
you could simply use an auto ("local") variable. But, maybe that doesn't
apply to the rest of the patches, and/or g_new is the idiomatic way,
with regard to other tests. So, up to you.

With an attempt to address (1), and regardless of (2):

Reviewed-by: Laszlo Ersek <lersek@redhat.com>

Thanks
Laszlo


  reply	other threads:[~2019-10-04 18:58 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-03 22:54 [PATCH 0/7] fw_cfg: Run tests on big-endian Philippe Mathieu-Daudé
2019-10-03 22:54 ` [PATCH 1/7] tests/libqos/fw_cfg: Document io_fw_cfg_init to drop io_fw_cfg_uninit Philippe Mathieu-Daudé
2019-10-04 18:39   ` Laszlo Ersek
2019-10-03 22:54 ` [PATCH 2/7] tests/libqos/fw_cfg: Document mm_fw_cfg_init to drop mm_fw_cfg_uninit Philippe Mathieu-Daudé
2019-10-04 18:40   ` Laszlo Ersek
2019-10-03 22:54 ` [PATCH 3/7] tests/libqos/fw_cfg: Document pc_fw_cfg_init to drop pc_fw_cfg_uninit Philippe Mathieu-Daudé
2019-10-04 18:42   ` Laszlo Ersek
2019-10-03 22:54 ` [PATCH 4/7] tests/fw_cfg: Let the tests use a context Philippe Mathieu-Daudé
2019-10-04 18:50   ` Laszlo Ersek [this message]
2019-10-03 22:54 ` [PATCH 5/7] tests/libqos/fw_cfg: Pass QTestState as argument Philippe Mathieu-Daudé
2019-10-04 18:57   ` Laszlo Ersek
2019-10-03 22:54 ` [PATCH 6/7] tests/fw_cfg: Declare one QFWCFG for all tests Philippe Mathieu-Daudé
2019-10-04 19:04   ` Laszlo Ersek
2019-10-03 22:54 ` [PATCH 7/7] tests/fw_cfg: Run the tests on big-endian targets Philippe Mathieu-Daudé
2019-10-04  8:05   ` Laurent Vivier
2019-10-04  8:53     ` Philippe Mathieu-Daudé
2019-10-04  8:59       ` Laurent Vivier
2019-10-04  9:03         ` Philippe Mathieu-Daudé
2019-10-04  9:14           ` Laurent Vivier
2019-10-04  9:18             ` Philippe Mathieu-Daudé
2019-10-07  6:17     ` Thomas Huth
2019-10-04  0:12 ` [PATCH 0/7] fw_cfg: Run tests on big-endian no-reply

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=081e5bdb-73b3-9bb5-0ded-8a98577763f9@redhat.com \
    --to=lersek@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=liq3ea@gmail.com \
    --cc=lvivier@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=thuth@redhat.com \
    /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).