Skip to contentSkip to conversation

fast qom tree get

PATCH Superseded Steve Sistare 4 participants 15 messages Jul 8, 2025 – Jul 10, 2025

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover fast qom tree get

Using qom-list and qom-get to get all the nodes and property values in a QOM tree can take multiple seconds because it requires 1000's of individual QOM requests. Some managers fetch the entire tree or a large subset of it when starting a new VM, and this cost is a substantial fraction of start up time.

To reduce this cost, consider QAPI calls that fetch more information in each call:
* qom-list-get: given a path, return a list of properties and values.
* qom-list-getv: given a list of paths, return a list of properties and values for each path.
* qom-tree-get: given a path, return all descendant nodes rooted at that path, with properties and values for each.

In all cases, a returned property is represented by ObjectPropertyValue, with fields name, type, and value. If an error occurs when reading a value the value field is omitted. Thus an error for one property will not cause a bulk fetch operation to fail.

To evaluate each method, I modified scripts/qmp/qom-tree to use the method, verified all methods produce the same output, and timed each using:

  qemu-system-x86_64 -display none \
    -chardev socket,id=monitor0,path=/tmp/vm1.sock,server=on,wait=off \
    -mon monitor0,mode=control &

time qom-tree -s /tmp/vm1.sock > /dev/null

I only measured once per method, but the variation is low after a warm up run. The 'real - user - sys' column is a proxy for QEMU CPU time.

method               real(s)   user(s)   sys(s)  (real - user - sys)(s)
qom-list / qom-get   2.048     0.932     0.057   1.059
qom-list-get         0.402     0.230     0.029   0.143
qom-list-getv        0.200     0.132     0.015   0.053
qom-tree-get         0.143     0.123     0.012   0.008

qom-tree-get is the fastest, reducing elapsed time by a factor of 14X, and reducing QEMU CPU time by 132X.

qom-list-getv is slower when fetching the entire tree, but can beat qom-tree-get when only a subset of the tree needs to be fetched (not shown). To keep things simple, provide only qom-list-getv.

Changes in V3:
* dropped qom-tree-get
* modified the qom-tree script to use qom-list-getv
* cosmetic changes in the docs and code.

Changes in V2:
* removed "qom: qom_resolve_path", which was pulled separately
* dropped the error member
* fixed missing _list_tree in qom.py
* updated 10.0 to 10.1

Steve Sistare (3):
qom: qom-list-getv
python: use qom-list-getv tests/qtest/qom-test: unit test for qom-list-getv

 python/qemu/utils/qom.py        | 43 +++++++++++++++------------
 python/qemu/utils/qom_common.py | 53 ++++++++++++++++++++++++++++++++++
 qapi/qom.json                   | 50 ++++++++++++++++++++++++++++++++
 qom/qom-qmp-cmds.c              | 53 ++++++++++++++++++++++++++++++++++
 tests/qtest/qom-test.c          | 64 +++++++++++++++++++++++++++++++++++++++++
 5 files changed, 245 insertions(+), 18 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v3 1/3 qom: qom-list-getv

Define the qom-list-getv command, which fetches all the properties and values for a list of paths. This is faster than qom-tree-get when fetching a subset of the QOM tree. See qom.json for details.

---
 qapi/qom.json      | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 qom/qom-qmp-cmds.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 103 insertions(+)
qapi/qom.json +50 -0
index b133b06..c16c2dd 100644
@@ -46,6 +46,34 @@
             '*default-value': 'any' } }
 
 ##
+# @ObjectPropertyValue:
+#
+# @name: the name of the property
+#
+# @type: the type of the property, as described in @ObjectPropertyInfo
+#
+# @value: the value of the property.  Absent when the property cannot
+#     be read.
+#
+# Since 10.1
+##
+{ 'struct': 'ObjectPropertyValue',
+  'data': { 'name': 'str',
+            'type': 'str',
+            '*value': 'any' } }
+
+##
+# @ObjectPropertiesValues:
+#
+# @properties: a list of properties.
+#
+# Since 10.1
+##
+{ 'struct': 'ObjectPropertiesValues',
+  'data': { 'properties': [ 'ObjectPropertyValue' ] }}
+
+
+##
 # @qom-list:
 #
 # This command will list any properties of a object given a path in
@@ -126,6 +154,28 @@
   'allow-preconfig': true }
 
 ##
+# @qom-list-getv:
+#
+# List properties and their values for each object path in the input
+# list.
+#
+# @paths: The absolute or partial path for each object, as described
+#     in @qom-get
+#
+# Errors:
+#     - If any path is not valid or is ambiguous
+#
+# Returns: A list of @ObjectPropertiesValues.  Each element contains
+#     the properties of the corresponding element in @paths.
+#
+# Since 10.1
+##
+{ 'command': 'qom-list-getv',
+  'data': { 'paths': [ 'str' ] },
+  'returns': [ 'ObjectPropertiesValues' ],
+  'allow-preconfig': true }
+
+##
 # @qom-set:
 #
 # This command will set a property from a object model path.
qom/qom-qmp-cmds.c +53 -0

59 lines not on this page · raw message

Signature · 1 line
1.8.3.1
Reviewed-by on v3 1/3
#2 lore raw

Re: [PATCH V3 1/3] qom: qom-list-getv

Quoted 9 lines · Steve Sistare

Define the qom-list-getv command, which fetches all the properties and values for a list of paths. This is faster than qom-tree-get when fetching a subset of the QOM tree. See qom.json for details.

---
  qapi/qom.json      | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
  qom/qom-qmp-cmds.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
  2 files changed, 103 insertions(+)
#3 lore raw

Re: [PATCH V3 1/3] qom: qom-list-getv

Quoted 13 lines · Philippe Mathieu-Daudé
Quoted 11 lines · Steve Sistare

Define the qom-list-getv command, which fetches all the properties and values for a list of paths.  This is faster than qom-tree-get when fetching a subset of the QOM tree.  See qom.json for details.

---
  qapi/qom.json      | 50 ++++++++++++++++++++++++++++++++++++++++++++
++++++
  qom/qom-qmp-cmds.c | 53 ++++++++++++++++++++++++++++++++++++++++++++
+++++++++

  2 files changed, 103 insertions(+)
Quoted 1 line

and:

#4 lore raw

Re: [PATCH V3 1/3] qom: qom-list-getv

In reply to Steve Sistare
Quoted 5 lines · Steve Sistare

Define the qom-list-getv command, which fetches all the properties and values for a list of paths. This is faster than qom-tree-get when fetching a subset of the QOM tree. See qom.json for details.

You cover letter explains *why* we want this. Please include the relevant parts here, so the rationale gets captured in git.

Quoted 11 lines
---
 qapi/qom.json      | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 qom/qom-qmp-cmds.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 103 insertions(+)
qapi/qom.json +0 -0
index b133b06..c16c2dd 100644
@@ -46,6 +46,34 @@
             '*default-value': 'any' } }

qapi/qom.json line 56

Quoted 10 lines
qapi/qom.json +8 -0
 
 ##
+# @ObjectPropertyValue:
+#
+# @name: the name of the property
+#
+# @type: the type of the property, as described in @ObjectPropertyInfo
+#
+# @value: the value of the property.  Absent when the property cannot
+#     be read.

Best to consistently end the descriptions with a period.

Quoted 24 lines
qapi/qom.json +20 -0
+#
+# Since 10.1
+##
+{ 'struct': 'ObjectPropertyValue',
+  'data': { 'name': 'str',
+            'type': 'str',
+            '*value': 'any' } }
+
+##
+# @ObjectPropertiesValues:
+#
+# @properties: a list of properties.
+#
+# Since 10.1
+##
+{ 'struct': 'ObjectPropertiesValues',
+  'data': { 'properties': [ 'ObjectPropertyValue' ] }}
+
+
+##
 # @qom-list:
 #
 # This command will list any properties of a object given a path in

qapi/qom.json line 163

Quoted 10 lines
qapi/qom.json +7 -0
@@ -126,6 +154,28 @@
   'allow-preconfig': true }
 
 ##
+# @qom-list-getv:
+#
+# List properties and their values for each object path in the input
+# list.
+#
+# @paths: The absolute or partial path for each object, as described
+#     in @qom-get

John Snow's "[PATCH 00/18] QAPI: add cross-references to qapi docs" rewrites things so they become links in generated HTML. @qom-get beccomes qom-get. Please use qom-get to avoid the semantic conflict.

qapi/qom.json line 169

Quoted 6 lines
qapi/qom.json +6 -0
+#
+# Errors:
+#     - If any path is not valid or is ambiguous
+#
+# Returns: A list of @ObjectPropertiesValues.  Each element contains
+#     the properties of the corresponding element in @paths.

I understand you patterned this after qom-get. It comes out like

Return:
"[""ObjectPropertiesValues""]" -- A list of "ObjectPropertiesValues". Each element contains the properties of the corresponding element in "paths".

in the generated manual. 'A list of "ObjectPropertiesValues"' is redundant. John Snow's "[PATCH v5 4/4] qapi: rephrase return docs to avoid type name" cleans up existing instances, including qom-get.

Perhaps something like "A list where each element contains information on the properties of the object referenced by the corresponding element in @paths." Or shorter: "A list where each element is the result for the corresponding element of @paths".

qapi/qom.json line 181

Quoted 12 lines
qapi/qom.json +9 -0
+#
+# Since 10.1
+##
+{ 'command': 'qom-list-getv',
+  'data': { 'paths': [ 'str' ] },
+  'returns': [ 'ObjectPropertiesValues' ],
+  'allow-preconfig': true }
+
+##
 # @qom-set:
 #
 # This command will set a property from a object model path.

The schema looks good. Not entirely happy with the names. Naming is hard! Type names are not part of the interface, so let's not worry about them too much. The command name will be set in stone, though.

When you named the command qom-list-getv, you also had qom-list-get. qom-list-get works on a single path, and -getv on multiple paths. The "v" suffix feels like a natural choice among people used to C. But does it make sense without its buddy?

How do you feel about calling it qom-list-get? qom-get-many? Other ideas?

qom/qom-qmp-cmds.c

Quoted 1 line
qom/qom-qmp-cmds.c +0 -0

[...]

The C code looks good to me.

#5 lore raw

Re: [PATCH V3 1/3] qom: qom-list-getv

Quoted 10 lines · Markus Armbruster
Quoted 5 lines · Steve Sistare

Define the qom-list-getv command, which fetches all the properties and values for a list of paths. This is faster than qom-tree-get when fetching a subset of the QOM tree. See qom.json for details.

You cover letter explains *why* we want this. Please include the relevant parts here, so the rationale gets captured in git.

Sure, and I forgot to delete the reference to qom-tree-get:

Define the qom-list-get command, which fetches all the properties and values for a list of paths. This is faster than qom-list plus qom-get, especially when fetching a large subset of the QOM tree. Some managers do so when starting a new VM, and this cost can be a substantial fraction of start up time.

Quoted 12 lines
Quoted 12 lines
---
  qapi/qom.json      | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
  qom/qom-qmp-cmds.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
  2 files changed, 103 insertions(+)
qapi/qom.json +0 -0
index b133b06..c16c2dd 100644
@@ -46,6 +46,34 @@
              '*default-value': 'any' } }
 
Quoted 11 lines

qapi/qom.json line 56

Quoted 9 lines
qapi/qom.json +8 -0
  ##
+# @ObjectPropertyValue:
+#
+# @name: the name of the property
+#
+# @type: the type of the property, as described in @ObjectPropertyInfo
+#
+# @value: the value of the property.  Absent when the property cannot
+#     be read.

Best to consistently end the descriptions with a period.

OK.

The majority of short descriptions in this file do not end with a period, so I inferred that was the recommended style.

Quoted 26 lines
Quoted 26 lines
qapi/qom.json +20 -0
+#
+# Since 10.1
+##
+{ 'struct': 'ObjectPropertyValue',
+  'data': { 'name': 'str',
+            'type': 'str',
+            '*value': 'any' } }
+
+##
+# @ObjectPropertiesValues:
+#
+# @properties: a list of properties.
+#
+# Since 10.1
+##
+{ 'struct': 'ObjectPropertiesValues',
+  'data': { 'properties': [ 'ObjectPropertyValue' ] }}
+
+
+##
  # @qom-list:
  #
  # This command will list any properties of a object given a path in
@@ -126,6 +154,28 @@
    'allow-preconfig': true }
 
Quoted 13 lines

qapi/qom.json line 163

Quoted 8 lines
qapi/qom.json +7 -0
  ##
+# @qom-list-getv:
+#
+# List properties and their values for each object path in the input
+# list.
+#
+# @paths: The absolute or partial path for each object, as described
+#     in @qom-get

John Snow's "[PATCH 00/18] QAPI: add cross-references to qapi docs" rewrites things so they become links in generated HTML. @qom-get beccomes qom-get. Please use qom-get to avoid the semantic conflict.

OK. I see his pending changes in this file.

Quoted 14 lines

qapi/qom.json line 169

Quoted 6 lines
qapi/qom.json +6 -0
+#
+# Errors:
+#     - If any path is not valid or is ambiguous
+#
+# Returns: A list of @ObjectPropertiesValues.  Each element contains
+#     the properties of the corresponding element in @paths.

I understand you patterned this after qom-get. It comes out like

Return:
"[""ObjectPropertiesValues""]" -- A list of "ObjectPropertiesValues". Each element contains the properties of the corresponding element in "paths".

Quoted 8 lines

in the generated manual. 'A list of "ObjectPropertiesValues"' is redundant. John Snow's "[PATCH v5 4/4] qapi: rephrase return docs to avoid type name" cleans up existing instances, including qom-get.

Perhaps something like "A list where each element contains information on the properties of the object referenced by the corresponding element in @paths." Or shorter: "A list where each element is the result for the corresponding element of @paths".

OK, I'll use the latter.

Quoted 17 lines

qapi/qom.json line 181

Quoted 12 lines
qapi/qom.json +9 -0
+#
+# Since 10.1
+##
+{ 'command': 'qom-list-getv',
+  'data': { 'paths': [ 'str' ] },
+  'returns': [ 'ObjectPropertiesValues' ],
+  'allow-preconfig': true }
+
+##
  # @qom-set:
  #
  # This command will set a property from a object model path.

The schema looks good. Not entirely happy with the names. Naming is hard! Type names are not part of the interface, so let's not worry about them too much. The command name will be set in stone, though.

Quoted 7 lines

When you named the command qom-list-getv, you also had qom-list-get. qom-list-get works on a single path, and -getv on multiple paths. The "v" suffix feels like a natural choice among people used to C. But does it make sense without its buddy?

How do you feel about calling it qom-list-get? qom-get-many? Other ideas?

qom-list-get is good, as long as we never add the single-path version of the call. No reason to IMO.

In the cover letter I will rename the existing qom-list-get to qom-list-get-one for the purpose of describing the experiments.

Quoted 6 lines

qom/qom-qmp-cmds.c

Quoted 2 lines
qom/qom-qmp-cmds.c +0 -0

[...]

The C code looks good to me.

Cool.

- Steve

#6 lore raw

PATCH v3 2/3 python: use qom-list-getv

In reply to Steve Sistare

Use qom-list-getv to speed up the qom-tree command.

---
 python/qemu/utils/qom.py        | 43 +++++++++++++++++++--------------
 python/qemu/utils/qom_common.py | 53 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 78 insertions(+), 18 deletions(-)
python/qemu/utils/qom.py +25 -18
index 426a0f2..6b2f1ab 100644
@@ -224,28 +224,35 @@ def __init__(self, args: argparse.Namespace):
         super().__init__(args)
         self.path = args.path
 
-    def _list_node(self, path: str) -> None:
-        print(path)
-        items = self.qom_list(path)
-        for item in items:
-            if item.child:
-                continue
-            try:
-                rsp = self.qmp.cmd('qom-get', path=path,
-                                   property=item.name)
-                print(f"  {item.name}: {rsp} ({item.type})")
-            except ExecuteError as err:
-                print(f"  {item.name}: <EXCEPTION: {err!s}> ({item.type})")
-        print('')
-        for item in items:
-            if not item.child:
-                continue
+    def _list_nodes(self, paths: [str]) -> None:
+        all_paths_props = self.qom_list_getv(paths)
+        i = 0
+
+        for props in all_paths_props:
+            path = paths[i]
+            i = i + 1
+            print(path)
             if path == '/':
                 path = ''
-            self._list_node(f"{path}/{item.name}")
+            newpaths = []
+
+            for item in props.properties:
+                if item.child:
+                    newpaths += [ f"{path}/{item.name}" ]
+                else:
+                    value = item.value
+                    if value == None:
+                        value = f"<EXCEPTION: property could not be read>"
+                    print(f"  {item.name}: {value} ({item.type})")
+
+            print('')
+
+            if newpaths:
+                self._list_nodes(newpaths)
+
 
     def run(self) -> int:
-        self._list_node(self.path)
+        self._list_nodes([self.path])
         return 0
 
 
python/qemu/utils/qom_common.py +53 -0

65 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#7 lore raw

PATCH v3 3/3 tests/qtest/qom-test: unit test for qom-list-getv

In reply to Steve Sistare

Add a unit test for qom-list-getv.

---
 tests/qtest/qom-test.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)
tests/qtest/qom-test.c +64 -0
index 27d70bc..4defff1 100644
@@ -11,11 +11,72 @@
 
 #include "qobject/qdict.h"
 #include "qobject/qlist.h"
+#include "qobject/qstring.h"
 #include "qemu/cutils.h"
 #include "libqtest.h"
 
 static int verbosity_level;
 
+static void test_getv(QTestState *qts, QList *paths)
+{
+    QListEntry *entry, *prop_entry, *path_entry;
+    g_autoptr(QDict) response = NULL;
+    QDict *args = qdict_new();
+    QDict *prop;
+    QList *return_list;
+
+    if (verbosity_level >= 2) {
+        g_test_message("Obtaining properties for paths:");
+        QLIST_FOREACH_ENTRY(paths, path_entry) {
+            QString *qstr = qobject_to(QString, qlist_entry_obj(path_entry));
+            g_test_message("  %s", qstring_get_str(qstr));
+        }
+    }
+
+    qdict_put_obj(args, "paths", QOBJECT(qlist_copy(paths)));
+    response = qtest_qmp(qts, "{ 'execute': 'qom-list-getv',"
+                              "  'arguments': %p }", args);
+    g_assert(response);
+    g_assert(qdict_haskey(response, "return"));
+    return_list = qobject_to(QList, qdict_get(response, "return"));
+
+    path_entry = QTAILQ_FIRST(&paths->head);
+    QLIST_FOREACH_ENTRY(return_list, entry) {
+        QDict *obj = qobject_to(QDict, qlist_entry_obj(entry));
+        g_assert(qdict_haskey(obj, "properties"));
+        QList *properties = qobject_to(QList, qdict_get(obj, "properties"));
+        bool has_child = false;
+
+        QLIST_FOREACH_ENTRY(properties, prop_entry) {
+            prop = qobject_to(QDict, qlist_entry_obj(prop_entry));
+            g_assert(qdict_haskey(prop, "name"));
+            g_assert(qdict_haskey(prop, "type"));
+            has_child |= strstart(qdict_get_str(prop, "type"), "child<", NULL);
+        }
+
+        if (has_child) {
+            /* build a list of child paths */
+            QString *qstr = qobject_to(QString, qlist_entry_obj(path_entry));
+            const char *path = qstring_get_str(qstr);
+            g_autoptr(QList) child_paths = qlist_new();
+
+            QLIST_FOREACH_ENTRY(properties, prop_entry) {
+                prop = qobject_to(QDict, qlist_entry_obj(prop_entry));
+                if (strstart(qdict_get_str(prop, "type"), "child<", NULL)) {
+                    g_autofree char *child_path = 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-getv call */
+            test_getv(qts, child_paths);
+        }
+
+        path_entry = QTAILQ_NEXT(path_entry, next);
+    }
+}
+
 static void test_properties(QTestState *qts, const char *path, bool recurse)
 {
     char *child_path;
@@ -85,6 +146,7 @@ static void test_machine(gconstpointer data)
     const char *machine = data;
     QDict *response;
     QTestState *qts;
+    g_autoptr(QList) paths = qlist_new();
 
     qts = qtest_initf("-machine %s", machine);
 
@@ -100,6 +162,8 @@ static void test_machine(gconstpointer data)
     }
 
     test_properties(qts, "/machine", true);
+    qlist_append_str(paths, "/machine");
+    test_getv(qts, paths);
 
     response = qtest_qmp(qts, "{ 'execute': 'quit' }");
     g_assert(qdict_haskey(response, "return"));
Signature · 1 line
1.8.3.1
Tested-by on v3 3/3
#9 lore raw

Re: [PATCH V3 3/3] tests/qtest/qom-test: unit test for qom-list-getv

In reply to Steve Sistare

Hi Steve,

Quoted 20 lines · Steve Sistare

Add a unit test for qom-list-getv.

---
  tests/qtest/qom-test.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 64 insertions(+)
tests/qtest/qom-test.c +1 -0
index 27d70bc..4defff1 100644
@@ -11,11 +11,72 @@
 
  #include "qobject/qdict.h"
  #include "qobject/qlist.h"
+#include "qobject/qstring.h"
  #include "qemu/cutils.h"
  #include "libqtest.h"
 
  static int verbosity_level;

tests/qtest/qom-test.c line 28

Quoted 10 lines
tests/qtest/qom-test.c +9 -0
 
+static void test_getv(QTestState *qts, QList *paths)
+{
+    QListEntry *entry, *prop_entry, *path_entry;
+    g_autoptr(QDict) response = NULL;
+    QDict *args = qdict_new();
+    QDict *prop;
+    QList *return_list;
+
+    if (verbosity_level >= 2) {

But I note this doesn't assert anything except if you use V=3 and look at the output.

Maybe stick it to a particular machine and check for a particular path and its properties?

Quoted 50 lines
tests/qtest/qom-test.c +50 -0
+        g_test_message("Obtaining properties for paths:");
+        QLIST_FOREACH_ENTRY(paths, path_entry) {
+            QString *qstr = qobject_to(QString, qlist_entry_obj(path_entry));
+            g_test_message("  %s", qstring_get_str(qstr));
+        }
+    }
+
+    qdict_put_obj(args, "paths", QOBJECT(qlist_copy(paths)));
+    response = qtest_qmp(qts, "{ 'execute': 'qom-list-getv',"
+                              "  'arguments': %p }", args);
+    g_assert(response);
+    g_assert(qdict_haskey(response, "return"));
+    return_list = qobject_to(QList, qdict_get(response, "return"));
+
+    path_entry = QTAILQ_FIRST(&paths->head);
+    QLIST_FOREACH_ENTRY(return_list, entry) {
+        QDict *obj = qobject_to(QDict, qlist_entry_obj(entry));
+        g_assert(qdict_haskey(obj, "properties"));
+        QList *properties = qobject_to(QList, qdict_get(obj, "properties"));
+        bool has_child = false;
+
+        QLIST_FOREACH_ENTRY(properties, prop_entry) {
+            prop = qobject_to(QDict, qlist_entry_obj(prop_entry));
+            g_assert(qdict_haskey(prop, "name"));
+            g_assert(qdict_haskey(prop, "type"));
+            has_child |= strstart(qdict_get_str(prop, "type"), "child<", NULL);
+        }
+
+        if (has_child) {
+            /* build a list of child paths */
+            QString *qstr = qobject_to(QString, qlist_entry_obj(path_entry));
+            const char *path = qstring_get_str(qstr);
+            g_autoptr(QList) child_paths = qlist_new();
+
+            QLIST_FOREACH_ENTRY(properties, prop_entry) {
+                prop = qobject_to(QDict, qlist_entry_obj(prop_entry));
+                if (strstart(qdict_get_str(prop, "type"), "child<", NULL)) {
+                    g_autofree char *child_path = 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-getv call */
+            test_getv(qts, child_paths);
+        }
+
+        path_entry = QTAILQ_NEXT(path_entry, next);
+    }
+}
#10 lore raw

Re: [PATCH V3 3/3] tests/qtest/qom-test: unit test for qom-list-getv

Quoted 31 lines · Philippe Mathieu-Daudé

Hi Steve,

Quoted 15 lines · Steve Sistare

Add a unit test for qom-list-getv.

---
  tests/qtest/qom-test.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 64 insertions(+)
tests/qtest/qom-test.c +1 -0
index 27d70bc..4defff1 100644
@@ -11,11 +11,72 @@
    #include "qobject/qdict.h"
  #include "qobject/qlist.h"
+#include "qobject/qstring.h"
  #include "qemu/cutils.h"
  #include "libqtest.h"

tests/qtest/qom-test.c line 25

Quoted 10 lines
tests/qtest/qom-test.c +8 -0
    static int verbosity_level;
  +static void test_getv(QTestState *qts, QList *paths)
+{
+    QListEntry *entry, *prop_entry, *path_entry;
+    g_autoptr(QDict) response = NULL;
+    QDict *args = qdict_new();
+    QDict *prop;
+    QList *return_list;
+
+    if (verbosity_level >= 2) {
Quoted 5 lines

But I note this doesn't assert anything except if you use V=3 and look at the output.

Maybe stick it to a particular machine and check for a particular path and its properties?

Or create some suitable thing with -object, and get that. No machine dependence.

[...]

#11 lore raw

Re: [PATCH V3 3/3] tests/qtest/qom-test: unit test for qom-list-getv

In reply to Philippe Mathieu-Daudé
Quoted 33 lines · Philippe Mathieu-Daudé

Hi Steve,

Quoted 17 lines · Steve Sistare

Add a unit test for qom-list-getv.

---
  tests/qtest/qom-test.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++

  1 file changed, 64 insertions(+)
tests/qtest/qom-test.c +1 -0
index 27d70bc..4defff1 100644
@@ -11,11 +11,72 @@
   #include "qobject/qdict.h"
   #include "qobject/qlist.h"
+#include "qobject/qstring.h"
   #include "qemu/cutils.h"
   #include "libqtest.h"

tests/qtest/qom-test.c line 25

Quoted 10 lines
tests/qtest/qom-test.c +9 -0
   static int verbosity_level;
+static void test_getv(QTestState *qts, QList *paths)
+{
+    QListEntry *entry, *prop_entry, *path_entry;
+    g_autoptr(QDict) response = NULL;
+    QDict *args = qdict_new();
+    QDict *prop;
+    QList *return_list;
+
+    if (verbosity_level >= 2) {
Quoted 2 lines

But I note this doesn't assert anything except if you use V=3 and look at the output.

I don't follow. It unconditionally traverses the whole tree and asserts that properties are present. Plus, for V >= 2, it prints paths. It is patterned after test_properties() in the same file.

- Steve

Quoted 53 lines

Maybe stick it to a particular machine and check for a particular path and its properties?

Quoted 50 lines
tests/qtest/qom-test.c +50 -0
+        g_test_message("Obtaining properties for paths:");
+        QLIST_FOREACH_ENTRY(paths, path_entry) {
+            QString *qstr = qobject_to(QString, qlist_entry_obj(path_entry));
+            g_test_message("  %s", qstring_get_str(qstr));
+        }
+    }
+
+    qdict_put_obj(args, "paths", QOBJECT(qlist_copy(paths)));
+    response = qtest_qmp(qts, "{ 'execute': 'qom-list-getv',"
+                              "  'arguments': %p }", args);
+    g_assert(response);
+    g_assert(qdict_haskey(response, "return"));
+    return_list = qobject_to(QList, qdict_get(response, "return"));
+
+    path_entry = QTAILQ_FIRST(&paths->head);
+    QLIST_FOREACH_ENTRY(return_list, entry) {
+        QDict *obj = qobject_to(QDict, qlist_entry_obj(entry));
+        g_assert(qdict_haskey(obj, "properties"));
+        QList *properties = qobject_to(QList, qdict_get(obj, "properties"));
+        bool has_child = false;
+
+        QLIST_FOREACH_ENTRY(properties, prop_entry) {
+            prop = qobject_to(QDict, qlist_entry_obj(prop_entry));
+            g_assert(qdict_haskey(prop, "name"));
+            g_assert(qdict_haskey(prop, "type"));
+            has_child |= strstart(qdict_get_str(prop, "type"), "child<", NULL);
+        }
+
+        if (has_child) {
+            /* build a list of child paths */
+            QString *qstr = qobject_to(QString, qlist_entry_obj(path_entry));
+            const char *path = qstring_get_str(qstr);
+            g_autoptr(QList) child_paths = qlist_new();
+
+            QLIST_FOREACH_ENTRY(properties, prop_entry) {
+                prop = qobject_to(QDict, qlist_entry_obj(prop_entry));
+                if (strstart(qdict_get_str(prop, "type"), "child<", NULL)) {
+                    g_autofree char *child_path = 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-getv call */
+            test_getv(qts, child_paths);
+        }
+
+        path_entry = QTAILQ_NEXT(path_entry, next);
+    }
+}
#12 lore raw

Re: [PATCH V3 3/3] tests/qtest/qom-test: unit test for qom-list-getv

Quoted 35 lines · Steven Sistare
Quoted 34 lines · Philippe Mathieu-Daudé

Hi Steve,

Quoted 18 lines · Steve Sistare

Add a unit test for qom-list-getv.

---
  tests/qtest/qom-test.c | 64 +++++++++++++++++++++++++++++++++++++++
+++++++++++

  1 file changed, 64 insertions(+)
tests/qtest/qom-test.c +1 -0
index 27d70bc..4defff1 100644
@@ -11,11 +11,72 @@
   #include "qobject/qdict.h"
   #include "qobject/qlist.h"
+#include "qobject/qstring.h"
   #include "qemu/cutils.h"
   #include "libqtest.h"

tests/qtest/qom-test.c line 25

Quoted 10 lines
tests/qtest/qom-test.c +9 -0
   static int verbosity_level;
+static void test_getv(QTestState *qts, QList *paths)
+{
+    QListEntry *entry, *prop_entry, *path_entry;
+    g_autoptr(QDict) response = NULL;
+    QDict *args = qdict_new();
+    QDict *prop;
+    QList *return_list;
+
+    if (verbosity_level >= 2) {
Quoted 6 lines
Quoted 2 lines

But I note this doesn't assert anything except if you use V=3 and look at the output.

I don't follow.  It unconditionally traverses the whole tree and asserts that properties are present.  Plus, for V >= 2, it prints paths. It is patterned after test_properties() in the same file.

Indeed, sorry. Good enough for me then, so:

#13 lore raw

Re: [PATCH V3 3/3] tests/qtest/qom-test: unit test for qom-list-getv

In reply to Steven Sistare
Quoted 33 lines · Steven Sistare
Quoted 32 lines · Philippe Mathieu-Daudé

Hi Steve,

Quoted 17 lines · Steve Sistare

Add a unit test for qom-list-getv.

---
  tests/qtest/qom-test.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++

  1 file changed, 64 insertions(+)
tests/qtest/qom-test.c +1 -0
index 27d70bc..4defff1 100644
@@ -11,11 +11,72 @@
   #include "qobject/qdict.h"
   #include "qobject/qlist.h"
+#include "qobject/qstring.h"
   #include "qemu/cutils.h"
   #include "libqtest.h"

tests/qtest/qom-test.c line 25

Quoted 10 lines
tests/qtest/qom-test.c +9 -0
   static int verbosity_level;
+static void test_getv(QTestState *qts, QList *paths)
+{
+    QListEntry *entry, *prop_entry, *path_entry;
+    g_autoptr(QDict) response = NULL;
+    QDict *args = qdict_new();
+    QDict *prop;
+    QList *return_list;
+
+    if (verbosity_level >= 2) {
Quoted 5 lines
Quoted 2 lines

But I note this doesn't assert anything except if you use V=3 and look at the output.

I don't follow. It unconditionally traverses the whole tree and asserts that properties are present. Plus, for V >= 2, it prints paths.

It starts with path "/machine".

For each property returned for that path, it checks there is a name and type.

It collects the paths where the type starts with "child<" into a list, and recurses. So it walks the entire tree under "/machine".

It does not examine property values at all. This is a gap in testing.

It does not check properties against expectations. The test would silently pass if qom-list-getv always returned [], or if it always returned crap types like "". Another gap.

Checking all this for the entire tree is entirely impractical. But we could check it for a suitable path of our choice. I recommend to avoid going into machine-dependent weeds there. Maybe create some suitable thing with -object, and check that.

If you can't afford implementing this, document the gaps in a TODO comment.

Quoted 1 line

It is patterned after test_properties() in the same file.

Same gaps :)

[...]

#14 lore raw

Re: [PATCH V3 3/3] tests/qtest/qom-test: unit test for qom-list-getv

Quoted 46 lines · Markus Armbruster
Quoted 33 lines · Steven Sistare
Quoted 32 lines · Philippe Mathieu-Daudé

Hi Steve,

Quoted 17 lines · Steve Sistare

Add a unit test for qom-list-getv.

---
   tests/qtest/qom-test.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++
   1 file changed, 64 insertions(+)
tests/qtest/qom-test.c +1 -0
index 27d70bc..4defff1 100644
@@ -11,11 +11,72 @@
   #include "qobject/qdict.h"
   #include "qobject/qlist.h"
+#include "qobject/qstring.h"
   #include "qemu/cutils.h"
   #include "libqtest.h"

tests/qtest/qom-test.c line 25

Quoted 10 lines
tests/qtest/qom-test.c +9 -0
   static int verbosity_level;
+static void test_getv(QTestState *qts, QList *paths)
+{
+    QListEntry *entry, *prop_entry, *path_entry;
+    g_autoptr(QDict) response = NULL;
+    QDict *args = qdict_new();
+    QDict *prop;
+    QList *return_list;
+
+    if (verbosity_level >= 2) {
Quoted 5 lines
Quoted 2 lines

But I note this doesn't assert anything except if you use V=3 and look at the output.

I don't follow. It unconditionally traverses the whole tree and asserts that properties are present. Plus, for V >= 2, it prints paths.

It starts with path "/machine".

For each property returned for that path, it checks there is a name and type.

Quoted 8 lines

It collects the paths where the type starts with "child<" into a list, and recurses. So it walks the entire tree under "/machine".

It does not examine property values at all. This is a gap in testing.

It does not check properties against expectations. The test would silently pass if qom-list-getv always returned [], or if it always returned crap types like "". Another gap.

I will assert that the returned list is not empty.

Quoted 4 lines

Checking all this for the entire tree is entirely impractical. But we could check it for a suitable path of our choice. I recommend to avoid going into machine-dependent weeds there. Maybe create some suitable thing with -object, and check that.

OK. I will keep the existing traversal test, and add a test for an object's property value.

- Steve

Quoted 9 lines

If you can't afford implementing this, document the gaps in a TODO comment.

Quoted 1 line

It is patterned after test_properties() in the same file.

Same gaps :)

[...]