From nobody Wed Feb 11 10:14:16 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.24 as permitted sender) client-ip=209.132.183.24; envelope-from=libvir-list-bounces@redhat.com; helo=mx3-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.24 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by mx.zohomail.com with SMTPS id 1489596038189121.39847999416986; Wed, 15 Mar 2017 09:40:38 -0700 (PDT) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v2FGb5TK005306; Wed, 15 Mar 2017 12:37:05 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v2FGb3r5025034 for ; Wed, 15 Mar 2017 12:37:03 -0400 Received: from angien.brq.redhat.com (dhcp129-47.brq.redhat.com [10.34.129.47]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2FGafIV000870; Wed, 15 Mar 2017 12:37:02 -0400 From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 15 Mar 2017 17:37:29 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 17/23] tests: qemumonitorjson: Add test case for node name detection code 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-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The code is rather magic so a test case will help making sure that everything works well. The first case is a simple backing chain. --- .../qemumonitorjson-nodename-1.json | 268 +++++++++++++++++= ++++ .../qemumonitorjson-nodename-1.result | 15 ++ tests/qemumonitorjsontest.c | 116 +++++++++ 3 files changed, 399 insertions(+) create mode 100644 tests/qemumonitorjsondata/qemumonitorjson-nodename-1.js= on create mode 100644 tests/qemumonitorjsondata/qemumonitorjson-nodename-1.re= sult diff --git a/tests/qemumonitorjsondata/qemumonitorjson-nodename-1.json b/te= sts/qemumonitorjsondata/qemumonitorjson-nodename-1.json new file mode 100644 index 000000000..fe2f32176 --- /dev/null +++ b/tests/qemumonitorjsondata/qemumonitorjson-nodename-1.json @@ -0,0 +1,268 @@ +[ + { + "iops_rd": 0, + "detect_zeroes": "off", + "image": { + "virtual-size": 9663676416, + "filename": "/var/lib/libvirt/images/rhel7.3.qcow2", + "cluster-size": 65536, + "format": "qcow2", + "actual-size": 9665384448, + "format-specific": { + "type": "qcow2", + "data": { + "compat": "1.1", + "lazy-refcounts": true, + "refcount-bits": 16, + "corrupt": false + } + }, + "dirty-flag": false + }, + "iops_wr": 0, + "ro": true, + "node-name": "#block567", + "backing_file_depth": 0, + "drv": "qcow2", + "iops": 0, + "bps_wr": 0, + "write_threshold": 0, + "encrypted": false, + "bps": 0, + "bps_rd": 0, + "cache": { + "no-flush": false, + "direct": false, + "writeback": true + }, + "file": "/var/lib/libvirt/images/rhel7.3.qcow2", + "encryption_key_missing": false + }, + { + "iops_rd": 0, + "detect_zeroes": "off", + "image": { + "virtual-size": 9665380352, + "filename": "/var/lib/libvirt/images/rhel7.3.qcow2", + "format": "file", + "actual-size": 9665384448, + "dirty-flag": false + }, + "iops_wr": 0, + "ro": true, + "node-name": "#block424", + "backing_file_depth": 0, + "drv": "file", + "iops": 0, + "bps_wr": 0, + "write_threshold": 0, + "encrypted": false, + "bps": 0, + "bps_rd": 0, + "cache": { + "no-flush": false, + "direct": false, + "writeback": true + }, + "file": "/var/lib/libvirt/images/rhel7.3.qcow2", + "encryption_key_missing": false + }, + { + "iops_rd": 0, + "detect_zeroes": "off", + "image": { + "backing-image": { + "virtual-size": 9663676416, + "filename": "/var/lib/libvirt/images/rhel7.3.qcow2", + "cluster-size": 65536, + "format": "qcow2", + "actual-size": 9665384448, + "format-specific": { + "type": "qcow2", + "data": { + "compat": "1.1", + "lazy-refcounts": true, + "refcount-bits": 16, + "corrupt": false + } + }, + "dirty-flag": false + }, + "backing-filename-format": "qcow2", + "virtual-size": 9663676416, + "filename": "/var/lib/libvirt/images/rhel7.3.1483536402", + "cluster-size": 65536, + "format": "qcow2", + "actual-size": 200704, + "format-specific": { + "type": "qcow2", + "data": { + "compat": "1.1", + "lazy-refcounts": false, + "refcount-bits": 16, + "corrupt": false + } + }, + "full-backing-filename": "/var/lib/libvirt/images/rhel7.3.qcow2", + "backing-filename": "/var/lib/libvirt/images/rhel7.3.qcow2", + "dirty-flag": false + }, + "iops_wr": 0, + "ro": true, + "node-name": "#block331", + "backing_file_depth": 1, + "drv": "qcow2", + "iops": 0, + "bps_wr": 0, + "write_threshold": 0, + "backing_file": "/var/lib/libvirt/images/rhel7.3.qcow2", + "encrypted": false, + "bps": 0, + "bps_rd": 0, + "cache": { + "no-flush": false, + "direct": false, + "writeback": true + }, + "file": "/var/lib/libvirt/images/rhel7.3.1483536402", + "encryption_key_missing": false + }, + { + "iops_rd": 0, + "detect_zeroes": "off", + "image": { + "virtual-size": 197120, + "filename": "/var/lib/libvirt/images/rhel7.3.1483536402", + "format": "file", + "actual-size": 200704, + "dirty-flag": false + }, + "iops_wr": 0, + "ro": true, + "node-name": "#block281", + "backing_file_depth": 0, + "drv": "file", + "iops": 0, + "bps_wr": 0, + "write_threshold": 0, + "encrypted": false, + "bps": 0, + "bps_rd": 0, + "cache": { + "no-flush": false, + "direct": false, + "writeback": true + }, + "file": "/var/lib/libvirt/images/rhel7.3.1483536402", + "encryption_key_missing": false + }, + { + "iops_rd": 0, + "detect_zeroes": "off", + "image": { + "backing-image": { + "backing-image": { + "virtual-size": 9663676416, + "filename": "/var/lib/libvirt/images/rhel7.3.qcow2", + "cluster-size": 65536, + "format": "qcow2", + "actual-size": 9665384448, + "format-specific": { + "type": "qcow2", + "data": { + "compat": "1.1", + "lazy-refcounts": true, + "refcount-bits": 16, + "corrupt": false + } + }, + "dirty-flag": false + }, + "backing-filename-format": "qcow2", + "virtual-size": 9663676416, + "filename": "/var/lib/libvirt/images/rhel7.3.1483536402", + "cluster-size": 65536, + "format": "qcow2", + "actual-size": 200704, + "format-specific": { + "type": "qcow2", + "data": { + "compat": "1.1", + "lazy-refcounts": false, + "refcount-bits": 16, + "corrupt": false + } + }, + "full-backing-filename": "/var/lib/libvirt/images/rhel7.3.qcow2", + "backing-filename": "/var/lib/libvirt/images/rhel7.3.qcow2", + "dirty-flag": false + }, + "backing-filename-format": "qcow2", + "virtual-size": 9663676416, + "filename": "/var/lib/libvirt/images/rhel7.3.1483545313", + "cluster-size": 65536, + "format": "qcow2", + "actual-size": 32968704, + "format-specific": { + "type": "qcow2", + "data": { + "compat": "1.1", + "lazy-refcounts": false, + "refcount-bits": 16, + "corrupt": false + } + }, + "full-backing-filename": "/var/lib/libvirt/images/rhel7.3.14835364= 02", + "backing-filename": "/var/lib/libvirt/images/rhel7.3.1483536402", + "dirty-flag": false + }, + "iops_wr": 0, + "ro": false, + "node-name": "#block118", + "backing_file_depth": 2, + "drv": "qcow2", + "iops": 0, + "bps_wr": 0, + "write_threshold": 0, + "backing_file": "/var/lib/libvirt/images/rhel7.3.1483536402", + "encrypted": false, + "bps": 0, + "bps_rd": 0, + "cache": { + "no-flush": false, + "direct": false, + "writeback": true + }, + "file": "/var/lib/libvirt/images/rhel7.3.1483545313", + "encryption_key_missing": false + }, + { + "iops_rd": 0, + "detect_zeroes": "off", + "image": { + "virtual-size": 33030144, + "filename": "/var/lib/libvirt/images/rhel7.3.1483545313", + "format": "file", + "actual-size": 32968704, + "dirty-flag": false + }, + "iops_wr": 0, + "ro": false, + "node-name": "#block078", + "backing_file_depth": 0, + "drv": "file", + "iops": 0, + "bps_wr": 0, + "write_threshold": 0, + "encrypted": false, + "bps": 0, + "bps_rd": 0, + "cache": { + "no-flush": false, + "direct": false, + "writeback": true + }, + "file": "/var/lib/libvirt/images/rhel7.3.1483545313", + "encryption_key_missing": false + } +] diff --git a/tests/qemumonitorjsondata/qemumonitorjson-nodename-1.result b/= tests/qemumonitorjsondata/qemumonitorjson-nodename-1.result new file mode 100644 index 000000000..e43f3d366 --- /dev/null +++ b/tests/qemumonitorjsondata/qemumonitorjson-nodename-1.result @@ -0,0 +1,15 @@ +filename : '/var/lib/libvirt/images/rhel7.3.1483545313' +format node : '#block118' +storage node: '#block078' +backingfile : '/var/lib/libvirt/images/rhel7.3.1483536402' +backing ptr : '#block331' + filename : '/var/lib/libvirt/images/rhel7.3.1483536402' + format node : '#block331' + storage node: '#block281' + backingfile : '/var/lib/libvirt/images/rhel7.3.qcow2' + backing ptr : '#block567' + filename : '/var/lib/libvirt/images/rhel7.3.qcow2' + format node : '#block567' + storage node: '#block424' + backingfile : '' + backing ptr : '' diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 402c87d45..fcc1540a8 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -23,6 +23,7 @@ #include "testutilsqemu.h" #include "qemumonitortestutils.h" #include "qemu/qemu_domain.h" +#include "qemu/qemu_block.h" #include "qemu/qemu_monitor_json.h" #include "virthread.h" #include "virerror.h" @@ -2659,6 +2660,109 @@ testQemuMonitorCPUInfo(const void *opaque) } +struct testBlockNodeNameDetectData { + const char *name; + const char *nodenames; +}; + + +static void +testBlockNodeNameDetectFormat(virBufferPtr buf, + const char *basenode, + virHashTablePtr nodedata) +{ + qemuBlockNodeNameBackingChainDataPtr entry =3D NULL; + const char *node =3D basenode; + + virBufferSetIndent(buf, 0); + + while (node) { + if (!(entry =3D virHashLookup(nodedata, node))) + break; + + virBufferAsprintf(buf, "filename : '%s'\n", entry->qemufilename= ); + virBufferAsprintf(buf, "format node : '%s'\n", + NULLSTR(entry->nodeformat)); + virBufferAsprintf(buf, "storage node: '%s'\n", + NULLSTR(entry->nodestorage)); + virBufferAsprintf(buf, "backingfile : '%s'\n", + NULLSTR(entry->backingstore)); + virBufferAsprintf(buf, "backing ptr : '%s'\n", + NULLSTR(entry->nodebacking)); + + virBufferAdjustIndent(buf, 2); + + node =3D entry->nodebacking; + } + + virBufferSetIndent(buf, 0); + virBufferAddLit(buf, "\n"); +} + + +static int +testBlockNodeNameDetect(const void *opaque) +{ + const struct testBlockNodeNameDetectData *data =3D opaque; + char *jsonFile =3D NULL; + char *jsonStr =3D NULL; + char *resultFile =3D NULL; + char *actual =3D NULL; + char **nodenames =3D NULL; + char **next; + virJSONValuePtr json =3D NULL; + virHashTablePtr nodedata =3D NULL; + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + int ret =3D -1; + + if (virAsprintf(&jsonFile, + "%s/qemumonitorjsondata/qemumonitorjson-nodename-%s.js= on", + abs_srcdir, data->name) < 0 || + virAsprintf(&resultFile, + "%s/qemumonitorjsondata/qemumonitorjson-nodename-%s.re= sult", + abs_srcdir, data->name) < 0) + goto cleanup; + + if (!(nodenames =3D virStringSplit(data->nodenames, ",", 0))) + goto cleanup; + + if (virTestLoadFile(jsonFile, &jsonStr) < 0) + goto cleanup; + + if (!(json =3D virJSONValueFromString(jsonStr))) + goto cleanup; + + if (!(nodedata =3D qemuBlockNodeNameGetBackingChain(json))) + goto cleanup; + + for (next =3D nodenames; *next; next++) + testBlockNodeNameDetectFormat(&buf, *next, nodedata); + + virBufferTrim(&buf, "\n", -1); + + if (virBufferCheckError(&buf) < 0) + goto cleanup; + + actual =3D virBufferContentAndReset(&buf); + + if (virTestCompareToFile(actual, resultFile) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + VIR_FREE(jsonFile); + VIR_FREE(resultFile); + VIR_FREE(jsonStr); + VIR_FREE(actual); + virHashFree(nodedata); + virStringListFree(nodenames); + virJSONValueFree(json); + + return ret; +} + + static int mymain(void) { @@ -2793,6 +2897,18 @@ 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) = \ + do { = \ + struct testBlockNodeNameDetectData testdata =3D {testname, testnod= es}; \ + if (virTestRun("node-name-detect(" testname ")", = \ + testBlockNodeNameDetect, &testdata) < 0) = \ + ret =3D -1; = \ + } while (0) + + DO_TEST_BLOCK_NODE_DETECT("1", "#block118"); + +#undef DO_TEST_BLOCK_NODE_DETECT + qemuTestDriverFree(&driver); return (ret =3D=3D 0) ? EXIT_SUCCESS : EXIT_FAILURE; --=20 2.12.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list