Add test cases for the responsible-properties output parameter introduced in the previous patch: - responsible-properties populated correctly from QMP response - responsible-properties NULL when key is absent from response - responsible-properties NULL when array is empty - subset result with responsible-properties Each case is wrapped in its own block so responsibleProps is automatically freed after each subtest. Signed-off-by: Rorie Reyes <rreyes@linux.ibm.com> --- tests/qemumonitorjsontest.c | 100 ++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index db44a725ee..5dc8ba67e6 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -2654,6 +2654,80 @@ testQemuMonitorJSONqemuMonitorJSONGetCPUModelComparison(const void *opaque) if (!(test = qemuMonitorTestNewSchema(data->xmlopt, data->schema))) return -1; + /* responsible-properties populated correctly */ + { + g_auto(GStrv) responsibleProps = NULL; + + if (qemuMonitorTestAddItem(test, "query-cpu-model-comparison", + "{\"return\":{\"result\":\"incompatible\"," + "\"responsible-properties\":[\"prop_a\",\"prop_b\"]}}") < 0) + return -1; + + if (qemuMonitorJSONGetCPUModelComparison(qemuMonitorTestGetMonitor(test), + cpu_a, cpu_b, + &responsibleProps) != VIR_CPU_COMPARE_INCOMPATIBLE) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "unexpected result for incompatible with props"); + return -1; + } + + if (!responsibleProps || + STRNEQ_NULLABLE(responsibleProps[0], "prop_a") || + STRNEQ_NULLABLE(responsibleProps[1], "prop_b") || + responsibleProps[2] != NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "unexpected responsible-properties"); + return -1; + } + } + + /* responsible-properties absent from response — must be NULL */ + { + g_auto(GStrv) responsibleProps = NULL; + + if (qemuMonitorTestAddItem(test, "query-cpu-model-comparison", + "{\"return\":{\"result\":\"incompatible\"}}") < 0) + return -1; + + if (qemuMonitorJSONGetCPUModelComparison(qemuMonitorTestGetMonitor(test), + cpu_a, cpu_b, + &responsibleProps) != VIR_CPU_COMPARE_INCOMPATIBLE) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "unexpected result"); + return -1; + } + + if (responsibleProps) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "responsible-properties should be NULL when key absent"); + return -1; + } + } + + /* responsible-properties empty array — must be NULL */ + { + g_auto(GStrv) responsibleProps = NULL; + + if (qemuMonitorTestAddItem(test, "query-cpu-model-comparison", + "{\"return\":{\"result\":\"incompatible\"," + "\"responsible-properties\":[]}}") < 0) + return -1; + + if (qemuMonitorJSONGetCPUModelComparison(qemuMonitorTestGetMonitor(test), + cpu_a, cpu_b, + &responsibleProps) != VIR_CPU_COMPARE_INCOMPATIBLE) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "unexpected result"); + return -1; + } + + if (responsibleProps) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "responsible-properties should be NULL for empty array"); + return -1; + } + } + /* identical */ { if (qemuMonitorTestAddItem(test, "query-cpu-model-comparison", @@ -2710,6 +2784,32 @@ testQemuMonitorJSONqemuMonitorJSONGetCPUModelComparison(const void *opaque) } } + /* subset with responsible-properties */ + { + g_auto(GStrv) responsibleProps = NULL; + + if (qemuMonitorTestAddItem(test, "query-cpu-model-comparison", + "{\"return\":{\"result\":\"subset\"," + "\"responsible-properties\":[\"feat_x\"]}}") < 0) + return -1; + + if (qemuMonitorJSONGetCPUModelComparison(qemuMonitorTestGetMonitor(test), + cpu_a, cpu_b, + &responsibleProps) != VIR_CPU_COMPARE_INCOMPATIBLE) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "unexpected result for subset with props"); + return -1; + } + + if (!responsibleProps || + STRNEQ_NULLABLE(responsibleProps[0], "feat_x") || + responsibleProps[1] != NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "unexpected responsible-properties"); + return -1; + } + } + return 0; } -- 2.48.1