aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2019-05-21 14:56:57 +0100
committerPeter Maydell <peter.maydell@linaro.org>2019-05-21 14:56:57 +0100
commit247ba27c528c52e4a41c233c1c9a699f40e4d2a5 (patch)
treecec47b9b84e1e099b1295468f59fe31490c6e379 /tests
parent62516a0a18cd156d913dd625baca52c46743223b (diff)
parentba02ff90ee1dcaf7aa5645075217e555ae2c54ea (diff)
Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging
pci, pc, virtio: features, fixes reconnect for vhost blk tests for UEFI misc other stuff Signed-off-by: Michael S. Tsirkin <mst@redhat.com> # gpg: Signature made Tue 21 May 2019 14:41:32 BST # gpg: using RSA key 281F0DB8D28D5469 # gpg: Good signature from "Michael S. Tsirkin <mst@kernel.org>" [full] # gpg: aka "Michael S. Tsirkin <mst@redhat.com>" [full] # Primary key fingerprint: 0270 606B 6F3C DF3D 0B17 0970 C350 3912 AFBE 8E67 # Subkey fingerprint: 5D09 FD08 71C8 F85B 94CA 8A0D 281F 0DB8 D28D 5469 * remotes/mst/tags/for_upstream: (34 commits) tests: acpi: print error unable to dump ACPI table during rebuild tests: acpi: refactor rebuild-expected-aml.sh to dump ACPI tables for a specified list of targets tests: acpi: allow to override default accelerator tests: acpi: ignore SMBIOS tests when UEFI firmware is used tests: acpi: add a way to start tests with UEFI firmware tests: acpi: add acpi_find_rsdp_address_uefi() helper tests: acpi: move boot_sector_init() into x86 tests branch tests: acpi: skip FACS table if board uses hw reduced ACPI profile tests: acpi: fetch X_DSDT if pointer to DSDT is 0 tests: acpi: make pointer to RSDP 64bit tests: acpi: make RSDT test routine handle XSDT tests: acpi: make acpi_fetch_table() take size of fetched table pointer tests: acpi: rename acpi_parse_rsdp_table() into acpi_fetch_rsdp_table() pci: Simplify pci_bus_is_root() pcie: Remove redundant test in pcie_mmcfg_data_{read,write}() libvhost-user: fix bad vu_log_write hw/arm/virt-acpi-build: pass AcpiMcfgInfo to build_mcfg() i386, acpi: remove mcfg_ prefix in AcpiMcfgInfo members hw/arm/virt-acpi-build: remove unnecessary variable mcfg_start do not call vhost_net_cleanup() on running net from char user event ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/acpi-utils.c68
-rw-r--r--tests/acpi-utils.h7
-rw-r--r--tests/bios-tables-test.c130
-rwxr-xr-xtests/data/acpi/rebuild-expected-aml.sh23
-rw-r--r--tests/vmgenid-test.c6
5 files changed, 159 insertions, 75 deletions
diff --git a/tests/acpi-utils.c b/tests/acpi-utils.c
index cc33b460ab..d2a202efca 100644
--- a/tests/acpi-utils.c
+++ b/tests/acpi-utils.c
@@ -51,19 +51,7 @@ uint32_t acpi_find_rsdp_address(QTestState *qts)
return off;
}
-uint64_t acpi_get_xsdt_address(uint8_t *rsdp_table)
-{
- uint64_t xsdt_physical_address;
- uint8_t revision = rsdp_table[15 /* Revision offset */];
-
- /* We must have revision 2 if we're looking for an XSDT pointer */
- g_assert(revision == 2);
-
- memcpy(&xsdt_physical_address, &rsdp_table[24 /* XsdtAddress offset */], 8);
- return le64_to_cpu(xsdt_physical_address);
-}
-
-void acpi_parse_rsdp_table(QTestState *qts, uint32_t addr, uint8_t *rsdp_table)
+void acpi_fetch_rsdp_table(QTestState *qts, uint64_t addr, uint8_t *rsdp_table)
{
uint8_t revision;
@@ -91,13 +79,15 @@ void acpi_parse_rsdp_table(QTestState *qts, uint32_t addr, uint8_t *rsdp_table)
* actual one.
*/
void acpi_fetch_table(QTestState *qts, uint8_t **aml, uint32_t *aml_len,
- const uint8_t *addr_ptr, const char *sig,
+ const uint8_t *addr_ptr, int addr_size, const char *sig,
bool verify_checksum)
{
- uint32_t addr, len;
+ uint32_t len;
+ uint64_t addr = 0;
- memcpy(&addr, addr_ptr , sizeof(addr));
- addr = le32_to_cpu(addr);
+ g_assert(addr_size == 4 || addr_size == 8);
+ memcpy(&addr, addr_ptr , addr_size);
+ addr = le64_to_cpu(addr);
qtest_memread(qts, addr + 4, &len, 4); /* Length of ACPI table */
*aml_len = le32_to_cpu(len);
*aml = g_malloc0(*aml_len);
@@ -111,3 +101,47 @@ void acpi_fetch_table(QTestState *qts, uint8_t **aml, uint32_t *aml_len,
g_assert(!acpi_calc_checksum(*aml, *aml_len));
}
}
+
+#define GUID_SIZE 16
+static const uint8_t AcpiTestSupportGuid[GUID_SIZE] = {
+ 0xb1, 0xa6, 0x87, 0xab,
+ 0x34, 0x20,
+ 0xa0, 0xbd,
+ 0x71, 0xbd, 0x37, 0x50, 0x07, 0x75, 0x77, 0x85 };
+
+typedef struct {
+ uint8_t signature_guid[GUID_SIZE];
+ uint64_t rsdp10;
+ uint64_t rsdp20;
+} __attribute__((packed)) UefiTestSupport;
+
+/* Wait at most 600 seconds (test is slow with TCG and --enable-debug) */
+#define TEST_DELAY (1 * G_USEC_PER_SEC / 10)
+#define TEST_CYCLES MAX((600 * G_USEC_PER_SEC / TEST_DELAY), 1)
+#define MB 0x100000ULL
+uint64_t acpi_find_rsdp_address_uefi(QTestState *qts, uint64_t start,
+ uint64_t size)
+{
+ int i, j;
+ uint8_t data[GUID_SIZE];
+
+ for (i = 0; i < TEST_CYCLES; ++i) {
+ for (j = 0; j < size / MB; j++) {
+ /* look for GUID at every 1Mb block */
+ uint64_t addr = start + j * MB;
+
+ qtest_memread(qts, addr, data, sizeof(data));
+ if (!memcmp(AcpiTestSupportGuid, data, sizeof(data))) {
+ UefiTestSupport ret;
+
+ qtest_memread(qts, addr, &ret, sizeof(ret));
+ ret.rsdp10 = le64_to_cpu(ret.rsdp10);
+ ret.rsdp20 = le64_to_cpu(ret.rsdp20);
+ return ret.rsdp20 ? ret.rsdp20 : ret.rsdp10;
+ }
+ }
+ g_usleep(TEST_DELAY);
+ }
+ g_assert_not_reached();
+ return 0;
+}
diff --git a/tests/acpi-utils.h b/tests/acpi-utils.h
index 73fe24f044..0c86780689 100644
--- a/tests/acpi-utils.h
+++ b/tests/acpi-utils.h
@@ -46,10 +46,11 @@ typedef struct {
uint8_t acpi_calc_checksum(const uint8_t *data, int len);
uint32_t acpi_find_rsdp_address(QTestState *qts);
-uint64_t acpi_get_xsdt_address(uint8_t *rsdp_table);
-void acpi_parse_rsdp_table(QTestState *qts, uint32_t addr, uint8_t *rsdp_table);
+uint64_t acpi_find_rsdp_address_uefi(QTestState *qts, uint64_t start,
+ uint64_t size);
+void acpi_fetch_rsdp_table(QTestState *qts, uint64_t addr, uint8_t *rsdp_table);
void acpi_fetch_table(QTestState *qts, uint8_t **aml, uint32_t *aml_len,
- const uint8_t *addr_ptr, const char *sig,
+ const uint8_t *addr_ptr, int addr_size, const char *sig,
bool verify_checksum);
#endif /* TEST_ACPI_UTILS_H */
diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c
index a506dcbb29..11e07be093 100644
--- a/tests/bios-tables-test.c
+++ b/tests/bios-tables-test.c
@@ -24,9 +24,15 @@
#define ACPI_REBUILD_EXPECTED_AML "TEST_ACPI_REBUILD_AML"
typedef struct {
+ const char *accel;
const char *machine;
const char *variant;
- uint32_t rsdp_addr;
+ const char *uefi_fl1;
+ const char *uefi_fl2;
+ const char *cd;
+ const uint64_t ram_start;
+ const uint64_t scan_len;
+ uint64_t rsdp_addr;
uint8_t rsdp_table[36 /* ACPI 2.0+ RSDP size */];
GArray *tables;
uint32_t smbios_ep_addr;
@@ -77,22 +83,13 @@ static void free_test_data(test_data *data)
g_array_free(data->tables, true);
}
-static void test_acpi_rsdp_address(test_data *data)
-{
- uint32_t off = acpi_find_rsdp_address(data->qts);
- g_assert_cmphex(off, <, 0x100000);
- data->rsdp_addr = off;
-}
-
static void test_acpi_rsdp_table(test_data *data)
{
- uint8_t *rsdp_table = data->rsdp_table, revision;
- uint32_t addr = data->rsdp_addr;
+ uint8_t *rsdp_table = data->rsdp_table;
- acpi_parse_rsdp_table(data->qts, addr, rsdp_table);
- revision = rsdp_table[15 /* Revision offset */];
+ acpi_fetch_rsdp_table(data->qts, data->rsdp_addr, rsdp_table);
- switch (revision) {
+ switch (rsdp_table[15 /* Revision offset */]) {
case 0: /* ACPI 1.0 RSDP */
/* With rev 1, checksum is only for the first 20 bytes */
g_assert(!acpi_calc_checksum(rsdp_table, 20));
@@ -107,21 +104,29 @@ static void test_acpi_rsdp_table(test_data *data)
}
}
-static void test_acpi_rsdt_table(test_data *data)
+static void test_acpi_rxsdt_table(test_data *data)
{
+ const char *sig = "RSDT";
AcpiSdtTable rsdt = {};
+ int entry_size = 4;
+ int addr_off = 16 /* RsdtAddress */;
uint8_t *ent;
- /* read RSDT table */
+ if (data->rsdp_table[15 /* Revision offset */] != 0) {
+ addr_off = 24 /* XsdtAddress */;
+ entry_size = 8;
+ sig = "XSDT";
+ }
+ /* read [RX]SDT table */
acpi_fetch_table(data->qts, &rsdt.aml, &rsdt.aml_len,
- &data->rsdp_table[16 /* RsdtAddress */], "RSDT", true);
+ &data->rsdp_table[addr_off], entry_size, sig, true);
/* Load all tables and add to test list directly RSDT referenced tables */
- ACPI_FOREACH_RSDT_ENTRY(rsdt.aml, rsdt.aml_len, ent, 4 /* Entry size */) {
+ ACPI_FOREACH_RSDT_ENTRY(rsdt.aml, rsdt.aml_len, ent, entry_size) {
AcpiSdtTable ssdt_table = {};
acpi_fetch_table(data->qts, &ssdt_table.aml, &ssdt_table.aml_len, ent,
- NULL, true);
+ entry_size, NULL, true);
/* Add table to ASL test tables list */
g_array_append_val(data->tables, ssdt_table);
}
@@ -134,16 +139,29 @@ static void test_acpi_fadt_table(test_data *data)
AcpiSdtTable table = g_array_index(data->tables, typeof(table), 0);
uint8_t *fadt_aml = table.aml;
uint32_t fadt_len = table.aml_len;
+ uint32_t val;
+ int dsdt_offset = 40 /* DSDT */;
+ int dsdt_entry_size = 4;
g_assert(compare_signature(&table, "FACP"));
/* Since DSDT/FACS isn't in RSDT, add them to ASL test list manually */
- acpi_fetch_table(data->qts, &table.aml, &table.aml_len,
- fadt_aml + 36 /* FIRMWARE_CTRL */, "FACS", false);
- g_array_append_val(data->tables, table);
+ memcpy(&val, fadt_aml + 112 /* Flags */, 4);
+ val = le32_to_cpu(val);
+ if (!(val & 1UL << 20 /* HW_REDUCED_ACPI */)) {
+ acpi_fetch_table(data->qts, &table.aml, &table.aml_len,
+ fadt_aml + 36 /* FIRMWARE_CTRL */, 4, "FACS", false);
+ g_array_append_val(data->tables, table);
+ }
+ memcpy(&val, fadt_aml + dsdt_offset, 4);
+ val = le32_to_cpu(val);
+ if (!val) {
+ dsdt_offset = 140 /* X_DSDT */;
+ dsdt_entry_size = 8;
+ }
acpi_fetch_table(data->qts, &table.aml, &table.aml_len,
- fadt_aml + 40 /* DSDT */, "DSDT", true);
+ fadt_aml + dsdt_offset, dsdt_entry_size, "DSDT", true);
g_array_append_val(data->tables, table);
memset(fadt_aml + 36, 0, 4); /* sanitize FIRMWARE_CTRL ptr */
@@ -177,11 +195,14 @@ static void dump_aml_files(test_data *data, bool rebuild)
sdt->aml, ext);
fd = g_open(aml_file, O_WRONLY|O_TRUNC|O_CREAT,
S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH);
+ if (fd < 0) {
+ perror(aml_file);
+ }
+ g_assert(fd >= 0);
} else {
fd = g_file_open_tmp("aml-XXXXXX", &sdt->aml_file, &error);
g_assert_no_error(error);
}
- g_assert(fd >= 0);
ret = qemu_write_full(fd, sdt->aml, sdt->aml_len);
g_assert(ret == sdt->aml_len);
@@ -505,23 +526,44 @@ static void test_smbios_structs(test_data *data)
static void test_acpi_one(const char *params, test_data *data)
{
char *args;
-
- /* Disable kernel irqchip to be able to override apic irq0. */
- args = g_strdup_printf("-machine %s,accel=%s,kernel-irqchip=off "
- "-net none -display none %s "
- "-drive id=hd0,if=none,file=%s,format=raw "
- "-device ide-hd,drive=hd0 ",
- data->machine, "kvm:tcg",
- params ? params : "", disk);
+ bool use_uefi = data->uefi_fl1 && data->uefi_fl2;
+
+ if (use_uefi) {
+ /*
+ * TODO: convert '-drive if=pflash' to new syntax (see e33763be7cd3)
+ * when arm/virt boad starts to support it.
+ */
+ args = g_strdup_printf("-machine %s,accel=%s -nodefaults -nographic "
+ "-drive if=pflash,format=raw,file=%s,readonly "
+ "-drive if=pflash,format=raw,file=%s,snapshot=on -cdrom %s %s",
+ data->machine, data->accel ? data->accel : "kvm:tcg",
+ data->uefi_fl1, data->uefi_fl2, data->cd, params ? params : "");
+
+ } else {
+ /* Disable kernel irqchip to be able to override apic irq0. */
+ args = g_strdup_printf("-machine %s,accel=%s,kernel-irqchip=off "
+ "-net none -display none %s "
+ "-drive id=hd0,if=none,file=%s,format=raw "
+ "-device ide-hd,drive=hd0 ",
+ data->machine, data->accel ? data->accel : "kvm:tcg",
+ params ? params : "", disk);
+ }
data->qts = qtest_init(args);
- boot_sector_test(data->qts);
+ 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);
+ }
data->tables = g_array_new(false, true, sizeof(AcpiSdtTable));
- test_acpi_rsdp_address(data);
test_acpi_rsdp_table(data);
- test_acpi_rsdt_table(data);
+ test_acpi_rxsdt_table(data);
test_acpi_fadt_table(data);
if (iasl) {
@@ -532,8 +574,15 @@ static void test_acpi_one(const char *params, test_data *data)
}
}
- test_smbios_entry_point(data);
- test_smbios_structs(data);
+ /*
+ * TODO: make SMBIOS tests work with UEFI firmware,
+ * Bug on uefi-test-tools to provide entry point:
+ * https://bugs.launchpad.net/qemu/+bug/1821884
+ */
+ if (!use_uefi) {
+ test_smbios_entry_point(data);
+ test_smbios_structs(data);
+ }
assert(!global_qtest);
qtest_quit(data->qts);
@@ -769,13 +818,14 @@ int main(int argc, char *argv[])
const char *arch = qtest_get_arch();
int ret;
- ret = boot_sector_init(disk);
- if(ret)
- return ret;
-
g_test_init(&argc, &argv, NULL);
if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
+ ret = boot_sector_init(disk);
+ if (ret) {
+ return ret;
+ }
+
qtest_add_func("acpi/piix4", test_acpi_piix4_tcg);
qtest_add_func("acpi/piix4/bridge", test_acpi_piix4_tcg_bridge);
qtest_add_func("acpi/q35", test_acpi_q35_tcg);
diff --git a/tests/data/acpi/rebuild-expected-aml.sh b/tests/data/acpi/rebuild-expected-aml.sh
index abdff70a0d..ff7e62249d 100755
--- a/tests/data/acpi/rebuild-expected-aml.sh
+++ b/tests/data/acpi/rebuild-expected-aml.sh
@@ -7,21 +7,12 @@
#
# Authors:
# Marcel Apfelbaum <marcel.a@redhat.com>
+# Igor Mammedov <imammedo@redhat.com>
#
# This work is licensed under the terms of the GNU GPLv2.
# See the COPYING.LIB file in the top-level directory.
-qemu=
-
-if [ -e x86_64-softmmu/qemu-system-x86_64 ]; then
- qemu="x86_64-softmmu/qemu-system-x86_64"
-elif [ -e i386-softmmu/qemu-system-i386 ]; then
- qemu="i386-softmmu/qemu-system-i386"
-else
- echo "Run 'make' to build the qemu exectutable!"
- echo "Run this script from the build directory."
- exit 1;
-fi
+qemu_bins="x86_64-softmmu/qemu-system-x86_64"
if [ ! -e "tests/bios-tables-test" ]; then
echo "Test: bios-tables-test is required! Run make check before this script."
@@ -29,6 +20,14 @@ if [ ! -e "tests/bios-tables-test" ]; then
exit 1;
fi
-TEST_ACPI_REBUILD_AML=y QTEST_QEMU_BINARY=$qemu tests/bios-tables-test
+for qemu in $qemu_bins; do
+ if [ ! -e $qemu ]; then
+ echo "Run 'make' to build the following QEMU executables: $qemu_bins"
+ echo "Also, run this script from the build directory."
+ exit 1;
+ fi
+ TEST_ACPI_REBUILD_AML=y QTEST_QEMU_BINARY=$qemu tests/bios-tables-test
+done
+
echo "The files were rebuilt and can be added to git."
diff --git a/tests/vmgenid-test.c b/tests/vmgenid-test.c
index ae38ee5ac0..85d8e6463e 100644
--- a/tests/vmgenid-test.c
+++ b/tests/vmgenid-test.c
@@ -40,14 +40,14 @@ static uint32_t acpi_find_vgia(QTestState *qts)
g_assert_cmphex(rsdp_offset, <, RSDP_ADDR_INVALID);
- acpi_parse_rsdp_table(qts, rsdp_offset, rsdp_table);
+ acpi_fetch_rsdp_table(qts, rsdp_offset, rsdp_table);
acpi_fetch_table(qts, &rsdt, &rsdt_len, &rsdp_table[16 /* RsdtAddress */],
- "RSDT", true);
+ 4, "RSDT", true);
ACPI_FOREACH_RSDT_ENTRY(rsdt, rsdt_len, ent, 4 /* Entry size */) {
uint8_t *table_aml;
- acpi_fetch_table(qts, &table_aml, &table_length, ent, NULL, true);
+ acpi_fetch_table(qts, &table_aml, &table_length, ent, 4, NULL, true);
if (!memcmp(table_aml + 16 /* OEM Table ID */, "VMGENID", 7)) {
uint32_t vgia_val;
uint8_t *aml = &table_aml[36 /* AML byte-code start */];