From nobody Mon Feb 9 12:09:47 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1544466190955360.6323593448262; Mon, 10 Dec 2018 10:23:10 -0800 (PST) Received: from localhost ([::1]:34185 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWQCy-0002iA-9u for importer@patchew.org; Mon, 10 Dec 2018 13:23:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59274) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWQAo-0001XX-CY for qemu-devel@nongnu.org; Mon, 10 Dec 2018 13:20:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gWQAl-0006PA-MR for qemu-devel@nongnu.org; Mon, 10 Dec 2018 13:20:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56620) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gWQAl-0006Nx-93 for qemu-devel@nongnu.org; Mon, 10 Dec 2018 13:20:51 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 02D4930A5A63; Mon, 10 Dec 2018 18:20:50 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.37.153.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id CA9C75C1B5; Mon, 10 Dec 2018 18:20:48 +0000 (UTC) From: Igor Mammedov To: qemu-devel@nongnu.org Date: Mon, 10 Dec 2018 19:10:11 +0100 Message-Id: <1544465415-207855-6-git-send-email-imammedo@redhat.com> In-Reply-To: <1544465415-207855-1-git-send-email-imammedo@redhat.com> References: <1544465415-207855-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Mon, 10 Dec 2018 18:20:50 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 5/9] tests: acpi: reuse fetch_table() for fetching FACS and DSDT X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , Samuel Ortiz , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" It allows to remove a bit more of code duplication and reuse common utility to get ACPI tables from guest (modulo RSDP). While at it, consolidate signature checking into fetch_table() instead of open-codding it. Considering FACS is special and doesn't have checksum, make checksum validation optin, the same goes for signature verification. PS: By pure accident, patch also fixes FACS not being tested against reference table since it wasn't added to data::tables list. But we managed not to regress it since reference file was added by commit (d25979380 acpi unit-test: add test files) back in 2013 Signed-off-by: Igor Mammedov --- tests/bios-tables-test.c | 74 +++++++++++++++++---------------------------= ---- 1 file changed, 26 insertions(+), 48 deletions(-) diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c index bea33a6..df61fc2 100644 --- a/tests/bios-tables-test.c +++ b/tests/bios-tables-test.c @@ -28,9 +28,6 @@ typedef struct { const char *variant; uint32_t rsdp_addr; uint8_t rsdp_table[36 /* ACPI 2.0+ RSDP size */]; - uint32_t dsdt_addr; - uint32_t facs_addr; - AcpiFacsDescriptorRev1 facs_table; GArray *tables; uint32_t smbios_ep_addr; struct smbios_21_entry_point smbios_ep_table; @@ -75,17 +72,27 @@ static void free_test_data(test_data *data) } =20 /** fetch_table - * load ACPI table at @addr into table descriptor @sdt_table - * and check that header checksum matches actual one. + * load ACPI table at @addr_ptr offset pointer into table descriptor + * @sdt_table and check that signature/checksum matches actual one. */ -static void fetch_table(AcpiSdtTable *sdt_table, uint32_t addr) +static void fetch_table(AcpiSdtTable *sdt_table, uint8_t *addr_ptr, + const char *sig, bool verify_checksum) { + uint32_t addr; + + memcpy(&addr, addr_ptr , sizeof(addr)); + addr =3D le32_to_cpu(addr); memread(addr + 4, &sdt_table->aml_len, 4); /* Length of ACPI table */ sdt_table->aml_len =3D le32_to_cpu(sdt_table->aml_len); sdt_table->aml =3D g_malloc0(sdt_table->aml_len); memread(addr, sdt_table->aml, sdt_table->aml_len); /* get whole table = */ =20 - g_assert(!acpi_calc_checksum(sdt_table->aml, sdt_table->aml_len)); + if (sig) { + ACPI_ASSERT_CMP(sdt_table->header->signature, sig); + } + if (verify_checksum) { + g_assert(!acpi_calc_checksum(sdt_table->aml, sdt_table->aml_len)); + } } =20 static void test_acpi_rsdp_address(test_data *data) @@ -119,16 +126,13 @@ static void test_acpi_rsdp_table(test_data *data) =20 static void test_acpi_rsdt_table(test_data *data) { - uint32_t addr =3D acpi_get_rsdt_address(data->rsdp_table); const int entry_size =3D 4 /* 32-bit Entry size */; const int tables_off =3D 36 /* 1st Entry */; AcpiSdtTable rsdt =3D {}; int i, table_len, table_nr; - uint32_t *entry; =20 /* read the header */ - fetch_table(&rsdt, addr); - ACPI_ASSERT_CMP(rsdt.header->signature, "RSDT"); + fetch_table(&rsdt, &data->rsdp_table[16 /* RsdtAddress */], "RSDT", tr= ue); =20 /* Load all tables and add to test list directly RSDT referenced table= s */ table_len =3D le32_to_cpu(rsdt.header->length); @@ -136,9 +140,8 @@ static void test_acpi_rsdt_table(test_data *data) for (i =3D 0; i < table_nr; i++) { AcpiSdtTable ssdt_table =3D {}; =20 - entry =3D (uint32_t *)(rsdt.aml + tables_off + i * entry_size); - addr =3D le32_to_cpu(*entry); - fetch_table(&ssdt_table, addr); + fetch_table(&ssdt_table, rsdt.aml + tables_off + i * entry_size, + NULL, true); =20 /* Add table to ASL test tables list */ g_array_append_val(data->tables, ssdt_table); @@ -149,12 +152,17 @@ static void test_acpi_rsdt_table(test_data *data) static void test_acpi_fadt_table(test_data *data) { /* FADT table is 1st */ - AcpiSdtTable *fadt =3D &g_array_index(data->tables, typeof(*fadt), 0); + AcpiSdtTable table =3D g_array_index(data->tables, typeof(table), 0); + uint8_t *fadt_aml =3D table.aml; + + ACPI_ASSERT_CMP(table.header->signature, "FACP"); =20 - ACPI_ASSERT_CMP(fadt->header->signature, "FACP"); + /* Since DSDT/FACS isn't in RSDT, add them to ASL test list manually */ + fetch_table(&table, fadt_aml + 36 /* FIRMWARE_CTRL */, "FACS", false); + g_array_append_val(data->tables, table); =20 - memcpy(&data->facs_addr, fadt->aml + 36 /* FIRMWARE_CTRL */, 4); - memcpy(&data->dsdt_addr, fadt->aml + 40 /* DSDT */, 4); + fetch_table(&table, fadt_aml + 40 /* DSDT */, "DSDT", true); + g_array_append_val(data->tables, table); } =20 static void sanitize_fadt_ptrs(test_data *data) @@ -187,34 +195,6 @@ static void sanitize_fadt_ptrs(test_data *data) } } =20 -static void test_acpi_facs_table(test_data *data) -{ - AcpiFacsDescriptorRev1 *facs_table =3D &data->facs_table; - uint32_t addr =3D le32_to_cpu(data->facs_addr); - - ACPI_READ_FIELD(facs_table->signature, addr); - ACPI_READ_FIELD(facs_table->length, addr); - ACPI_READ_FIELD(facs_table->hardware_signature, addr); - ACPI_READ_FIELD(facs_table->firmware_waking_vector, addr); - ACPI_READ_FIELD(facs_table->global_lock, addr); - ACPI_READ_FIELD(facs_table->flags, addr); - ACPI_READ_ARRAY(facs_table->resverved3, addr); - - ACPI_ASSERT_CMP(facs_table->signature, "FACS"); -} - -static void test_acpi_dsdt_table(test_data *data) -{ - AcpiSdtTable dsdt_table =3D {}; - uint32_t addr =3D le32_to_cpu(data->dsdt_addr); - - fetch_table(&dsdt_table, addr); - ACPI_ASSERT_CMP(dsdt_table.header->signature, "DSDT"); - - /* Since DSDT isn't in RSDT, add DSDT to ASL test tables list manually= */ - g_array_append_val(data->tables, dsdt_table); -} - static void dump_aml_files(test_data *data, bool rebuild) { AcpiSdtTable *sdt; @@ -595,8 +575,6 @@ static void test_acpi_one(const char *params, test_data= *data) test_acpi_rsdp_table(data); test_acpi_rsdt_table(data); test_acpi_fadt_table(data); - test_acpi_facs_table(data); - test_acpi_dsdt_table(data); =20 sanitize_fadt_ptrs(data); =20 --=20 2.7.4