From nobody Sat Nov 15 12:18:14 2025 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=1752506043; cv=none; d=zohomail.com; s=zohoarc; b=HJu1dW8U54VjvW/0LvLOCLYrjTZyG9xPYaSigXGVSgLpPsvw3ZUs+BJIfdRNEvTibcl82bpTZnEmcDnd10Vi3ZB6pXPWfAdhhMCpY3awPfWeMwdMvOY82Po9l9gy9B2C7URcVrQlJhaxgxi7RJc95ZqsCrC7tBEvduodSBWL1Os= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752506043; 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=I7HHDjdxFdMzPaAdUoWmAmkFEVUaW8PBBDWsg7Z3n6M=; b=fTZU2P5hzO+letebyVInBHGQQYexwnRLnyUe2cPSYOX2tiRioYbAJCycGG8bpmdgzeERDj+16SI01q8JMrHs+da2u9CueVbv84ImFigsG0iVal3fZsDXPt3jiLJTl/2ns+vfXNIquprHKsTBWJUNYW0SW4FyK8+VmK74fNbrj68= 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752506043308538.9440082778854; Mon, 14 Jul 2025 08:14:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubKqC-0005TP-Gx; Mon, 14 Jul 2025 11:11:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubJUu-0000TC-Pc for qemu-devel@nongnu.org; Mon, 14 Jul 2025 09:45:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubJUd-0003eb-DK for qemu-devel@nongnu.org; Mon, 14 Jul 2025 09:45:36 -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-609-jFQ9ZYBqMO-t96nP7_6YIA-1; Mon, 14 Jul 2025 09:45:11 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 95D4E1955F08; Mon, 14 Jul 2025 13:45:09 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.45.242.6]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 053D01956094; Mon, 14 Jul 2025 13:45:09 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 4045221E60FF; Mon, 14 Jul 2025 15:44:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752500716; 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=I7HHDjdxFdMzPaAdUoWmAmkFEVUaW8PBBDWsg7Z3n6M=; b=PzwFVzCPTH3HcQJ39aYWGZqft9qfT0Imjcf3MDCQCEcsbtVgAI0KwpsH2XUnnJcCDCzqBA ztgoZIBcKwn70KEtudFjkdXnNgqpAnY8ui3lxQGX91YbcIplXQwdcDly8v2VpD4W1ePKWg yquTKSaT1LulnEs0NGXHxZs2egGEtSw= X-MC-Unique: jFQ9ZYBqMO-t96nP7_6YIA-1 X-Mimecast-MFC-AGG-ID: jFQ9ZYBqMO-t96nP7_6YIA_1752500709 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, Steve Sistare , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 32/32] tests/qtest/qom-test: unit test for qom-list-get Date: Mon, 14 Jul 2025 15:44:58 +0200 Message-ID: <20250714134458.2991097-33-armbru@redhat.com> In-Reply-To: <20250714134458.2991097-1-armbru@redhat.com> References: <20250714134458.2991097-1-armbru@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 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=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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: 1752506044696116600 From: Steve Sistare Add a unit test for qom-list-get. Signed-off-by: Steve Sistare Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Markus Armbruster Message-ID: <1752248703-217318-4-git-send-email-steven.sistare@oracle.com> Signed-off-by: Markus Armbruster --- tests/qtest/qom-test.c | 116 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 115 insertions(+), 1 deletion(-) diff --git a/tests/qtest/qom-test.c b/tests/qtest/qom-test.c index 27d70bc11c..4ade1c728c 100644 --- a/tests/qtest/qom-test.c +++ b/tests/qtest/qom-test.c @@ -11,11 +11,119 @@ =20 #include "qobject/qdict.h" #include "qobject/qlist.h" +#include "qobject/qstring.h" #include "qemu/cutils.h" #include "libqtest.h" =20 +#define RAM_NAME "node0" +#define RAM_SIZE 65536 + static int verbosity_level; =20 +/* + * Verify that the /object/RAM_NAME 'size' property is RAM_SIZE. + */ +static void test_list_get_value(QTestState *qts) +{ + QDict *args =3D qdict_new(); + g_autoptr(QDict) response =3D NULL; + g_autoptr(QList) paths =3D qlist_new(); + QListEntry *entry, *prop_entry; + const char *prop_name; + QList *properties, *return_list; + QDict *obj; + + qlist_append_str(paths, "/objects/" RAM_NAME); + qdict_put_obj(args, "paths", QOBJECT(qlist_copy(paths))); + response =3D qtest_qmp(qts, "{ 'execute': 'qom-list-get'," + " 'arguments': %p }", args); + g_assert(response); + g_assert(qdict_haskey(response, "return")); + return_list =3D qobject_to(QList, qdict_get(response, "return")); + + entry =3D QTAILQ_FIRST(&return_list->head); + obj =3D qobject_to(QDict, qlist_entry_obj(entry)); + g_assert(qdict_haskey(obj, "properties")); + properties =3D qobject_to(QList, qdict_get(obj, "properties")); + + QLIST_FOREACH_ENTRY(properties, prop_entry) { + QDict *prop =3D qobject_to(QDict, qlist_entry_obj(prop_entry)); + + g_assert(qdict_haskey(prop, "name")); + g_assert(qdict_haskey(prop, "value")); + + prop_name =3D qdict_get_str(prop, "name"); + if (!strcmp(prop_name, "type")) { + g_assert_cmpstr(qdict_get_str(prop, "value"), =3D=3D, + "memory-backend-ram"); + + } else if (!strcmp(prop_name, "size")) { + g_assert_cmpint(qdict_get_int(prop, "value"), =3D=3D, RAM_SIZE= ); + } + } +} + +static void test_list_get(QTestState *qts, QList *paths) +{ + QListEntry *entry, *prop_entry, *path_entry; + g_autoptr(QDict) response =3D NULL; + QDict *args =3D qdict_new(); + QDict *prop; + QList *return_list; + + if (verbosity_level >=3D 2) { + g_test_message("Obtaining properties for paths:"); + QLIST_FOREACH_ENTRY(paths, path_entry) { + QString *qstr =3D qobject_to(QString, qlist_entry_obj(path_ent= ry)); + g_test_message(" %s", qstring_get_str(qstr)); + } + } + + qdict_put_obj(args, "paths", QOBJECT(qlist_copy(paths))); + response =3D qtest_qmp(qts, "{ 'execute': 'qom-list-get'," + " 'arguments': %p }", args); + g_assert(response); + g_assert(qdict_haskey(response, "return")); + return_list =3D qobject_to(QList, qdict_get(response, "return")); + g_assert(!qlist_empty(return_list)); + + path_entry =3D QTAILQ_FIRST(&paths->head); + QLIST_FOREACH_ENTRY(return_list, entry) { + QDict *obj =3D qobject_to(QDict, qlist_entry_obj(entry)); + g_assert(qdict_haskey(obj, "properties")); + QList *properties =3D qobject_to(QList, qdict_get(obj, "properties= ")); + bool has_child =3D false; + + QLIST_FOREACH_ENTRY(properties, prop_entry) { + prop =3D qobject_to(QDict, qlist_entry_obj(prop_entry)); + g_assert(qdict_haskey(prop, "name")); + g_assert(qdict_haskey(prop, "type")); + has_child |=3D strstart(qdict_get_str(prop, "type"), "child<",= NULL); + } + + if (has_child) { + /* build a list of child paths */ + QString *qstr =3D qobject_to(QString, qlist_entry_obj(path_ent= ry)); + const char *path =3D qstring_get_str(qstr); + g_autoptr(QList) child_paths =3D qlist_new(); + + QLIST_FOREACH_ENTRY(properties, prop_entry) { + prop =3D qobject_to(QDict, qlist_entry_obj(prop_entry)); + if (strstart(qdict_get_str(prop, "type"), "child<", NULL))= { + g_autofree char *child_path =3D g_strdup_printf( + "%s/%s", path, qdict_get_str(prop, "name")); + qlist_append_str(child_paths, child_path); + } + } + + /* fetch props for all children with one qom-list-get call */ + test_list_get(qts, child_paths); + } + + path_entry =3D QTAILQ_NEXT(path_entry, next); + } +} + static void test_properties(QTestState *qts, const char *path, bool recurs= e) { char *child_path; @@ -85,8 +193,10 @@ static void test_machine(gconstpointer data) const char *machine =3D data; QDict *response; QTestState *qts; + g_autoptr(QList) paths =3D qlist_new(); =20 - qts =3D qtest_initf("-machine %s", machine); + qts =3D qtest_initf("-machine %s -object memory-backend-ram,id=3D%s,si= ze=3D%d", + machine, RAM_NAME, RAM_SIZE); =20 if (g_test_slow()) { /* Make sure we can get the machine class properties: */ @@ -101,6 +211,10 @@ static void test_machine(gconstpointer data) =20 test_properties(qts, "/machine", true); =20 + qlist_append_str(paths, "/machine"); + test_list_get(qts, paths); + test_list_get_value(qts); + response =3D qtest_qmp(qts, "{ 'execute': 'quit' }"); g_assert(qdict_haskey(response, "return")); qobject_unref(response); --=20 2.49.0