qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: qemu-devel@nongnu.org, Peter Maydell <peter.maydell@linaro.org>
Subject: [PULL v2 12/15] libqtest: Rename qmp_assert_error_class() to qmp_expect_error_and_unref()
Date: Wed,  2 Sep 2020 17:49:29 +0200	[thread overview]
Message-ID: <20200902154932.390595-13-thuth@redhat.com> (raw)
In-Reply-To: <20200902154932.390595-1-thuth@redhat.com>

From: Markus Armbruster <armbru@redhat.com>

qmp_assert_error_class() does more than just assert: it also unrefs
the @rsp argument.  Rename to qmp_expect_error_and_unref() to reduce
confusion.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200902115733.1229537-1-armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/qtest/drive_del-test.c  |  2 +-
 tests/qtest/libqos/libqtest.h |  4 ++--
 tests/qtest/libqtest.c        |  2 +-
 tests/qtest/qmp-cmd-test.c    | 16 ++++++++--------
 tests/qtest/qmp-test.c        | 32 ++++++++++++++++----------------
 tests/test-qga.c              |  2 +-
 6 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/tests/qtest/drive_del-test.c b/tests/qtest/drive_del-test.c
index 2ab11ad225..2d765865ce 100644
--- a/tests/qtest/drive_del-test.c
+++ b/tests/qtest/drive_del-test.c
@@ -103,7 +103,7 @@ static void test_after_failed_device_add(void)
                               "   'drive': 'drive0'"
                               "}}", driver);
     g_assert(response);
-    qmp_assert_error_class(response, "GenericError");
+    qmp_expect_error_and_unref(response, "GenericError");
 
     /* Delete the drive */
     drive_del(qts);
diff --git a/tests/qtest/libqos/libqtest.h b/tests/qtest/libqos/libqtest.h
index f5cf93c386..a6ee1654f2 100644
--- a/tests/qtest/libqos/libqtest.h
+++ b/tests/qtest/libqos/libqtest.h
@@ -704,13 +704,13 @@ void qtest_qmp_device_del(QTestState *qts, const char *id);
 bool qmp_rsp_is_err(QDict *rsp);
 
 /**
- * qmp_assert_error_class:
+ * qmp_expect_error_and_unref:
  * @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);
+void qmp_expect_error_and_unref(QDict *rsp, const char *class);
 
 /**
  * qtest_probe_child:
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 26f1223642..58f58e1ece 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -1359,7 +1359,7 @@ bool qmp_rsp_is_err(QDict *rsp)
     return !!error;
 }
 
-void qmp_assert_error_class(QDict *rsp, const char *class)
+void qmp_expect_error_and_unref(QDict *rsp, const char *class)
 {
     QDict *error = qdict_get_qdict(rsp, "error");
 
diff --git a/tests/qtest/qmp-cmd-test.c b/tests/qtest/qmp-cmd-test.c
index f34e68858a..3109a9fe96 100644
--- a/tests/qtest/qmp-cmd-test.c
+++ b/tests/qtest/qmp-cmd-test.c
@@ -210,19 +210,19 @@ static void test_object_add_failure_modes(void)
     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");
+    qmp_expect_error_and_unref(resp, "GenericError");
 
     /* attempt to create an object without qom-type */
     resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':"
                      " {'id': 'ram1' } }");
     g_assert_nonnull(resp);
-    qmp_assert_error_class(resp, "GenericError");
+    qmp_expect_error_and_unref(resp, "GenericError");
 
     /* attempt to delete an object that does not exist */
     resp = qtest_qmp(qts, "{'execute': 'object-del', 'arguments':"
                      " {'id': 'ram1' } }");
     g_assert_nonnull(resp);
-    qmp_assert_error_class(resp, "GenericError");
+    qmp_expect_error_and_unref(resp, "GenericError");
 
     /* attempt to create 2 objects with duplicate id */
     resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':"
@@ -236,7 +236,7 @@ static void test_object_add_failure_modes(void)
                      " {'qom-type': 'memory-backend-ram', 'id': 'ram1',"
                      " 'props': {'size': 1048576 } } }");
     g_assert_nonnull(resp);
-    qmp_assert_error_class(resp, "GenericError");
+    qmp_expect_error_and_unref(resp, "GenericError");
 
     /* delete ram1 object */
     resp = qtest_qmp(qts, "{'execute': 'object-del', 'arguments':"
@@ -251,7 +251,7 @@ static void test_object_add_failure_modes(void)
                      " 'props': {'size': '1048576' } } }");
     g_assert_nonnull(resp);
     /* now do it right */
-    qmp_assert_error_class(resp, "GenericError");
+    qmp_expect_error_and_unref(resp, "GenericError");
 
     resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':"
                      " {'qom-type': 'memory-backend-ram', 'id': 'ram1',"
@@ -272,7 +272,7 @@ static void test_object_add_failure_modes(void)
                      " {'qom-type': 'memory-backend-ram',"
                      " 'props': {'size': 1048576 } } }");
     g_assert_nonnull(resp);
-    qmp_assert_error_class(resp, "GenericError");
+    qmp_expect_error_and_unref(resp, "GenericError");
 
     /* now do it right */
     resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':"
@@ -294,7 +294,7 @@ static void test_object_add_failure_modes(void)
                      " {'qom-type': 'memory-backend-ram', 'id': 'ram1',"
                      " 'props': {'sized': 1048576 } } }");
     g_assert_nonnull(resp);
-    qmp_assert_error_class(resp, "GenericError");
+    qmp_expect_error_and_unref(resp, "GenericError");
 
     /* now do it right */
     resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':"
@@ -321,7 +321,7 @@ static void test_object_add_failure_modes(void)
     resp = qtest_qmp(qts, "{'execute': 'object-del', 'arguments':"
                      " {'id': 'ram1' } }");
     g_assert_nonnull(resp);
-    qmp_assert_error_class(resp, "GenericError");
+    qmp_expect_error_and_unref(resp, "GenericError");
 
     qtest_quit(qts);
 }
diff --git a/tests/qtest/qmp-test.c b/tests/qtest/qmp-test.c
index 5950c3ebbb..e1032c5a21 100644
--- a/tests/qtest/qmp-test.c
+++ b/tests/qtest/qmp-test.c
@@ -38,7 +38,7 @@ static void assert_recovered(QTestState *qts)
     QDict *resp;
 
     resp = qtest_qmp(qts, "{ 'execute': 'no-such-cmd' }");
-    qmp_assert_error_class(resp, "CommandNotFound");
+    qmp_expect_error_and_unref(resp, "CommandNotFound");
 }
 
 static void test_malformed(QTestState *qts)
@@ -48,58 +48,58 @@ static void test_malformed(QTestState *qts)
     /* syntax error */
     qtest_qmp_send_raw(qts, "{]\n");
     resp = qtest_qmp_receive(qts);
-    qmp_assert_error_class(resp, "GenericError");
+    qmp_expect_error_and_unref(resp, "GenericError");
     assert_recovered(qts);
 
     /* lexical error: impossible byte outside string */
     qtest_qmp_send_raw(qts, "{\xFF");
     resp = qtest_qmp_receive(qts);
-    qmp_assert_error_class(resp, "GenericError");
+    qmp_expect_error_and_unref(resp, "GenericError");
     assert_recovered(qts);
 
     /* lexical error: funny control character outside string */
     qtest_qmp_send_raw(qts, "{\x01");
     resp = qtest_qmp_receive(qts);
-    qmp_assert_error_class(resp, "GenericError");
+    qmp_expect_error_and_unref(resp, "GenericError");
     assert_recovered(qts);
 
     /* lexical error: impossible byte in string */
     qtest_qmp_send_raw(qts, "{'bad \xFF");
     resp = qtest_qmp_receive(qts);
-    qmp_assert_error_class(resp, "GenericError");
+    qmp_expect_error_and_unref(resp, "GenericError");
     assert_recovered(qts);
 
     /* lexical error: control character in string */
     qtest_qmp_send_raw(qts, "{'execute': 'nonexistent', 'id':'\n");
     resp = qtest_qmp_receive(qts);
-    qmp_assert_error_class(resp, "GenericError");
+    qmp_expect_error_and_unref(resp, "GenericError");
     assert_recovered(qts);
 
     /* lexical error: interpolation */
     qtest_qmp_send_raw(qts, "%%p");
     resp = qtest_qmp_receive(qts);
-    qmp_assert_error_class(resp, "GenericError");
+    qmp_expect_error_and_unref(resp, "GenericError");
     assert_recovered(qts);
 
     /* Not even a dictionary */
     resp = qtest_qmp(qts, "null");
-    qmp_assert_error_class(resp, "GenericError");
+    qmp_expect_error_and_unref(resp, "GenericError");
 
     /* No "execute" key */
     resp = qtest_qmp(qts, "{}");
-    qmp_assert_error_class(resp, "GenericError");
+    qmp_expect_error_and_unref(resp, "GenericError");
 
     /* "execute" isn't a string */
     resp = qtest_qmp(qts, "{ 'execute': true }");
-    qmp_assert_error_class(resp, "GenericError");
+    qmp_expect_error_and_unref(resp, "GenericError");
 
     /* "arguments" isn't a dictionary */
     resp = qtest_qmp(qts, "{ 'execute': 'no-such-cmd', 'arguments': [] }");
-    qmp_assert_error_class(resp, "GenericError");
+    qmp_expect_error_and_unref(resp, "GenericError");
 
     /* extra key */
     resp = qtest_qmp(qts, "{ 'execute': 'no-such-cmd', 'extra': true }");
-    qmp_assert_error_class(resp, "GenericError");
+    qmp_expect_error_and_unref(resp, "GenericError");
 }
 
 static void test_qmp_protocol(void)
@@ -121,7 +121,7 @@ static void test_qmp_protocol(void)
 
     /* Test valid command before handshake */
     resp = qtest_qmp(qts, "{ 'execute': 'query-version' }");
-    qmp_assert_error_class(resp, "CommandNotFound");
+    qmp_expect_error_and_unref(resp, "CommandNotFound");
 
     /* Test malformed commands before handshake */
     test_malformed(qts);
@@ -134,7 +134,7 @@ static void test_qmp_protocol(void)
 
     /* Test repeated handshake */
     resp = qtest_qmp(qts, "{ 'execute': 'qmp_capabilities' }");
-    qmp_assert_error_class(resp, "CommandNotFound");
+    qmp_expect_error_and_unref(resp, "CommandNotFound");
 
     /* Test valid command */
     resp = qtest_qmp(qts, "{ 'execute': 'query-version' }");
@@ -154,7 +154,7 @@ static void test_qmp_protocol(void)
     /* Test command failure with 'id' */
     resp = qtest_qmp(qts, "{ 'execute': 'human-monitor-command', 'id': 2 }");
     g_assert_cmpint(qdict_get_int(resp, "id"), ==, 2);
-    qmp_assert_error_class(resp, "GenericError");
+    qmp_expect_error_and_unref(resp, "GenericError");
 
     qtest_quit(qts);
 }
@@ -327,7 +327,7 @@ static void test_qmp_missing_any_arg(void)
     resp = qtest_qmp(qts, "{'execute': 'qom-set', 'arguments':"
                      " { 'path': '/machine', 'property': 'rtc-time' } }");
     g_assert_nonnull(resp);
-    qmp_assert_error_class(resp, "GenericError");
+    qmp_expect_error_and_unref(resp, "GenericError");
     qtest_quit(qts);
 }
 
diff --git a/tests/test-qga.c b/tests/test-qga.c
index 4ac4c22109..65d7992edc 100644
--- a/tests/test-qga.c
+++ b/tests/test-qga.c
@@ -246,7 +246,7 @@ static void test_qga_invalid_oob(gconstpointer fix)
     ret = qmp_fd(fixture->fd, "{'exec-oob': 'guest-ping'}");
     g_assert_nonnull(ret);
 
-    qmp_assert_error_class(ret, "GenericError");
+    qmp_expect_error_and_unref(ret, "GenericError");
 }
 
 static void test_qga_invalid_args(gconstpointer fix)
-- 
2.18.2



  parent reply	other threads:[~2020-09-02 15:57 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-02 15:49 [PULL v2 00/15] Cirrus-CI improvements, and other CI-related fixes, m68k Thomas Huth
2020-09-02 15:49 ` [PULL v2 01/15] configure: Fix atomic64 test for --enable-werror on macOS Thomas Huth
2020-09-02 15:49 ` [PULL v2 02/15] cirrus.yml: Compile FreeBSD with -Werror Thomas Huth
2020-09-02 15:49 ` [PULL v2 03/15] cirrus.yml: Compile macOS " Thomas Huth
2020-09-02 15:49 ` [PULL v2 04/15] cirrus.yml: Update the macOS jobs to Catalina Thomas Huth
2020-09-02 15:49 ` [PULL v2 05/15] cirrus.yml: Split FreeBSD job into two parts Thomas Huth
2020-09-02 15:49 ` [PULL v2 06/15] meson: fix keymaps without qemu-keymap Thomas Huth
2020-09-02 15:49 ` [PULL v2 07/15] configure: Add system = 'linux' for meson when cross-compiling Thomas Huth
2020-09-02 15:49 ` [PULL v2 08/15] hw/m68k: QOMify the mcf5206 system integration module Thomas Huth
2020-09-02 15:49 ` [PULL v2 09/15] tests/qtest/ahci: Improve error handling (NEGATIVE_RETURNS) Thomas Huth
2020-09-02 15:49 ` [PULL v2 10/15] tests/qtest/tpm: Declare input buffers const and static Thomas Huth
2020-09-02 15:49 ` [PULL v2 11/15] tests/qtest/ipmi-kcs: Fix assert side-effect Thomas Huth
2020-09-02 15:49 ` Thomas Huth [this message]
2020-09-02 15:49 ` [PULL v2 13/15] gitlab/travis: Rework the disabled features tests Thomas Huth
2020-09-02 15:49 ` [PULL v2 14/15] gitlab-ci.yml: Run check-qtest and check-unit at the end of the fuzzer job Thomas Huth
2020-09-02 15:49 ` [PULL v2 15/15] gitlab-ci.yml: Set artifacts expiration time Thomas Huth
2020-09-02 20:19 ` [PULL v2 00/15] Cirrus-CI improvements, and other CI-related fixes, m68k Peter Maydell
2020-09-03  5:11   ` Thomas Huth
2020-09-03  5:47     ` Gerd Hoffmann
2020-09-03 10:48       ` Peter Maydell
2020-09-03 10:52         ` Thomas Huth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200902154932.390595-13-thuth@redhat.com \
    --to=thuth@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).