[PATCH 02/15] testutilsqemuschema: Introduce testQEMUSchemaValidateCommand

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The new helper splits out all steps necessary to validate a QMP command
against the schema.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 tests/testutilsqemuschema.c | 44 +++++++++++++++++++++++++++++++++++++
 tests/testutilsqemuschema.h |  6 +++++
 2 files changed, 50 insertions(+)

diff --git a/tests/testutilsqemuschema.c b/tests/testutilsqemuschema.c
index 7b82ff27b2..60409a0f91 100644
--- a/tests/testutilsqemuschema.c
+++ b/tests/testutilsqemuschema.c
@@ -517,6 +517,50 @@ testQEMUSchemaValidate(virJSONValuePtr obj,
 }


+/**
+ * testQEMUSchemaValidateCommand:
+ * @command: command to validate
+ * @arguments: arguments of @command to validate
+ * @schema: hash table containing schema entries
+ * @debug: a virBuffer which will be filled with debug information if provided
+ *
+ * Validates whether @command and it's @arguments conforms to the QAPI schema
+ * passed in via @schema. Returns 0, if the command and args matches @schema,
+ * -1 if it does not and -2 if there is a problem with the schema or with
+ *  internals.
+ *
+ * @debug is filled with information regarding the validation process
+ */
+int
+testQEMUSchemaValidateCommand(const char *command,
+                              virJSONValuePtr arguments,
+                              virHashTablePtr schema,
+                              virBufferPtr debug)
+{
+    g_autofree char *schemapatharguments = g_strdup_printf("%s/arg-type", command);
+    g_autoptr(virJSONValue) emptyargs = NULL;
+    virJSONValuePtr schemarootcommand;
+    virJSONValuePtr schemarootarguments;
+
+    if (virQEMUQAPISchemaPathGet(command, schema, &schemarootcommand) < 0 ||
+        !schemarootcommand) {
+        virBufferAsprintf(debug, "ERROR: command '%s' not found in the schema", command);
+        return -1;
+    }
+
+    if (!arguments)
+        arguments = emptyargs = virJSONValueNewObject();
+
+    if (virQEMUQAPISchemaPathGet(schemapatharguments, schema, &schemarootarguments) < 0 ||
+        !schemarootarguments) {
+        virBufferAsprintf(debug, "ERROR: failed to look up 'arg-type' of  '%s'", command);
+        return -1;
+    }
+
+    return testQEMUSchemaValidateRecurse(arguments, schemarootarguments, schema, debug);
+}
+
+
 /**
  * testQEMUSchemaGetLatest:
  *
diff --git a/tests/testutilsqemuschema.h b/tests/testutilsqemuschema.h
index 84ee9a9670..e3a375b038 100644
--- a/tests/testutilsqemuschema.h
+++ b/tests/testutilsqemuschema.h
@@ -28,6 +28,12 @@ testQEMUSchemaValidate(virJSONValuePtr obj,
                        virHashTablePtr schema,
                        virBufferPtr debug);

+int
+testQEMUSchemaValidateCommand(const char *command,
+                              virJSONValuePtr arguments,
+                              virHashTablePtr schema,
+                              virBufferPtr debug);
+
 virJSONValuePtr
 testQEMUSchemaGetLatest(const char* arch);

-- 
2.26.2





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux