qemumonitorjsontest: add test for cpu baseline

Signed-off-by: Collin Walling <walling@linux.ibm.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Collin Walling 2020-02-20 17:01:48 -05:00 committed by Michal Privoznik
parent eee09435ee
commit fa2404bf4f

View File

@ -3022,6 +3022,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 static int
mymain(void) mymain(void)
{ {
@ -3306,6 +3382,7 @@ mymain(void)
} }
DO_TEST(qemuMonitorJSONGetCPUModelComparison); DO_TEST(qemuMonitorJSONGetCPUModelComparison);
DO_TEST(qemuMonitorJSONGetCPUModelBaseline);
cleanup: cleanup:
VIR_FREE(metaschemastr); VIR_FREE(metaschemastr);