[PATCH v1 0/3] qemumonitorjson tests for cpu compare and baseline

These patches implement tests for the libvirt qemu_monitor_json API for the hypervisor-cpu-compare and -baseline commands. The input and output data is mocked with arbitrary values. A prerequisite patch is included to load the capabilities schema for a specific architecture. Originally, only the x86 capabilities were loaded for the qemu_monitor_json tests. By accepting a string denoting which architecture's QEMU capabilities we'd like to load, we can now test the comparison and baseline code that is currently only supported on s390. Collin Walling (3): qemumonitorjsontest: load schema based on specified arch qemumonitorjsontest: add tests for cpu comparison qemumonitorjsontest: add test for cpu baseline tests/qemublocktest.c | 2 +- tests/qemuhotplugtest.c | 2 +- tests/qemumonitorjsontest.c | 131 +++++++++++++++++++++++++++++++++++++++++++- tests/testutilsqemuschema.c | 8 +-- tests/testutilsqemuschema.h | 4 +- 5 files changed, 137 insertions(+), 10 deletions(-) -- 2.7.4

There are some architectures that support capabilities that others do not (e.g. s390x supports cpu comparison and baseline via QEMU). Let's make testQEMUSchemaLoad accept a string to specify the schema to load based on the specified arch. Signed-off-by: Collin Walling <walling@linux.ibm.com> --- tests/qemublocktest.c | 2 +- tests/qemuhotplugtest.c | 2 +- tests/qemumonitorjsontest.c | 4 ++-- tests/testutilsqemuschema.c | 8 ++++---- tests/testutilsqemuschema.h | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c index 5a564b7..7b7948d 100644 --- a/tests/qemublocktest.c +++ b/tests/qemublocktest.c @@ -981,7 +981,7 @@ mymain(void) #define TEST_DISK_TO_JSON(nme) TEST_DISK_TO_JSON_FULL(nme, false) - if (!(diskxmljsondata.schema = testQEMUSchemaLoad())) { + if (!(diskxmljsondata.schema = testQEMUSchemaLoad("x86_64"))) { ret = -1; goto cleanup; } diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c index 6a3e61c..9dd4266 100644 --- a/tests/qemuhotplugtest.c +++ b/tests/qemuhotplugtest.c @@ -620,7 +620,7 @@ mymain(void) if (!(driver.domainEventState = virObjectEventStateNew())) return EXIT_FAILURE; - if (!(qmpschema = testQEMUSchemaLoad())) { + if (!(qmpschema = testQEMUSchemaLoad("x86_64"))) { VIR_TEST_VERBOSE("failed to load qapi schema\n"); return EXIT_FAILURE; } diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 24e0ce1..cd7fa1f 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -2995,7 +2995,7 @@ mymain(void) virEventRegisterDefaultImpl(); - if (!(qapiData.schema = testQEMUSchemaLoad())) { + if (!(qapiData.schema = testQEMUSchemaLoad("x86_64"))) { VIR_TEST_VERBOSE("failed to load qapi schema"); ret = -1; goto cleanup; @@ -3232,7 +3232,7 @@ mymain(void) DO_TEST_QAPI_VALIDATE("alternate 2", "blockdev-add/arg-type", false, "{\"driver\":\"qcow2\",\"file\": 1234}"); - if (!(metaschema = testQEMUSchemaGetLatest()) || + if (!(metaschema = testQEMUSchemaGetLatest("x86_64")) || !(metaschemastr = virJSONValueToString(metaschema, false))) { VIR_TEST_VERBOSE("failed to load latest qapi schema"); ret = -1; diff --git a/tests/testutilsqemuschema.c b/tests/testutilsqemuschema.c index 9a1b1fe..7b82ff2 100644 --- a/tests/testutilsqemuschema.c +++ b/tests/testutilsqemuschema.c @@ -524,7 +524,7 @@ testQEMUSchemaValidate(virJSONValuePtr obj, * replies file used for qemucapabilitiestest for the x86_64 architecture. */ virJSONValuePtr -testQEMUSchemaGetLatest(void) +testQEMUSchemaGetLatest(const char* arch) { char *capsLatestFile = NULL; char *capsLatest = NULL; @@ -533,7 +533,7 @@ testQEMUSchemaGetLatest(void) virJSONValuePtr reply = NULL; virJSONValuePtr schema = NULL; - if (!(capsLatestFile = testQemuGetLatestCapsForArch("x86_64", "replies"))) { + if (!(capsLatestFile = testQemuGetLatestCapsForArch(arch, "replies"))) { VIR_TEST_VERBOSE("failed to find latest caps replies"); return NULL; } @@ -575,11 +575,11 @@ testQEMUSchemaGetLatest(void) virHashTablePtr -testQEMUSchemaLoad(void) +testQEMUSchemaLoad(const char* arch) { virJSONValuePtr schema; - if (!(schema = testQEMUSchemaGetLatest())) + if (!(schema = testQEMUSchemaGetLatest(arch))) return NULL; return virQEMUQAPISchemaConvert(schema); diff --git a/tests/testutilsqemuschema.h b/tests/testutilsqemuschema.h index de9da7c..84ee9a9 100644 --- a/tests/testutilsqemuschema.h +++ b/tests/testutilsqemuschema.h @@ -29,7 +29,7 @@ testQEMUSchemaValidate(virJSONValuePtr obj, virBufferPtr debug); virJSONValuePtr -testQEMUSchemaGetLatest(void); +testQEMUSchemaGetLatest(const char* arch); virHashTablePtr -testQEMUSchemaLoad(void); +testQEMUSchemaLoad(const char* arch); -- 2.7.4

Signed-off-by: Collin Walling <walling@linux.ibm.com> --- tests/qemumonitorjsontest.c | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index cd7fa1f..5568af5 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -2981,6 +2981,48 @@ testQemuMonitorJSONTransaction(const void *opaque) static int +testQemuMonitorJSONqemuMonitorJSONGetCPUModelComparison(const void *opaque) +{ + const testGenericData *data = opaque; + g_autoptr(qemuMonitorTest) test = NULL; + virCPUDefPtr cpu_a; + virCPUDefPtr cpu_b = NULL; + g_autofree char *result = NULL; + int ret = -1; + + if (!(test = qemuMonitorTestNewSchema(data->xmlopt, data->schema))) + return -1; + + if (qemuMonitorTestAddItem(test, "query-cpu-model-comparison", + "{\"return\":{\"result\":\"test\"}}") < 0) + return -1; + + if (VIR_ALLOC(cpu_a) < 0 || VIR_ALLOC(cpu_b) < 0) + goto cleanup; + + cpu_a->model = g_strdup("cpu_a"); + cpu_b->model = g_strdup("cpu_b"); + + if (qemuMonitorJSONGetCPUModelComparison(qemuMonitorTestGetMonitor(test), + cpu_a, cpu_b, &result) < 0) + goto cleanup; + + if (!result || STRNEQ(result, "test")) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "Compare result not set"); + goto cleanup; + } + + ret = 0; + + cleanup: + virCPUDefFree(cpu_a); + virCPUDefFree(cpu_b); + return ret; +} + + +static int mymain(void) { int ret = 0; @@ -3257,6 +3299,14 @@ mymain(void) #undef DO_TEST_QUERY_JOBS + if (!(qapiData.schema = testQEMUSchemaLoad("s390x"))) { + VIR_TEST_VERBOSE("failed to load qapi schema for s390x"); + ret = -1; + goto cleanup; + } + + DO_TEST(qemuMonitorJSONGetCPUModelComparison); + cleanup: VIR_FREE(metaschemastr); virJSONValueFree(metaschema); -- 2.7.4

Signed-off-by: Collin Walling <walling@linux.ibm.com> --- tests/qemumonitorjsontest.c | 77 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 5568af5..e9f95e3 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -3023,6 +3023,82 @@ testQemuMonitorJSONqemuMonitorJSONGetCPUModelComparison(const void *opaque) static int +testQemuMonitorJSONqemuMonitorJSONGetCPUModelBaseline(const void *opaque) +{ + const testGenericData *data = opaque; + g_autoptr(qemuMonitorTest) test = NULL; + virCPUDefPtr cpu_a; + virCPUDefPtr cpu_b = NULL; + qemuMonitorCPUModelInfoPtr baseline = NULL; + int ret = -1; + + if (!(test = qemuMonitorTestNewSchema(data->xmlopt, data->schema))) + return -1; + + if (qemuMonitorTestAddItem(test, "query-cpu-model-baseline", + "{ " + " \"return\": { " + " \"model\": { " + " \"name\": \"cpu_c\", " + " \"props\": { " + " \"feat_a\": true, " + " \"feat_b\": false " + " } " + " } " + " } " + "}") < 0) + return -1; + + if (VIR_ALLOC(cpu_a) < 0 || VIR_ALLOC(cpu_b) < 0) + goto cleanup; + + cpu_a->model = g_strdup("cpu_a"); + cpu_b->model = g_strdup("cpu_b"); + + if (virCPUDefAddFeature(cpu_a, "feat_a", VIR_CPU_FEATURE_REQUIRE) < 0 || + virCPUDefAddFeature(cpu_a, "feat_b", VIR_CPU_FEATURE_REQUIRE) < 0 || + virCPUDefAddFeature(cpu_a, "feat_c", VIR_CPU_FEATURE_REQUIRE) < 0) + goto cleanup; + + if (qemuMonitorJSONGetCPUModelBaseline(qemuMonitorTestGetMonitor(test), + cpu_a, cpu_b, &baseline) < 0) + goto cleanup; + + if (!baseline) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "Baseline missing result"); + goto cleanup; + } + if (!baseline->name) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "Baseline missing model name"); + goto cleanup; + } + if (baseline->nprops != 2) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "Baseline missing properties"); + goto cleanup; + } + if (STRNEQ(baseline->props[0].name, "feat_a") || + !baseline->props[0].value.boolean || + STRNEQ(baseline->props[1].name, "feat_b") || + baseline->props[1].value.boolean) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "Baseline property error"); + goto cleanup; + } + + ret = 0; + + cleanup: + virCPUDefFree(cpu_a); + virCPUDefFree(cpu_b); + qemuMonitorCPUModelInfoFree(baseline); + return ret; +} + + +static int mymain(void) { int ret = 0; @@ -3306,6 +3382,7 @@ mymain(void) } DO_TEST(qemuMonitorJSONGetCPUModelComparison); + DO_TEST(qemuMonitorJSONGetCPUModelBaseline); cleanup: VIR_FREE(metaschemastr); -- 2.7.4

On 2/20/20 11:01 PM, Collin Walling wrote:
These patches implement tests for the libvirt qemu_monitor_json API for the hypervisor-cpu-compare and -baseline commands. The input and output data is mocked with arbitrary values.
A prerequisite patch is included to load the capabilities schema for a specific architecture. Originally, only the x86 capabilities were loaded for the qemu_monitor_json tests. By accepting a string denoting which architecture's QEMU capabilities we'd like to load, we can now test the comparison and baseline code that is currently only supported on s390.
Collin Walling (3): qemumonitorjsontest: load schema based on specified arch qemumonitorjsontest: add tests for cpu comparison qemumonitorjsontest: add test for cpu baseline
tests/qemublocktest.c | 2 +- tests/qemuhotplugtest.c | 2 +- tests/qemumonitorjsontest.c | 131 +++++++++++++++++++++++++++++++++++++++++++- tests/testutilsqemuschema.c | 8 +-- tests/testutilsqemuschema.h | 4 +- 5 files changed, 137 insertions(+), 10 deletions(-)
Reviewed-by: Michal Privoznik <mprivozn@redhat.com> and pushed. Michal
participants (2)
-
Collin Walling
-
Michal Privoznik