diff mbox series

[1/5] tests: fw_cfg: Rename pc_fw_cfg_* to fw_cfg_*

Message ID 20191203122753.19792-2-zhengxiang9@huawei.com
State New
Headers show
Series tests: Enable fw_cfg tests on AArch64 | expand

Commit Message

Xiang Zheng Dec. 3, 2019, 12:27 p.m. UTC
Rename pc_fw_cfg_* to fw_cfg_* to make them common for other
architectures so that we can run fw_cfg tests on aarch64.

Signed-off-by: Xiang Zheng <zhengxiang9@huawei.com>
---
 tests/fw_cfg-test.c      | 48 ++++++++++++++++++++--------------------
 tests/hd-geo-test.c      |  6 ++---
 tests/libqos/fw_cfg.h    | 20 +++++++++++++----
 tests/libqos/malloc-pc.c |  4 ++--
 4 files changed, 45 insertions(+), 33 deletions(-)

Comments

Peter Maydell Dec. 3, 2019, 12:34 p.m. UTC | #1
On Tue, 3 Dec 2019 at 12:29, Xiang Zheng <zhengxiang9@huawei.com> wrote:
>
> Rename pc_fw_cfg_* to fw_cfg_* to make them common for other
> architectures so that we can run fw_cfg tests on aarch64.
>
> Signed-off-by: Xiang Zheng <zhengxiang9@huawei.com>

> -static inline QFWCFG *pc_fw_cfg_init(QTestState *qts)
> +static inline QFWCFG *fw_cfg_init(QTestState *qts)
>  {
> -    return io_fw_cfg_init(qts, 0x510);
> +    const char *arch = qtest_get_arch();
> +
> +    if (!strcmp(arch, "aarch64")) {
> +        return mm_fw_cfg_init(qts, 0x09020000);
> +    } else {
> +        return io_fw_cfg_init(qts, 0x510);
> +    }

Presence and address of the fw_cfg device depends
on the machine type, not the architecture, so is
it possible to write this so that it varies by
machine type, rather than by guest arch ?
There should also presumably be a fallback path
for "fw_cfg not present here", I suppose.

thanks
-- PMM
Xiang Zheng Dec. 4, 2019, 6:13 a.m. UTC | #2
On 2019/12/3 20:34, Peter Maydell wrote:
> On Tue, 3 Dec 2019 at 12:29, Xiang Zheng <zhengxiang9@huawei.com> wrote:
>>
>> Rename pc_fw_cfg_* to fw_cfg_* to make them common for other
>> architectures so that we can run fw_cfg tests on aarch64.
>>
>> Signed-off-by: Xiang Zheng <zhengxiang9@huawei.com>
> 
>> -static inline QFWCFG *pc_fw_cfg_init(QTestState *qts)
>> +static inline QFWCFG *fw_cfg_init(QTestState *qts)
>>  {
>> -    return io_fw_cfg_init(qts, 0x510);
>> +    const char *arch = qtest_get_arch();
>> +
>> +    if (!strcmp(arch, "aarch64")) {
>> +        return mm_fw_cfg_init(qts, 0x09020000);
>> +    } else {
>> +        return io_fw_cfg_init(qts, 0x510);
>> +    }
> 
> Presence and address of the fw_cfg device depends
> on the machine type, not the architecture, so is
> it possible to write this so that it varies by
> machine type, rather than by guest arch ?
> There should also presumably be a fallback path
> for "fw_cfg not present here", I suppose.
> 

Yes, "0x09020000" is the address of the fw_cfg device on virt machine, I
should have noticed it. I will have a try for varying the addresses
by machine type.
diff mbox series

Patch

diff --git a/tests/fw_cfg-test.c b/tests/fw_cfg-test.c
index 5dc807ba23..5a5342fa9d 100644
--- a/tests/fw_cfg-test.c
+++ b/tests/fw_cfg-test.c
@@ -30,13 +30,13 @@  static void test_fw_cfg_signature(void)
     char buf[5];
 
     s = qtest_init("");
-    fw_cfg = pc_fw_cfg_init(s);
+    fw_cfg = fw_cfg_init(s);
 
     qfw_cfg_get(fw_cfg, FW_CFG_SIGNATURE, buf, 4);
     buf[4] = 0;
 
     g_assert_cmpstr(buf, ==, "QEMU");
-    pc_fw_cfg_uninit(fw_cfg);
+    fw_cfg_uninit(fw_cfg);
     qtest_quit(s);
 }
 
@@ -47,12 +47,12 @@  static void test_fw_cfg_id(void)
     uint32_t id;
 
     s = qtest_init("");
-    fw_cfg = pc_fw_cfg_init(s);
+    fw_cfg = fw_cfg_init(s);
 
     id = qfw_cfg_get_u32(fw_cfg, FW_CFG_ID);
     g_assert((id == 1) ||
              (id == 3));
-    pc_fw_cfg_uninit(fw_cfg);
+    fw_cfg_uninit(fw_cfg);
     qtest_quit(s);
 }
 
@@ -68,12 +68,12 @@  static void test_fw_cfg_uuid(void)
     };
 
     s = qtest_init("-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8");
-    fw_cfg = pc_fw_cfg_init(s);
+    fw_cfg = fw_cfg_init(s);
 
     qfw_cfg_get(fw_cfg, FW_CFG_UUID, buf, 16);
     g_assert(memcmp(buf, uuid, sizeof(buf)) == 0);
 
-    pc_fw_cfg_uninit(fw_cfg);
+    fw_cfg_uninit(fw_cfg);
     qtest_quit(s);
 
 }
@@ -84,11 +84,11 @@  static void test_fw_cfg_ram_size(void)
     QTestState *s;
 
     s = qtest_init("");
-    fw_cfg = pc_fw_cfg_init(s);
+    fw_cfg = fw_cfg_init(s);
 
     g_assert_cmpint(qfw_cfg_get_u64(fw_cfg, FW_CFG_RAM_SIZE), ==, ram_size);
 
-    pc_fw_cfg_uninit(fw_cfg);
+    fw_cfg_uninit(fw_cfg);
     qtest_quit(s);
 }
 
@@ -98,11 +98,11 @@  static void test_fw_cfg_nographic(void)
     QTestState *s;
 
     s = qtest_init("");
-    fw_cfg = pc_fw_cfg_init(s);
+    fw_cfg = fw_cfg_init(s);
 
     g_assert_cmpint(qfw_cfg_get_u16(fw_cfg, FW_CFG_NOGRAPHIC), ==, 0);
 
-    pc_fw_cfg_uninit(fw_cfg);
+    fw_cfg_uninit(fw_cfg);
     qtest_quit(s);
 }
 
@@ -112,11 +112,11 @@  static void test_fw_cfg_nb_cpus(void)
     QTestState *s;
 
     s = qtest_init("");
-    fw_cfg = pc_fw_cfg_init(s);
+    fw_cfg = fw_cfg_init(s);
 
     g_assert_cmpint(qfw_cfg_get_u16(fw_cfg, FW_CFG_NB_CPUS), ==, nb_cpus);
 
-    pc_fw_cfg_uninit(fw_cfg);
+    fw_cfg_uninit(fw_cfg);
     qtest_quit(s);
 }
 
@@ -126,10 +126,10 @@  static void test_fw_cfg_max_cpus(void)
     QTestState *s;
 
     s = qtest_init("");
-    fw_cfg = pc_fw_cfg_init(s);
+    fw_cfg = fw_cfg_init(s);
 
     g_assert_cmpint(qfw_cfg_get_u16(fw_cfg, FW_CFG_MAX_CPUS), ==, max_cpus);
-    pc_fw_cfg_uninit(fw_cfg);
+    fw_cfg_uninit(fw_cfg);
     qtest_quit(s);
 }
 
@@ -141,7 +141,7 @@  static void test_fw_cfg_numa(void)
     uint64_t *node_mask;
 
     s = qtest_init("");
-    fw_cfg = pc_fw_cfg_init(s);
+    fw_cfg = fw_cfg_init(s);
 
     g_assert_cmpint(qfw_cfg_get_u64(fw_cfg, FW_CFG_NUMA), ==, nb_nodes);
 
@@ -158,7 +158,7 @@  static void test_fw_cfg_numa(void)
 
     g_free(node_mask);
     g_free(cpu_mask);
-    pc_fw_cfg_uninit(fw_cfg);
+    fw_cfg_uninit(fw_cfg);
     qtest_quit(s);
 }
 
@@ -168,10 +168,10 @@  static void test_fw_cfg_boot_menu(void)
     QTestState *s;
 
     s = qtest_init("");
-    fw_cfg = pc_fw_cfg_init(s);
+    fw_cfg = fw_cfg_init(s);
 
     g_assert_cmpint(qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_MENU), ==, boot_menu);
-    pc_fw_cfg_uninit(fw_cfg);
+    fw_cfg_uninit(fw_cfg);
     qtest_quit(s);
 }
 
@@ -183,14 +183,14 @@  static void test_fw_cfg_reboot_timeout(void)
     size_t filesize;
 
     s = qtest_init("-boot reboot-timeout=15");
-    fw_cfg = pc_fw_cfg_init(s);
+    fw_cfg = fw_cfg_init(s);
 
     filesize = qfw_cfg_get_file(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);
-    pc_fw_cfg_uninit(fw_cfg);
+    fw_cfg_uninit(fw_cfg);
     qtest_quit(s);
 }
 
@@ -203,14 +203,14 @@  static void test_fw_cfg_no_reboot_timeout(void)
 
     /* Special value -1 means "don't reboot" */
     s = qtest_init("-boot reboot-timeout=-1");
-    fw_cfg = pc_fw_cfg_init(s);
+    fw_cfg = fw_cfg_init(s);
 
     filesize = qfw_cfg_get_file(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, ==, UINT32_MAX);
-    pc_fw_cfg_uninit(fw_cfg);
+    fw_cfg_uninit(fw_cfg);
     qtest_quit(s);
 }
 
@@ -222,14 +222,14 @@  static void test_fw_cfg_splash_time(void)
     size_t filesize;
 
     s = qtest_init("-boot splash-time=12");
-    fw_cfg = pc_fw_cfg_init(s);
+    fw_cfg = fw_cfg_init(s);
 
     filesize = qfw_cfg_get_file(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);
-    pc_fw_cfg_uninit(fw_cfg);
+    fw_cfg_uninit(fw_cfg);
     qtest_quit(s);
 }
 
diff --git a/tests/hd-geo-test.c b/tests/hd-geo-test.c
index 7e86c5416c..a9b8a07403 100644
--- a/tests/hd-geo-test.c
+++ b/tests/hd-geo-test.c
@@ -693,7 +693,7 @@  static void test_override(TestArgs *args, CHSResult expected[])
     joined_args = g_strjoinv(" ", args->argv);
 
     qts = qtest_init(joined_args);
-    fw_cfg = pc_fw_cfg_init(qts);
+    fw_cfg = fw_cfg_init(qts);
 
     read_bootdevices(fw_cfg, expected);
 
@@ -829,7 +829,7 @@  static void test_override_scsi_hot_unplug(void)
     joined_args = g_strjoinv(" ", args->argv);
 
     qts = qtest_init(joined_args);
-    fw_cfg = pc_fw_cfg_init(qts);
+    fw_cfg = fw_cfg_init(qts);
 
     read_bootdevices(fw_cfg, expected);
 
@@ -889,7 +889,7 @@  static void test_override_virtio_hot_unplug(void)
     joined_args = g_strjoinv(" ", args->argv);
 
     qts = qtest_init(joined_args);
-    fw_cfg = pc_fw_cfg_init(qts);
+    fw_cfg = fw_cfg_init(qts);
 
     read_bootdevices(fw_cfg, expected);
 
diff --git a/tests/libqos/fw_cfg.h b/tests/libqos/fw_cfg.h
index 13325cc4ff..708aa922ed 100644
--- a/tests/libqos/fw_cfg.h
+++ b/tests/libqos/fw_cfg.h
@@ -39,14 +39,26 @@  void mm_fw_cfg_uninit(QFWCFG *fw_cfg);
 QFWCFG *io_fw_cfg_init(QTestState *qts, uint16_t base);
 void io_fw_cfg_uninit(QFWCFG *fw_cfg);
 
-static inline QFWCFG *pc_fw_cfg_init(QTestState *qts)
+static inline QFWCFG *fw_cfg_init(QTestState *qts)
 {
-    return io_fw_cfg_init(qts, 0x510);
+    const char *arch = qtest_get_arch();
+
+    if (!strcmp(arch, "aarch64")) {
+        return mm_fw_cfg_init(qts, 0x09020000);
+    } else {
+        return io_fw_cfg_init(qts, 0x510);
+    }
 }
 
-static inline void pc_fw_cfg_uninit(QFWCFG *fw_cfg)
+static inline void fw_cfg_uninit(QFWCFG *fw_cfg)
 {
-    io_fw_cfg_uninit(fw_cfg);
+    const char *arch = qtest_get_arch();
+
+    if (!strcmp(arch, "aarch64")) {
+        mm_fw_cfg_uninit(fw_cfg);
+    } else {
+        io_fw_cfg_uninit(fw_cfg);
+    }
 }
 
 #endif
diff --git a/tests/libqos/malloc-pc.c b/tests/libqos/malloc-pc.c
index 6f92ce4135..5c58bf6e88 100644
--- a/tests/libqos/malloc-pc.c
+++ b/tests/libqos/malloc-pc.c
@@ -23,11 +23,11 @@ 
 void pc_alloc_init(QGuestAllocator *s, QTestState *qts, QAllocOpts flags)
 {
     uint64_t ram_size;
-    QFWCFG *fw_cfg = pc_fw_cfg_init(qts);
+    QFWCFG *fw_cfg = fw_cfg_init(qts);
 
     ram_size = qfw_cfg_get_u64(fw_cfg, FW_CFG_RAM_SIZE);
     alloc_init(s, flags, 1 << 20, MIN(ram_size, 0xE0000000), PAGE_SIZE);
 
     /* clean-up */
-    pc_fw_cfg_uninit(fw_cfg);
+    fw_cfg_uninit(fw_cfg);
 }