From patchwork Fri Nov 13 20:16:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 544447 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 83A34141434 for ; Sat, 14 Nov 2015 07:19:40 +1100 (AEDT) Received: from localhost ([::1]:55028 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZxKos-0003Eh-D7 for incoming@patchwork.ozlabs.org; Fri, 13 Nov 2015 15:19:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38505) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZxKm7-0006de-Vz for qemu-devel@nongnu.org; Fri, 13 Nov 2015 15:16:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZxKm6-00053H-US for qemu-devel@nongnu.org; Fri, 13 Nov 2015 15:16:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34612) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZxKm6-000535-PL for qemu-devel@nongnu.org; Fri, 13 Nov 2015 15:16:46 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 5DBCD8F2F5; Fri, 13 Nov 2015 20:16:46 +0000 (UTC) Received: from scv.usersys.redhat.com (vpn-58-158.rdu2.redhat.com [10.10.58.158]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tADKGfAu003264; Fri, 13 Nov 2015 15:16:45 -0500 From: John Snow To: qemu-devel@nongnu.org Date: Fri, 13 Nov 2015 15:16:39 -0500 Message-Id: <1447445800-25013-6-git-send-email-jsnow@redhat.com> In-Reply-To: <1447445800-25013-1-git-send-email-jsnow@redhat.com> References: <1447445800-25013-1-git-send-email-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: peter.maydell@linaro.org, jsnow@redhat.com Subject: [Qemu-devel] [PULL 5/6] libqos: add qemu-img presence check 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 To allow tests to optionally exercise additional tests that require the qemu-img tool that may not be present in all builds. Signed-off-by: John Snow Message-id: 1447439479-16775-3-git-send-email-jsnow@redhat.com --- tests/libqos/libqos.c | 28 +++++++++++++++++++++++----- tests/libqos/libqos.h | 1 + 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/tests/libqos/libqos.c b/tests/libqos/libqos.c index 8d7c5a9..2d1a802 100644 --- a/tests/libqos/libqos.c +++ b/tests/libqos/libqos.c @@ -147,6 +147,23 @@ void migrate(QOSState *from, QOSState *to, const char *uri) set_context(to); } +bool have_qemu_img(void) +{ + char *rpath; + const char *path = getenv("QTEST_QEMU_IMG"); + if (!path) { + return false; + } + + rpath = realpath(path, NULL); + if (!rpath) { + return false; + } else { + free(rpath); + return true; + } +} + void mkimg(const char *file, const char *fmt, unsigned size_mb) { gchar *cli; @@ -155,13 +172,14 @@ void mkimg(const char *file, const char *fmt, unsigned size_mb) GError *err = NULL; char *qemu_img_path; gchar *out, *out2; - char *abs_path; + char *qemu_img_abs_path; qemu_img_path = getenv("QTEST_QEMU_IMG"); - abs_path = realpath(qemu_img_path, NULL); - assert(qemu_img_path); + g_assert(qemu_img_path); + qemu_img_abs_path = realpath(qemu_img_path, NULL); + g_assert(qemu_img_abs_path); - cli = g_strdup_printf("%s create -f %s %s %uM", abs_path, + cli = g_strdup_printf("%s create -f %s %s %uM", qemu_img_abs_path, fmt, file, size_mb); ret = g_spawn_command_line_sync(cli, &out, &out2, &rc, &err); if (err) { @@ -183,7 +201,7 @@ void mkimg(const char *file, const char *fmt, unsigned size_mb) g_free(out); g_free(out2); g_free(cli); - free(abs_path); + free(qemu_img_abs_path); } void mkqcow2(const char *file, unsigned size_mb) diff --git a/tests/libqos/libqos.h b/tests/libqos/libqos.h index 492a651..ca14d2e 100644 --- a/tests/libqos/libqos.h +++ b/tests/libqos/libqos.h @@ -19,6 +19,7 @@ typedef struct QOSState { QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap); QOSState *qtest_boot(QOSOps *ops, const char *cmdline_fmt, ...); void qtest_shutdown(QOSState *qs); +bool have_qemu_img(void); void mkimg(const char *file, const char *fmt, unsigned size_mb); void mkqcow2(const char *file, unsigned size_mb); void set_context(QOSState *s);