From nobody Wed Aug 26 14:17:18 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1779314175; cv=none; d=zohomail.com; s=zohoarc; b=SqNDTVPq7FlsleX6YRu7pvnGcv/HBobYh6QFInytjqD0S45TnA1iwU1THP/QCz8QaT6f2h+23v+FHEQUWD5Xk+92dbmE5aJD4mXvW8B096U+2dGngPLEOrQBTe4vbrQmDWiCO4hiirqo2hgn2cMVTjr8orE8pO2WciO14jI06bk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779314175; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=fRPtQELqolxkJtRA6vnIe5NUc3hcSq+toynCIGwIkSk=; b=byJCV9Cuo6//JubWOsgu/XvjiZcml+Y3+x9eERpD6WtIgrXMNtQOhresfYbHybJ1nMsblYYz57K7fckNH8pLJswkKWPGhKoVbw93xX/CAba2JmwTycGJSrxgRVHA82Rhw0FUf8Q8rIQP/Tlihq9L407H88JczDDHNli56GHxRcU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779314175124939.785449474952; Wed, 20 May 2026 14:56:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wPorb-0000cF-O0; Wed, 20 May 2026 17:54:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wPoqi-0007bj-PC for qemu-devel@nongnu.org; Wed, 20 May 2026 17:53:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wPoqg-0004y7-HY for qemu-devel@nongnu.org; Wed, 20 May 2026 17:53:08 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-160-_GE0mzQRM9qjbj1qj3dzrQ-1; Wed, 20 May 2026 17:53:04 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9DB41195608E for ; Wed, 20 May 2026 21:53:03 +0000 (UTC) Received: from localhost (unknown [10.44.24.26]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 804811800465; Wed, 20 May 2026 21:53:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779313986; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fRPtQELqolxkJtRA6vnIe5NUc3hcSq+toynCIGwIkSk=; b=LXBtVAGG/SVlei4QH0/Q8VRRoqkFD/RqI6ZBHWzuNdHK3RBXHq28CTMORC1GxxU0celbdW i6Wl9Zh2lPWimI3dcqpp2k7+zq4ePrFUI4NlD2Cwf8OJjHTjGElz9pB3vvt6EFeZyG4Pwr fSCwf+QPpb1zru1UEEkWH7XOrE+VFQs= X-MC-Unique: _GE0mzQRM9qjbj1qj3dzrQ-1 X-Mimecast-MFC-AGG-ID: _GE0mzQRM9qjbj1qj3dzrQ_1779313983 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 21 May 2026 01:49:31 +0400 Subject: [PATCH 30/40] tests/qtest/device-introspect-test: fix test without HMP MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260521-qemu-no-hmp-v1-30-d104f809e145@redhat.com> References: <20260521-qemu-no-hmp-v1-0-d104f809e145@redhat.com> In-Reply-To: <20260521-qemu-no-hmp-v1-0-d104f809e145@redhat.com> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Developer-Signature: v=1; a=openpgp-sha256; l=7498; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=/JxQv6h3FUqjsdGwFy0SeHfp3oZCxzfgsDm04W8itkE=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqDiyEvyi6wX6t3QC8ySVOtpVgcIoTm1LgDIlGL qtspRZhoaOJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCag4shAAKCRDa6OEJdZac 5YfwD/9v2JZt6StUTHSbHBV0GgHoE8D1/ByKNJQPEIqd1XRHtYFACluZj69wzcHyFtrR75coRRR EoOgvuT4rox4EpQjIrgY7iZvj7+vNb0heTwABfQtw99HbkfNpPdzDNf/FlbMKZKzso/CP3jtemr XB5OmM2AHwNdJwd5S0X/2ysj2jCjCHMaCM5G7m1epThw05pdSsGUckANWLtipB/5dWtvIgh2+vl JrE2pkRADY0IkUm+IUQOs+YW1jQ7dr41D0z1Fe7EgaUS7VEtIg9aRc0UyTNIFFSLOwRTFt0BLd3 hO+6K72LOJHc+LpNny0Jy5YYCZJ/PbEkamFCnJoh+Mdac90aIxnQXgagiCUUSbypHvJ5oUUU4xj YIoL46LLBbXnprRQrEEWdWzXYzahGEzOZw7V6VHf/y+okIzs3w0pnHFC27yosh4D/up4vpWo3q5 RMeLo5d3nA2Bb+WRPkRWT+Q5GytFpUDQxnzWt45MdND8Od2nKfLGqTk5W0+TfLhDphOvTN3FvsV BCFocXMjor2Pzp86cNTTQ3vwN1EuG1KTPMoTYsKaV9esFPasdh7mqBohQMvVZ0niqNxnH7SY7so OH+/QK7bGx7TuLrdhi811LG6BnnN9kgvACrvDqlvEYUe1aQYCdywV8TxhtN5Taa3uHgLRGZKrCp I422op5L88vJcYQ== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1779314176200158500 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=C3=A9 Lureau --- tests/qtest/device-introspect-test.c | 111 +++++++++++++++++++++++++++----= ---- 1 file changed, 88 insertions(+), 23 deletions(-) diff --git a/tests/qtest/device-introspect-test.c b/tests/qtest/device-intr= ospect-test.c index f84cec51dc2..f6eca2c8eb7 100644 --- a/tests/qtest/device-introspect-test.c +++ b/tests/qtest/device-introspect-test.c @@ -11,10 +11,10 @@ */ =20 /* - * Covers QMP device-list-properties and HMP device_add help. We - * currently don't check that their output makes sense, only that QEMU - * survives. Useful since we've had an astounding number of crash - * bugs around here. + * Covers QMP device-list-properties and HMP device_add help (if + * CONFIG_HMP). We currently don't check that the output makes sense, + * only that QEMU survives. Useful since we've had an astounding + * number of crash bugs around here. */ =20 #include "qemu/osdep.h" @@ -100,11 +100,60 @@ static QList *device_type_list(QTestState *qts, bool = abstract) return qom_list_types(qts, "device", abstract); } =20 +/* + * 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 *resu= lt) +{ + QDict *resp; + QList *list; + QListEntry *e; + GList *children =3D NULL; + + resp =3D qtest_qmp(qts, "{'execute': 'qom-list'," + " 'arguments': {'path': %s}}", path); + g_assert(qdict_haskey(resp, "return")); + list =3D qdict_get_qlist(resp, "return"); + + QLIST_FOREACH_ENTRY(list, e) { + QDict *prop =3D qobject_to(QDict, qlist_entry_obj(e)); + const char *type =3D qdict_get_str(prop, "type"); + if (g_str_has_prefix(type, "child<")) { + const char *name =3D qdict_get_str(prop, "name"); + children =3D g_list_prepend(children, g_strdup(name)); + } + } + + children =3D g_list_sort_with_data(children, (GCompareDataFunc)g_strcm= p0, + NULL); + + for (GList *l =3D children; l; l =3D l->next) { + const char *name =3D l->data; + g_autofree char *child_path =3D (!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 =3D g_string_new(""); + qom_tree_walk(qts, "/", result); + return g_string_free(result, FALSE); +} + static void test_one_device(QTestState *qts, const char *type) { QDict *resp; - char *help, *escaped; - GRegex *comma; =20 g_test_message("Testing device '%s'", type); =20 @@ -113,19 +162,21 @@ static void test_one_device(QTestState *qts, const ch= ar *type) type); qobject_unref(resp); =20 - comma =3D g_regex_new(",", 0, 0, NULL); - escaped =3D g_regex_replace_literal(comma, type, -1, 0, ",,", 0, NULL); - g_regex_unref(comma); +#ifdef CONFIG_HMP + { + g_autofree char *escaped =3D NULL; + g_autoptr(GRegex) comma =3D NULL; =20 - help =3D qtest_hmp(qts, "device_add \"%s,help\"", escaped); - g_free(help); - g_free(escaped); + comma =3D g_regex_new(",", 0, 0, NULL); + escaped =3D g_regex_replace_literal(comma, type, -1, 0, ",,", 0, N= ULL); + g_free(qtest_hmp(qts, "device_add \"%s,help\"", escaped)); + } +#endif } =20 static void test_device_intro_list(void) { QList *types; - char *help; QTestState *qts; =20 qts =3D qtest_init(common_args); @@ -133,8 +184,11 @@ static void test_device_intro_list(void) types =3D device_type_list(qts, true); qobject_unref(types); =20 - help =3D qtest_hmp(qts, "device_add help"); - g_free(help); +#ifdef CONFIG_HMP + { + g_free(qtest_hmp(qts, "device_add help")); + } +#endif =20 qtest_quit(qts); } @@ -198,18 +252,22 @@ static void test_qom_list_fields(void) static void test_device_intro_none(void) { QTestState *qts =3D qtest_init(common_args); - g_autofree char *qom_tree_start =3D qtest_hmp(qts, "info qom-tree"); + g_autofree char *qom_tree_start =3D qom_tree_str(qts); g_autofree char *qom_tree_end =3D NULL; +#ifdef CONFIG_HMP g_autofree char *qtree_start =3D qtest_hmp(qts, "info qtree"); g_autofree char *qtree_end =3D NULL; +#endif =20 test_one_device(qts, "nonexistent"); =20 /* Make sure that really nothing changed in the trees */ - qom_tree_end =3D qtest_hmp(qts, "info qom-tree"); + qom_tree_end =3D qom_tree_str(qts); g_assert_cmpstr(qom_tree_start, =3D=3D, qom_tree_end); +#ifdef CONFIG_HMP qtree_end =3D qtest_hmp(qts, "info qtree"); g_assert_cmpstr(qtree_start, =3D=3D, qtree_end); +#endif =20 qtest_quit(qts); } @@ -217,18 +275,22 @@ static void test_device_intro_none(void) static void test_device_intro_abstract(void) { QTestState *qts =3D qtest_init(common_args); - g_autofree char *qom_tree_start =3D qtest_hmp(qts, "info qom-tree"); + g_autofree char *qom_tree_start =3D qom_tree_str(qts); g_autofree char *qom_tree_end =3D NULL; +#ifdef CONFIG_HMP g_autofree char *qtree_start =3D qtest_hmp(qts, "info qtree"); g_autofree char *qtree_end =3D NULL; +#endif =20 test_one_device(qts, "device"); =20 /* Make sure that really nothing changed in the trees */ - qom_tree_end =3D qtest_hmp(qts, "info qom-tree"); + qom_tree_end =3D qom_tree_str(qts); g_assert_cmpstr(qom_tree_start, =3D=3D, qom_tree_end); +#ifdef CONFIG_HMP qtree_end =3D qtest_hmp(qts, "info qtree"); g_assert_cmpstr(qtree_start, =3D=3D, qtree_end); +#endif =20 qtest_quit(qts); } @@ -239,10 +301,12 @@ static void test_device_intro_concrete(const void *ar= gs) QListEntry *entry; const char *type; QTestState *qts =3D qtest_init(args); - g_autofree char *qom_tree_start =3D qtest_hmp(qts, "info qom-tree"); + g_autofree char *qom_tree_start =3D qom_tree_str(qts); g_autofree char *qom_tree_end =3D NULL; +#ifdef CONFIG_HMP g_autofree char *qtree_start =3D qtest_hmp(qts, "info qtree"); g_autofree char *qtree_end =3D NULL; +#endif =20 types =3D device_type_list(qts, false); =20 @@ -255,14 +319,15 @@ static void test_device_intro_concrete(const void *ar= gs) =20 /* * Some devices leave dangling pointers in QOM behind. - * "info qom-tree" or "info qtree" have a good chance at crashing then. + * Walking the QOM tree via qom-list has a good chance at crashing the= n. * Also make sure that the tree did not change. */ - qom_tree_end =3D qtest_hmp(qts, "info qom-tree"); + qom_tree_end =3D qom_tree_str(qts); g_assert_cmpstr(qom_tree_start, =3D=3D, qom_tree_end); - +#ifdef CONFIG_HMP qtree_end =3D qtest_hmp(qts, "info qtree"); g_assert_cmpstr(qtree_start, =3D=3D, qtree_end); +#endif =20 qobject_unref(types); qtest_quit(qts); --=20 2.54.0