From patchwork Wed Jan 25 01:43:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ben@skyportsystems.com X-Patchwork-Id: 9536289 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 63DB76046A for ; Wed, 25 Jan 2017 01:44:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 54A8426B39 for ; Wed, 25 Jan 2017 01:44:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4995827D8D; Wed, 25 Jan 2017 01:44:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 801A826B39 for ; Wed, 25 Jan 2017 01:44:44 +0000 (UTC) Received: from localhost ([::1]:56737 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cWCdf-0003mY-EL for patchwork-qemu-devel@patchwork.kernel.org; Tue, 24 Jan 2017 20:44:43 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47523) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cWCd0-0003jI-N6 for qemu-devel@nongnu.org; Tue, 24 Jan 2017 20:44:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cWCcz-0005Ov-NT for qemu-devel@nongnu.org; Tue, 24 Jan 2017 20:44:02 -0500 Received: from mail-yw0-x22c.google.com ([2607:f8b0:4002:c05::22c]:32973) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cWCcz-0005On-Hf for qemu-devel@nongnu.org; Tue, 24 Jan 2017 20:44:01 -0500 Received: by mail-yw0-x22c.google.com with SMTP id u68so3013803ywg.0 for ; Tue, 24 Jan 2017 17:44:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skyportsystems.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=ugP5NXfnQv77+SNcFjKodK/DY4T2KPyCbclNk+ptxlo=; b=HkBiiGqeTlOVoW//AfKYuaEp6ifGkFytJMr8Wn1mZlAP7/oe0nlgM7bk6Hmfvn4Cha WS3HDDj9VgdgCMacOoO+bwn5tjhnuD9FUEoOqHVS06BgeJPs7x91uwC3XYJkPReke0rJ puHHMq61L4dPMDaYo/U5QLJLaGbFmre1SjNPs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=ugP5NXfnQv77+SNcFjKodK/DY4T2KPyCbclNk+ptxlo=; b=ooTwKtzLK4CV4X8uhr6ODo1v8eCmJaVU8XCjLzqFtwJ9ojVqfX4N1oCZ+It9bTsMy2 92Xm0odpdd12bkF2k75gW4y2tm/2ENnmD3V7CjqLD5e67xqwmGAmofZatKrVaGGHGNPX MHYEiIeVJl2AMt/aKmRjIzDaSyNnL5VZJeHNOZ4JXKuL+0bZaiiNnU00A6dt558Qv6vd ZttPoR6OyZaNU58O2xX/BMNSNMO4vEqBKrTbjFrv1Nk/TW2D+aSxREo8GAul5IBHTH+Y 1ZZ8ZPSxEyhLgMGX7wwwUo1GrQ8BdTG9PRg64TQarVp/H9/TVNDQQVLSEdZnzmj9YKLU yhmA== X-Gm-Message-State: AIkVDXJcIfDpS8w7sNpryZYGMfNZbY0uF1D2YsaXsYlf66y5eOBXxFdEq2vZ//1MTYNlYPpl X-Received: by 10.129.153.79 with SMTP id q76mr28173484ywg.162.1485308640984; Tue, 24 Jan 2017 17:44:00 -0800 (PST) Received: from Arrow.corp.skyportsystems.com (162-199-88-38.lightspeed.sntcca.sbcglobal.net. [162.199.88.38]) by smtp.gmail.com with ESMTPSA id w126sm10757317yww.41.2017.01.24.17.43.59 (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 24 Jan 2017 17:44:00 -0800 (PST) From: ben@skyportsystems.com To: qemu-devel@nongnu.org Date: Tue, 24 Jan 2017 17:43:27 -0800 Message-Id: <9c90a6dd473ee547c050c052c161e7fdb0f8a5d3.1485308342.git.ben@skyportsystems.com> X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4002:c05::22c Subject: [Qemu-devel] [PATCH v4 8/9] tests: Move reusable ACPI macros into a new header file 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: Ben Warren Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Ben Warren Also usable by upcoming VM Generation ID tests Signed-off-by: Ben Warren --- tests/acpi-utils.h | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/bios-tables-test.c | 72 +--------------------------------------------- 2 files changed, 76 insertions(+), 71 deletions(-) create mode 100644 tests/acpi-utils.h diff --git a/tests/acpi-utils.h b/tests/acpi-utils.h new file mode 100644 index 0000000..d5e5eff --- /dev/null +++ b/tests/acpi-utils.h @@ -0,0 +1,75 @@ +#ifndef TEST_ACPI_UTILS_H +#define TEST_ACPI_UTILS_H + +/* DSDT and SSDTs format */ +typedef struct { + AcpiTableHeader header; + gchar *aml; /* aml bytecode from guest */ + gsize aml_len; + gchar *aml_file; + gchar *asl; /* asl code generated from aml */ + gsize asl_len; + gchar *asl_file; + bool tmp_files_retain; /* do not delete the temp asl/aml */ +} QEMU_PACKED AcpiSdtTable; + +#define ACPI_READ_FIELD(field, addr) \ + do { \ + switch (sizeof(field)) { \ + case 1: \ + field = readb(addr); \ + break; \ + case 2: \ + field = readw(addr); \ + break; \ + case 4: \ + field = readl(addr); \ + break; \ + case 8: \ + field = readq(addr); \ + break; \ + default: \ + g_assert(false); \ + } \ + addr += sizeof(field); \ + } while (0); + +#define ACPI_READ_ARRAY_PTR(arr, length, addr) \ + do { \ + int idx; \ + for (idx = 0; idx < length; ++idx) { \ + ACPI_READ_FIELD(arr[idx], addr); \ + } \ + } while (0); + +#define ACPI_READ_ARRAY(arr, addr) \ + ACPI_READ_ARRAY_PTR(arr, sizeof(arr) / sizeof(arr[0]), addr) + +#define ACPI_READ_TABLE_HEADER(table, addr) \ + do { \ + ACPI_READ_FIELD((table)->signature, addr); \ + ACPI_READ_FIELD((table)->length, addr); \ + ACPI_READ_FIELD((table)->revision, addr); \ + ACPI_READ_FIELD((table)->checksum, addr); \ + ACPI_READ_ARRAY((table)->oem_id, addr); \ + ACPI_READ_ARRAY((table)->oem_table_id, addr); \ + ACPI_READ_FIELD((table)->oem_revision, addr); \ + ACPI_READ_ARRAY((table)->asl_compiler_id, addr); \ + ACPI_READ_FIELD((table)->asl_compiler_revision, addr); \ + } while (0); + +#define ACPI_ASSERT_CMP(actual, expected) do { \ + uint32_t ACPI_ASSERT_CMP_le = cpu_to_le32(actual); \ + char ACPI_ASSERT_CMP_str[5] = {}; \ + memcpy(ACPI_ASSERT_CMP_str, &ACPI_ASSERT_CMP_le, 4); \ + g_assert_cmpstr(ACPI_ASSERT_CMP_str, ==, expected); \ +} while (0) + +#define ACPI_ASSERT_CMP64(actual, expected) do { \ + uint64_t ACPI_ASSERT_CMP_le = cpu_to_le64(actual); \ + char ACPI_ASSERT_CMP_str[9] = {}; \ + memcpy(ACPI_ASSERT_CMP_str, &ACPI_ASSERT_CMP_le, 8); \ + g_assert_cmpstr(ACPI_ASSERT_CMP_str, ==, expected); \ +} while (0) + +#endif /* TEST_ACPI_UTILS_H */ diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c index 5404805..c642f7f 100644 --- a/tests/bios-tables-test.c +++ b/tests/bios-tables-test.c @@ -17,6 +17,7 @@ #include "hw/acpi/acpi-defs.h" #include "hw/smbios/smbios.h" #include "qemu/bitmap.h" +#include "acpi-utils.h" #include "boot-sector.h" #define MACHINE_PC "pc" @@ -24,18 +25,6 @@ #define ACPI_REBUILD_EXPECTED_AML "TEST_ACPI_REBUILD_AML" -/* DSDT and SSDTs format */ -typedef struct { - AcpiTableHeader header; - gchar *aml; /* aml bytecode from guest */ - gsize aml_len; - gchar *aml_file; - gchar *asl; /* asl code generated from aml */ - gsize asl_len; - gchar *asl_file; - bool tmp_files_retain; /* do not delete the temp asl/aml */ -} QEMU_PACKED AcpiSdtTable; - typedef struct { const char *machine; const char *variant; @@ -53,65 +42,6 @@ typedef struct { int required_struct_types_len; } test_data; -#define ACPI_READ_FIELD(field, addr) \ - do { \ - switch (sizeof(field)) { \ - case 1: \ - field = readb(addr); \ - break; \ - case 2: \ - field = readw(addr); \ - break; \ - case 4: \ - field = readl(addr); \ - break; \ - case 8: \ - field = readq(addr); \ - break; \ - default: \ - g_assert(false); \ - } \ - addr += sizeof(field); \ - } while (0); - -#define ACPI_READ_ARRAY_PTR(arr, length, addr) \ - do { \ - int idx; \ - for (idx = 0; idx < length; ++idx) { \ - ACPI_READ_FIELD(arr[idx], addr); \ - } \ - } while (0); - -#define ACPI_READ_ARRAY(arr, addr) \ - ACPI_READ_ARRAY_PTR(arr, sizeof(arr)/sizeof(arr[0]), addr) - -#define ACPI_READ_TABLE_HEADER(table, addr) \ - do { \ - ACPI_READ_FIELD((table)->signature, addr); \ - ACPI_READ_FIELD((table)->length, addr); \ - ACPI_READ_FIELD((table)->revision, addr); \ - ACPI_READ_FIELD((table)->checksum, addr); \ - ACPI_READ_ARRAY((table)->oem_id, addr); \ - ACPI_READ_ARRAY((table)->oem_table_id, addr); \ - ACPI_READ_FIELD((table)->oem_revision, addr); \ - ACPI_READ_ARRAY((table)->asl_compiler_id, addr); \ - ACPI_READ_FIELD((table)->asl_compiler_revision, addr); \ - } while (0); - -#define ACPI_ASSERT_CMP(actual, expected) do { \ - uint32_t ACPI_ASSERT_CMP_le = cpu_to_le32(actual); \ - char ACPI_ASSERT_CMP_str[5] = {}; \ - memcpy(ACPI_ASSERT_CMP_str, &ACPI_ASSERT_CMP_le, 4); \ - g_assert_cmpstr(ACPI_ASSERT_CMP_str, ==, expected); \ -} while (0) - -#define ACPI_ASSERT_CMP64(actual, expected) do { \ - uint64_t ACPI_ASSERT_CMP_le = cpu_to_le64(actual); \ - char ACPI_ASSERT_CMP_str[9] = {}; \ - memcpy(ACPI_ASSERT_CMP_str, &ACPI_ASSERT_CMP_le, 8); \ - g_assert_cmpstr(ACPI_ASSERT_CMP_str, ==, expected); \ -} while (0) - static char disk[] = "tests/acpi-test-disk-XXXXXX"; static const char *data_dir = "tests/acpi-test-data"; #ifdef CONFIG_IASL