Blame SOURCES/libvirt-testQemuDiskXMLToProps-Store-all-per-image-data-in-one-structure.patch

d76c62
From bafa6f68029a497c78b3823694b6a2149622bc9e Mon Sep 17 00:00:00 2001
d76c62
Message-Id: <bafa6f68029a497c78b3823694b6a2149622bc9e@dist-git>
d76c62
From: Peter Krempa <pkrempa@redhat.com>
d76c62
Date: Tue, 24 Mar 2020 16:26:01 +0100
d76c62
Subject: [PATCH] testQemuDiskXMLToProps: Store all per-image data in one
d76c62
 structure
d76c62
MIME-Version: 1.0
d76c62
Content-Type: text/plain; charset=UTF-8
d76c62
Content-Transfer-Encoding: 8bit
d76c62
d76c62
We had two non-syncrhonized arrays holding the individual data. This was
d76c62
a lazy way to do it when I was adding new tests recently. Since it's
d76c62
hard to extend with new data to test refactor the storage of test data
d76c62
to use a new struct where all per-image data are kept and can be
d76c62
extended easily.
d76c62
d76c62
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
d76c62
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
d76c62
(cherry picked from commit 93171b63c3a28dad06c3af6d2483d953a6f79ad2)
d76c62
https://bugzilla.redhat.com/show_bug.cgi?id=1804617
d76c62
Message-Id: <b8cad280efeab0fe40e4d426167d3095b8419d3a.1585063415.git.pkrempa@redhat.com>
d76c62
Reviewed-by: Ján Tomko <jtomko@redhat.com>
d76c62
---
d76c62
 tests/qemublocktest.c | 90 ++++++++++++++++++++++++++-----------------
d76c62
 1 file changed, 54 insertions(+), 36 deletions(-)
d76c62
d76c62
diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c
d76c62
index 14c80960b1..c009db7996 100644
d76c62
--- a/tests/qemublocktest.c
d76c62
+++ b/tests/qemublocktest.c
d76c62
@@ -180,6 +180,13 @@ testJSONtoJSON(const void *args)
d76c62
 }
d76c62
 
d76c62
 
d76c62
+struct testQemuDiskXMLToJSONImageData {
d76c62
+    virJSONValuePtr formatprops;
d76c62
+    virJSONValuePtr storageprops;
d76c62
+    virJSONValuePtr storagepropssrc;
d76c62
+};
d76c62
+
d76c62
+
d76c62
 struct testQemuDiskXMLToJSONData {
d76c62
     virQEMUDriverPtr driver;
d76c62
     virHashTablePtr schema;
d76c62
@@ -187,11 +194,8 @@ struct testQemuDiskXMLToJSONData {
d76c62
     const char *name;
d76c62
     bool fail;
d76c62
 
d76c62
-    virJSONValuePtr *props;
d76c62
-    size_t nprops;
d76c62
-
d76c62
-    virJSONValuePtr *propssrc;
d76c62
-    size_t npropssrc;
d76c62
+    struct testQemuDiskXMLToJSONImageData *images;
d76c62
+    size_t nimages;
d76c62
 
d76c62
     virQEMUCapsPtr qemuCaps;
d76c62
 };
d76c62
@@ -202,16 +206,13 @@ testQemuDiskXMLToPropsClear(struct testQemuDiskXMLToJSONData *data)
d76c62
 {
d76c62
     size_t i;
d76c62
 
d76c62
-    for (i = 0; i < data->nprops; i++)
d76c62
-        virJSONValueFree(data->props[i]);
d76c62
-
d76c62
-    for (i = 0; i < data->npropssrc; i++)
d76c62
-        virJSONValueFree(data->propssrc[i]);
d76c62
-
d76c62
-    data->nprops = 0;
d76c62
-    VIR_FREE(data->props);
d76c62
-    data->npropssrc = 0;
d76c62
-    VIR_FREE(data->propssrc);
d76c62
+    for (i = 0; i < data->nimages; i++) {
d76c62
+        virJSONValueFree(data->images[i].formatprops);
d76c62
+        virJSONValueFree(data->images[i].storageprops);
d76c62
+        virJSONValueFree(data->images[i].storagepropssrc);
d76c62
+    }
d76c62
+    data->nimages = 0;
d76c62
+    VIR_FREE(data->images);
d76c62
 }
d76c62
 
d76c62
 
d76c62
@@ -286,6 +287,7 @@ testQemuDiskXMLToProps(const void *opaque)
d76c62
     }
d76c62
 
d76c62
     for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) {
d76c62
+
d76c62
         if (testQemuDiskXMLToJSONFakeSecrets(n) < 0)
d76c62
             return -1;
d76c62
 
d76c62
@@ -306,10 +308,14 @@ testQemuDiskXMLToProps(const void *opaque)
d76c62
             return -1;
d76c62
         }
d76c62
 
d76c62
-        if (VIR_APPEND_ELEMENT(data->props, data->nprops, formatProps) < 0 ||
d76c62
-            VIR_APPEND_ELEMENT(data->props, data->nprops, storageProps) < 0 ||
d76c62
-            VIR_APPEND_ELEMENT(data->propssrc, data->npropssrc, storageSrcOnlyProps) < 0)
d76c62
+        if (VIR_REALLOC_N(data->images, data->nimages + 1) < 0)
d76c62
             return -1;
d76c62
+
d76c62
+        data->images[data->nimages].formatprops = g_steal_pointer(&formatProps);
d76c62
+        data->images[data->nimages].storageprops = g_steal_pointer(&storageProps);
d76c62
+        data->images[data->nimages].storagepropssrc = g_steal_pointer(&storageSrcOnlyProps);
d76c62
+
d76c62
+        data->nimages++;
d76c62
     }
d76c62
 
d76c62
     return 0;
d76c62
@@ -326,27 +332,37 @@ testQemuDiskXMLToPropsValidateSchema(const void *opaque)
d76c62
     if (data->fail)
d76c62
         return EXIT_AM_SKIP;
d76c62
 
d76c62
-    for (i = 0; i < data->nprops; i++) {
d76c62
+    for (i = 0; i < data->nimages; i++) {
d76c62
         g_auto(virBuffer) debug = VIR_BUFFER_INITIALIZER;
d76c62
 
d76c62
-        if (testQEMUSchemaValidate(data->props[i], data->schemaroot,
d76c62
+        if (testQEMUSchemaValidate(data->images[i].formatprops, data->schemaroot,
d76c62
                                    data->schema, &debug) < 0) {
d76c62
             g_autofree char *debugmsg = virBufferContentAndReset(&debug);
d76c62
-            g_autofree char *propsstr = virJSONValueToString(data->props[i], true);
d76c62
+            g_autofree char *propsstr = virJSONValueToString(data->images[i].formatprops, true);
d76c62
             VIR_TEST_VERBOSE("json does not conform to QAPI schema");
d76c62
             VIR_TEST_DEBUG("json:\n%s\ndoes not match schema. Debug output:\n %s",
d76c62
                            propsstr, NULLSTR(debugmsg));
d76c62
             ret = -1;
d76c62
         }
d76c62
-    }
d76c62
 
d76c62
-    for (i = 0; i < data->npropssrc; i++) {
d76c62
-        g_auto(virBuffer) debug = VIR_BUFFER_INITIALIZER;
d76c62
+        virBufferFreeAndReset(&debug);
d76c62
 
d76c62
-        if (testQEMUSchemaValidate(data->propssrc[i], data->schemaroot,
d76c62
+        if (testQEMUSchemaValidate(data->images[i].storageprops, data->schemaroot,
d76c62
                                    data->schema, &debug) < 0) {
d76c62
             g_autofree char *debugmsg = virBufferContentAndReset(&debug);
d76c62
-            g_autofree char *propsstr = virJSONValueToString(data->propssrc[i], true);
d76c62
+            g_autofree char *propsstr = virJSONValueToString(data->images[i].storageprops, true);
d76c62
+            VIR_TEST_VERBOSE("json does not conform to QAPI schema");
d76c62
+            VIR_TEST_DEBUG("json:\n%s\ndoes not match schema. Debug output:\n %s",
d76c62
+                           propsstr, NULLSTR(debugmsg));
d76c62
+            ret = -1;
d76c62
+        }
d76c62
+
d76c62
+        virBufferFreeAndReset(&debug);
d76c62
+
d76c62
+        if (testQEMUSchemaValidate(data->images[i].storagepropssrc, data->schemaroot,
d76c62
+                                   data->schema, &debug) < 0) {
d76c62
+            g_autofree char *debugmsg = virBufferContentAndReset(&debug);
d76c62
+            g_autofree char *propsstr = virJSONValueToString(data->images[i].storagepropssrc, true);
d76c62
             VIR_TEST_VERBOSE("json does not conform to QAPI schema");
d76c62
             VIR_TEST_DEBUG("json:\n%s\ndoes not match schema. Debug output:\n %s",
d76c62
                            propsstr, NULLSTR(debugmsg));
d76c62
@@ -372,13 +388,17 @@ testQemuDiskXMLToPropsValidateFile(const void *opaque)
d76c62
 
d76c62
     jsonpath = g_strdup_printf("%s%s.json", testQemuDiskXMLToJSONPath, data->name);
d76c62
 
d76c62
-    for (i = 0; i < data->nprops; i++) {
d76c62
-        g_autofree char *jsonstr = NULL;
d76c62
+    for (i = 0; i < data->nimages; i++) {
d76c62
+        g_autofree char *formatprops = NULL;
d76c62
+        g_autofree char *storageprops = NULL;
d76c62
 
d76c62
-        if (!(jsonstr = virJSONValueToString(data->props[i], true)))
d76c62
+        if (!(formatprops = virJSONValueToString(data->images[i].formatprops, true)))
d76c62
             return -1;
d76c62
 
d76c62
-        virBufferAdd(&buf, jsonstr, -1);
d76c62
+        if (!(storageprops = virJSONValueToString(data->images[i].storageprops, true)))
d76c62
+            return -1;
d76c62
+
d76c62
+        virBufferStrcat(&buf, formatprops, storageprops, NULL);
d76c62
     }
d76c62
 
d76c62
     actual = virBufferContentAndReset(&buf;;
d76c62
@@ -402,10 +422,10 @@ testQemuDiskXMLToPropsValidateFileSrcOnly(const void *opaque)
d76c62
     jsonpath = g_strdup_printf("%s%s-srconly.json", testQemuDiskXMLToJSONPath,
d76c62
                                data->name);
d76c62
 
d76c62
-    for (i = 0; i < data->npropssrc; i++) {
d76c62
+    for (i = 0; i < data->nimages; i++) {
d76c62
         g_autofree char *jsonstr = NULL;
d76c62
 
d76c62
-        if (!(jsonstr = virJSONValueToString(data->propssrc[i], true)))
d76c62
+        if (!(jsonstr = virJSONValueToString(data->images[i].storagepropssrc, true)))
d76c62
             return -1;
d76c62
 
d76c62
         virBufferAdd(&buf, jsonstr, -1);
d76c62
@@ -1117,10 +1137,8 @@ mymain(void)
d76c62
 #define TEST_DISK_TO_JSON_FULL(nme, fl) \
d76c62
     do { \
d76c62
         diskxmljsondata.name = nme; \
d76c62
-        diskxmljsondata.props = NULL; \
d76c62
-        diskxmljsondata.nprops = 0; \
d76c62
-        diskxmljsondata.propssrc = NULL; \
d76c62
-        diskxmljsondata.npropssrc = 0; \
d76c62
+        diskxmljsondata.images = NULL; \
d76c62
+        diskxmljsondata.nimages = 0; \
d76c62
         diskxmljsondata.fail = fl; \
d76c62
         if (virTestRun("disk xml to props " nme, testQemuDiskXMLToProps, \
d76c62
                        &diskxmljsondata) < 0) \
d76c62
-- 
d76c62
2.26.0
d76c62