Skip to contentSkip to conversation

tests: add a few QMP-related tests

PATCH In review Marc-André Lureau 2 participants 8 messages Aug 30, 2018 – Aug 31, 2018

lore
Share & tools
lore
#0 lore raw

v5 cover tests: add a few QMP-related tests

Hi,

The test patches from "[PATCH v4 00/10] monitor: various code simplification and fixes" series.

v5:
- add "tests: add qmp_assert_error_class()" patch
- commit message tweaks, TODO

Marc-André Lureau (4):
tests: add qmp_assert_error_class()
tests: add qmp/object-add-without-props test
tests: add qmp/qom-set-without-value test
tests: add a qmp success-response test

 tests/libqtest.h                        |  9 +++
 tests/drive_del-test.c                  |  5 +-
 tests/libqtest.c                        | 11 ++++
 tests/qmp-cmd-test.c                    | 18 +++++
 tests/qmp-test.c                        | 87 +++++++++++--------------
 tests/test-qga.c                        |  9 +--
 tests/test-qmp-cmds.c                   | 17 +++++
 tests/qapi-schema/qapi-schema-test.json |  2 +
 tests/qapi-schema/qapi-schema-test.out  |  2 +
 9 files changed, 99 insertions(+), 61 deletions(-)
Signature · 1 line
2.19.0.rc0.48.gb9dfa238d5
#1 lore raw

PATCH v5 1/4 tests: add qmp_assert_error_class()

This helper will simplify a bunch of code checking for QMP errors and can be shared by various tests. Note that test-qga does check for error description as well, so don't replace the code there for now.

---
 tests/libqtest.h       |  9 ++++++
 tests/drive_del-test.c |  5 +--
 tests/libqtest.c       | 11 +++++++
 tests/qmp-test.c       | 73 +++++++++++++-----------------------------
 tests/test-qga.c       |  9 ++----
 5 files changed, 46 insertions(+), 61 deletions(-)
tests/libqtest.h +9 -0
index 36d5caecd4..ed88ff99d5 100644
@@ -1004,4 +1004,13 @@ void qtest_qmp_device_del(const char *id);
  */
 bool qmp_rsp_is_err(QDict *rsp);
 
+/**
+ * qmp_assert_error_class:
+ * @rsp: QMP response to check for error
+ * @class: an error class
+ *
+ * Assert the response has the given error class and discard @rsp.
+ */
+void qmp_assert_error_class(QDict *rsp, const char *class);
+
 #endif
tests/drive_del-test.c +1 -4
index 673c10140f..4a1a0889c8 100644
@@ -67,7 +67,6 @@ static void test_after_failed_device_add(void)
 {
     char driver[32];
     QDict *response;
-    QDict *error;
 
     snprintf(driver, sizeof(driver), "virtio-blk-%s",
              qvirtio_get_dev_type());
@@ -83,9 +82,7 @@ static void test_after_failed_device_add(void)
                    "   'drive': 'drive0'"
                    "}}", driver);
     g_assert(response);
-    error = qdict_get_qdict(response, "error");
-    g_assert_cmpstr(qdict_get_try_str(error, "class"), ==, "GenericError");
-    qobject_unref(response);
+    qmp_assert_error_class(response, "GenericError");
 
     /* Delete the drive */
     drive_del();
tests/libqtest.c +11 -0
index d635c5bea0..2cd5736642 100644
@@ -1194,3 +1194,14 @@ bool qmp_rsp_is_err(QDict *rsp)
     qobject_unref(rsp);
     return !!error;
 }
+
+void qmp_assert_error_class(QDict *rsp, const char *class)
+{
+    QDict *error = qdict_get_qdict(rsp, "error");
+
+    g_assert_cmpstr(qdict_get_try_str(error, "class"), ==, class);
+    g_assert_nonnull(qdict_get_try_str(error, "desc"));
+    g_assert(!qdict_haskey(rsp, "return"));
+
+    qobject_unref(rsp);
+}
tests/qmp-test.c +23 -50

151 lines not on this page · raw message

tests/test-qga.c +2 -7
index f69cdf6c03..3d6377436a 100644
@@ -244,17 +244,12 @@ static void test_qga_invalid_id(gconstpointer fix)
 static void test_qga_invalid_oob(gconstpointer fix)
 {
     const TestFixture *fixture = fix;
-    QDict *ret, *error;
-    const char *class;
+    QDict *ret;
 
     ret = qmp_fd(fixture->fd, "{'exec-oob': 'guest-ping'}");
     g_assert_nonnull(ret);
 
-    error = qdict_get_qdict(ret, "error");
-    class = qdict_get_try_str(error, "class");
-    g_assert_cmpstr(class, ==, "GenericError");
-
-    qobject_unref(ret);
+    qmp_assert_error_class(ret, "GenericError");
 }
 
 static void test_qga_invalid_args(gconstpointer fix)
Signature · 1 line
2.19.0.rc0.48.gb9dfa238d5
Reviewed-by on v5 1/4
#2 lore raw

Re: [Qemu-devel] [PATCH v5 1/4] tests: add qmp_assert_error_class()

Quoted 4 lines · Marc-André Lureau

This helper will simplify a bunch of code checking for QMP errors and can be shared by various tests. Note that test-qga does check for error description as well, so don't replace the code there for now.

Quoted 8 lines
---
 tests/libqtest.h       |  9 ++++++
 tests/drive_del-test.c |  5 +--
 tests/libqtest.c       | 11 +++++++
 tests/qmp-test.c       | 73 +++++++++++++-----------------------------
 tests/test-qga.c       |  9 ++----
 5 files changed, 46 insertions(+), 61 deletions(-)
#3 lore raw

PATCH v5 2/4 tests: add qmp/object-add-without-props test

In reply to Marc-André Lureau

test_object_add_without_props() tests a bug in qmp_object_add() we fixed in commit e64c75a975. Sadly, we don't have systematic object-add tests. This lone test can go into qmp-cmd-test for want of a better home.

---
 tests/qmp-cmd-test.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
tests/qmp-cmd-test.c +18 -0
index c5b70df974..d12cac539c 100644
@@ -197,6 +197,19 @@ static void add_query_tests(QmpSchema *schema)
     }
 }
 
+static void test_object_add_without_props(void)
+{
+    QTestState *qts;
+    QDict *resp;
+
+    qts = qtest_init(common_args);
+    resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':"
+                    " {'qom-type': 'memory-backend-ram', 'id': 'ram1' } }");
+    g_assert_nonnull(resp);
+    qmp_assert_error_class(resp, "GenericError");
+    qtest_quit(qts);
+}
+
 int main(int argc, char *argv[])
 {
     QmpSchema schema;
@@ -206,6 +219,11 @@ int main(int argc, char *argv[])
 
     qmp_schema_init(&schema);
     add_query_tests(&schema);
+
+    qtest_add_func("qmp/object-add-without-props",
+                   test_object_add_without_props);
+    /* TODO: add coverage of generic object-add failure modes */
+
     ret = g_test_run();
 
     qmp_schema_cleanup(&schema);
Signature · 1 line
2.19.0.rc0.48.gb9dfa238d5
Reviewed-by on v5 2/4
#4 lore raw

Re: [Qemu-devel] [PATCH v5 2/4] tests: add qmp/object-add-without-props test

Quoted 9 lines · Marc-André Lureau

test_object_add_without_props() tests a bug in qmp_object_add() we fixed in commit e64c75a975. Sadly, we don't have systematic object-add tests. This lone test can go into qmp-cmd-test for want of a better home.

---
 tests/qmp-cmd-test.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
#5 lore raw

PATCH v5 3/4 tests: add qmp/qom-set-without-value test

In reply to Marc-André Lureau

test_qom_set_without_value() is about a bug in infrastructure used by the QMP core, fixed in commit c489780203. We covered the bug in infrastructure unit tests (commit bce3035a44). I wrote that test earlier, to cover QMP level as well, the test could go into qmp-test.

---
 tests/qmp-test.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
tests/qmp-test.c +14 -0
index b3472281ae..2b923f02db 100644
@@ -321,6 +321,19 @@ static void test_qmp_preconfig(void)
     qtest_quit(qs);
 }
 
+static void test_qom_set_without_value(void)
+{
+    QTestState *qts;
+    QDict *resp;
+
+    qts = qtest_init(common_args);
+    resp = qtest_qmp(qts, "{'execute': 'qom-set', 'arguments':"
+                     " { 'path': '/machine', 'property': 'rtc-time' } }");
+    g_assert_nonnull(resp);
+    qmp_assert_error_class(resp, "GenericError");
+    qtest_quit(qts);
+}
+
 int main(int argc, char *argv[])
 {
     g_test_init(&argc, &argv, NULL);
@@ -328,6 +341,7 @@ int main(int argc, char *argv[])
     qtest_add_func("qmp/protocol", test_qmp_protocol);
     qtest_add_func("qmp/oob", test_qmp_oob);
     qtest_add_func("qmp/preconfig", test_qmp_preconfig);
+    qtest_add_func("qmp/qom-set-without-value", test_qom_set_without_value);
 
     return g_test_run();
 }
Signature · 1 line
2.19.0.rc0.48.gb9dfa238d5
Reviewed-by on v5 3/4
#6 lore raw

Re: [Qemu-devel] [PATCH v5 3/4] tests: add qmp/qom-set-without-value test

Quoted 9 lines · Marc-André Lureau

test_qom_set_without_value() is about a bug in infrastructure used by the QMP core, fixed in commit c489780203. We covered the bug in infrastructure unit tests (commit bce3035a44). I wrote that test earlier, to cover QMP level as well, the test could go into qmp-test.

---
 tests/qmp-test.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
#7 lore raw

PATCH v5 4/4 tests: add a qmp success-response test

In reply to Marc-André Lureau

Verify the usage of this schema feature and the API behaviour. This should be the only case where qmp_dispatch() returns NULL.

---
 tests/test-qmp-cmds.c                   | 17 +++++++++++++++++
 tests/qapi-schema/qapi-schema-test.json |  2 ++
 tests/qapi-schema/qapi-schema-test.out  |  2 ++
 3 files changed, 21 insertions(+)
tests/test-qmp-cmds.c +17 -0
index ab414fa0c9..4ab2b6e5ce 100644
@@ -32,6 +32,10 @@ void qmp_test_flags_command(Error **errp)
 {
 }
 
+void qmp_cmd_success_response(Error **errp)
+{
+}
+
 Empty2 *qmp_user_def_cmd0(Error **errp)
 {
     return g_new0(Empty2, 1);
@@ -153,6 +157,17 @@ static void test_dispatch_cmd_failure(void)
     qobject_unref(req);
 }
 
+static void test_dispatch_cmd_success_response(void)
+{
+    QDict *req = qdict_new();
+    QDict *resp;
+
+    qdict_put_str(req, "execute", "cmd-success-response");
+    resp = qmp_dispatch(&qmp_commands, QOBJECT(req), false);
+    g_assert_null(resp);
+    qobject_unref(req);
+}
+
 static QObject *test_qmp_dispatch(QDict *req)
 {
     QDict *resp;
@@ -289,6 +304,8 @@ int main(int argc, char **argv)
     g_test_add_func("/qmp/dispatch_cmd", test_dispatch_cmd);
     g_test_add_func("/qmp/dispatch_cmd_failure", test_dispatch_cmd_failure);
     g_test_add_func("/qmp/dispatch_cmd_io", test_dispatch_cmd_io);
+    g_test_add_func("/qmp/dispatch_cmd_success_response",
+                    test_dispatch_cmd_success_response);
     g_test_add_func("/qmp/dealloc_types", test_dealloc_types);
     g_test_add_func("/qmp/dealloc_partial", test_dealloc_partial);
 
tests/qapi-schema/qapi-schema-test.json +2 -0
index 11aa4c8f8d..fb03163430 100644
@@ -137,6 +137,8 @@
   'data': {'ud1a': 'UserDefOne', '*ud1b': 'UserDefOne'},
   'returns': 'UserDefTwo' }
 
+{ 'command': 'cmd-success-response', 'data': {}, 'success-response': false }
+
 # Returning a non-dictionary requires a name from the whitelist
 { 'command': 'guest-get-time', 'data': {'a': 'int', '*b': 'int' },
   'returns': 'int' }
tests/qapi-schema/qapi-schema-test.out +2 -0
index 0da92455da..218ac7d556 100644
@@ -156,6 +156,8 @@ object q_obj_user_def_cmd2-arg
     member ud1b: UserDefOne optional=True
 command user_def_cmd2 q_obj_user_def_cmd2-arg -> UserDefTwo
    gen=True success_response=True boxed=False oob=False preconfig=False
+command cmd-success-response None -> None
+   gen=True success_response=False boxed=False oob=False preconfig=False
 object q_obj_guest-get-time-arg
     member a: int optional=False
     member b: int optional=True
Signature · 1 line
2.19.0.rc0.48.gb9dfa238d5