From patchwork Wed Nov 13 16:11:25 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcel Apfelbaum X-Patchwork-Id: 290984 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BE4EF2C00B7 for ; Thu, 14 Nov 2013 03:14:40 +1100 (EST) Received: from localhost ([::1]:49533 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vgd5S-0001Xl-4Z for incoming@patchwork.ozlabs.org; Wed, 13 Nov 2013 11:14:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47901) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vgd58-0001WX-6a for qemu-devel@nongnu.org; Wed, 13 Nov 2013 11:14:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vgd52-0007cH-2p for qemu-devel@nongnu.org; Wed, 13 Nov 2013 11:14:18 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58722) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vgd51-0007c6-R5 for qemu-devel@nongnu.org; Wed, 13 Nov 2013 11:14:12 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rADGEAgU024056 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 13 Nov 2013 11:14:11 -0500 Received: from localhost.localdomain.com (vpn-200-114.tlv.redhat.com [10.35.200.114]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id rADGE88n023872; Wed, 13 Nov 2013 11:14:09 -0500 From: Marcel Apfelbaum To: qemu-devel@nongnu.org Date: Wed, 13 Nov 2013 18:11:25 +0200 Message-Id: <1384359085-6876-1-git-send-email-marcel.a@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: mst@redhat.com Subject: [Qemu-devel] [PATCH for-1.7] acpi unit-test: ensure both 1.6 machine and default machine received the same acpi tables X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Machines before 1.6 used ACPI supplied by SeaBios, for 1.7+ machines the tables are build by qemu. This patch checks that both machines have the same ACPI tables. Also checks the signature of FACS table. Signed-off-by: Marcel Apfelbaum --- Note that for the moment we check only that the machines have the same tables and not the content of the tables. This patch assumes that the new bios.bin is used. tests/acpi-test.c | 106 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 83 insertions(+), 23 deletions(-) diff --git a/tests/acpi-test.c b/tests/acpi-test.c index d6ff66f..ba66963 100644 --- a/tests/acpi-test.c +++ b/tests/acpi-test.c @@ -30,10 +30,11 @@ typedef struct { AcpiRsdpDescriptor rsdp_table; AcpiRsdtDescriptorRev1 rsdt_table; AcpiFadtDescriptorRev1 fadt_table; + AcpiFacsDescriptorRev1 facs_table; uint32_t *rsdt_tables_addr; int rsdt_tables_nr; AcpiSdtTable dsdt_table; - AcpiSdtTable *ssdt_tables; + GArray *ssdt_tables; } test_data; #define LOW(x) ((x) & 0xff) @@ -117,6 +118,18 @@ static uint8_t boot_sector[0x200] = { static const char *disk = "tests/acpi-test-disk.raw"; +static void free_test_data(test_data *data) +{ + int i; + + g_free(data->rsdt_tables_addr); + for (i = 0; i < data->ssdt_tables->len; ++i) { + g_free(g_array_index(data->ssdt_tables, AcpiSdtTable, i).aml); + } + g_array_free(data->ssdt_tables, false); + g_free(data->dsdt_table.aml); +} + static uint8_t acpi_checksum(const uint8_t *data, int len) { int i; @@ -252,6 +265,22 @@ static void test_acpi_fadt_table(test_data *data) g_assert(!acpi_checksum((uint8_t *)fadt_table, fadt_table->length)); } +static void test_acpi_facs_table(test_data *data) +{ + AcpiFacsDescriptorRev1 *facs_table = &data->facs_table; + uint32_t addr = data->fadt_table.firmware_ctrl; + + 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); + + g_assert_cmphex(facs_table->signature, ==, ACPI_FACS_SIGNATURE); +} + static void test_dst_table(AcpiSdtTable *sdt_table, uint32_t addr) { uint8_t checksum; @@ -278,30 +307,30 @@ static void test_acpi_dsdt_table(test_data *data) static void test_acpi_ssdt_tables(test_data *data) { - AcpiSdtTable *ssdt_tables; + GArray *ssdt_tables; int ssdt_tables_nr = data->rsdt_tables_nr - 1; /* fadt is first */ int i; - ssdt_tables = g_new0(AcpiSdtTable, ssdt_tables_nr); + ssdt_tables = g_array_sized_new(false, true, sizeof(AcpiSdtTable), + ssdt_tables_nr); for (i = 0; i < ssdt_tables_nr; i++) { - AcpiSdtTable *ssdt_table = &ssdt_tables[i]; + AcpiSdtTable ssdt_table; uint32_t addr = data->rsdt_tables_addr[i + 1]; /* fadt is first */ - - test_dst_table(ssdt_table, addr); + test_dst_table(&ssdt_table, addr); + g_array_append_val(ssdt_tables, ssdt_table); } data->ssdt_tables = ssdt_tables; } -static void test_acpi_one(const char *params) +static void test_acpi_one(const char *params, test_data *data) { char *args; uint8_t signature_low; uint8_t signature_high; uint16_t signature; int i; - test_data data; - memset(&data, 0, sizeof(data)); + memset(data, 0, sizeof(*data)); args = g_strdup_printf("-net none -display none %s %s", params ? params : "", disk); qtest_start(args); @@ -325,30 +354,61 @@ static void test_acpi_one(const char *params) } g_assert_cmphex(signature, ==, SIGNATURE); - test_acpi_rsdp_address(&data); - test_acpi_rsdp_table(&data); - test_acpi_rsdt_table(&data); - test_acpi_fadt_table(&data); - test_acpi_dsdt_table(&data); - test_acpi_ssdt_tables(&data); - - g_free(data.rsdt_tables_addr); - for (i = 0; i < (data.rsdt_tables_nr - 1); ++i) { - g_free(data.ssdt_tables[i].aml); - } - g_free(data.ssdt_tables); - g_free(data.dsdt_table.aml); + test_acpi_rsdp_address(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); + test_acpi_ssdt_tables(data); qtest_quit(global_qtest); g_free(args); } +static gint compare_table_signature(gconstpointer a, gconstpointer b) +{ + AcpiSdtTable *table1 = (AcpiSdtTable *)a; + AcpiSdtTable *table2 = (AcpiSdtTable *)b; + return (gint)table1->header.signature - (gint)table2->header.signature; +} + +static void test_acpi_compare_machines(test_data *data1, test_data *data2) +{ + int i; + + /* + * Check that both machine have the same acpi tables. + * We only need to check the ssdt tables, because all + * the other tables are always present */ + g_assert_cmpuint(data1->ssdt_tables->len, ==, data2->ssdt_tables->len); + + g_array_sort(data1->ssdt_tables, compare_table_signature); + g_array_sort(data2->ssdt_tables, compare_table_signature); + + for (i = 0; i < data1->ssdt_tables->len; ++i) { + AcpiSdtTable *table1 = &g_array_index(data1->ssdt_tables, AcpiSdtTable, i); + AcpiSdtTable *table2 = &g_array_index(data2->ssdt_tables, AcpiSdtTable, i); + + g_assert_cmphex(table1->header.signature, ==, table2->header.signature); + } +} + static void test_acpi_tcg(void) { + test_data data, data_16; + /* Supplying -machine accel argument overrides the default (qtest). * This is to make guest actually run. */ - test_acpi_one("-machine accel=tcg"); + test_acpi_one("-machine accel=tcg", &data); + test_acpi_one("-machine pc-i440fx-1.6,accel=tcg", &data_16); + + /* for 1.6 the acpi tables come from bios */ + test_acpi_compare_machines(&data, &data_16); + + free_test_data(&data); + free_test_data(&data_16); } int main(int argc, char *argv[])