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