All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Laurent Vivier" <lvivier@redhat.com>,
	"Thomas Huth" <thuth@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>,
	"Li Qiang" <liq3ea@gmail.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Laszlo Ersek" <lersek@redhat.com>
Subject: [PATCH 6/7] tests/fw_cfg: Declare one QFWCFG for all tests
Date: Fri,  4 Oct 2019 00:54:36 +0200	[thread overview]
Message-ID: <20191003225437.16651-7-philmd@redhat.com> (raw)
In-Reply-To: <20191003225437.16651-1-philmd@redhat.com>

It is pointless to create/remove a QFWCFG object for each test.
Move it to the test context and create/remove it only once.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 tests/fw_cfg-test.c | 74 +++++++++++++++++----------------------------
 1 file changed, 27 insertions(+), 47 deletions(-)

diff --git a/tests/fw_cfg-test.c b/tests/fw_cfg-test.c
index 6fb52a4d08..12dbaf4e67 100644
--- a/tests/fw_cfg-test.c
+++ b/tests/fw_cfg-test.c
@@ -25,47 +25,42 @@ static uint16_t boot_menu = 0;
 
 typedef struct {
     const char *machine_name;
+    QFWCFG *fw_cfg;
 } QTestCtx;
 
 static void test_fw_cfg_signature(const void *opaque)
 {
     QTestCtx *ctx = (QTestCtx *)opaque;
-    QFWCFG *fw_cfg;
     QTestState *s;
     char buf[5];
 
     s = qtest_initf("-M %s", ctx->machine_name);
-    fw_cfg = pc_fw_cfg_init();
 
-    qfw_cfg_get(s, fw_cfg, FW_CFG_SIGNATURE, buf, 4);
+    qfw_cfg_get(s, ctx->fw_cfg, FW_CFG_SIGNATURE, buf, 4);
     buf[4] = 0;
-
     g_assert_cmpstr(buf, ==, "QEMU");
-    g_free(fw_cfg);
+
     qtest_quit(s);
 }
 
 static void test_fw_cfg_id(const void *opaque)
 {
     QTestCtx *ctx = (QTestCtx *)opaque;
-    QFWCFG *fw_cfg;
     QTestState *s;
     uint32_t id;
 
     s = qtest_initf("-M %s", ctx->machine_name);
-    fw_cfg = pc_fw_cfg_init();
 
-    id = qfw_cfg_get_u32(s, fw_cfg, FW_CFG_ID);
+    id = qfw_cfg_get_u32(s, ctx->fw_cfg, FW_CFG_ID);
     g_assert((id == 1) ||
              (id == 3));
-    g_free(fw_cfg);
+
     qtest_quit(s);
 }
 
 static void test_fw_cfg_uuid(const void *opaque)
 {
     QTestCtx *ctx = (QTestCtx *)opaque;
-    QFWCFG *fw_cfg;
     QTestState *s;
 
     uint8_t buf[16];
@@ -75,12 +70,10 @@ static void test_fw_cfg_uuid(const void *opaque)
     };
 
     s = qtest_initf("-M %s -uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8", ctx->machine_name);
-    fw_cfg = pc_fw_cfg_init();
 
-    qfw_cfg_get(s, fw_cfg, FW_CFG_UUID, buf, 16);
+    qfw_cfg_get(s, ctx->fw_cfg, FW_CFG_UUID, buf, 16);
     g_assert(memcmp(buf, uuid, sizeof(buf)) == 0);
 
-    g_free(fw_cfg);
     qtest_quit(s);
 
 }
@@ -88,80 +81,71 @@ static void test_fw_cfg_uuid(const void *opaque)
 static void test_fw_cfg_ram_size(const void *opaque)
 {
     QTestCtx *ctx = (QTestCtx *)opaque;
-    QFWCFG *fw_cfg;
     QTestState *s;
 
     s = qtest_initf("-M %s", ctx->machine_name);
-    fw_cfg = pc_fw_cfg_init();
 
-    g_assert_cmpint(qfw_cfg_get_u64(s, fw_cfg, FW_CFG_RAM_SIZE), ==, ram_size);
+    g_assert_cmpint(qfw_cfg_get_u64(s, ctx->fw_cfg, FW_CFG_RAM_SIZE),
+                    ==, ram_size);
 
-    g_free(fw_cfg);
     qtest_quit(s);
 }
 
 static void test_fw_cfg_nographic(const void *opaque)
 {
     QTestCtx *ctx = (QTestCtx *)opaque;
-    QFWCFG *fw_cfg;
     QTestState *s;
 
     s = qtest_initf("-M %s", ctx->machine_name);
-    fw_cfg = pc_fw_cfg_init();
 
-    g_assert_cmpint(qfw_cfg_get_u16(s, fw_cfg, FW_CFG_NOGRAPHIC), ==, 0);
+    g_assert_cmpint(qfw_cfg_get_u16(s, ctx->fw_cfg, FW_CFG_NOGRAPHIC), ==, 0);
 
-    g_free(fw_cfg);
     qtest_quit(s);
 }
 
 static void test_fw_cfg_nb_cpus(const void *opaque)
 {
     QTestCtx *ctx = (QTestCtx *)opaque;
-    QFWCFG *fw_cfg;
     QTestState *s;
 
     s = qtest_initf("-M %s", ctx->machine_name);
-    fw_cfg = pc_fw_cfg_init();
 
-    g_assert_cmpint(qfw_cfg_get_u16(s, fw_cfg, FW_CFG_NB_CPUS), ==, nb_cpus);
+    g_assert_cmpint(qfw_cfg_get_u16(s, ctx->fw_cfg, FW_CFG_NB_CPUS),
+                    ==, nb_cpus);
 
-    g_free(fw_cfg);
     qtest_quit(s);
 }
 
 static void test_fw_cfg_max_cpus(const void *opaque)
 {
     QTestCtx *ctx = (QTestCtx *)opaque;
-    QFWCFG *fw_cfg;
     QTestState *s;
 
     s = qtest_initf("-M %s", ctx->machine_name);
-    fw_cfg = pc_fw_cfg_init();
 
-    g_assert_cmpint(qfw_cfg_get_u16(s, fw_cfg, FW_CFG_MAX_CPUS), ==, max_cpus);
-    g_free(fw_cfg);
+    g_assert_cmpint(qfw_cfg_get_u16(s, ctx->fw_cfg, FW_CFG_MAX_CPUS),
+                    ==, max_cpus);
+
     qtest_quit(s);
 }
 
 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_initf("-M %s", ctx->machine_name);
-    fw_cfg = pc_fw_cfg_init();
 
-    g_assert_cmpint(qfw_cfg_get_u64(s, fw_cfg, FW_CFG_NUMA), ==, nb_nodes);
+    g_assert_cmpint(qfw_cfg_get_u64(s, ctx->fw_cfg, FW_CFG_NUMA),
+                    ==, nb_nodes);
 
     cpu_mask = g_new0(uint64_t, max_cpus);
     node_mask = g_new0(uint64_t, nb_nodes);
 
-    qfw_cfg_read_data(s, fw_cfg, cpu_mask, sizeof(uint64_t) * max_cpus);
-    qfw_cfg_read_data(s, fw_cfg, node_mask, sizeof(uint64_t) * nb_nodes);
+    qfw_cfg_read_data(s, ctx->fw_cfg, cpu_mask, sizeof(uint64_t) * max_cpus);
+    qfw_cfg_read_data(s, ctx->fw_cfg, node_mask, sizeof(uint64_t) * nb_nodes);
 
     if (nb_nodes) {
         g_assert(cpu_mask[0] & 0x01);
@@ -170,62 +154,56 @@ static void test_fw_cfg_numa(const void *opaque)
 
     g_free(node_mask);
     g_free(cpu_mask);
-    g_free(fw_cfg);
+
     qtest_quit(s);
 }
 
 static void test_fw_cfg_boot_menu(const void *opaque)
 {
     QTestCtx *ctx = (QTestCtx *)opaque;
-    QFWCFG *fw_cfg;
     QTestState *s;
 
     s = qtest_initf("-M %s", ctx->machine_name);
-    fw_cfg = pc_fw_cfg_init();
 
-    g_assert_cmpint(qfw_cfg_get_u16(s, fw_cfg, FW_CFG_BOOT_MENU),
+    g_assert_cmpint(qfw_cfg_get_u16(s, ctx->fw_cfg, FW_CFG_BOOT_MENU),
                     ==, boot_menu);
-    g_free(fw_cfg);
+
     qtest_quit(s);
 }
 
 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_initf("-M %s -boot reboot-timeout=15", ctx->machine_name);
-    fw_cfg = pc_fw_cfg_init();
 
-    filesize = qfw_cfg_get_file(s, fw_cfg, "etc/boot-fail-wait",
+    filesize = qfw_cfg_get_file(s, ctx->fw_cfg, "etc/boot-fail-wait",
                                 &reboot_timeout, sizeof(reboot_timeout));
     g_assert_cmpint(filesize, ==, sizeof(reboot_timeout));
     reboot_timeout = le32_to_cpu(reboot_timeout);
     g_assert_cmpint(reboot_timeout, ==, 15);
-    g_free(fw_cfg);
+
     qtest_quit(s);
 }
 
 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_initf("-M %s -boot splash-time=12", ctx->machine_name);
-    fw_cfg = pc_fw_cfg_init();
 
-    filesize = qfw_cfg_get_file(s, fw_cfg, "etc/boot-menu-wait",
+    filesize = qfw_cfg_get_file(s, ctx->fw_cfg, "etc/boot-menu-wait",
                                 &splash_time, sizeof(splash_time));
     g_assert_cmpint(filesize, ==, sizeof(splash_time));
     splash_time = le16_to_cpu(splash_time);
     g_assert_cmpint(splash_time, ==, 12);
-    g_free(fw_cfg);
+
     qtest_quit(s);
 }
 
@@ -237,6 +215,7 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
 
     ctx->machine_name = "pc";
+    ctx->fw_cfg = pc_fw_cfg_init();
 
     qtest_add_data_func("fw_cfg/signature", ctx, test_fw_cfg_signature);
     qtest_add_data_func("fw_cfg/id", ctx, test_fw_cfg_id);
@@ -259,6 +238,7 @@ int main(int argc, char **argv)
 
     ret = g_test_run();
 
+    g_free(ctx->fw_cfg);
     g_free(ctx);
 
     return ret;
-- 
2.20.1



  parent reply	other threads:[~2019-10-03 23:23 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
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 ` Philippe Mathieu-Daudé [this message]
2019-10-04 19:04   ` [PATCH 6/7] tests/fw_cfg: Declare one QFWCFG for all tests 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=20191003225437.16651-7-philmd@redhat.com \
    --to=philmd@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=lersek@redhat.com \
    --cc=liq3ea@gmail.com \
    --cc=lvivier@redhat.com \
    --cc=pbonzini@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 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.