qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [RFC 3/3] qmp: Include parent types on 'qom-list-types' out


From: Eduardo Habkost
Subject: [Qemu-devel] [RFC 3/3] qmp: Include parent types on 'qom-list-types' output
Date: Fri, 19 May 2017 23:09:14 -0300

Include list of parent types of each type on 'qom-list-types' output.

Without this, there's no way to figure out the parents of a given type
without making additional 'qom-list-types' queries.

In addition to the test case for the new feature, update the
abstract-interface test case to use the new field and avoid the
"qom-list-types implements=object" trick.

Signed-off-by: Eduardo Habkost <address@hidden>
---
I would to include a "interfaces" field in the future, too, but
this would require extending the core QOM API to allow that.
---
 qapi-schema.json               |  6 ++++-
 qmp.c                          | 16 +++++++++++
 tests/device-introspect-test.c | 61 +++++++++++++++++++++++++++++++++++-------
 3 files changed, 72 insertions(+), 11 deletions(-)

diff --git a/qapi-schema.json b/qapi-schema.json
index cbf1e2a837..169dfd2d7f 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3037,12 +3037,16 @@
 # @abstract: the type is abstract and can't be directly instantiated
 #            (since 2.10)
 #
+# @parent-types: parent types.  Parent types implemented by the type.  Note 
that
+#           this doesn't include interface names also implemented by the type.
+#           (since 2.10)
+#
 # Since: 1.1
 #
 # Notes: This command is experimental and may change syntax in future releases.
 ##
 { 'struct': 'ObjectTypeInfo',
-  'data': { 'name': 'str', 'abstract': 'bool' } }
+  'data': { 'name': 'str', 'abstract': 'bool', 'parent-types': [ 'str' ] } }
 
 ##
 # @qom-list-types:
diff --git a/qmp.c b/qmp.c
index 8066705dbe..5b50f6f650 100644
--- a/qmp.c
+++ b/qmp.c
@@ -436,6 +436,21 @@ void qmp_change(const char *device, const char *target,
     }
 }
 
+static strList *qom_type_get_parents(ObjectClass *klass)
+{
+    ObjectClass *parent = object_class_get_parent(klass);
+    strList *r = NULL;
+
+    if (!parent) {
+        return NULL;
+    }
+
+    r = g_new0(strList, 1);
+    r->value = g_strdup(object_class_get_name(parent));
+    r->next = qom_type_get_parents(parent);
+    return r;
+}
+
 static void qom_list_types_tramp(ObjectClass *klass, void *data)
 {
     ObjectTypeInfoList *e, **pret = data;
@@ -444,6 +459,7 @@ static void qom_list_types_tramp(ObjectClass *klass, void 
*data)
     info = g_malloc0(sizeof(*info));
     info->name = g_strdup(object_class_get_name(klass));
     info->abstract = object_class_is_abstract(klass);
+    info->parent_types = qom_type_get_parents(klass);
 
     e = g_malloc0(sizeof(*e));
     e->value = info;
diff --git a/tests/device-introspect-test.c b/tests/device-introspect-test.c
index d5aacb4ed1..350b862f3b 100644
--- a/tests/device-introspect-test.c
+++ b/tests/device-introspect-test.c
@@ -61,6 +61,20 @@ static QDict *type_list_find(QList *types, const char *name)
     return NULL;
 }
 
+static bool str_list_has(QList *strlist, const char *str)
+{
+    QListEntry *e;
+
+    QLIST_FOREACH_ENTRY(strlist, e) {
+        const char *s = 
qstring_get_str(qobject_to_qstring(qlist_entry_obj(e)));
+        if (!strcmp(s, str)) {
+            return true;
+        }
+    }
+
+    return false;
+}
+
 static QList *device_type_list(bool abstract)
 {
     return qom_list_types("device", abstract);
@@ -103,6 +117,31 @@ static void test_device_intro_list(void)
     qtest_end();
 }
 
+/*
+ * Ensure all entries returned by qom-list-types implements=<parent>
+ * have <parent> in parent-types.
+ */
+static void test_qom_list_parents(const char *parent)
+{
+    QList *types;
+    QListEntry *e;
+
+    types = qom_list_types(parent, true);
+
+    QLIST_FOREACH_ENTRY(types, e) {
+        QDict *d = qobject_to_qdict(qlist_entry_obj(e));
+
+        /* The parent type being queried is included in the list too, skip it 
*/
+        if (!strcmp(qdict_get_str(d, "name"), parent)) {
+            continue;
+        }
+
+        g_assert(str_list_has(qdict_get_qlist(d, "parent-types"), parent));
+    }
+
+    QDECREF(types);
+}
+
 static void test_qom_list_fields(void)
 {
     QList *all_types;
@@ -123,6 +162,10 @@ static void test_qom_list_fields(void)
         g_assert(abstract == expected_abstract);
     }
 
+    test_qom_list_parents("object");
+    test_qom_list_parents("device");
+    test_qom_list_parents("sys-bus-device");
+
     QDECREF(all_types);
     QDECREF(non_abstract);
     qtest_end();
@@ -165,23 +208,22 @@ static void test_device_intro_concrete(void)
 static void test_abstract_interfaces(void)
 {
     QList *all_types;
-    QList *obj_types;
     QListEntry *e;
 
     qtest_start(common_args);
-    /*
-     * qom-list-types implements=interface returns all types that
-     * implement _any_ interface (not just interface types), but
-     * we can filter them out because interfaces don't implement
-     * the "object" type.
-     */
+
     all_types = qom_list_types("interface", true);
-    obj_types = qom_list_types("object", true);
 
     QLIST_FOREACH_ENTRY(all_types, e) {
         QDict *d = qobject_to_qdict(qlist_entry_obj(e));
 
-        if (type_list_find(obj_types, qdict_get_str(d, "name"))) {
+        /*
+         * qom-list-types implements=interface returns all types
+         * that implement _any_ interface (not just interface
+         * types), so skip the ones that don't have "interface"
+         * on parent-types.
+         */
+        if (!str_list_has(qdict_get_qlist(d, "parent-types"), "interface")) {
             /* Not an interface type */
             continue;
         }
@@ -190,7 +232,6 @@ static void test_abstract_interfaces(void)
     }
 
     QDECREF(all_types);
-    QDECREF(obj_types);
     qtest_end();
 }
 
-- 
2.11.0.259.g40922b1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]