diff options
-rw-r--r-- | tests/qtest/bios-tables-test.c | 170 |
1 files changed, 146 insertions, 24 deletions
diff --git a/tests/qtest/bios-tables-test.c b/tests/qtest/bios-tables-test.c index 669202fc95..77053975aa 100644 --- a/tests/qtest/bios-tables-test.c +++ b/tests/qtest/bios-tables-test.c @@ -64,13 +64,17 @@ #include "boot-sector.h" #include "tpm-emu.h" #include "hw/acpi/tpm.h" - +#include "qemu/cutils.h" #define MACHINE_PC "pc" #define MACHINE_Q35 "q35" #define ACPI_REBUILD_EXPECTED_AML "TEST_ACPI_REBUILD_AML" +#define OEM_ID "TEST" +#define OEM_TABLE_ID "OEM" +#define OEM_TEST_ARGS "-machine oem-id="OEM_ID",oem-table-id="OEM_TABLE_ID + typedef struct { bool tcg_only; const char *machine; @@ -654,17 +658,28 @@ static void test_smbios_structs(test_data *data) } } -static void test_acpi_one(const char *params, test_data *data) +static void test_acpi_load_tables(test_data *data, bool use_uefi) { - char *args; - bool use_uefi = data->uefi_fl1 && data->uefi_fl2; - -#ifndef CONFIG_TCG - if (data->tcg_only) { - g_test_skip("TCG disabled, skipping ACPI tcg_only test"); - return; + if (use_uefi) { + g_assert(data->scan_len); + data->rsdp_addr = acpi_find_rsdp_address_uefi(data->qts, + data->ram_start, data->scan_len); + } else { + boot_sector_test(data->qts); + data->rsdp_addr = acpi_find_rsdp_address(data->qts); + g_assert_cmphex(data->rsdp_addr, <, 0x100000); } -#endif /* CONFIG_TCG */ + + data->tables = g_array_new(false, true, sizeof(AcpiSdtTable)); + test_acpi_rsdp_table(data); + test_acpi_rxsdt_table(data); + test_acpi_fadt_table(data); +} + +static char *test_acpi_create_args(test_data *data, const char *params, + bool use_uefi) +{ + char *args; if (use_uefi) { /* @@ -695,23 +710,24 @@ static void test_acpi_one(const char *params, test_data *data) params ? params : "", disk, data->blkdev ?: "ide-hd"); } + return args; +} - data->qts = qtest_init(args); +static void test_acpi_one(const char *params, test_data *data) +{ + char *args; + bool use_uefi = data->uefi_fl1 && data->uefi_fl2; - if (use_uefi) { - g_assert(data->scan_len); - data->rsdp_addr = acpi_find_rsdp_address_uefi(data->qts, - data->ram_start, data->scan_len); - } else { - boot_sector_test(data->qts); - data->rsdp_addr = acpi_find_rsdp_address(data->qts); - g_assert_cmphex(data->rsdp_addr, <, 0x100000); +#ifndef CONFIG_TCG + if (data->tcg_only) { + g_test_skip("TCG disabled, skipping ACPI tcg_only test"); + return; } +#endif /* CONFIG_TCG */ - data->tables = g_array_new(false, true, sizeof(AcpiSdtTable)); - test_acpi_rsdp_table(data); - test_acpi_rxsdt_table(data); - test_acpi_fadt_table(data); + args = test_acpi_create_args(data, params, use_uefi); + data->qts = qtest_init(args); + test_acpi_load_tables(data, use_uefi); if (getenv(ACPI_REBUILD_EXPECTED_AML)) { dump_aml_files(data, true); @@ -1292,6 +1308,109 @@ static void test_acpi_virt_tcg(void) free_test_data(&data); } +static void test_oem_fields(test_data *data) +{ + int i; + char oem_id[6]; + char oem_table_id[8]; + + strpadcpy(oem_id, sizeof oem_id, OEM_ID, ' '); + strpadcpy(oem_table_id, sizeof oem_table_id, OEM_TABLE_ID, ' '); + for (i = 0; i < data->tables->len; ++i) { + AcpiSdtTable *sdt; + + sdt = &g_array_index(data->tables, AcpiSdtTable, i); + /* FACS doesn't have OEMID and OEMTABLEID fields */ + if (compare_signature(sdt, "FACS")) { + continue; + } + + g_assert(memcmp(sdt->aml + 10, oem_id, 6) == 0); + g_assert(memcmp(sdt->aml + 16, oem_table_id, 8) == 0); + } +} + +static void test_acpi_oem_fields_pc(void) +{ + test_data data; + char *args; + + memset(&data, 0, sizeof(data)); + data.machine = MACHINE_PC; + data.required_struct_types = base_required_struct_types; + data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types); + + args = test_acpi_create_args(&data, + OEM_TEST_ARGS, false); + data.qts = qtest_init(args); + test_acpi_load_tables(&data, false); + test_oem_fields(&data); + qtest_quit(data.qts); + free_test_data(&data); + g_free(args); +} + +static void test_acpi_oem_fields_q35(void) +{ + test_data data; + char *args; + + memset(&data, 0, sizeof(data)); + data.machine = MACHINE_Q35; + data.required_struct_types = base_required_struct_types; + data.required_struct_types_len = ARRAY_SIZE(base_required_struct_types); + + args = test_acpi_create_args(&data, + OEM_TEST_ARGS, false); + data.qts = qtest_init(args); + test_acpi_load_tables(&data, false); + test_oem_fields(&data); + qtest_quit(data.qts); + free_test_data(&data); + g_free(args); +} + +static void test_acpi_oem_fields_microvm(void) +{ + test_data data; + char *args; + + test_acpi_microvm_prepare(&data); + + args = test_acpi_create_args(&data, + OEM_TEST_ARGS",acpi=on", false); + data.qts = qtest_init(args); + test_acpi_load_tables(&data, false); + test_oem_fields(&data); + qtest_quit(data.qts); + free_test_data(&data); + g_free(args); +} + +static void test_acpi_oem_fields_virt(void) +{ + test_data data = { + .machine = "virt", + .tcg_only = true, + .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd", + .uefi_fl2 = "pc-bios/edk2-arm-vars.fd", + .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2", + .ram_start = 0x40000000ULL, + .scan_len = 128ULL * 1024 * 1024, + }; + char *args; + + args = test_acpi_create_args(&data, + "-cpu cortex-a57 "OEM_TEST_ARGS, true); + data.qts = qtest_init(args); + test_acpi_load_tables(&data, true); + test_oem_fields(&data); + qtest_quit(data.qts); + free_test_data(&data); + g_free(args); +} + + int main(int argc, char *argv[]) { const char *arch = qtest_get_arch(); @@ -1304,9 +1423,10 @@ int main(int argc, char *argv[]) if (ret) { return ret; } - + qtest_add_func("acpi/q35/oem-fields", test_acpi_oem_fields_q35); qtest_add_func("acpi/q35/tpm-tis", test_acpi_q35_tcg_tpm_tis); qtest_add_func("acpi/piix4", test_acpi_piix4_tcg); + qtest_add_func("acpi/oem-fields", test_acpi_oem_fields_pc); qtest_add_func("acpi/piix4/bridge", test_acpi_piix4_tcg_bridge); qtest_add_func("acpi/piix4/pci-hotplug/no_root_hotplug", test_acpi_piix4_no_root_hotplug); @@ -1333,6 +1453,7 @@ int main(int argc, char *argv[]) qtest_add_func("acpi/microvm/usb", test_acpi_microvm_usb_tcg); qtest_add_func("acpi/microvm/rtc", test_acpi_microvm_rtc_tcg); qtest_add_func("acpi/microvm/ioapic2", test_acpi_microvm_ioapic2_tcg); + qtest_add_func("acpi/microvm/oem-fields", test_acpi_oem_fields_microvm); if (strcmp(arch, "x86_64") == 0) { qtest_add_func("acpi/microvm/pcie", test_acpi_microvm_pcie_tcg); } @@ -1341,6 +1462,7 @@ int main(int argc, char *argv[]) qtest_add_func("acpi/virt/numamem", test_acpi_virt_tcg_numamem); qtest_add_func("acpi/virt/memhp", test_acpi_virt_tcg_memhp); qtest_add_func("acpi/virt/pxb", test_acpi_virt_tcg_pxb); + qtest_add_func("acpi/virt/oem-fields", test_acpi_oem_fields_virt); } ret = g_test_run(); boot_sector_cleanup(disk); |