[RFC PATCH 4/7] testQEMUSchemaValidateEnum: Refactor logic to simplify switching to new QMP schema format

Peter Krempa pkrempa at redhat.com
Mon Sep 20 13:49:35 UTC 2021


QEMU-6.2 is reporting enum values in the new 'members' array which we'll
be switching to. Rewrite the logic so that adding the new checker is
more straightforward.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 tests/testutilsqemuschema.c | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/tests/testutilsqemuschema.c b/tests/testutilsqemuschema.c
index f6347231a8..e75345b582 100644
--- a/tests/testutilsqemuschema.c
+++ b/tests/testutilsqemuschema.c
@@ -319,7 +319,6 @@ testQEMUSchemaValidateEnum(virJSONValue *obj,
 {
     const char *objstr;
     virJSONValue *values = NULL;
-    virJSONValue *value;
     size_t i;

     if (virJSONValueGetType(obj) != VIR_JSON_TYPE_STRING) {
@@ -329,24 +328,24 @@ testQEMUSchemaValidateEnum(virJSONValue *obj,

     objstr = virJSONValueGetString(obj);

-    if (!(values = virJSONValueObjectGetArray(root, "values"))) {
-        virBufferAsprintf(ctxt->debug, "ERROR: missing enum values in schema '%s'",
-                          NULLSTR(virJSONValueObjectGetString(root, "name")));
-        return -2;
-    }
-
-    for (i = 0; i < virJSONValueArraySize(values); i++) {
-        value = virJSONValueArrayGet(values, i);
+    if ((values = virJSONValueObjectGetArray(root, "values"))) {
+        for (i = 0; i < virJSONValueArraySize(values); i++) {
+            virJSONValue *value = virJSONValueArrayGet(values, i);

-        if (STREQ_NULLABLE(objstr, virJSONValueGetString(value))) {
-            virBufferAsprintf(ctxt->debug, "'%s' OK", NULLSTR(objstr));
-            return 0;
+            if (STREQ_NULLABLE(objstr, virJSONValueGetString(value))) {
+                virBufferAsprintf(ctxt->debug, "'%s' OK", NULLSTR(objstr));
+                return 0;
+            }
         }
+
+        virBufferAsprintf(ctxt->debug, "ERROR: enum value '%s' is not in schema",
+                          NULLSTR(objstr));
+        return -1;
     }

-    virBufferAsprintf(ctxt->debug, "ERROR: enum value '%s' is not in schema",
-                      NULLSTR(objstr));
-    return -1;
+    virBufferAsprintf(ctxt->debug, "ERROR: missing enum values in schema '%s'",
+                      NULLSTR(virJSONValueObjectGetString(root, "name")));
+    return -2;
 }


-- 
2.31.1




More information about the libvir-list mailing list