qmp: Include 'abstract' field on 'qom-list-types' output
A client may be interested in getting the list of both abstract and non-abstract types. Instead of requiring them to make multiple queries with different filter arguments, just return an 'abstract' field in 'qom-list-types'. In addition to the new test code for validating this field, update the abstract-interfaces test case to query for all 'interface' subtypes (including abstract ones), and to look at the 'abstract' field directly. Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> Message-Id: <20170707122215.8819-3-ehabkost@redhat.com> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
This commit is contained in:
parent
dbb2a604a9
commit
87467eae37
@ -3051,10 +3051,13 @@
|
|||||||
#
|
#
|
||||||
# @name: the type name found in the search
|
# @name: the type name found in the search
|
||||||
#
|
#
|
||||||
|
# @abstract: the type is abstract and can't be directly instantiated.
|
||||||
|
# Omitted if false. (since 2.10)
|
||||||
|
#
|
||||||
# Since: 1.1
|
# Since: 1.1
|
||||||
##
|
##
|
||||||
{ 'struct': 'ObjectTypeInfo',
|
{ 'struct': 'ObjectTypeInfo',
|
||||||
'data': { 'name': 'str' } }
|
'data': { 'name': 'str', '*abstract': 'bool' } }
|
||||||
|
|
||||||
##
|
##
|
||||||
# @qom-list-types:
|
# @qom-list-types:
|
||||||
|
1
qmp.c
1
qmp.c
@ -433,6 +433,7 @@ static void qom_list_types_tramp(ObjectClass *klass, void *data)
|
|||||||
|
|
||||||
info = g_malloc0(sizeof(*info));
|
info = g_malloc0(sizeof(*info));
|
||||||
info->name = g_strdup(object_class_get_name(klass));
|
info->name = g_strdup(object_class_get_name(klass));
|
||||||
|
info->has_abstract = info->abstract = object_class_is_abstract(klass);
|
||||||
|
|
||||||
e = g_malloc0(sizeof(*e));
|
e = g_malloc0(sizeof(*e));
|
||||||
e->value = info;
|
e->value = info;
|
||||||
|
@ -103,6 +103,33 @@ static void test_device_intro_list(void)
|
|||||||
qtest_end();
|
qtest_end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_qom_list_fields(void)
|
||||||
|
{
|
||||||
|
QList *all_types;
|
||||||
|
QList *non_abstract;
|
||||||
|
QListEntry *e;
|
||||||
|
|
||||||
|
qtest_start(common_args);
|
||||||
|
|
||||||
|
all_types = qom_list_types(NULL, true);
|
||||||
|
non_abstract = qom_list_types(NULL, false);
|
||||||
|
|
||||||
|
QLIST_FOREACH_ENTRY(all_types, e) {
|
||||||
|
QDict *d = qobject_to_qdict(qlist_entry_obj(e));
|
||||||
|
const char *name = qdict_get_str(d, "name");
|
||||||
|
bool abstract = qdict_haskey(d, "abstract") ?
|
||||||
|
qdict_get_bool(d, "abstract") :
|
||||||
|
false;
|
||||||
|
bool expected_abstract = !type_list_find(non_abstract, name);
|
||||||
|
|
||||||
|
g_assert(abstract == expected_abstract);
|
||||||
|
}
|
||||||
|
|
||||||
|
QDECREF(all_types);
|
||||||
|
QDECREF(non_abstract);
|
||||||
|
qtest_end();
|
||||||
|
}
|
||||||
|
|
||||||
static void test_device_intro_none(void)
|
static void test_device_intro_none(void)
|
||||||
{
|
{
|
||||||
qtest_start(common_args);
|
qtest_start(common_args);
|
||||||
@ -144,25 +171,24 @@ static void test_abstract_interfaces(void)
|
|||||||
QListEntry *e;
|
QListEntry *e;
|
||||||
|
|
||||||
qtest_start(common_args);
|
qtest_start(common_args);
|
||||||
/* qom-list-types implements=interface would return any type
|
/*
|
||||||
* that implements _any_ interface (not just interface types),
|
* qom-list-types implements=interface returns all types that
|
||||||
* so use a trick to find the interface type names:
|
* implement _any_ interface (not just interface types), but
|
||||||
* - list all object types
|
* we can filter them out because interfaces don't implement
|
||||||
* - list all types, and look for items that are not
|
* the "object" type.
|
||||||
* on the first list
|
|
||||||
*/
|
*/
|
||||||
all_types = qom_list_types(NULL, false);
|
all_types = qom_list_types("interface", true);
|
||||||
obj_types = qom_list_types("object", false);
|
obj_types = qom_list_types("object", true);
|
||||||
|
|
||||||
QLIST_FOREACH_ENTRY(all_types, e) {
|
QLIST_FOREACH_ENTRY(all_types, e) {
|
||||||
QDict *d = qobject_to_qdict(qlist_entry_obj(e));
|
QDict *d = qobject_to_qdict(qlist_entry_obj(e));
|
||||||
|
|
||||||
/*
|
if (type_list_find(obj_types, qdict_get_str(d, "name"))) {
|
||||||
* An interface (incorrectly) marked as non-abstract would
|
/* Not an interface type */
|
||||||
* appear on all_types, but not on obj_types:
|
continue;
|
||||||
*/
|
}
|
||||||
g_assert(type_list_find(obj_types, qdict_get_str(d, "name")));
|
|
||||||
|
|
||||||
|
g_assert(qdict_haskey(d, "abstract") && qdict_get_bool(d, "abstract"));
|
||||||
}
|
}
|
||||||
|
|
||||||
QDECREF(all_types);
|
QDECREF(all_types);
|
||||||
@ -175,6 +201,7 @@ int main(int argc, char **argv)
|
|||||||
g_test_init(&argc, &argv, NULL);
|
g_test_init(&argc, &argv, NULL);
|
||||||
|
|
||||||
qtest_add_func("device/introspect/list", test_device_intro_list);
|
qtest_add_func("device/introspect/list", test_device_intro_list);
|
||||||
|
qtest_add_func("device/introspect/list-fields", test_qom_list_fields);
|
||||||
qtest_add_func("device/introspect/none", test_device_intro_none);
|
qtest_add_func("device/introspect/none", test_device_intro_none);
|
||||||
qtest_add_func("device/introspect/abstract", test_device_intro_abstract);
|
qtest_add_func("device/introspect/abstract", test_device_intro_abstract);
|
||||||
qtest_add_func("device/introspect/concrete", test_device_intro_concrete);
|
qtest_add_func("device/introspect/concrete", test_device_intro_concrete);
|
||||||
|
Loading…
Reference in New Issue
Block a user