qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>, qemu-devel@nongnu.org
Cc: Michael Labiuk <michael.labiuk@virtuozzo.com>
Subject: [PULL 03/16] tests/x86: add helper qtest_qmp_device_del_send()
Date: Wed, 12 Oct 2022 16:33:03 +0200	[thread overview]
Message-ID: <20221012143316.988561-4-thuth@redhat.com> (raw)
In-Reply-To: <20221012143316.988561-1-thuth@redhat.com>

From: Michael Labiuk <michael.labiuk@virtuozzo.com>

Move sending 'device_del' command to separate function.
Function can be used in case of addition action is needed to start
actual removing device after sending command.

Signed-off-by: Michael Labiuk <michael.labiuk@virtuozzo.com>
Message-Id: <20220929223547.1429580-2-michael.labiuk@virtuozzo.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
[thuth: Fixed typo]
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/qtest/libqtest.h         | 10 ++++++++++
 tests/qtest/device-plug-test.c | 15 ++-------------
 tests/qtest/drive_del-test.c   |  6 +-----
 tests/qtest/libqos/pci-pc.c    |  8 +-------
 tests/qtest/libqtest.c         | 16 ++++++++++------
 5 files changed, 24 insertions(+), 31 deletions(-)

diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h
index 3abc75964d..65c040e504 100644
--- a/tests/qtest/libqtest.h
+++ b/tests/qtest/libqtest.h
@@ -761,12 +761,22 @@ void qtest_qmp_device_add(QTestState *qts, const char *driver, const char *id,
 void qtest_qmp_add_client(QTestState *qts, const char *protocol, int fd);
 #endif /* _WIN32 */
 
+/**
+ * qtest_qmp_device_del_send:
+ * @qts: QTestState instance to operate on
+ * @id: Identification string
+ *
+ * Generic hot-unplugging test via the device_del QMP command.
+ */
+void qtest_qmp_device_del_send(QTestState *qts, const char *id);
+
 /**
  * qtest_qmp_device_del:
  * @qts: QTestState instance to operate on
  * @id: Identification string
  *
  * Generic hot-unplugging test via the device_del QMP command.
+ * Waiting for command completion event.
  */
 void qtest_qmp_device_del(QTestState *qts, const char *id);
 
diff --git a/tests/qtest/device-plug-test.c b/tests/qtest/device-plug-test.c
index e595b45b66..3841de1b8c 100644
--- a/tests/qtest/device-plug-test.c
+++ b/tests/qtest/device-plug-test.c
@@ -15,17 +15,6 @@
 #include "qapi/qmp/qdict.h"
 #include "qapi/qmp/qstring.h"
 
-static void device_del(QTestState *qtest, const char *id)
-{
-    QDict *resp;
-
-    resp = qtest_qmp(qtest,
-                     "{'execute': 'device_del', 'arguments': { 'id': %s } }", id);
-
-    g_assert(qdict_haskey(resp, "return"));
-    qobject_unref(resp);
-}
-
 static void system_reset(QTestState *qtest)
 {
     QDict *resp;
@@ -68,7 +57,7 @@ static void process_device_remove(QTestState *qtest, const char *id)
      * be processed. However during system reset, the removal will be
      * handled, removing the device.
      */
-    device_del(qtest, id);
+    qtest_qmp_device_del_send(qtest, id);
     system_reset(qtest);
     wait_device_deleted_event(qtest, id);
 }
@@ -112,7 +101,7 @@ static void test_ccw_unplug(void)
 {
     QTestState *qtest = qtest_initf("-device virtio-balloon-ccw,id=dev0");
 
-    device_del(qtest, "dev0");
+    qtest_qmp_device_del_send(qtest, "dev0");
     wait_device_deleted_event(qtest, "dev0");
 
     qtest_quit(qtest);
diff --git a/tests/qtest/drive_del-test.c b/tests/qtest/drive_del-test.c
index 5e6d58b4dd..467e752b0d 100644
--- a/tests/qtest/drive_del-test.c
+++ b/tests/qtest/drive_del-test.c
@@ -143,11 +143,7 @@ static void device_del(QTestState *qts, bool and_reset)
 {
     QDict *response;
 
-    response = qtest_qmp(qts, "{'execute': 'device_del',"
-                         " 'arguments': { 'id': 'dev0' } }");
-    g_assert(response);
-    g_assert(qdict_haskey(response, "return"));
-    qobject_unref(response);
+    qtest_qmp_device_del_send(qts, "dev0");
 
     if (and_reset) {
         response = qtest_qmp(qts, "{'execute': 'system_reset' }");
diff --git a/tests/qtest/libqos/pci-pc.c b/tests/qtest/libqos/pci-pc.c
index 81c2c055ca..96046287ac 100644
--- a/tests/qtest/libqos/pci-pc.c
+++ b/tests/qtest/libqos/pci-pc.c
@@ -179,13 +179,7 @@ void qpci_free_pc(QPCIBus *bus)
 
 void qpci_unplug_acpi_device_test(QTestState *qts, const char *id, uint8_t slot)
 {
-    QDict *response;
-
-    response = qtest_qmp(qts, "{'execute': 'device_del',"
-                              " 'arguments': {'id': %s}}", id);
-    g_assert(response);
-    g_assert(!qdict_haskey(response, "error"));
-    qobject_unref(response);
+    qtest_qmp_device_del_send(qts, id);
 
     qtest_outl(qts, ACPI_PCIHP_ADDR + PCI_EJ_BASE, 1 << slot);
 
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 4f4b2d6477..7b6152807b 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -1371,15 +1371,19 @@ void qtest_qmp_add_client(QTestState *qts, const char *protocol, int fd)
  *
  * {"return": {}}
  */
-void qtest_qmp_device_del(QTestState *qts, const char *id)
+void qtest_qmp_device_del_send(QTestState *qts, const char *id)
 {
-    QDict *rsp;
-
-    rsp = qtest_qmp(qts, "{'execute': 'device_del', 'arguments': {'id': %s}}",
-                    id);
-
+    QDict *rsp = qtest_qmp(qts, "{'execute': 'device_del', "
+                                "'arguments': {'id': %s}}", id);
+    g_assert(rsp);
     g_assert(qdict_haskey(rsp, "return"));
+    g_assert(!qdict_haskey(rsp, "error"));
     qobject_unref(rsp);
+}
+
+void qtest_qmp_device_del(QTestState *qts, const char *id)
+{
+    qtest_qmp_device_del_send(qts, id);
     qtest_qmp_eventwait(qts, "DEVICE_DELETED");
 }
 
-- 
2.31.1



  parent reply	other threads:[~2022-10-12 14:37 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-12 14:33 [PULL 00/16] qtest patches (and one unit test and one avocado fix) Thomas Huth
2022-10-12 14:33 ` [PULL 01/16] qtest: "-display none" is set in qtest_init() Thomas Huth
2022-10-12 14:33 ` [PULL 02/16] tests/migration: remove the unused local variable Thomas Huth
2022-10-12 14:33 ` Thomas Huth [this message]
2022-10-12 14:33 ` [PULL 04/16] tests/x86: Add subtest with 'q35' machine type to device-plug-test Thomas Huth
2022-10-12 14:33 ` [PULL 05/16] tests/x86: Refactor hot unplug hd-geo-test Thomas Huth
2022-10-12 14:33 ` [PULL 06/16] tests/x86: Add 'q35' machine type to override-tests in hd-geo-test Thomas Huth
2022-10-12 14:33 ` [PULL 07/16] tests/x86: Add 'q35' machine type to hotplug hd-geo-test Thomas Huth
2022-10-12 14:33 ` [PULL 08/16] tests/x86: Fix comment typo in drive_del-test Thomas Huth
2022-10-12 14:33 ` [PULL 09/16] tests/x86: replace snprint() by g_strdup_printf() " Thomas Huth
2022-10-12 14:33 ` [PULL 10/16] tests/x86: Add 'q35' machine type to drive_del-test Thomas Huth
2022-10-12 14:33 ` [PULL 11/16] tests/x86: Add 'q35' machine type to ivshmem-test Thomas Huth
2022-10-12 14:33 ` [PULL 12/16] tests/avocado: Add missing require_netdev('user') checks Thomas Huth
2022-10-12 14:33 ` [PULL 13/16] qtest: start a VNC test Thomas Huth
2022-10-12 14:33 ` [PULL 14/16] tests/qtest: migration-test: Avoid using hardcoded /tmp Thomas Huth
2022-10-12 14:33 ` [PULL 15/16] tests/qtest: libqtest: Install signal handler via signal() Thomas Huth
2022-10-12 14:33 ` [PULL 16/16] tests/unit/test-image-locking: Fix handling of temporary files Thomas Huth
2022-10-13 20:29 ` [PULL 00/16] qtest patches (and one unit test and one avocado fix) Stefan Hajnoczi

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=20221012143316.988561-4-thuth@redhat.com \
    --to=thuth@redhat.com \
    --cc=michael.labiuk@virtuozzo.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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).