From nobody Fri May 16 05:32:18 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1501063407574206.78028783383434; Wed, 26 Jul 2017 03:03:27 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 40C74C058EDA; Wed, 26 Jul 2017 10:03:23 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1AD317ADAA; Wed, 26 Jul 2017 10:03:23 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 43CD7180BA8D; Wed, 26 Jul 2017 10:03:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6QA0xPt008779 for ; Wed, 26 Jul 2017 06:00:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id B79F56FE6D; Wed, 26 Jul 2017 10:00:59 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id 116666FE6A; Wed, 26 Jul 2017 10:00:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 40C74C058EDA Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 26 Jul 2017 12:00:37 +0200 Message-Id: <84a83c4f323860920fcc9b993ee2c4bc3e992063.1501062802.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 07/24] tests: utils: Add virTestLoadFilePath helper X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 26 Jul 2017 10:03:23 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This new helper loads and returns a file from 'abs_srcdir'. By using variable arguments for the function, it's not necessary to format the path separately in the test cases. --- tests/testutils.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ tests/testutils.h | 2 ++ 2 files changed, 53 insertions(+) diff --git a/tests/testutils.c b/tests/testutils.c index 7f1c4672b..f193cdf8b 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -356,6 +356,57 @@ virTestLoadFile(const char *file, char **buf) return 0; } + +static char * +virTestLoadFileGetPath(const char *p, + va_list ap) +{ + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + char *path =3D NULL; + + virBufferAddLit(&buf, abs_srcdir "/"); + + if (p) { + virBufferAdd(&buf, p, -1); + virBufferStrcatVArgs(&buf, ap); + } + + if (!(path =3D virBufferContentAndReset(&buf))) + VIR_TEST_VERBOSE("failed to format file path"); + + return path; +} + + +/** + * virTestLoadFilePath: + * @...: file name components. + * + * Constructs the test file path from variable arguments and loads the fil= e. + * 'abs_srcdir' is automatically prepended. + */ +char * +virTestLoadFilePath(const char *p, ...) +{ + char *path =3D NULL; + char *ret =3D NULL; + va_list ap; + + va_start(ap, p); + + if (!(path =3D virTestLoadFileGetPath(p, ap))) + goto cleanup; + + ignore_value(virTestLoadFile(path, &ret)); + + cleanup: + va_end(ap); + VIR_FREE(path); + + return ret; +} + + #ifndef WIN32 static void virTestCaptureProgramExecChild(const char *const argv[], diff --git a/tests/testutils.h b/tests/testutils.h index c7f02e468..98dfa990e 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -52,6 +52,8 @@ int virTestRun(const char *title, int (*body)(const void *data), const void *data); int virTestLoadFile(const char *file, char **buf); +char *virTestLoadFilePath(const char *p, ...) + ATTRIBUTE_SENTINEL; int virTestCaptureProgramOutput(const char *const argv[], char **buf, int = maxlen); void virTestClearCommandPath(char *cmdset); --=20 2.13.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list