summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEduardo Habkost2017-07-07 14:22:13 +0200
committerEduardo Habkost2017-07-17 20:41:30 +0200
commitdbb2a604a94f3899fa34bd1ede462f213e822e03 (patch)
tree923696b1d5d92bb4e108e4fa4b999d0a8be12839
parenti386: add Skylake-Server cpu model (diff)
downloadqemu-dbb2a604a94f3899fa34bd1ede462f213e822e03.tar.gz
qemu-dbb2a604a94f3899fa34bd1ede462f213e822e03.tar.xz
qemu-dbb2a604a94f3899fa34bd1ede462f213e822e03.zip
tests: Simplify abstract-interfaces check with a helper
Add a new type_list_find() helper to device-introspect-test.c, to simplify the code at test_abstract_interfaces(). Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> Message-Id: <20170707122215.8819-2-ehabkost@redhat.com> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
-rw-r--r--tests/device-introspect-test.c43
1 files changed, 25 insertions, 18 deletions
diff --git a/tests/device-introspect-test.c b/tests/device-introspect-test.c
index b1abb2ad89..f1e6dddfa3 100644
--- a/tests/device-introspect-test.c
+++ b/tests/device-introspect-test.c
@@ -45,6 +45,22 @@ static QList *qom_list_types(const char *implements, bool abstract)
return ret;
}
+/* Find an entry on a list returned by qom-list-types */
+static QDict *type_list_find(QList *types, const char *name)
+{
+ QListEntry *e;
+
+ QLIST_FOREACH_ENTRY(types, e) {
+ QDict *d = qobject_to_qdict(qlist_entry_obj(e));
+ const char *ename = qdict_get_str(d, "name");
+ if (!strcmp(ename, name)) {
+ return d;
+ }
+ }
+
+ return NULL;
+}
+
static QList *device_type_list(bool abstract)
{
return qom_list_types("device", abstract);
@@ -125,7 +141,7 @@ static void test_abstract_interfaces(void)
{
QList *all_types;
QList *obj_types;
- QListEntry *ae;
+ QListEntry *e;
qtest_start(common_args);
/* qom-list-types implements=interface would return any type
@@ -138,24 +154,15 @@ static void test_abstract_interfaces(void)
all_types = qom_list_types(NULL, false);
obj_types = qom_list_types("object", false);
- QLIST_FOREACH_ENTRY(all_types, ae) {
- QDict *at = qobject_to_qdict(qlist_entry_obj(ae));
- const char *aname = qdict_get_str(at, "name");
- QListEntry *oe;
- const char *found = NULL;
-
- QLIST_FOREACH_ENTRY(obj_types, oe) {
- QDict *ot = qobject_to_qdict(qlist_entry_obj(oe));
- const char *oname = qdict_get_str(ot, "name");
- if (!strcmp(aname, oname)) {
- found = oname;
- break;
- }
- }
+ QLIST_FOREACH_ENTRY(all_types, e) {
+ QDict *d = qobject_to_qdict(qlist_entry_obj(e));
+
+ /*
+ * An interface (incorrectly) marked as non-abstract would
+ * appear on all_types, but not on obj_types:
+ */
+ g_assert(type_list_find(obj_types, qdict_get_str(d, "name")));
- /* Using g_assert_cmpstr() will give more useful failure
- * messages than g_assert(found) */
- g_assert_cmpstr(aname, ==, found);
}
QDECREF(all_types);