From nobody Mon Feb 9 05:40:01 2026 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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549460565080389.0243629696462; Wed, 6 Feb 2019 05:42:45 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E35332D6E75; Wed, 6 Feb 2019 13:42:42 +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 3A5501001640; Wed, 6 Feb 2019 13:42:42 +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 B5A7F180339F; Wed, 6 Feb 2019 13:42:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x16DgAhg002034 for ; Wed, 6 Feb 2019 08:42:10 -0500 Received: by smtp.corp.redhat.com (Postfix) id E871A660BC; Wed, 6 Feb 2019 13:42:10 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-116-19.phx2.redhat.com [10.3.116.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9EC115C26D for ; Wed, 6 Feb 2019 13:42:10 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Wed, 6 Feb 2019 08:41:45 -0500 Message-Id: <20190206134147.18032-14-jferlan@redhat.com> In-Reply-To: <20190206134147.18032-1-jferlan@redhat.com> References: <20190206134147.18032-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 13/15] tests: Use VIR_AUTOFREE for various storage tests 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 06 Feb 2019 13:42:43 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Let's make use of the auto __cleanup capabilities cleaning up any now unnecessary goto paths. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety --- tests/storagebackendsheepdogtest.c | 50 ++++++++++++------------------ tests/storagepoolxml2argvtest.c | 18 +++-------- tests/storagepoolxml2xmltest.c | 33 ++++++-------------- tests/storagevolxml2argvtest.c | 42 +++++++++---------------- tests/storagevolxml2xmltest.c | 38 +++++++---------------- tests/virstoragetest.c | 45 +++++++-------------------- tests/virstorageutiltest.c | 7 ++--- 7 files changed, 75 insertions(+), 158 deletions(-) diff --git a/tests/storagebackendsheepdogtest.c b/tests/storagebackendsheep= dogtest.c index 03ddf76d65..1806f9725f 100644 --- a/tests/storagebackendsheepdogtest.c +++ b/tests/storagebackendsheepdogtest.c @@ -57,32 +57,27 @@ test_node_info_parser(const void *opaque) { const struct testNodeInfoParserData *data =3D opaque; collie_test test =3D data->data; - int ret =3D -1; - char *output =3D NULL; + VIR_AUTOFREE(char *) output =3D NULL; VIR_AUTOPTR(virStoragePoolDef) pool =3D NULL; =20 if (!(pool =3D virStoragePoolDefParseFile(data->poolxml))) - goto cleanup; + return -1; =20 if (VIR_STRDUP(output, test.output) < 0) - goto cleanup; + return -1; =20 if (virStorageBackendSheepdogParseNodeInfo(pool, output) !=3D test.expected_return) - goto cleanup; + return -1; =20 - if (test.expected_return) { - ret =3D 0; - goto cleanup; - } + if (test.expected_return) + return 0; =20 if (pool->capacity =3D=3D test.expected_capacity && pool->allocation =3D=3D test.expected_allocation) - ret =3D 0; + return 0; =20 - cleanup: - VIR_FREE(output); - return ret; + return -1; } =20 static int @@ -90,36 +85,31 @@ test_vdi_list_parser(const void *opaque) { const struct testVDIListParserData *data =3D opaque; collie_test test =3D data->data; - int ret =3D -1; - char *output =3D NULL; + VIR_AUTOFREE(char *) output =3D NULL; VIR_AUTOPTR(virStoragePoolDef) pool =3D NULL; VIR_AUTOPTR(virStorageVolDef) vol =3D NULL; =20 if (!(pool =3D virStoragePoolDefParseFile(data->poolxml))) - goto cleanup; + return -1; =20 if (!(vol =3D virStorageVolDefParseFile(pool, data->volxml, 0))) - goto cleanup; + return -1; =20 if (VIR_STRDUP(output, test.output) < 0) - goto cleanup; + return -1; =20 if (virStorageBackendSheepdogParseVdiList(vol, output) !=3D test.expected_return) - goto cleanup; + return -1; =20 - if (test.expected_return) { - ret =3D 0; - goto cleanup; - } + if (test.expected_return) + return 0; =20 if (vol->target.capacity =3D=3D test.expected_capacity && vol->target.allocation =3D=3D test.expected_allocation) - ret =3D 0; + return 0; =20 - cleanup: - VIR_FREE(output); - return ret; + return -1; } =20 =20 @@ -127,8 +117,8 @@ static int mymain(void) { int ret =3D 0; - char *poolxml =3D NULL; - char *volxml =3D NULL; + VIR_AUTOFREE(char *) poolxml =3D NULL; + VIR_AUTOFREE(char *) volxml =3D NULL; =20 collie_test node_info_tests[] =3D { {"", -1, 0, 0}, @@ -215,8 +205,6 @@ mymain(void) } =20 cleanup: - VIR_FREE(poolxml); - VIR_FREE(volxml); return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } =20 diff --git a/tests/storagepoolxml2argvtest.c b/tests/storagepoolxml2argvtes= t.c index 116a75c3ea..e76e86527f 100644 --- a/tests/storagepoolxml2argvtest.c +++ b/tests/storagepoolxml2argvtest.c @@ -88,7 +88,6 @@ testCompareXMLToArgvFiles(bool shouldFail, ret =3D 0; =20 cleanup: - VIR_FREE(actualCmdline); virStoragePoolObjEndAPI(&pool); if (shouldFail) { virResetLastError(); @@ -106,27 +105,20 @@ struct testInfo { static int testCompareXMLToArgvHelper(const void *data) { - int result =3D -1; const struct testInfo *info =3D data; - char *poolxml =3D NULL; - char *cmdline =3D NULL; + VIR_AUTOFREE(char *) poolxml =3D NULL; + VIR_AUTOFREE(char *) cmdline =3D NULL; =20 if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/%s.xml", abs_srcdir, info->pool) < 0) - goto cleanup; + return -1; =20 if (virAsprintf(&cmdline, "%s/storagepoolxml2argvdata/%s%s.argv", abs_srcdir, info->pool, info->platformSuffix) < 0 && !info->shouldFail) - goto cleanup; - - result =3D testCompareXMLToArgvFiles(info->shouldFail, poolxml, cmdlin= e); - - cleanup: - VIR_FREE(poolxml); - VIR_FREE(cmdline); + return -1; =20 - return result; + return testCompareXMLToArgvFiles(info->shouldFail, poolxml, cmdline); } =20 =20 diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c index c8d5c41cd4..bd3408e8b8 100644 --- a/tests/storagepoolxml2xmltest.c +++ b/tests/storagepoolxml2xmltest.c @@ -18,47 +18,34 @@ static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml) { - char *actual =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) actual =3D NULL; VIR_AUTOPTR(virStoragePoolDef) dev =3D NULL; =20 if (!(dev =3D virStoragePoolDefParseFile(inxml))) - goto fail; + return -1; =20 if (!(actual =3D virStoragePoolDefFormat(dev))) - goto fail; + return -1; =20 if (virTestCompareToFile(actual, outxml) < 0) - goto fail; + return -1; =20 - ret =3D 0; - - fail: - VIR_FREE(actual); - return ret; + return 0; } =20 static int testCompareXMLToXMLHelper(const void *data) { - int result =3D -1; - char *inxml =3D NULL; - char *outxml =3D NULL; + VIR_AUTOFREE(char *) inxml =3D NULL; + VIR_AUTOFREE(char *) outxml =3D NULL; =20 if (virAsprintf(&inxml, "%s/storagepoolxml2xmlin/%s.xml", abs_srcdir, (const char*)data) < 0 || virAsprintf(&outxml, "%s/storagepoolxml2xmlout/%s.xml", - abs_srcdir, (const char*)data) < 0) { - goto cleanup; - } - - result =3D testCompareXMLToXMLFiles(inxml, outxml); - - cleanup: - VIR_FREE(inxml); - VIR_FREE(outxml); + abs_srcdir, (const char*)data) < 0) + return -1; =20 - return result; + return testCompareXMLToXMLFiles(inxml, outxml); } =20 static int diff --git a/tests/storagevolxml2argvtest.c b/tests/storagevolxml2argvtest.c index 38bb2ae004..3a4c020f68 100644 --- a/tests/storagevolxml2argvtest.c +++ b/tests/storagevolxml2argvtest.c @@ -42,9 +42,9 @@ testCompareXMLToArgvFiles(bool shouldFail, unsigned int flags, unsigned long parse_flags) { - char *actualCmdline =3D NULL; virStorageVolEncryptConvertStep convertStep =3D VIR_STORAGE_VOL_ENCRYP= T_NONE; int ret =3D -1; + VIR_AUTOFREE(char *) actualCmdline =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; VIR_AUTOPTR(virStorageVolDef) vol =3D NULL; VIR_AUTOPTR(virStorageVolDef) inputvol =3D NULL; @@ -109,7 +109,7 @@ testCompareXMLToArgvFiles(bool shouldFail, goto cleanup; } else { char *createCmdline =3D actualCmdline; - char *cvtCmdline; + VIR_AUTOFREE(char *) cvtCmdline =3D NULL; int rc; =20 if (!(cvtCmdline =3D virCommandToString(cmd, false))) @@ -119,7 +119,6 @@ testCompareXMLToArgvFiles(bool shouldFail, createCmdline, cvtCmdline); =20 VIR_FREE(createCmdline); - VIR_FREE(cvtCmdline); if (rc < 0) goto cleanup; } @@ -139,7 +138,6 @@ testCompareXMLToArgvFiles(bool shouldFail, ret =3D 0; =20 cleanup: - VIR_FREE(actualCmdline); virStoragePoolObjEndAPI(&obj); return ret; } @@ -158,45 +156,35 @@ struct testInfo { static int testCompareXMLToArgvHelper(const void *data) { - int result =3D -1; const struct testInfo *info =3D data; - char *poolxml =3D NULL; - char *inputpoolxml =3D NULL; - char *volxml =3D NULL; - char *inputvolxml =3D NULL; - char *cmdline =3D NULL; + VIR_AUTOFREE(char *) poolxml =3D NULL; + VIR_AUTOFREE(char *) inputpoolxml =3D NULL; + VIR_AUTOFREE(char *) volxml =3D NULL; + VIR_AUTOFREE(char *) inputvolxml =3D NULL; + VIR_AUTOFREE(char *) cmdline =3D NULL; =20 if (info->inputvol && virAsprintf(&inputvolxml, "%s/storagevolxml2xmlin/%s.xml", abs_srcdir, info->inputvol) < 0) - goto cleanup; + return -1; if (info->inputpool && virAsprintf(&inputpoolxml, "%s/storagepoolxml2xmlin/%s.xml", abs_srcdir, info->inputpool) < 0) - goto cleanup; + return -1; if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/%s.xml", abs_srcdir, info->pool) < 0 || virAsprintf(&volxml, "%s/storagevolxml2xmlin/%s.xml", abs_srcdir, info->vol) < 0) { - goto cleanup; + return -1; } if (virAsprintf(&cmdline, "%s/storagevolxml2argvdata/%s.argv", abs_srcdir, info->cmdline) < 0 && !info->shouldFail) - goto cleanup; - - result =3D testCompareXMLToArgvFiles(info->shouldFail, poolxml, volxml, - inputpoolxml, inputvolxml, - cmdline, info->flags, - info->parseflags); - - cleanup: - VIR_FREE(poolxml); - VIR_FREE(volxml); - VIR_FREE(inputvolxml); - VIR_FREE(inputpoolxml); - VIR_FREE(cmdline); + return -1; =20 - return result; + return testCompareXMLToArgvFiles(info->shouldFail, poolxml, volxml, + inputpoolxml, inputvolxml, + cmdline, info->flags, + info->parseflags); } =20 =20 diff --git a/tests/storagevolxml2xmltest.c b/tests/storagevolxml2xmltest.c index cb78bd5b28..7c5d8e7e38 100644 --- a/tests/storagevolxml2xmltest.c +++ b/tests/storagevolxml2xmltest.c @@ -17,28 +17,23 @@ static int testCompareXMLToXMLFiles(const char *poolxml, const char *inxml, const char *outxml, unsigned int flags) { - char *actual =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) actual =3D NULL; VIR_AUTOPTR(virStoragePoolDef) pool =3D NULL; VIR_AUTOPTR(virStorageVolDef) dev =3D NULL; =20 if (!(pool =3D virStoragePoolDefParseFile(poolxml))) - goto fail; + return -1; =20 if (!(dev =3D virStorageVolDefParseFile(pool, inxml, flags))) - goto fail; + return -1; =20 if (!(actual =3D virStorageVolDefFormat(pool, dev))) - goto fail; + return -1; =20 if (virTestCompareToFile(actual, outxml) < 0) - goto fail; + return -1; =20 - ret =3D 0; - - fail: - VIR_FREE(actual); - return ret; + return 0; } =20 struct testInfo { @@ -50,29 +45,20 @@ struct testInfo { static int testCompareXMLToXMLHelper(const void *data) { - int result =3D -1; const struct testInfo *info =3D data; - char *poolxml =3D NULL; - char *inxml =3D NULL; - char *outxml =3D NULL; + VIR_AUTOFREE(char *) poolxml =3D NULL; + VIR_AUTOFREE(char *) inxml =3D NULL; + VIR_AUTOFREE(char *) outxml =3D NULL; =20 if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/%s.xml", abs_srcdir, info->pool) < 0 || virAsprintf(&inxml, "%s/storagevolxml2xmlin/%s.xml", abs_srcdir, info->name) < 0 || virAsprintf(&outxml, "%s/storagevolxml2xmlout/%s.xml", - abs_srcdir, info->name) < 0) { - goto cleanup; - } - - result =3D testCompareXMLToXMLFiles(poolxml, inxml, outxml, info->flag= s); - - cleanup: - VIR_FREE(poolxml); - VIR_FREE(inxml); - VIR_FREE(outxml); + abs_srcdir, info->name) < 0) + return -1; =20 - return result; + return testCompareXMLToXMLFiles(poolxml, inxml, outxml, info->flags); } =20 =20 diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index c448d8b733..71c371891f 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -129,7 +129,7 @@ testPrepImages(void) { int ret =3D EXIT_FAILURE; VIR_AUTOPTR(virCommand) cmd =3D NULL; - char *buf =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; bool compat =3D false; =20 qemuimg =3D virFindFileInPath("qemu-img"); @@ -245,7 +245,6 @@ testPrepImages(void) =20 ret =3D 0; cleanup: - VIR_FREE(buf); if (ret) testCleanupImages(); return ret; @@ -313,7 +312,7 @@ testStorageChain(const void *args) virStorageSourcePtr meta; virStorageSourcePtr elt; size_t i =3D 0; - char *broken =3D NULL; + VIR_AUTOFREE(char *) broken =3D NULL; =20 meta =3D testStorageFileGetMetadata(data->start, data->format, -1, -1); if (!meta) { @@ -349,8 +348,8 @@ testStorageChain(const void *args) =20 elt =3D meta; while (virStorageSourceIsBacking(elt)) { - char *expect =3D NULL; - char *actual =3D NULL; + VIR_AUTOFREE(char *) expect =3D NULL; + VIR_AUTOFREE(char *) actual =3D NULL; =20 if (i =3D=3D data->nfiles) { fprintf(stderr, "probed chain was too long\n"); @@ -379,18 +378,12 @@ testStorageChain(const void *args) elt->format, virStorageNetProtocolTypeToString(elt->protocol), NULLSTR(elt->nhosts ? elt->hosts[0].name : NULL)) = < 0) { - VIR_FREE(expect); - VIR_FREE(actual); goto cleanup; } if (STRNEQ(expect, actual)) { virTestDifference(stderr, expect, actual); - VIR_FREE(expect); - VIR_FREE(actual); goto cleanup; } - VIR_FREE(expect); - VIR_FREE(actual); elt =3D elt->backingStore; i++; } @@ -401,7 +394,6 @@ testStorageChain(const void *args) =20 ret =3D 0; cleanup: - VIR_FREE(broken); virStorageSourceFree(meta); return ret; } @@ -539,8 +531,7 @@ static int testPathCanonicalize(const void *args) { const struct testPathCanonicalizeData *data =3D args; - char *canon =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) canon =3D NULL; =20 canon =3D virStorageFileCanonicalizePath(data->path, testPathCanonicalizeReadlink, @@ -551,15 +542,10 @@ testPathCanonicalize(const void *args) "path canonicalization of '%s' failed: expected '%s' got '= %s'\n", data->path, NULLSTR(data->expect), NULLSTR(canon)); =20 - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(canon); - - return ret; + return 0; } =20 static virStorageSource backingchain[12]; @@ -629,14 +615,13 @@ static int testPathRelative(const void *args) { const struct testPathRelativeBacking *data =3D args; - char *actual =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) actual =3D NULL; =20 if (virStorageFileGetRelativeBackingPath(data->top, data->base, &actual) < 0) { fprintf(stderr, "relative backing path resolution failed\n"); - goto cleanup; + return -1; } =20 if (STRNEQ_NULLABLE(data->expect, actual)) { @@ -644,15 +629,10 @@ testPathRelative(const void *args) "expected '%s', got '%s'\n", data->top->path, data->base->path, NULLSTR(data->expect), NULLSTR(actual)); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(actual); - - return ret; + return 0; } =20 =20 @@ -667,7 +647,7 @@ testBackingParse(const void *args) const struct testBackingParseData *data =3D args; virBuffer buf =3D VIR_BUFFER_INITIALIZER; virStorageSourcePtr src =3D NULL; - char *xml =3D NULL; + VIR_AUTOFREE(char *) xml =3D NULL; int ret =3D -1; =20 if (!(src =3D virStorageSourceNewFromBackingAbsolute(data->backing))) { @@ -702,7 +682,6 @@ testBackingParse(const void *args) cleanup: virStorageSourceFree(src); virBufferFreeAndReset(&buf); - VIR_FREE(xml); =20 return ret; } diff --git a/tests/virstorageutiltest.c b/tests/virstorageutiltest.c index d91c5d4d6f..766a910975 100644 --- a/tests/virstorageutiltest.c +++ b/tests/virstorageutiltest.c @@ -45,8 +45,8 @@ testGlusterExtractPoolSources(const void *opaque) .sources =3D NULL }; size_t i; - char *srcxmldata =3D NULL; - char *actual =3D NULL; + VIR_AUTOFREE(char *) srcxmldata =3D NULL; + VIR_AUTOFREE(char *) actual =3D NULL; int ret =3D -1; =20 if (virTestLoadFile(data->srcxml, &srcxmldata) < 0) @@ -62,9 +62,6 @@ testGlusterExtractPoolSources(const void *opaque) ret =3D virTestCompareToFile(actual, data->dstxml); =20 cleanup: - VIR_FREE(srcxmldata); - VIR_FREE(actual); - for (i =3D 0; i < list.nsources; i++) virStoragePoolSourceClear(&list.sources[i]); VIR_FREE(list.sources); --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list