[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH V2 3/5] tests/qtest/qom-test: unit test for qom-tree-get
From: |
Steve Sistare |
Subject: |
[PATCH V2 3/5] tests/qtest/qom-test: unit test for qom-tree-get |
Date: |
Mon, 12 May 2025 06:47:13 -0700 |
Add a unit test for qom-tree-get
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
tests/qtest/qom-test.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
diff --git a/tests/qtest/qom-test.c b/tests/qtest/qom-test.c
index 27d70bc..d8792bd 100644
--- a/tests/qtest/qom-test.c
+++ b/tests/qtest/qom-test.c
@@ -16,6 +16,54 @@
static int verbosity_level;
+static void test_tree_node(QDict *node)
+{
+ QDict *prop, *child;
+ QList *props, *children;
+ QListEntry *entry;
+
+ g_assert(qdict_haskey(node, "name"));
+ g_assert(qdict_haskey(node, "properties"));
+
+ if (verbosity_level >= 3) {
+ g_test_message("%s", qdict_get_str(node, "name"));
+ }
+
+ props = qobject_to(QList, qdict_get(node, "properties"));
+ QLIST_FOREACH_ENTRY(props, entry) {
+ prop = qobject_to(QDict, qlist_entry_obj(entry));
+ g_assert(qdict_haskey(prop, "name"));
+ g_assert(qdict_haskey(prop, "type"));
+ }
+
+ if (!qdict_haskey(node, "children")) {
+ return;
+ }
+
+ children = qobject_to(QList, qdict_get(node, "children"));
+ QLIST_FOREACH_ENTRY(children, entry) {
+ child = qobject_to(QDict, qlist_entry_obj(entry));
+ test_tree_node(child);
+ }
+}
+
+static void test_tree(QTestState *qts, const char *path)
+{
+ g_autoptr(QDict) response = NULL;
+ QDict *node;
+
+ if (verbosity_level >= 2) {
+ g_test_message("Obtaining tree at %s", path);
+ }
+ response = qtest_qmp(qts, "{ 'execute': 'qom-tree-get',"
+ " 'arguments': { 'path': %s } }", path);
+ g_assert(response);
+
+ g_assert(qdict_haskey(response, "return"));
+ node = qobject_to(QDict, qdict_get(response, "return"));
+ test_tree_node(node);
+}
+
static void test_properties(QTestState *qts, const char *path, bool recurse)
{
char *child_path;
@@ -100,6 +148,7 @@ static void test_machine(gconstpointer data)
}
test_properties(qts, "/machine", true);
+ test_tree(qts, "/machine");
response = qtest_qmp(qts, "{ 'execute': 'quit' }");
g_assert(qdict_haskey(response, "return"));
--
1.8.3.1