From patchwork Thu Dec 26 14:07:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcel Apfelbaum X-Patchwork-Id: 305270 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 2084C2C0092 for ; Fri, 27 Dec 2013 01:08:50 +1100 (EST) Received: from localhost ([::1]:45771 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VwBcF-0007WT-5i for incoming@patchwork.ozlabs.org; Thu, 26 Dec 2013 09:08:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44891) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VwBbn-0007IE-RM for qemu-devel@nongnu.org; Thu, 26 Dec 2013 09:08:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VwBbe-0008IU-KL for qemu-devel@nongnu.org; Thu, 26 Dec 2013 09:08:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56387) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VwBbe-0008IP-CI for qemu-devel@nongnu.org; Thu, 26 Dec 2013 09:08:10 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rBQE899D006111 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 26 Dec 2013 09:08:09 -0500 Received: from localhost.localdomain.com (vpn-200-207.tlv.redhat.com [10.35.200.207]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id rBQE84s6029531; Thu, 26 Dec 2013 09:08:08 -0500 From: Marcel Apfelbaum To: qemu-devel@nongnu.org Date: Thu, 26 Dec 2013 16:07:59 +0200 Message-Id: <1388066879-29290-3-git-send-email-marcel.a@redhat.com> In-Reply-To: <1388066879-29290-1-git-send-email-marcel.a@redhat.com> References: <1388066879-29290-1-git-send-email-marcel.a@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 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 v3 2/2] acpi unit-test: hook to rebuild expected aml files 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 When running the test with TEST_ACPI_REBUILD_AML=y environment variable, the test will rebuild and validate the expected aml files. Signed-off-by: Marcel Apfelbaum --- v2 -> v3: Addressed Michael S. Tsirkin's comments: - Used qemu_write_full instead of write v1 -> v2: Addressed Michael S. Tsirkin's comments: - added TEST_ prefix to the environment variable tests/acpi-test.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/tests/acpi-test.c b/tests/acpi-test.c index 954d9b9..5aa0a00 100644 --- a/tests/acpi-test.c +++ b/tests/acpi-test.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "qemu-common.h" #include "libqtest.h" #include "qemu/compiler.h" @@ -21,6 +22,8 @@ #define MACHINE_PC "pc" #define MACHINE_Q35 "q35" +#define ACPI_REBUILD_EXPECTED_AML "TEST_ACPI_REBUILD_AML" + /* DSDT and SSDTs format */ typedef struct { AcpiTableHeader header; @@ -363,23 +366,39 @@ static void test_acpi_ssdt_tables(test_data *data) } } -static void dump_aml_files(test_data *data) +static void dump_aml_files(test_data *data, bool rebuild) { AcpiSdtTable *sdt; GError *error = NULL; + gchar *aml_file = NULL; gint fd; int i; + ssize_t ret; for (i = 0; i < data->ssdt_tables->len; ++i) { sdt = &g_array_index(data->ssdt_tables, AcpiSdtTable, i); g_assert(sdt->aml); - fd = g_file_open_tmp("aml-XXXXXX", &sdt->aml_file, &error); - g_assert_no_error(error); + if (rebuild) { + aml_file = g_strdup_printf("%s/%s/%.4s", data_dir, data->machine, + (gchar *)&sdt->header.signature); + fd = g_open(aml_file, O_WRONLY|O_TRUNC|O_CREAT, + S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH); + } else { + fd = g_file_open_tmp("aml-XXXXXX", &sdt->aml_file, &error); + g_assert_no_error(error); + } + g_assert(fd >= 0); - write(fd, sdt, sizeof(AcpiTableHeader)); - write(fd, sdt->aml, sdt->aml_len); + ret = qemu_write_full(fd, sdt, sizeof(AcpiTableHeader)); + g_assert(ret == sizeof(AcpiTableHeader)); + ret = qemu_write_full(fd, sdt->aml, sdt->aml_len); + g_assert(ret == sdt->aml_len); close(fd); + + if (aml_file) { + g_free(aml_file); + } } } @@ -487,7 +506,7 @@ static void test_acpi_asl(test_data *data) memset(&exp_data, 0, sizeof(exp_data)); exp_data.ssdt_tables = load_expected_aml(data); - dump_aml_files(data); + dump_aml_files(data, false); for (i = 0; i < data->ssdt_tables->len; ++i) { GString *asl, *exp_asl; @@ -553,7 +572,11 @@ static void test_acpi_one(const char *params, test_data *data) test_acpi_ssdt_tables(data); if (iasl) { - test_acpi_asl(data); + if (getenv(ACPI_REBUILD_EXPECTED_AML)) { + dump_aml_files(data, true); + } else { + test_acpi_asl(data); + } } qtest_quit(global_qtest);