1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-01-10 05:17:59 +03:00

tests: qemumonitorjson: Simplify node name detection test

We can now iterate the hash table and print all detected backing chains.
This simplifies calling of the test cases.

Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Peter Krempa 2017-07-26 09:42:11 +02:00
parent 4983368367
commit acfd2fdcbf
2 changed files with 23 additions and 33 deletions

View File

@ -1,3 +1,4 @@
drive-virtio-disk0
filename : '/var/lib/libvirt/images/rhel7.3.1483545313' filename : '/var/lib/libvirt/images/rhel7.3.1483545313'
format node : '#block187' format node : '#block187'
storage node: '#block033' storage node: '#block033'

View File

@ -2696,23 +2696,19 @@ testQemuMonitorCPUInfo(const void *opaque)
} }
struct testBlockNodeNameDetectData { static int
const char *name; testBlockNodeNameDetectFormat(void *payload,
const char *nodenames; const void *name,
}; void *opaque)
static void
testBlockNodeNameDetectFormat(virBufferPtr buf,
const char *diskalias,
virHashTablePtr nodedata)
{ {
qemuBlockNodeNameBackingChainDataPtr entry = NULL; qemuBlockNodeNameBackingChainDataPtr entry = payload;
const char *diskalias = name;
virBufferPtr buf = opaque;
virBufferSetIndent(buf, 0); virBufferSetIndent(buf, 0);
if (!(entry = virHashLookup(nodedata, diskalias))) virBufferAdd(buf, diskalias, -1);
return; virBufferAddLit(buf, "\n");
while (entry) { while (entry) {
virBufferAsprintf(buf, "filename : '%s'\n", entry->qemufilename); virBufferAsprintf(buf, "filename : '%s'\n", entry->qemufilename);
@ -2728,18 +2724,17 @@ testBlockNodeNameDetectFormat(virBufferPtr buf,
virBufferSetIndent(buf, 0); virBufferSetIndent(buf, 0);
virBufferAddLit(buf, "\n"); virBufferAddLit(buf, "\n");
return 0;
} }
static int static int
testBlockNodeNameDetect(const void *opaque) testBlockNodeNameDetect(const void *opaque)
{ {
const struct testBlockNodeNameDetectData *data = opaque; const char *testname = opaque;
const char *pathprefix = "qemumonitorjsondata/qemumonitorjson-nodename-"; const char *pathprefix = "qemumonitorjsondata/qemumonitorjson-nodename-";
char *resultFile = NULL; char *resultFile = NULL;
char *actual = NULL; char *actual = NULL;
char **nodenames = NULL;
char **next;
virJSONValuePtr namedNodesJson = NULL; virJSONValuePtr namedNodesJson = NULL;
virJSONValuePtr blockstatsJson = NULL; virJSONValuePtr blockstatsJson = NULL;
virHashTablePtr nodedata = NULL; virHashTablePtr nodedata = NULL;
@ -2747,17 +2742,14 @@ testBlockNodeNameDetect(const void *opaque)
int ret = -1; int ret = -1;
if (virAsprintf(&resultFile, "%s/%s%s.result", if (virAsprintf(&resultFile, "%s/%s%s.result",
abs_srcdir, pathprefix, data->name) < 0) abs_srcdir, pathprefix, testname) < 0)
goto cleanup; goto cleanup;
if (!(nodenames = virStringSplit(data->nodenames, ",", 0))) if (!(namedNodesJson = virTestLoadFileJSON(pathprefix, testname,
goto cleanup;
if (!(namedNodesJson = virTestLoadFileJSON(pathprefix, data->name,
"-named-nodes.json", NULL))) "-named-nodes.json", NULL)))
goto cleanup; goto cleanup;
if (!(blockstatsJson = virTestLoadFileJSON(pathprefix, data->name, if (!(blockstatsJson = virTestLoadFileJSON(pathprefix, testname,
"-blockstats.json", NULL))) "-blockstats.json", NULL)))
goto cleanup; goto cleanup;
@ -2765,8 +2757,7 @@ testBlockNodeNameDetect(const void *opaque)
blockstatsJson))) blockstatsJson)))
goto cleanup; goto cleanup;
for (next = nodenames; *next; next++) virHashForEach(nodedata, testBlockNodeNameDetectFormat, &buf);
testBlockNodeNameDetectFormat(&buf, *next, nodedata);
virBufferTrim(&buf, "\n", -1); virBufferTrim(&buf, "\n", -1);
@ -2784,7 +2775,6 @@ testBlockNodeNameDetect(const void *opaque)
VIR_FREE(resultFile); VIR_FREE(resultFile);
VIR_FREE(actual); VIR_FREE(actual);
virHashFree(nodedata); virHashFree(nodedata);
virStringListFree(nodenames);
virJSONValueFree(namedNodesJson); virJSONValueFree(namedNodesJson);
virJSONValueFree(blockstatsJson); virJSONValueFree(blockstatsJson);
@ -2927,18 +2917,17 @@ mymain(void)
DO_TEST_CPU_INFO("ppc64-hotplug-4", 24); DO_TEST_CPU_INFO("ppc64-hotplug-4", 24);
DO_TEST_CPU_INFO("ppc64-no-threads", 16); DO_TEST_CPU_INFO("ppc64-no-threads", 16);
#define DO_TEST_BLOCK_NODE_DETECT(testname, testnodes) \ #define DO_TEST_BLOCK_NODE_DETECT(testname) \
do { \ do { \
struct testBlockNodeNameDetectData testdata = {testname, testnodes}; \
if (virTestRun("node-name-detect(" testname ")", \ if (virTestRun("node-name-detect(" testname ")", \
testBlockNodeNameDetect, &testdata) < 0) \ testBlockNodeNameDetect, testname) < 0) \
ret = -1; \ ret = -1; \
} while (0) } while (0)
DO_TEST_BLOCK_NODE_DETECT("basic", "drive-virtio-disk0"); DO_TEST_BLOCK_NODE_DETECT("basic");
/* DO_TEST_BLOCK_NODE_DETECT("same-backing", "#block170,#block574"); */ /* DO_TEST_BLOCK_NODE_DETECT("same-backing"); */
/* DO_TEST_BLOCK_NODE_DETECT("relative", "#block153,#block1177"); */ /* DO_TEST_BLOCK_NODE_DETECT("relative"); */
/* DO_TEST_BLOCK_NODE_DETECT("gluster", "#block1008"); */ /* DO_TEST_BLOCK_NODE_DETECT("gluster"); */
#undef DO_TEST_BLOCK_NODE_DETECT #undef DO_TEST_BLOCK_NODE_DETECT
@ -2947,4 +2936,4 @@ mymain(void)
return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE; return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
} }
VIR_TEST_MAIN(mymain) VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virdeterministichashmock.so")