A new qtest is written that exercizes the fw-cfg DMA based read and write ops
to write values into vmcoreinfo fw-cfg file and read them back and verify that
they are the same.
Signed-off-by: Ani Sinha <anisinha@redhat.com>
---
MAINTAINERS | 2 +
tests/qtest/meson.build | 1 +
tests/qtest/vmcoreinfo-test.c | 90 +++++++++++++++++++++++++++++++++++
3 files changed, 93 insertions(+)
create mode 100644 tests/qtest/vmcoreinfo-test.c
diff --git a/MAINTAINERS b/MAINTAINERS
index 846b81e3ec..57167c3c73 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3016,6 +3016,7 @@ F: include/system/device_tree.h
Dump
S: Supported
M: Marc-André Lureau <marcandre.lureau@redhat.com>
+R: Ani Sinha <anisinha@redhat.com>
F: dump/
F: hw/misc/vmcoreinfo.c
F: include/hw/misc/vmcoreinfo.h
@@ -3026,6 +3027,7 @@ F: qapi/dump.json
F: scripts/dump-guest-memory.py
F: stubs/dump.c
F: docs/specs/vmcoreinfo.rst
+F: tests/qtest/vmcoreinfo-test.c
Error reporting
M: Markus Armbruster <armbru@redhat.com>
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
index 94b28e5a53..fc669336a6 100644
--- a/tests/qtest/meson.build
+++ b/tests/qtest/meson.build
@@ -57,6 +57,7 @@ qtests_i386 = \
(config_all_devices.has_key('CONFIG_AHCI_ICH9') ? ['tco-test'] : []) + \
(config_all_devices.has_key('CONFIG_FDC_ISA') ? ['fdc-test'] : []) + \
(config_all_devices.has_key('CONFIG_I440FX') ? ['fw_cfg-test'] : []) + \
+ (config_all_devices.has_key('CONFIG_FW_CFG_DMA') ? ['vmcoreinfo-test'] : []) + \
(config_all_devices.has_key('CONFIG_I440FX') ? ['i440fx-test'] : []) + \
(config_all_devices.has_key('CONFIG_I440FX') ? ['ide-test'] : []) + \
(config_all_devices.has_key('CONFIG_I440FX') ? ['numa-test'] : []) + \
diff --git a/tests/qtest/vmcoreinfo-test.c b/tests/qtest/vmcoreinfo-test.c
new file mode 100644
index 0000000000..dcf3b5ae05
--- /dev/null
+++ b/tests/qtest/vmcoreinfo-test.c
@@ -0,0 +1,90 @@
+/*
+ * qtest vmcoreinfo test case
+ *
+ * Copyright Red Hat. 2025.
+ *
+ * Authors:
+ * Ani Sinha <anisinha@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/units.h"
+#include "libqos/libqos-pc.h"
+#include "libqtest.h"
+#include "standard-headers/linux/qemu_fw_cfg.h"
+#include "libqos/fw_cfg.h"
+#include "qemu/bswap.h"
+#include "hw/misc/vmcoreinfo.h"
+
+static void test_vmcoreinfo_write_basic(void)
+{
+ QFWCFG *fw_cfg;
+ QOSState *qs;
+ FWCfgVMCoreInfo info;
+ size_t filesize;
+ uint16_t guest_format;
+ uint16_t host_format;
+ uint32_t size;
+ uint64_t paddr;
+
+ qs = qtest_pc_boot("-device vmcoreinfo");
+ fw_cfg = pc_fw_cfg_init(qs->qts);
+
+ memset(&info, 0 , sizeof(info));
+ /* read vmcoreinfo and read back the host format */
+ filesize = qfw_cfg_read_file(fw_cfg, qs, FW_CFG_VMCOREINFO_FILENAME,
+ &info, sizeof(info));
+ g_assert_cmpint(filesize, ==, sizeof(info));
+
+ host_format = le16_to_cpu(info.host_format);
+ g_assert_cmpint(host_format, ==, FW_CFG_VMCOREINFO_FORMAT_ELF);
+
+ memset(&info, 0 , sizeof(info));
+ info.guest_format = cpu_to_le16(FW_CFG_VMCOREINFO_FORMAT_ELF);
+ info.size = cpu_to_le32(1 * MiB);
+ info.paddr = cpu_to_le64(0xffffff00);
+ info.host_format = cpu_to_le16(host_format);
+
+ /* write the values to the host */
+ filesize = qfw_cfg_write_file(fw_cfg, qs, FW_CFG_VMCOREINFO_FILENAME,
+ &info, sizeof(info));
+ g_assert_cmpint(filesize, ==, sizeof(info));
+
+ memset(&info, 0 , sizeof(info));
+
+ /* now read back the values we wrote and compare that they are the same */
+ filesize = qfw_cfg_read_file(fw_cfg, qs, FW_CFG_VMCOREINFO_FILENAME,
+ &info, sizeof(info));
+ g_assert_cmpint(filesize, ==, sizeof(info));
+
+ size = le32_to_cpu(info.size);
+ paddr = le64_to_cpu(info.paddr);
+ guest_format = le16_to_cpu(info.guest_format);
+
+ g_assert_cmpint(size, ==, 1 * MiB);
+ g_assert_cmpint(paddr, ==, 0xffffff00);
+ g_assert_cmpint(guest_format, ==, FW_CFG_VMCOREINFO_FORMAT_ELF);
+
+ pc_fw_cfg_uninit(fw_cfg);
+ qtest_shutdown(qs);
+}
+
+int main(int argc, char **argv)
+{
+ const char *arch = qtest_get_arch();
+
+ g_test_init(&argc, &argv, NULL);
+
+ if (strcmp(arch, "i386") && strcmp(arch, "x86_64")) {
+ /* skip for non-x86 */
+ exit(EXIT_SUCCESS);
+ }
+
+ qtest_add_func("vmcoreinfo/basic-write",
+ test_vmcoreinfo_write_basic);
+
+ return g_test_run();
+}
--
2.45.2
Ani Sinha <anisinha@redhat.com> writes: > A new qtest is written that exercizes the fw-cfg DMA based read and write ops > to write values into vmcoreinfo fw-cfg file and read them back and verify that > they are the same. > > Signed-off-by: Ani Sinha <anisinha@redhat.com> Reviewed-by: Fabiano Rosas <farosas@suse.de>
On Mon, Jan 20, 2025 at 10:09 AM Ani Sinha <anisinha@redhat.com> wrote:
>
> A new qtest is written that exercizes the fw-cfg DMA based read and write ops
> to write values into vmcoreinfo fw-cfg file and read them back and verify that
> they are the same.
>
> Signed-off-by: Ani Sinha <anisinha@redhat.com>
Final ping on this patch.
> ---
> MAINTAINERS | 2 +
> tests/qtest/meson.build | 1 +
> tests/qtest/vmcoreinfo-test.c | 90 +++++++++++++++++++++++++++++++++++
> 3 files changed, 93 insertions(+)
> create mode 100644 tests/qtest/vmcoreinfo-test.c
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 846b81e3ec..57167c3c73 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -3016,6 +3016,7 @@ F: include/system/device_tree.h
> Dump
> S: Supported
> M: Marc-André Lureau <marcandre.lureau@redhat.com>
> +R: Ani Sinha <anisinha@redhat.com>
> F: dump/
> F: hw/misc/vmcoreinfo.c
> F: include/hw/misc/vmcoreinfo.h
> @@ -3026,6 +3027,7 @@ F: qapi/dump.json
> F: scripts/dump-guest-memory.py
> F: stubs/dump.c
> F: docs/specs/vmcoreinfo.rst
> +F: tests/qtest/vmcoreinfo-test.c
>
> Error reporting
> M: Markus Armbruster <armbru@redhat.com>
> diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
> index 94b28e5a53..fc669336a6 100644
> --- a/tests/qtest/meson.build
> +++ b/tests/qtest/meson.build
> @@ -57,6 +57,7 @@ qtests_i386 = \
> (config_all_devices.has_key('CONFIG_AHCI_ICH9') ? ['tco-test'] : []) + \
> (config_all_devices.has_key('CONFIG_FDC_ISA') ? ['fdc-test'] : []) + \
> (config_all_devices.has_key('CONFIG_I440FX') ? ['fw_cfg-test'] : []) + \
> + (config_all_devices.has_key('CONFIG_FW_CFG_DMA') ? ['vmcoreinfo-test'] : []) + \
> (config_all_devices.has_key('CONFIG_I440FX') ? ['i440fx-test'] : []) + \
> (config_all_devices.has_key('CONFIG_I440FX') ? ['ide-test'] : []) + \
> (config_all_devices.has_key('CONFIG_I440FX') ? ['numa-test'] : []) + \
> diff --git a/tests/qtest/vmcoreinfo-test.c b/tests/qtest/vmcoreinfo-test.c
> new file mode 100644
> index 0000000000..dcf3b5ae05
> --- /dev/null
> +++ b/tests/qtest/vmcoreinfo-test.c
> @@ -0,0 +1,90 @@
> +/*
> + * qtest vmcoreinfo test case
> + *
> + * Copyright Red Hat. 2025.
> + *
> + * Authors:
> + * Ani Sinha <anisinha@redhat.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + */
> +
> +#include "qemu/osdep.h"
> +#include "qemu/units.h"
> +#include "libqos/libqos-pc.h"
> +#include "libqtest.h"
> +#include "standard-headers/linux/qemu_fw_cfg.h"
> +#include "libqos/fw_cfg.h"
> +#include "qemu/bswap.h"
> +#include "hw/misc/vmcoreinfo.h"
> +
> +static void test_vmcoreinfo_write_basic(void)
> +{
> + QFWCFG *fw_cfg;
> + QOSState *qs;
> + FWCfgVMCoreInfo info;
> + size_t filesize;
> + uint16_t guest_format;
> + uint16_t host_format;
> + uint32_t size;
> + uint64_t paddr;
> +
> + qs = qtest_pc_boot("-device vmcoreinfo");
> + fw_cfg = pc_fw_cfg_init(qs->qts);
> +
> + memset(&info, 0 , sizeof(info));
> + /* read vmcoreinfo and read back the host format */
> + filesize = qfw_cfg_read_file(fw_cfg, qs, FW_CFG_VMCOREINFO_FILENAME,
> + &info, sizeof(info));
> + g_assert_cmpint(filesize, ==, sizeof(info));
> +
> + host_format = le16_to_cpu(info.host_format);
> + g_assert_cmpint(host_format, ==, FW_CFG_VMCOREINFO_FORMAT_ELF);
> +
> + memset(&info, 0 , sizeof(info));
> + info.guest_format = cpu_to_le16(FW_CFG_VMCOREINFO_FORMAT_ELF);
> + info.size = cpu_to_le32(1 * MiB);
> + info.paddr = cpu_to_le64(0xffffff00);
> + info.host_format = cpu_to_le16(host_format);
> +
> + /* write the values to the host */
> + filesize = qfw_cfg_write_file(fw_cfg, qs, FW_CFG_VMCOREINFO_FILENAME,
> + &info, sizeof(info));
> + g_assert_cmpint(filesize, ==, sizeof(info));
> +
> + memset(&info, 0 , sizeof(info));
> +
> + /* now read back the values we wrote and compare that they are the same */
> + filesize = qfw_cfg_read_file(fw_cfg, qs, FW_CFG_VMCOREINFO_FILENAME,
> + &info, sizeof(info));
> + g_assert_cmpint(filesize, ==, sizeof(info));
> +
> + size = le32_to_cpu(info.size);
> + paddr = le64_to_cpu(info.paddr);
> + guest_format = le16_to_cpu(info.guest_format);
> +
> + g_assert_cmpint(size, ==, 1 * MiB);
> + g_assert_cmpint(paddr, ==, 0xffffff00);
> + g_assert_cmpint(guest_format, ==, FW_CFG_VMCOREINFO_FORMAT_ELF);
> +
> + pc_fw_cfg_uninit(fw_cfg);
> + qtest_shutdown(qs);
> +}
> +
> +int main(int argc, char **argv)
> +{
> + const char *arch = qtest_get_arch();
> +
> + g_test_init(&argc, &argv, NULL);
> +
> + if (strcmp(arch, "i386") && strcmp(arch, "x86_64")) {
> + /* skip for non-x86 */
> + exit(EXIT_SUCCESS);
> + }
> +
> + qtest_add_func("vmcoreinfo/basic-write",
> + test_vmcoreinfo_write_basic);
> +
> + return g_test_run();
> +}
> --
> 2.45.2
>
© 2016 - 2026 Red Hat, Inc.