[libvirt] [PATCH 03/21] tests: qemumonitorjson: Add tests for QAPI schema query

Peter Krempa pkrempa at redhat.com
Mon Apr 15 16:01:56 UTC 2019


While we technically test the query strings in the qemucapabilitiestest
this was done to help refactor and extend the QAPI schema query
infrastructure.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 tests/qemumonitorjsontest.c | 45 +++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index e3d23a8800..bcd7d37b03 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -2836,9 +2836,30 @@ struct testQAPISchemaData {
     const char *query;
     const char *json;
     bool success;
+    int rc;
+    bool replyobj;
 };


+static int
+testQAPISchemaQuery(const void *opaque)
+{
+    const struct testQAPISchemaData *data = opaque;
+    virJSONValuePtr replyobj = NULL;
+    int rc;
+
+    rc = virQEMUQAPISchemaPathGet(data->query, data->schema, &replyobj);
+
+    if (data->rc != rc || data->replyobj != !!replyobj) {
+        VIR_TEST_VERBOSE("\n success: expected '%d' got '%d', replyobj: expected '%d' got '%d'",
+                         data->rc, rc, data->replyobj, !!replyobj);
+        return -1;
+    }
+
+    return 0;
+}
+
+
 static int
 testQAPISchemaValidate(const void *opaque)
 {
@@ -3056,6 +3077,30 @@ mymain(void)

 #undef DO_TEST_BLOCK_NODE_DETECT

+#define DO_TEST_QAPI_QUERY(nme, qry, scc, rplobj) \
+    do { \
+        qapiData.name = nme; \
+        qapiData.query = qry; \
+        qapiData.rc = scc; \
+        qapiData.replyobj = rplobj; \
+        if (virTestRun("qapi schema query" nme, testQAPISchemaQuery, &qapiData) < 0)\
+            ret = -1; \
+    } while (0)
+
+    DO_TEST_QAPI_QUERY("command", "blockdev-add", 0, true);
+    DO_TEST_QAPI_QUERY("event", "RTC_CHANGE", 0, true);
+    DO_TEST_QAPI_QUERY("object property", "screendump/arg-type/device", 0, true);
+    DO_TEST_QAPI_QUERY("optional property", "block-commit/arg-type/*top", 0, true);
+    DO_TEST_QAPI_QUERY("variant", "blockdev-add/arg-type/+file", 0, true);
+    DO_TEST_QAPI_QUERY("variant property", "blockdev-add/arg-type/+file/filename", 0, true);
+
+    DO_TEST_QAPI_QUERY("nonexistent command", "nonexistent", 0, false);
+    DO_TEST_QAPI_QUERY("nonexistent attr", "screendump/arg-type/nonexistent", 0, false);
+    DO_TEST_QAPI_QUERY("nonexistent variant", "blockdev-add/arg-type/+nonexistent", 0, false);
+
+#undef DO_TEST_QAPI_QUERY
+
+
 #define DO_TEST_QAPI_VALIDATE(nme, rootquery, scc, jsonstr) \
     do { \
         qapiData.name = nme; \
-- 
2.20.1




More information about the libvir-list mailing list