This test is based off vmgenid test from Ben Warren <b...@skyportsystems.com>. It simply checks the vmcoreinfo ACPI device is present and that the memory region associated can be read.
Signed-off-by: Marc-André Lureau <marcandre.lur...@redhat.com> --- tests/vmcoreinfo-test.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/Makefile.include | 2 + 2 files changed, 143 insertions(+) create mode 100644 tests/vmcoreinfo-test.c diff --git a/tests/vmcoreinfo-test.c b/tests/vmcoreinfo-test.c new file mode 100644 index 0000000000..a54f3b5c6a --- /dev/null +++ b/tests/vmcoreinfo-test.c @@ -0,0 +1,141 @@ +/* + * QTest testcase for VM coreinfo device + * + * Copyright (c) 2017 Red Hat, Inc. + * Copyright (c) 2017 Skyport Systems + * + * 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 <glib.h> +#include <string.h> +#include <unistd.h> +#include "qemu/osdep.h" +#include "qemu/bitmap.h" +#include "qemu/uuid.h" +#include "hw/acpi/acpi-defs.h" +#include "boot-sector.h" +#include "acpi-utils.h" +#include "libqtest.h" + +#define RSDP_ADDR_INVALID 0x100000 /* RSDP must be below this address */ + +typedef struct { + AcpiTableHeader header; + gchar name_op; + gchar vcia[4]; + gchar val_op; + uint32_t vcia_val; +} QEMU_PACKED VmciTable; + +static uint32_t acpi_find_vcia(void) +{ + uint32_t rsdp_offset; + AcpiRsdpDescriptor rsdp_table; + uint32_t rsdt; + AcpiRsdtDescriptorRev1 rsdt_table; + int tables_nr; + uint32_t *tables; + AcpiTableHeader ssdt_table; + VmciTable vmci_table; + int i; + + /* Wait for guest firmware to finish and start the payload. */ + boot_sector_test(); + + /* Tables should be initialized now. */ + rsdp_offset = acpi_find_rsdp_address(); + + g_assert_cmphex(rsdp_offset, <, RSDP_ADDR_INVALID); + + acpi_parse_rsdp_table(rsdp_offset, &rsdp_table); + + rsdt = rsdp_table.rsdt_physical_address; + /* read the header */ + ACPI_READ_TABLE_HEADER(&rsdt_table, rsdt); + ACPI_ASSERT_CMP(rsdt_table.signature, "RSDT"); + + /* compute the table entries in rsdt */ + tables_nr = (rsdt_table.length - sizeof(AcpiRsdtDescriptorRev1)) / + sizeof(uint32_t); + g_assert_cmpint(tables_nr, >, 0); + + /* get the addresses of the tables pointed by rsdt */ + tables = g_new0(uint32_t, tables_nr); + ACPI_READ_ARRAY_PTR(tables, tables_nr, rsdt); + + for (i = 0; i < tables_nr; i++) { + ACPI_READ_TABLE_HEADER(&ssdt_table, tables[i]); + if (!strncmp((char *)ssdt_table.oem_table_id, "VMCOREIN", 8)) { + /* the first entry in the table should be VCIA + * That's all we need + */ + ACPI_READ_FIELD(vmci_table.name_op, tables[i]); + g_assert(vmci_table.name_op == 0x08); /* name */ + ACPI_READ_ARRAY(vmci_table.vcia, tables[i]); + g_assert(memcmp(vmci_table.vcia, "VCIA", 4) == 0); + ACPI_READ_FIELD(vmci_table.val_op, tables[i]); + g_assert(vmci_table.val_op == 0x0C); /* dword */ + ACPI_READ_FIELD(vmci_table.vcia_val, tables[i]); + /* The GUID is written at a fixed offset into the fw_cfg file + * in order to implement the "OVMF SDT Header probe suppressor" + * see docs/specs/vmgenid.txt for more details + */ + g_free(tables); + return vmci_table.vcia_val; + } + } + g_free(tables); + return 0; +} + +static char disk[] = "tests/vmci-test-disk-XXXXXX"; + +static char *cmd_strdup(void) +{ + return g_strdup_printf("-machine accel=tcg " + "-device vmcoreinfo,id=testvmvci " + "-drive id=hd0,if=none,file=%s,format=raw " + "-device ide-hd,drive=hd0 ", + disk); +} + +static void vmcoreinfo_test(void) +{ + gchar *cmd; + uint32_t vmci_addr; + int i; + + cmd = cmd_strdup(); + qtest_start(cmd); + + vmci_addr = acpi_find_vcia(); + g_assert(vmci_addr); + + for (i = 0; i < 4096; i++) { + /* check the memory region can be read */ + readb(vmci_addr + i); + } + + qtest_quit(global_qtest); + g_free(cmd); +} + +int main(int argc, char **argv) +{ + int ret; + + ret = boot_sector_init(disk); + if (ret) { + return ret; + } + + g_test_init(&argc, &argv, NULL); + + qtest_add_func("/vmcoreinfo/test", vmcoreinfo_test); + ret = g_test_run(); + boot_sector_cleanup(disk); + + return ret; +} diff --git a/tests/Makefile.include b/tests/Makefile.include index cfbb689e0e..dd515f2159 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -251,6 +251,7 @@ gcov-files-i386-y += hw/usb/hcd-xhci.c check-qtest-i386-y += tests/pc-cpu-test$(EXESUF) check-qtest-i386-y += tests/q35-test$(EXESUF) check-qtest-i386-y += tests/vmgenid-test$(EXESUF) +check-qtest-i386-y += tests/vmcoreinfo-test$(EXESUF) gcov-files-i386-y += hw/pci-host/q35.c check-qtest-i386-$(CONFIG_VHOST_NET_TEST_i386) += tests/vhost-user-test$(EXESUF) ifeq ($(CONFIG_VHOST_NET_TEST_i386),) @@ -762,6 +763,7 @@ tests/test-arm-mptimer$(EXESUF): tests/test-arm-mptimer.o tests/test-qapi-util$(EXESUF): tests/test-qapi-util.o $(test-util-obj-y) tests/numa-test$(EXESUF): tests/numa-test.o tests/vmgenid-test$(EXESUF): tests/vmgenid-test.o tests/boot-sector.o tests/acpi-utils.o +tests/vmcoreinfo-test$(EXESUF): tests/vmcoreinfo-test.o tests/boot-sector.o tests/acpi-utils.o tests/migration/stress$(EXESUF): tests/migration/stress.o $(call quiet-command, $(LINKPROG) -static -O3 $(PTHREAD_LIB) -o $@ $< ,"LINK","$(TARGET_DIR)$@") -- 2.13.1.395.gf7b71de06