On 25/8/26 21:09, Marc-André Lureau wrote:
Replace "info qom-tree" with recursive qom-list walk.
Disable HMP-only code paths, info qtree, kinda duplicating the test.
Signed-off-by: Marc-André Lureau <[email protected]>
---
tests/qtest/device-introspect-test.c | 111 +++++++++++++++++++++++++++--------
1 file changed, 88 insertions(+), 23 deletions(-)
@@ -100,11 +100,60 @@ static QList *device_type_list(QTestState *qts, bool
abstract)
return qom_list_types(qts, "device", abstract);
}
+/*
+ * Recursively walk the QOM composition tree via qom-list and build a
+ * string representation. This serves two purposes: detecting dangling
+ * pointers (qom-list would crash QEMU) and detecting leaked objects
+ * (by comparing the output before and after device introspection).
+ */
+static void qom_tree_walk(QTestState *qts, const char *path, GString *result)
+{
+ QDict *resp;
+ QList *list;
+ QListEntry *e;
+ GList *children = NULL;
+
+ resp = qtest_qmp(qts, "{'execute': 'qom-list',"
+ " 'arguments': {'path': %s}}", path);
+ g_assert(qdict_haskey(resp, "return"));
+ list = qdict_get_qlist(resp, "return");
+
+ QLIST_FOREACH_ENTRY(list, e) {
+ QDict *prop = qobject_to(QDict, qlist_entry_obj(e));
+ const char *type = qdict_get_str(prop, "type");
+ if (g_str_has_prefix(type, "child<")) {
+ const char *name = qdict_get_str(prop, "name");
+ children = g_list_prepend(children, g_strdup(name));
+ }
+ }
+
+ children = g_list_sort_with_data(children, (GCompareDataFunc)g_strcmp0,
+ NULL);
+
+ for (GList *l = children; l; l = l->next) {
+ const char *name = l->data;
+ g_autofree char *child_path = (!strcmp(path, "/"))
+ ? g_strdup_printf("/%s", name)
+ : g_strdup_printf("%s/%s", path, name);
+
+ g_string_append_printf(result, "%s\n", child_path);
+ qom_tree_walk(qts, child_path, result);
+ }
+
+ g_list_free_full(children, g_free);
+ qobject_unref(resp);
+}
+
+static char *qom_tree_str(QTestState *qts)
+{
+ GString *result = g_string_new("");
+ qom_tree_walk(qts, "/", result);
+ return g_string_free(result, FALSE);
+}
Please split in 2 patches, refactor adding qom_tree_* first,
then restrict with CONFIG_HMP next. No need to repost, for both
patches:
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
That said your new method could be used in test_properties() in
tests/qtest/qom-test.c and test_object_rng() / test_docs_config_ich9()
in tests/qtest/readconfig-test.c. Left as future cleanup.