On Fri, Aug 05, 2016 at 03:56:05PM +0200, Peter Krempa wrote:
As the combination algorithm is rather complex and ugly it's
necessary
to make sure it works properly. Add test suite infrastructure for
testing it along with a basic test based on x86_64 platform.
---
...nitorjson-cpuinfo-x86-basic-pluggable-cpus.json | 50 ++++++++
...orjson-cpuinfo-x86-basic-pluggable-hotplug.json | 82 +++++++++++++
...emumonitorjson-cpuinfo-x86-basic-pluggable.data | 39 ++++++
tests/qemumonitorjsontest.c | 133 +++++++++++++++++++++
4 files changed, 304 insertions(+)
create mode 100644
tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-x86-basic-pluggable-cpus.json
create mode 100644
tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-x86-basic-pluggable-hotplug.json
create mode 100644
tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-x86-basic-pluggable.data
[...]
+static int
+testQemuMonitorCPUInfo(const void *opaque)
+{
+ const struct testCPUInfoData *data = opaque;
+ qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, data->xmlopt);
+ char *queryCpusFile = NULL;
+ char *queryHotpluggableFile = NULL;
+ char *dataFile = NULL;
+ char *queryCpusStr = NULL;
+ char *queryHotpluggableStr = NULL;
+ char *actual = NULL;
+ qemuMonitorCPUInfoPtr vcpus = NULL;
+ int rc;
+ int ret = -1;
+
+ if (!test)
+ return -1;
+
+ if (virAsprintf(&queryCpusFile,
+
"%s/qemumonitorjsondata/qemumonitorjson-cpuinfo-%s-cpus.json",
+ abs_srcdir, data->name) < 0 ||
+ virAsprintf(&queryHotpluggableFile,
+
"%s/qemumonitorjsondata/qemumonitorjson-cpuinfo-%s-hotplug.json",
+ abs_srcdir, data->name) < 0 ||
+ virAsprintf(&dataFile,
+ "%s/qemumonitorjsondata/qemumonitorjson-cpuinfo-%s.data",
+ abs_srcdir, data->name) < 0)
+ goto cleanup;
+
+ if (virTestLoadFile(queryCpusFile, &queryCpusStr) < 0)
+ goto cleanup;
+
+ if (virTestLoadFile(queryHotpluggableFile, &queryHotpluggableStr) < 0)
+ goto cleanup;
+
+ if (qemuMonitorTestAddItem(test, "query-hotpluggable-cpus",
queryHotpluggableStr) < 0)
This line is too long, please wrap it.
+ goto cleanup;
+
+ if (qemuMonitorTestAddItem(test, "query-cpus", queryCpusStr) < 0)
+ goto cleanup;
+
+ rc = qemuMonitorGetCPUInfo(qemuMonitorTestGetMonitor(test),
+ &vcpus, data->maxvcpus, true);
+
+ if (rc < 0)
+ goto cleanup;
+
+ actual = testQemuMonitorCPUInfoFormat(vcpus, data->maxvcpus);
+
+ if (virTestCompareToFile(actual, dataFile) < 0)
+ goto cleanup;
+
+ ret = 0;
+ cleanup:
+ VIR_FREE(queryCpusFile);
+ VIR_FREE(queryHotpluggableFile);
+ VIR_FREE(dataFile);
+ VIR_FREE(queryCpusStr);
+ VIR_FREE(queryHotpluggableStr);
+ VIR_FREE(actual);
+ qemuMonitorCPUInfoFree(vcpus, data->maxvcpus);
+ qemuMonitorTestFree(test);
+ return ret;
+}
ACK