Skip to contentSkip to conversation

qom-test: Test QOM properties

PATCH In review Andreas Färber 2 participants 3 messages Mar 11, 2014 – Mar 12, 2014

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 qom-test: Test QOM properties

Recursively walk all properties under /machine and try to retrieve their value. This is a regression test for link<> properties and the DeviceState::hotpluggable property.

Cf. be2f78b6b062eec5170e2612299fb8953046993f and

    1a37eca107cece3ed454bae29eef0bd1fac4a244

---
v2: Added g_test_message()s.

Applying to qom-next.

 tests/qom-test.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
tests/qom-test.c +43 -0
index b6671fb..4909258 100644
@@ -10,6 +10,7 @@
 #include <glib.h>
 #include <string.h>
 
+#include "qemu-common.h"
 #include "libqtest.h"
 #include "qemu/osdep.h"
 #include "qapi/qmp/types.h"
@@ -43,6 +44,44 @@ static bool is_blacklisted(const char *arch, const char *mach)
     return false;
 }
 
+static void test_properties(const char *path)
+{
+    char *cmd, *child_path;
+    QDict *response, *tuple;
+    QList *list;
+    QListEntry *entry;
+
+    g_test_message("Obtaining properties of %s", path);
+    cmd = g_strdup_printf("{ 'execute': 'qom-list',"
+                          "  'arguments': { 'path': '%s' } }", path);
+    response = qmp(cmd);
+    g_free(cmd);
+    g_assert(response);
+
+    g_assert(qdict_haskey(response, "return"));
+    list = qobject_to_qlist(qdict_get(response, "return"));
+    QLIST_FOREACH_ENTRY(list, entry) {
+        tuple = qobject_to_qdict(qlist_entry_obj(entry));
+        if (strstart(qdict_get_str(tuple, "type"), "child<", NULL)) {
+            child_path = g_strdup_printf("%s/%s",
+                                         path, qdict_get_str(tuple, "name"));
+            test_properties(child_path);
+            g_free(child_path);
+        } else {
+            const char *prop = qdict_get_str(tuple, "name");
+            g_test_message("Testing property %s.%s", path, prop);
+            cmd = g_strdup_printf("{ 'execute': 'qom-get',"
+                                  "  'arguments': { 'path': '%s',"
+                                  "                 'property': '%s' } }",
+                                  path, prop);
+            response = qmp(cmd);
+            g_free(cmd);
+            /* This may fail but should not, e.g., segfault. */
+            g_assert(response);
+        }
+    }
+}
+
 static void test_machine(gconstpointer data)
 {
     const char *machine = data;
@@ -51,8 +90,12 @@ static void test_machine(gconstpointer data)
 
     args = g_strdup_printf("-machine %s", machine);
     qtest_start(args);
+
+    test_properties("/machine");
+
     response = qmp("{ 'execute': 'quit' }");
     g_assert(qdict_haskey(response, "return"));
+
     qtest_end();
     g_free(args);
 }
Signature · 1 line
1.8.4.5
#1 lore raw
Quoted 6 lines · Andreas Färber

Recursively walk all properties under /machine and try to retrieve their value. This is a regression test for link<> properties and the DeviceState::hotpluggable property.

Cf. be2f78b6b062eec5170e2612299fb8953046993f and

    1a37eca107cece3ed454bae29eef0bd1fac4a244

I'm afraid the last sentence is too terse for me to understand.

Quoted 49 lines

---
v2: Added g_test_message()s.

Applying to qom-next.

 tests/qom-test.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
tests/qom-test.c +25 -0
index b6671fb..4909258 100644
@@ -10,6 +10,7 @@
 #include <glib.h>
 #include <string.h>
 
+#include "qemu-common.h"
 #include "libqtest.h"
 #include "qemu/osdep.h"
 #include "qapi/qmp/types.h"
@@ -43,6 +44,44 @@ static bool is_blacklisted(const char *arch, const char *mach)
     return false;
 }
 
+static void test_properties(const char *path)
+{
+    char *cmd, *child_path;
+    QDict *response, *tuple;
+    QList *list;
+    QListEntry *entry;
+
+    g_test_message("Obtaining properties of %s", path);
+    cmd = g_strdup_printf("{ 'execute': 'qom-list',"
+                          "  'arguments': { 'path': '%s' } }", path);
+    response = qmp(cmd);
+    g_free(cmd);
+    g_assert(response);
+
+    g_assert(qdict_haskey(response, "return"));
+    list = qobject_to_qlist(qdict_get(response, "return"));
+    QLIST_FOREACH_ENTRY(list, entry) {
+        tuple = qobject_to_qdict(qlist_entry_obj(entry));
+        if (strstart(qdict_get_str(tuple, "type"), "child<", NULL)) {
+            child_path = g_strdup_printf("%s/%s",
+                                         path, qdict_get_str(tuple, "name"));
+            test_properties(child_path);
+            g_free(child_path);
+        } else {

tests/qom-test.c static bool is_blacklisted(const char *arch, const char *mach) · line 80

Quoted 10 lines
tests/qom-test.c +10 -0
+            const char *prop = qdict_get_str(tuple, "name");
+            g_test_message("Testing property %s.%s", path, prop);
+            cmd = g_strdup_printf("{ 'execute': 'qom-get',"
+                                  "  'arguments': { 'path': '%s',"
+                                  "                 'property': '%s' } }",
+                                  path, prop);
+            response = qmp(cmd);
+            g_free(cmd);
+            /* This may fail but should not, e.g., segfault. */
+            g_assert(response);

I'm not sure I get your comment.

Quoted 10 lines
tests/qom-test.c +4 -0
+        }
+    }
+}
+
 static void test_machine(gconstpointer data)
 {
     const char *machine = data;
@@ -51,8 +90,12 @@ static void test_machine(gconstpointer data)
 
     args = g_strdup_printf("-machine %s", machine);

tests/qom-test.c static void test_machine(gconstpointer data) · line 101

Quoted 10 lines
tests/qom-test.c +4 -0
     qtest_start(args);
+
+    test_properties("/machine");
+
     response = qmp("{ 'execute': 'quit' }");
     g_assert(qdict_haskey(response, "return"));
+
     qtest_end();
     g_free(args);
 }

Looks like an excellent addition to the test suite. Thanks!

#2 lore raw

Am 12.03.2014 10:09, schrieb Markus Armbruster:

Quoted 10 lines
Quoted 6 lines · Andreas Färber

Recursively walk all properties under /machine and try to retrieve their value. This is a regression test for link<> properties and the DeviceState::hotpluggable property.

Cf. be2f78b6b062eec5170e2612299fb8953046993f and

    1a37eca107cece3ed454bae29eef0bd1fac4a244

I'm afraid the last sentence is too terse for me to understand.

Commit hashes of a) link<> property bug fix and b) hotpluggable property introduction. Both were about segfaults.

Quoted 54 lines
Quoted 54 lines

---
v2: Added g_test_message()s.

Applying to qom-next.

 tests/qom-test.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
tests/qom-test.c +29 -0
index b6671fb..4909258 100644
@@ -10,6 +10,7 @@
 #include <glib.h>
 #include <string.h>
 
+#include "qemu-common.h"
 #include "libqtest.h"
 #include "qemu/osdep.h"
 #include "qapi/qmp/types.h"
@@ -43,6 +44,44 @@ static bool is_blacklisted(const char *arch, const char *mach)
     return false;
 }
 
+static void test_properties(const char *path)
+{
+    char *cmd, *child_path;
+    QDict *response, *tuple;
+    QList *list;
+    QListEntry *entry;
+
+    g_test_message("Obtaining properties of %s", path);
+    cmd = g_strdup_printf("{ 'execute': 'qom-list',"
+                          "  'arguments': { 'path': '%s' } }", path);
+    response = qmp(cmd);
+    g_free(cmd);
+    g_assert(response);
+
+    g_assert(qdict_haskey(response, "return"));
+    list = qobject_to_qlist(qdict_get(response, "return"));
+    QLIST_FOREACH_ENTRY(list, entry) {
+        tuple = qobject_to_qdict(qlist_entry_obj(entry));
+        if (strstart(qdict_get_str(tuple, "type"), "child<", NULL)) {
+            child_path = g_strdup_printf("%s/%s",
+                                         path, qdict_get_str(tuple, "name"));
+            test_properties(child_path);
+            g_free(child_path);
+        } else {
+            const char *prop = qdict_get_str(tuple, "name");
+            g_test_message("Testing property %s.%s", path, prop);
+            cmd = g_strdup_printf("{ 'execute': 'qom-get',"
+                                  "  'arguments': { 'path': '%s',"
Quoted 8 lines

tests/qom-test.c static bool is_blacklisted(const char *arch, const char *mach) · line 80

Quoted 6 lines
tests/qom-test.c +6 -0
+                                  "                 'property': '%s' } }",
+                                  path, prop);
+            response = qmp(cmd);
+            g_free(cmd);
+            /* This may fail but should not, e.g., segfault. */
+            g_assert(response);

I'm not sure I get your comment.

Executing qom-get may return a QMP error when accessing a property, but it may not crash. Therefore not much we can assert in the response. If a segfault occurs, the process is gone at this point.

Quoted 10 lines
Quoted 10 lines
tests/qom-test.c +4 -0
+        }
+    }
+}
+
 static void test_machine(gconstpointer data)
 {
     const char *machine = data;
@@ -51,8 +90,12 @@ static void test_machine(gconstpointer data)
 
Quoted 13 lines

tests/qom-test.c static void test_machine(gconstpointer data) · line 101

Quoted 11 lines
tests/qom-test.c +4 -0
     args = g_strdup_printf("-machine %s", machine);
     qtest_start(args);
+
+    test_properties("/machine");
+
     response = qmp("{ 'execute': 'quit' }");
     g_assert(qdict_haskey(response, "return"));
+
     qtest_end();
     g_free(args);
 }

Looks like an excellent addition to the test suite. Thanks!

Unfortunately adds to the main-loop warnings.

Cheers,
Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg