From nobody Fri May 16 05:14:45 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 1501063428318448.610656384325; Wed, 26 Jul 2017 03:03:48 -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 945A7A9657; Wed, 26 Jul 2017 10:03:45 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 667ED5D978; Wed, 26 Jul 2017 10:03:45 +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 147C63889; Wed, 26 Jul 2017 10:03:24 +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 v6QA1Dth008906 for ; Wed, 26 Jul 2017 06:01:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id F0FFE6FE6D; Wed, 26 Jul 2017 10:01:12 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4D9336FE60; Wed, 26 Jul 2017 10:01:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 945A7A9657 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.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:46 +0200 Message-Id: <883a34077a986bf10c87c0348b0e13a2bdf6d035.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 16/24] tests: qemumonitorjson: Simplify node name detection test 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.38]); Wed, 26 Jul 2017 10:03:46 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" We can now iterate the hash table and print all detected backing chains. This simplifies calling of the test cases. --- .../qemumonitorjson-nodename-basic.result | 1 + tests/qemumonitorjsontest.c | 55 +++++++++---------= ---- 2 files changed, 23 insertions(+), 33 deletions(-) diff --git a/tests/qemumonitorjsondata/qemumonitorjson-nodename-basic.resul= t b/tests/qemumonitorjsondata/qemumonitorjson-nodename-basic.result index 09e0b36ac..bc183f8b9 100644 --- a/tests/qemumonitorjsondata/qemumonitorjson-nodename-basic.result +++ b/tests/qemumonitorjsondata/qemumonitorjson-nodename-basic.result @@ -1,3 +1,4 @@ +drive-virtio-disk0 filename : '/var/lib/libvirt/images/rhel7.3.1483545313' format node : '#block187' storage node: '#block033' diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index cb7a7dbdb..88169832e 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -2696,23 +2696,19 @@ testQemuMonitorCPUInfo(const void *opaque) } -struct testBlockNodeNameDetectData { - const char *name; - const char *nodenames; -}; - - -static void -testBlockNodeNameDetectFormat(virBufferPtr buf, - const char *diskalias, - virHashTablePtr nodedata) +static int +testBlockNodeNameDetectFormat(void *payload, + const void *name, + void *opaque) { - qemuBlockNodeNameBackingChainDataPtr entry =3D NULL; + qemuBlockNodeNameBackingChainDataPtr entry =3D payload; + const char *diskalias =3D name; + virBufferPtr buf =3D opaque; virBufferSetIndent(buf, 0); - if (!(entry =3D virHashLookup(nodedata, diskalias))) - return; + virBufferAdd(buf, diskalias, -1); + virBufferAddLit(buf, "\n"); while (entry) { virBufferAsprintf(buf, "filename : '%s'\n", entry->qemufilename= ); @@ -2728,18 +2724,17 @@ testBlockNodeNameDetectFormat(virBufferPtr buf, virBufferSetIndent(buf, 0); virBufferAddLit(buf, "\n"); + return 0; } static int testBlockNodeNameDetect(const void *opaque) { - const struct testBlockNodeNameDetectData *data =3D opaque; + const char *testname =3D opaque; const char *pathprefix =3D "qemumonitorjsondata/qemumonitorjson-nodena= me-"; char *resultFile =3D NULL; char *actual =3D NULL; - char **nodenames =3D NULL; - char **next; virJSONValuePtr namedNodesJson =3D NULL; virJSONValuePtr blockstatsJson =3D NULL; virHashTablePtr nodedata =3D NULL; @@ -2747,17 +2742,14 @@ testBlockNodeNameDetect(const void *opaque) int ret =3D -1; if (virAsprintf(&resultFile, "%s/%s%s.result", - abs_srcdir, pathprefix, data->name) < 0) - goto cleanup; - - if (!(nodenames =3D virStringSplit(data->nodenames, ",", 0))) + abs_srcdir, pathprefix, testname) < 0) goto cleanup; - if (!(namedNodesJson =3D virTestLoadFileJSON(pathprefix, data->name, + if (!(namedNodesJson =3D virTestLoadFileJSON(pathprefix, testname, "-named-nodes.json", NULL))) goto cleanup; - if (!(blockstatsJson =3D virTestLoadFileJSON(pathprefix, data->name, + if (!(blockstatsJson =3D virTestLoadFileJSON(pathprefix, testname, "-blockstats.json", NULL))) goto cleanup; @@ -2765,8 +2757,7 @@ testBlockNodeNameDetect(const void *opaque) blockstatsJson))) goto cleanup; - for (next =3D nodenames; *next; next++) - testBlockNodeNameDetectFormat(&buf, *next, nodedata); + virHashForEach(nodedata, testBlockNodeNameDetectFormat, &buf); virBufferTrim(&buf, "\n", -1); @@ -2784,7 +2775,6 @@ testBlockNodeNameDetect(const void *opaque) VIR_FREE(resultFile); VIR_FREE(actual); virHashFree(nodedata); - virStringListFree(nodenames); virJSONValueFree(namedNodesJson); virJSONValueFree(blockstatsJson); @@ -2927,18 +2917,17 @@ mymain(void) DO_TEST_CPU_INFO("ppc64-hotplug-4", 24); DO_TEST_CPU_INFO("ppc64-no-threads", 16); -#define DO_TEST_BLOCK_NODE_DETECT(testname, testnodes) = \ +#define DO_TEST_BLOCK_NODE_DETECT(testname) = \ do { = \ - struct testBlockNodeNameDetectData testdata =3D {testname, testnod= es}; \ if (virTestRun("node-name-detect(" testname ")", = \ - testBlockNodeNameDetect, &testdata) < 0) = \ + testBlockNodeNameDetect, testname) < 0) = \ ret =3D -1; = \ } while (0) - DO_TEST_BLOCK_NODE_DETECT("basic", "drive-virtio-disk0"); -/* DO_TEST_BLOCK_NODE_DETECT("same-backing", "#block170,#block574"); */ -/* DO_TEST_BLOCK_NODE_DETECT("relative", "#block153,#block1177"); */ -/* DO_TEST_BLOCK_NODE_DETECT("gluster", "#block1008"); */ + DO_TEST_BLOCK_NODE_DETECT("basic"); +/* DO_TEST_BLOCK_NODE_DETECT("same-backing"); */ +/* DO_TEST_BLOCK_NODE_DETECT("relative"); */ +/* DO_TEST_BLOCK_NODE_DETECT("gluster"); */ #undef DO_TEST_BLOCK_NODE_DETECT @@ -2947,4 +2936,4 @@ mymain(void) return (ret =3D=3D 0) ? EXIT_SUCCESS : EXIT_FAILURE; } -VIR_TEST_MAIN(mymain) +VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virdeterministichashmoc= k.so") --=20 2.13.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list