From patchwork Mon Dec 23 16:11:45 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 304803 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 A85092C0099 for ; Tue, 24 Dec 2013 03:40:37 +1100 (EST) Received: from localhost ([::1]:34257 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vv86l-0003KJ-MY for incoming@patchwork.ozlabs.org; Mon, 23 Dec 2013 11:11:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40694) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vv830-00066H-63 for qemu-devel@nongnu.org; Mon, 23 Dec 2013 11:08:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vv82u-0000tE-5w for qemu-devel@nongnu.org; Mon, 23 Dec 2013 11:08:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:65532) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vv82t-0000t0-Sg for qemu-devel@nongnu.org; Mon, 23 Dec 2013 11:07:56 -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 rBNG7sGu002061 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 23 Dec 2013 11:07:55 -0500 Received: from redhat.com (vpn1-7-122.ams2.redhat.com [10.36.7.122]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id rBNG7q4o031392; Mon, 23 Dec 2013 11:07:53 -0500 Date: Mon, 23 Dec 2013 18:11:45 +0200 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <1387815007-1272-7-git-send-email-mst@redhat.com> References: <1387815007-1272-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1387815007-1272-1-git-send-email-mst@redhat.com> X-Mutt-Fcc: =sent 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: Laszlo Ersek Subject: [Qemu-devel] [PULL 06/19] i440fx-test: generate temporary firmware blob 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 From: Laszlo Ersek The blob is 64K in size and contains 0x00..0xFF repeatedly. The client code added to main() wouldn't make much sense in the long term. It helps with debugging and it silences gcc about create_blob_file() being unused, and we'll replace it in the next patch anyway. Signed-off-by: Laszlo Ersek Signed-off-by: Michael S. Tsirkin --- tests/i440fx-test.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/tests/i440fx-test.c b/tests/i440fx-test.c index 3962bca..b6e0cd3 100644 --- a/tests/i440fx-test.c +++ b/tests/i440fx-test.c @@ -20,6 +20,11 @@ #include #include +#include +#include +#include +#include +#include #define BROKEN 1 @@ -272,13 +277,68 @@ static void test_i440fx_pam(gconstpointer opaque) qtest_end(); } +#define BLOB_SIZE ((size_t)65536) + +/* Create a blob file, and return its absolute pathname as a dynamically + * allocated string. + * The file is closed before the function returns. + * In case of error, NULL is returned. The function prints the error message. + */ +static char *create_blob_file(void) +{ + int ret, fd; + char *pathname; + GError *error = NULL; + + ret = -1; + fd = g_file_open_tmp("blob_XXXXXX", &pathname, &error); + if (fd == -1) { + fprintf(stderr, "unable to create blob file: %s\n", error->message); + g_error_free(error); + } else { + if (ftruncate(fd, BLOB_SIZE) == -1) { + fprintf(stderr, "ftruncate(\"%s\", %zu): %s\n", pathname, + BLOB_SIZE, strerror(errno)); + } else { + void *buf; + + buf = mmap(NULL, BLOB_SIZE, PROT_WRITE, MAP_SHARED, fd, 0); + if (buf == MAP_FAILED) { + fprintf(stderr, "mmap(\"%s\", %zu): %s\n", pathname, BLOB_SIZE, + strerror(errno)); + } else { + size_t i; + + for (i = 0; i < BLOB_SIZE; ++i) { + ((uint8_t *)buf)[i] = i; + } + munmap(buf, BLOB_SIZE); + ret = 0; + } + } + close(fd); + if (ret == -1) { + unlink(pathname); + g_free(pathname); + } + } + + return ret == -1 ? NULL : pathname; +} + int main(int argc, char **argv) { + char *fw_pathname; TestData data; int ret; g_test_init(&argc, &argv, NULL); + fw_pathname = create_blob_file(); + g_assert(fw_pathname != NULL); + unlink(fw_pathname); + g_free(fw_pathname); + data.num_cpus = 1; g_test_add_data_func("/i440fx/defaults", &data, test_i440fx_defaults);