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