Signed-off-by: Fabiano Rosas <faro...@suse.de>
---
 tests/qtest/libqtest.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 tests/qtest/libqtest.h | 12 ++++++++++++
 2 files changed, 54 insertions(+)

diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 94526b7f9c..7ee4831841 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -34,6 +34,9 @@
 #include "qemu/ctype.h"
 #include "qemu/cutils.h"
 #include "qemu/sockets.h"
+#include "qapi/error.h"
+#include "qapi/qapi-visit-introspect.h"
+#include "qapi/qobject-input-visitor.h"
 #include "qobject/qdict.h"
 #include "qobject/qjson.h"
 #include "qobject/qlist.h"
@@ -2091,3 +2094,42 @@ bool mkimg(const char *file, const char *fmt, unsigned 
size_mb)
 
     return ret && !err;
 }
+
+bool qtest_qmp_cmd_has_feature(QTestState *qts, const char *cmd,
+                               const char *feature)
+{
+    QDict *resp;
+    Visitor *qiv;
+    SchemaInfoList *tail;
+    SchemaInfo *si;
+    strList *str;
+
+    resp = qtest_qmp(qts, "{ 'execute': 'query-qmp-schema' }");
+
+    qiv = qobject_input_visitor_new(qdict_get(resp, "return"));
+    visit_type_SchemaInfoList(qiv, NULL, &tail, &error_abort);
+    visit_free(qiv);
+    qobject_unref(resp);
+
+    for (; tail; tail = tail->next) {
+        si = tail->value;
+
+        if (si->meta_type != SCHEMA_META_TYPE_COMMAND) {
+            continue;
+        }
+
+        if (g_str_equal(si->name, cmd)) {
+            break;
+        }
+    }
+
+    if (tail && si->has_features) {
+        for (str = si->features; str; str = str->next) {
+            if (g_str_equal(str->value, feature)) {
+                return true;
+            }
+        }
+    }
+
+    return false;
+}
diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h
index b3f2e7fbef..c609316223 100644
--- a/tests/qtest/libqtest.h
+++ b/tests/qtest/libqtest.h
@@ -1153,4 +1153,16 @@ bool have_qemu_img(void);
  */
 bool mkimg(const char *file, const char *fmt, unsigned size_mb);
 
+/**
+ * qtest_qmp_cmd_has_feature:
+ * @qts: QTestState instance
+ * @cmd: The QMP command being introspected
+ * @feature: Name of the feature to be checked
+ *
+ * Returns: true if the QMP command @cmd supports @feature, false otherwise.
+ */
+bool qtest_qmp_cmd_has_feature(QTestState *qts, const char *cmd,
+                               const char *feature);
+
+
 #endif
-- 
2.35.3


Reply via email to