Skip to contentSkip to conversation

Add 'q35' machine type to hotplug tests

PATCH In review Michael Labiuk via 4 participants 22 messages Sep 29, 2022 – Oct 18, 2022

lore
Share & tools
lore
#0 lore raw

v5 cover Add 'q35' machine type to hotplug tests

Add pci bridge setting to run hotplug tests on q35 machine type. Hotplug tests was bounded to 'pc' machine type by commit 7b172333f1b

v5 -> v4:

* Unify device removing in tests.
* Using qtest_has_machine("q35") as condition.
* fixed typos.
* Replaced snprintf.

v4 -> v3:

* Moving helper function process_device_remove() to separate commit.
* Refactoring hd-geo-test to avoid code duplication.

Michael Labiuk (9):
tests/x86: add helper qtest_qmp_device_del_send() tests/x86: Add subtest with 'q35' machine type to device-plug-test tests/x86: Refactor hot unplug hd-geo-test
tests/x86: Add 'q35' machine type to override-tests in hd-geo-test tests/x86: Add 'q35' machine type to hotplug hd-geo-test tests/x86: Fix comment typo in drive_del-test
tests/x86: replace snprint() by g_strdup_printf() in drive_del-test tests/x86: Add 'q35' machine type to drive_del-test tests/x86: Add 'q35' machine type to ivshmem-test

 tests/qtest/device-plug-test.c |  56 ++++--
 tests/qtest/drive_del-test.c   | 125 +++++++++++--
 tests/qtest/hd-geo-test.c      | 319 ++++++++++++++++++++++++---------
 tests/qtest/ivshmem-test.c     |  18 ++
 tests/qtest/libqos/pci-pc.c    |   8 +-
 tests/qtest/libqtest.c         |  16 +-
 tests/qtest/libqtest.h         |  10 ++
 7 files changed, 425 insertions(+), 127 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v5 1/9 tests/x86: add helper qtest_qmp_device_del_send()

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.

---
 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 ++++++++++------
 tests/qtest/libqtest.h         | 10 ++++++++++
 5 files changed, 24 insertions(+), 31 deletions(-)
tests/qtest/device-plug-test.c +2 -13
index e595b45b66..3841de1b8c 100644
@@ -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);
tests/qtest/drive_del-test.c +1 -5
index 5e6d58b4dd..467e752b0d 100644
@@ -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' }");
tests/qtest/libqos/pci-pc.c +1 -7
index 81c2c055ca..96046287ac 100644
@@ -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);
 
tests/qtest/libqtest.c +10 -6
index 4f4b2d6477..7b6152807b 100644
@@ -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");
 }
 
tests/qtest/libqtest.h +10 -0
index 3abc75964d..29ea9c697d 100644
@@ -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 comlition event.
  */
 void qtest_qmp_device_del(QTestState *qts, const char *id);
 
Signature · 1 line
2.34.1
Reviewed-by on v5 1/9
#2 lore raw

Re: [PATCH v5 1/9] tests/x86: add helper qtest_qmp_device_del_send()

Quoted 12 lines · Michael Labiuk via

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.

---
  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 ++++++++++------
  tests/qtest/libqtest.h         | 10 ++++++++++
  5 files changed, 24 insertions(+), 31 deletions(-)

[...]

Quoted 14 lines
tests/qtest/libqtest.h +6 -0
index 3abc75964d..29ea9c697d 100644
@@ -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.

tests/qtest/libqtest.h void qtest_qmp_device_add(QTestState *qts, const char *driver, const char *id, · line 779

Quoted 10 lines
tests/qtest/libqtest.h +4 -0
+ */
+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 comlition event.

Typo: "comlition" should be "completion", I guess?

Apart from that, patch looks fine, so with that fixed:

#3 lore raw

PATCH v5 2/9 tests/x86: Add subtest with 'q35' machine type to device-plug-test

In reply to Michael Labiuk via

Configure pci bridge setting to plug pci device and unplug.

---
 tests/qtest/device-plug-test.c | 41 ++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
tests/qtest/device-plug-test.c +41 -0
index 3841de1b8c..3f44f731d1 100644
@@ -79,6 +79,19 @@ static void test_pci_unplug_request(void)
     qtest_quit(qtest);
 }
 
+static void test_q35_pci_unplug_request(void)
+{
+
+    QTestState *qtest = qtest_initf("-machine q35 "
+                                    "-device pcie-root-port,id=p1 "
+                                    "-device pcie-pci-bridge,bus=p1,id=b1 "
+                                    "-device virtio-mouse-pci,bus=b1,id=dev0");
+
+    process_device_remove(qtest, "dev0");
+
+    qtest_quit(qtest);
+}
+
 static void test_pci_unplug_json_request(void)
 {
     const char *arch = qtest_get_arch();
@@ -97,6 +110,27 @@ static void test_pci_unplug_json_request(void)
     qtest_quit(qtest);
 }
 
+static void test_q35_pci_unplug_json_request(void)
+{
+    const char *port = "-device '{\"driver\": \"pcie-root-port\", "
+                                      "\"id\": \"p1\"}'";
+
+    const char *bridge = "-device '{\"driver\": \"pcie-pci-bridge\", "
+                                   "\"id\": \"b1\", "
+                                   "\"bus\": \"p1\"}'";
+
+    const char *device = "-device '{\"driver\": \"virtio-mouse-pci\", "
+                                   "\"bus\": \"b1\", "
+                                   "\"id\": \"dev0\"}'";
+
+    QTestState *qtest = qtest_initf("-machine q35 %s %s %s",
+                                    port, bridge, device);
+
+    process_device_remove(qtest, "dev0");
+
+    qtest_quit(qtest);
+}
+
 static void test_ccw_unplug(void)
 {
     QTestState *qtest = qtest_initf("-device virtio-balloon-ccw,id=dev0");
@@ -176,5 +210,12 @@ int main(int argc, char **argv)
                        test_spapr_phb_unplug_request);
     }
 
+    if (!strcmp(arch, "x86_64") && qtest_has_machine("q35")) {
+        qtest_add_func("/device-plug/q35-pci-unplug-request",
+                   test_q35_pci_unplug_request);
+        qtest_add_func("/device-plug/q35-pci-unplug-json-request",
+                   test_q35_pci_unplug_json_request);
+    }
+
     return g_test_run();
 }
Signature · 1 line
2.34.1
Reviewed-by on v5 2/9
#4 lore raw

Re: [PATCH v5 2/9] tests/x86: Add subtest with 'q35' machine type to device-plug-test

Quoted 6 lines · Michael Labiuk via

Configure pci bridge setting to plug pci device and unplug.

---
  tests/qtest/device-plug-test.c | 41 ++++++++++++++++++++++++++++++++++
  1 file changed, 41 insertions(+)
#5 lore raw

PATCH v5 3/9 tests/x86: Refactor hot unplug hd-geo-test

In reply to Michael Labiuk via

Moving common code to function.

---
 tests/qtest/hd-geo-test.c | 144 +++++++++++++++-----------------------
 1 file changed, 57 insertions(+), 87 deletions(-)
tests/qtest/hd-geo-test.c +57 -87
index ba772f4d7a..61f4c24b81 100644
@@ -691,7 +691,8 @@ static void add_virtio_disk(TestArgs *args,
     args->n_virtio_disks++;
 }
 
-static void test_override(TestArgs *args, CHSResult expected[])
+static void test_override(TestArgs *args, const char *arch,
+                          CHSResult expected[])
 {
     QTestState *qts;
     char *joined_args;
@@ -700,7 +701,7 @@ static void test_override(TestArgs *args, CHSResult expected[])
 
     joined_args = g_strjoinv(" ", args->argv);
 
-    qts = qtest_initf("-machine pc %s", joined_args);
+    qts = qtest_initf("-machine %s %s", arch, joined_args);
     fw_cfg = pc_fw_cfg_init(qts);
 
     read_bootdevices(fw_cfg, expected);
@@ -737,7 +738,7 @@ static void test_override_ide(void)
     add_ide_disk(args, 1, 0, 1, 9000, 120, 30);
     add_ide_disk(args, 2, 1, 0, 0, 1, 1);
     add_ide_disk(args, 3, 1, 1, 1, 0, 0);
-    test_override(args, expected);
+    test_override(args, "pc", expected);
 }
 
 static void test_override_scsi(void)
@@ -759,7 +760,7 @@ static void test_override_scsi(void)
     add_scsi_disk(args, 1, 0, 0, 1, 0, 9000, 120, 30);
     add_scsi_disk(args, 2, 0, 0, 2, 0, 1, 0, 0);
     add_scsi_disk(args, 3, 0, 0, 3, 0, 0, 1, 0);
-    test_override(args, expected);
+    test_override(args, "pc", expected);
 }
 
 static void test_override_scsi_2_controllers(void)
@@ -782,7 +783,7 @@ static void test_override_scsi_2_controllers(void)
     add_scsi_disk(args, 1, 0, 0, 1, 0, 9000, 120, 30);
     add_scsi_disk(args, 2, 1, 0, 0, 1, 1, 0, 0);
     add_scsi_disk(args, 3, 1, 0, 1, 2, 0, 1, 0);
-    test_override(args, expected);
+    test_override(args, "pc", expected);
 }
 
 static void test_override_virtio_blk(void)
@@ -797,7 +798,7 @@ static void test_override_virtio_blk(void)
     add_drive_with_mbr(args, empty_mbr, 1);
     add_virtio_disk(args, 0, "pci.0", 3, 10000, 120, 30);
     add_virtio_disk(args, 1, "pci.0", 4, 9000, 120, 30);
-    test_override(args, expected);
+    test_override(args, "pc", expected);
 }
 
 static void test_override_zero_chs(void)
@@ -808,16 +809,54 @@ static void test_override_zero_chs(void)
     };
     add_drive_with_mbr(args, empty_mbr, 1);
     add_ide_disk(args, 0, 1, 1, 0, 0, 0);
-    test_override(args, expected);
+    test_override(args, "pc", expected);
+}
+
+static void test_override_hot_unplug(TestArgs *args, const char *devid,
+                                     CHSResult expected[], CHSResult expected2[])
+{
+    QTestState *qts;
+    char *joined_args;
+    QFWCFG *fw_cfg;
+    QDict *response;
+    int i;
+
+    joined_args = g_strjoinv(" ", args->argv);
+
+    qts = qtest_initf("%s", joined_args);
+    fw_cfg = pc_fw_cfg_init(qts);
+
+    read_bootdevices(fw_cfg, expected);
+
+    /* unplug device an restart */
+    qtest_qmp_device_del_send(qts, devid);
+
+    response = qtest_qmp(qts,
+                         "{ 'execute': 'system_reset', 'arguments': { }}");
+    g_assert(response);
+    g_assert(!qdict_haskey(response, "error"));
+    qobject_unref(response);
+
+    qtest_qmp_eventwait(qts, "RESET");
+
+    read_bootdevices(fw_cfg, expected2);
+
+    g_free(joined_args);
+    qtest_quit(qts);
+
+    g_free(fw_cfg);
+
+    for (i = 0; i < args->n_drives; i++) {
+        unlink(args->drives[i]);
+        g_free(args->drives[i]);
+    }
+    g_free(args->drives);
+    g_strfreev(args->argv);
+    g_free(args);
 }
 
 static void test_override_scsi_hot_unplug(void)
 {
-    QTestState *qts;
-    char *joined_args;
-    QFWCFG *fw_cfg;
-    QDict *response;
-    int i;
     TestArgs *args = create_args();
     CHSResult expected[] = {
         {"/pci@i0cf8/scsi@2/channel@0/disk@0,0", {10000, 120, 30} },
@@ -834,51 +873,14 @@ static void test_override_scsi_hot_unplug(void)
     add_scsi_disk(args, 0, 0, 0, 0, 0, 10000, 120, 30);
     add_scsi_disk(args, 1, 0, 0, 1, 0, 20, 20, 20);
 
-    joined_args = g_strjoinv(" ", args->argv);
+    args->argc = append_arg(args->argc, args->argv, ARGV_SIZE,
+                            g_strdup("-machine pc"));
 
-    qts = qtest_initf("-machine pc %s", joined_args);
-    fw_cfg = pc_fw_cfg_init(qts);
-
-    read_bootdevices(fw_cfg, expected);
-
-    /* unplug device an restart */
-    response = qtest_qmp(qts,
-                         "{ 'execute': 'device_del',"
-                         "  'arguments': {'id': 'scsi-disk0' }}");
-    g_assert(response);
-    g_assert(!qdict_haskey(response, "error"));
-    qobject_unref(response);
-    response = qtest_qmp(qts,
-                         "{ 'execute': 'system_reset', 'arguments': { }}");
-    g_assert(response);
-    g_assert(!qdict_haskey(response, "error"));
-    qobject_unref(response);
-
-    qtest_qmp_eventwait(qts, "RESET");
-
-    read_bootdevices(fw_cfg, expected2);
-
-    g_free(joined_args);
-    qtest_quit(qts);
-
-    g_free(fw_cfg);
-
-    for (i = 0; i < args->n_drives; i++) {
-        unlink(args->drives[i]);
-        g_free(args->drives[i]);
-    }
-    g_free(args->drives);
-    g_strfreev(args->argv);
-    g_free(args);
+    test_override_hot_unplug(args, "scsi-disk0", expected, expected2);
 }
 
 static void test_override_virtio_hot_unplug(void)
 {
-    QTestState *qts;
-    char *joined_args;
-    QFWCFG *fw_cfg;
-    QDict *response;
-    int i;
     TestArgs *args = create_args();
     CHSResult expected[] = {
         {"/pci@i0cf8/scsi@2/disk@0,0", {10000, 120, 30} },
@@ -894,42 +896,10 @@ static void test_override_virtio_hot_unplug(void)
     add_virtio_disk(args, 0, "pci.0", 2, 10000, 120, 30);
     add_virtio_disk(args, 1, "pci.0", 3, 20, 20, 20);
 
-    joined_args = g_strjoinv(" ", args->argv);
+    args->argc = append_arg(args->argc, args->argv, ARGV_SIZE,
+                            g_strdup("-machine pc"));
 
-    qts = qtest_initf("-machine pc %s", joined_args);
-    fw_cfg = pc_fw_cfg_init(qts);
-
-    read_bootdevices(fw_cfg, expected);
-
-    /* unplug device an restart */
-    response = qtest_qmp(qts,
-                         "{ 'execute': 'device_del',"
-                         "  'arguments': {'id': 'virtio-disk0' }}");
-    g_assert(response);
-    g_assert(!qdict_haskey(response, "error"));
-    qobject_unref(response);
-    response = qtest_qmp(qts,
-                         "{ 'execute': 'system_reset', 'arguments': { }}");
-    g_assert(response);
-    g_assert(!qdict_haskey(response, "error"));
-    qobject_unref(response);
-
-    qtest_qmp_eventwait(qts, "RESET");
-
-    read_bootdevices(fw_cfg, expected2);
-
-    g_free(joined_args);
-    qtest_quit(qts);
-
-    g_free(fw_cfg);
-
-    for (i = 0; i < args->n_drives; i++) {
-        unlink(args->drives[i]);
-        g_free(args->drives[i]);
-    }
-    g_free(args->drives);
-    g_strfreev(args->argv);
-    g_free(args);
+    test_override_hot_unplug(args, "virtio-disk0", expected, expected2);
 }
 
 int main(int argc, char **argv)
Signature · 1 line
2.34.1
Reviewed-by on v5 3/9
#6 lore raw

Re: [PATCH v5 3/9] tests/x86: Refactor hot unplug hd-geo-test

Quoted 6 lines · Michael Labiuk via

Moving common code to function.

---
  tests/qtest/hd-geo-test.c | 144 +++++++++++++++-----------------------
  1 file changed, 57 insertions(+), 87 deletions(-)

Nice refactoring, nice diffstat!

#7 lore raw

PATCH v5 4/9 tests/x86: Add 'q35' machine type to override-tests in hd-geo-test

In reply to Michael Labiuk via
---
 tests/qtest/hd-geo-test.c | 97 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 97 insertions(+)
tests/qtest/hd-geo-test.c +97 -0
index 61f4c24b81..278464c379 100644
@@ -741,6 +741,27 @@ static void test_override_ide(void)
     test_override(args, "pc", expected);
 }
 
+static void test_override_sata(void)
+{
+    TestArgs *args = create_args();
+    CHSResult expected[] = {
+        {"/pci@i0cf8/pci8086,2922@1f,2/drive@0/disk@0", {10000, 120, 30} },
+        {"/pci@i0cf8/pci8086,2922@1f,2/drive@1/disk@0", {9000, 120, 30} },
+        {"/pci@i0cf8/pci8086,2922@1f,2/drive@2/disk@0", {0, 1, 1} },
+        {"/pci@i0cf8/pci8086,2922@1f,2/drive@3/disk@0", {1, 0, 0} },
+        {NULL, {0, 0, 0} }
+    };
+    add_drive_with_mbr(args, empty_mbr, 1);
+    add_drive_with_mbr(args, empty_mbr, 1);
+    add_drive_with_mbr(args, empty_mbr, 1);
+    add_drive_with_mbr(args, empty_mbr, 1);
+    add_ide_disk(args, 0, 0, 0, 10000, 120, 30);
+    add_ide_disk(args, 1, 1, 0, 9000, 120, 30);
+    add_ide_disk(args, 2, 2, 0, 0, 1, 1);
+    add_ide_disk(args, 3, 3, 0, 1, 0, 0);
+    test_override(args, "q35", expected);
+}
+
 static void test_override_scsi(void)
 {
     TestArgs *args = create_args();
@@ -763,6 +784,42 @@ static void test_override_scsi(void)
     test_override(args, "pc", expected);
 }
 
+static void setup_pci_bridge(TestArgs *args, const char *id, const char *rootid)
+{
+
+    char *root, *br;
+    root = g_strdup_printf("-device pcie-root-port,id=%s", rootid);
+    br = g_strdup_printf("-device pcie-pci-bridge,bus=%s,id=%s", rootid, id);
+
+    args->argc = append_arg(args->argc, args->argv, ARGV_SIZE, root);
+    args->argc = append_arg(args->argc, args->argv, ARGV_SIZE, br);
+}
+
+static void test_override_scsi_q35(void)
+{
+    TestArgs *args = create_args();
+    CHSResult expected[] = {
+        {   "/pci@i0cf8/pci-bridge@1/scsi@3/channel@0/disk@0,0",
+            {10000, 120, 30}
+        },
+        {"/pci@i0cf8/pci-bridge@1/scsi@3/channel@0/disk@1,0", {9000, 120, 30} },
+        {"/pci@i0cf8/pci-bridge@1/scsi@3/channel@0/disk@2,0", {1, 0, 0} },
+        {"/pci@i0cf8/pci-bridge@1/scsi@3/channel@0/disk@3,0", {0, 1, 0} },
+        {NULL, {0, 0, 0} }
+    };
+    add_drive_with_mbr(args, empty_mbr, 1);
+    add_drive_with_mbr(args, empty_mbr, 1);
+    add_drive_with_mbr(args, empty_mbr, 1);
+    add_drive_with_mbr(args, empty_mbr, 1);
+    setup_pci_bridge(args, "pcie.0", "br");
+    add_scsi_controller(args, "lsi53c895a", "br", 3);
+    add_scsi_disk(args, 0, 0, 0, 0, 0, 10000, 120, 30);
+    add_scsi_disk(args, 1, 0, 0, 1, 0, 9000, 120, 30);
+    add_scsi_disk(args, 2, 0, 0, 2, 0, 1, 0, 0);
+    add_scsi_disk(args, 3, 0, 0, 3, 0, 0, 1, 0);
+    test_override(args, "q35", expected);
+}
+
 static void test_override_scsi_2_controllers(void)
 {
     TestArgs *args = create_args();
@@ -801,6 +858,22 @@ static void test_override_virtio_blk(void)
     test_override(args, "pc", expected);
 }
 
+static void test_override_virtio_blk_q35(void)
+{
+    TestArgs *args = create_args();
+    CHSResult expected[] = {
+        {"/pci@i0cf8/pci-bridge@1/scsi@3/disk@0,0", {10000, 120, 30} },
+        {"/pci@i0cf8/pci-bridge@1/scsi@4/disk@0,0", {9000, 120, 30} },
+        {NULL, {0, 0, 0} }
+    };
+    add_drive_with_mbr(args, empty_mbr, 1);
+    add_drive_with_mbr(args, empty_mbr, 1);
+    setup_pci_bridge(args, "pcie.0", "br");
+    add_virtio_disk(args, 0, "br", 3, 10000, 120, 30);
+    add_virtio_disk(args, 1, "br", 4, 9000, 120, 30);
+    test_override(args, "q35", expected);
+}
+
 static void test_override_zero_chs(void)
 {
     TestArgs *args = create_args();
@@ -812,6 +885,17 @@ static void test_override_zero_chs(void)
     test_override(args, "pc", expected);
 }
 
+static void test_override_zero_chs_q35(void)
+{
+    TestArgs *args = create_args();
+    CHSResult expected[] = {
+        {NULL, {0, 0, 0} }
+    };
+    add_drive_with_mbr(args, empty_mbr, 1);
+    add_ide_disk(args, 0, 0, 0, 0, 0, 0);
+    test_override(args, "q35", expected);
+}
+
 static void test_override_hot_unplug(TestArgs *args, const char *devid,
                                      CHSResult expected[], CHSResult expected2[])
 {
@@ -944,6 +1028,19 @@ int main(int argc, char **argv)
                        test_override_scsi_hot_unplug);
         qtest_add_func("hd-geo/override/virtio_hot_unplug",
                        test_override_virtio_hot_unplug);
+
+        if (qtest_has_machine("q35")) {
+            qtest_add_func("hd-geo/override/sata", test_override_sata);
+            qtest_add_func("hd-geo/override/virtio_blk_q35",
+                           test_override_virtio_blk_q35);
+            qtest_add_func("hd-geo/override/zero_chs_q35",
+                           test_override_zero_chs_q35);
+
+            if (qtest_has_device("lsi53c895a")) {
+                qtest_add_func("hd-geo/override/scsi_q35",
+                               test_override_scsi_q35);
+            }
+        }
     } else {
         g_test_message("QTEST_QEMU_IMG not set or qemu-img missing; "
                        "skipping hd-geo/override/* tests");
Signature · 1 line
2.34.1
Acked-by on v5 4/9
#8 lore raw

Re: [PATCH v5 4/9] tests/x86: Add 'q35' machine type to override-tests in hd-geo-test

Quoted 131 lines · Michael Labiuk via
---
  tests/qtest/hd-geo-test.c | 97 +++++++++++++++++++++++++++++++++++++++
  1 file changed, 97 insertions(+)
tests/qtest/hd-geo-test.c +90 -0
index 61f4c24b81..278464c379 100644
@@ -741,6 +741,27 @@ static void test_override_ide(void)
      test_override(args, "pc", expected);
  }
 
+static void test_override_sata(void)
+{
+    TestArgs *args = create_args();
+    CHSResult expected[] = {
+        {"/pci@i0cf8/pci8086,2922@1f,2/drive@0/disk@0", {10000, 120, 30} },
+        {"/pci@i0cf8/pci8086,2922@1f,2/drive@1/disk@0", {9000, 120, 30} },
+        {"/pci@i0cf8/pci8086,2922@1f,2/drive@2/disk@0", {0, 1, 1} },
+        {"/pci@i0cf8/pci8086,2922@1f,2/drive@3/disk@0", {1, 0, 0} },
+        {NULL, {0, 0, 0} }
+    };
+    add_drive_with_mbr(args, empty_mbr, 1);
+    add_drive_with_mbr(args, empty_mbr, 1);
+    add_drive_with_mbr(args, empty_mbr, 1);
+    add_drive_with_mbr(args, empty_mbr, 1);
+    add_ide_disk(args, 0, 0, 0, 10000, 120, 30);
+    add_ide_disk(args, 1, 1, 0, 9000, 120, 30);
+    add_ide_disk(args, 2, 2, 0, 0, 1, 1);
+    add_ide_disk(args, 3, 3, 0, 1, 0, 0);
+    test_override(args, "q35", expected);
+}
+
  static void test_override_scsi(void)
  {
      TestArgs *args = create_args();
@@ -763,6 +784,42 @@ static void test_override_scsi(void)
      test_override(args, "pc", expected);
  }
 
+static void setup_pci_bridge(TestArgs *args, const char *id, const char *rootid)
+{
+
+    char *root, *br;
+    root = g_strdup_printf("-device pcie-root-port,id=%s", rootid);
+    br = g_strdup_printf("-device pcie-pci-bridge,bus=%s,id=%s", rootid, id);
+
+    args->argc = append_arg(args->argc, args->argv, ARGV_SIZE, root);
+    args->argc = append_arg(args->argc, args->argv, ARGV_SIZE, br);
+}
+
+static void test_override_scsi_q35(void)
+{
+    TestArgs *args = create_args();
+    CHSResult expected[] = {
+        {   "/pci@i0cf8/pci-bridge@1/scsi@3/channel@0/disk@0,0",
+            {10000, 120, 30}
+        },
+        {"/pci@i0cf8/pci-bridge@1/scsi@3/channel@0/disk@1,0", {9000, 120, 30} },
+        {"/pci@i0cf8/pci-bridge@1/scsi@3/channel@0/disk@2,0", {1, 0, 0} },
+        {"/pci@i0cf8/pci-bridge@1/scsi@3/channel@0/disk@3,0", {0, 1, 0} },
+        {NULL, {0, 0, 0} }
+    };
+    add_drive_with_mbr(args, empty_mbr, 1);
+    add_drive_with_mbr(args, empty_mbr, 1);
+    add_drive_with_mbr(args, empty_mbr, 1);
+    add_drive_with_mbr(args, empty_mbr, 1);
+    setup_pci_bridge(args, "pcie.0", "br");
+    add_scsi_controller(args, "lsi53c895a", "br", 3);
+    add_scsi_disk(args, 0, 0, 0, 0, 0, 10000, 120, 30);
+    add_scsi_disk(args, 1, 0, 0, 1, 0, 9000, 120, 30);
+    add_scsi_disk(args, 2, 0, 0, 2, 0, 1, 0, 0);
+    add_scsi_disk(args, 3, 0, 0, 3, 0, 0, 1, 0);
+    test_override(args, "q35", expected);
+}
+
  static void test_override_scsi_2_controllers(void)
  {
      TestArgs *args = create_args();
@@ -801,6 +858,22 @@ static void test_override_virtio_blk(void)
      test_override(args, "pc", expected);
  }
 
+static void test_override_virtio_blk_q35(void)
+{
+    TestArgs *args = create_args();
+    CHSResult expected[] = {
+        {"/pci@i0cf8/pci-bridge@1/scsi@3/disk@0,0", {10000, 120, 30} },
+        {"/pci@i0cf8/pci-bridge@1/scsi@4/disk@0,0", {9000, 120, 30} },
+        {NULL, {0, 0, 0} }
+    };
+    add_drive_with_mbr(args, empty_mbr, 1);
+    add_drive_with_mbr(args, empty_mbr, 1);
+    setup_pci_bridge(args, "pcie.0", "br");
+    add_virtio_disk(args, 0, "br", 3, 10000, 120, 30);
+    add_virtio_disk(args, 1, "br", 4, 9000, 120, 30);
+    test_override(args, "q35", expected);
+}
+
  static void test_override_zero_chs(void)
  {
      TestArgs *args = create_args();
@@ -812,6 +885,17 @@ static void test_override_zero_chs(void)
      test_override(args, "pc", expected);
  }
 
+static void test_override_zero_chs_q35(void)
+{
+    TestArgs *args = create_args();
+    CHSResult expected[] = {
+        {NULL, {0, 0, 0} }
+    };
+    add_drive_with_mbr(args, empty_mbr, 1);
+    add_ide_disk(args, 0, 0, 0, 0, 0, 0);
+    test_override(args, "q35", expected);
+}
+
  static void test_override_hot_unplug(TestArgs *args, const char *devid,
                                       CHSResult expected[], CHSResult expected2[])
  {
@@ -944,6 +1028,19 @@ int main(int argc, char **argv)
                         test_override_scsi_hot_unplug);
          qtest_add_func("hd-geo/override/virtio_hot_unplug",
                         test_override_virtio_hot_unplug);
+
+        if (qtest_has_machine("q35")) {
+            qtest_add_func("hd-geo/override/sata", test_override_sata);
+            qtest_add_func("hd-geo/override/virtio_blk_q35",
+                           test_override_virtio_blk_q35);
+            qtest_add_func("hd-geo/override/zero_chs_q35",

tests/qtest/hd-geo-test.c int main(int argc, char **argv) · line 1046

Quoted 10 lines
tests/qtest/hd-geo-test.c +7 -0
+                           test_override_zero_chs_q35);
+
+            if (qtest_has_device("lsi53c895a")) {
+                qtest_add_func("hd-geo/override/scsi_q35",
+                               test_override_scsi_q35);
+            }
+        }
      } else {
          g_test_message("QTEST_QEMU_IMG not set or qemu-img missing; "
                         "skipping hd-geo/override/* tests");
#9 lore raw

PATCH v5 5/9 tests/x86: Add 'q35' machine type to hotplug hd-geo-test

In reply to Michael Labiuk via

Add pci bridge setting to test hotplug.
Duplicate tests for plugging scsi and virtio devices for q35 machine type.

---
 tests/qtest/hd-geo-test.c | 76 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 75 insertions(+), 1 deletion(-)
tests/qtest/hd-geo-test.c +75 -1
index 278464c379..4a7628077b 100644
@@ -963,6 +963,42 @@ static void test_override_scsi_hot_unplug(void)
     test_override_hot_unplug(args, "scsi-disk0", expected, expected2);
 }
 
+static void test_override_scsi_hot_unplug_q35(void)
+{
+    TestArgs *args = create_args();
+    CHSResult expected[] = {
+        {
+            "/pci@i0cf8/pci-bridge@1/pci-bridge@0/scsi@2/channel@0/disk@0,0",
+            {10000, 120, 30}
+        },
+        {
+            "/pci@i0cf8/pci-bridge@1/pci-bridge@0/scsi@2/channel@0/disk@1,0",
+            {20, 20, 20}
+        },
+        {NULL, {0, 0, 0} }
+    };
+    CHSResult expected2[] = {
+        {
+            "/pci@i0cf8/pci-bridge@1/pci-bridge@0/scsi@2/channel@0/disk@1,0",
+            {20, 20, 20}
+        },
+        {NULL, {0, 0, 0} }
+    };
+
+    args->argc = append_arg(args->argc, args->argv, ARGV_SIZE,
+                            g_strdup("-device pcie-root-port,id=p0 "
+                                     "-device pcie-pci-bridge,bus=p0,id=b1 "
+                                     "-machine q35"));
+
+    add_drive_with_mbr(args, empty_mbr, 1);
+    add_drive_with_mbr(args, empty_mbr, 1);
+    add_scsi_controller(args, "virtio-scsi-pci", "b1", 2);
+    add_scsi_disk(args, 0, 0, 0, 0, 0, 10000, 120, 30);
+    add_scsi_disk(args, 1, 0, 0, 1, 0, 20, 20, 20);
+
+    test_override_hot_unplug(args, "scsi-disk0", expected, expected2);
+}
+
 static void test_override_virtio_hot_unplug(void)
 {
     TestArgs *args = create_args();
@@ -986,6 +1022,41 @@ static void test_override_virtio_hot_unplug(void)
     test_override_hot_unplug(args, "virtio-disk0", expected, expected2);
 }
 
+static void test_override_virtio_hot_unplug_q35(void)
+{
+    TestArgs *args = create_args();
+    CHSResult expected[] = {
+        {
+            "/pci@i0cf8/pci-bridge@1/pci-bridge@0/scsi@2/disk@0,0",
+            {10000, 120, 30}
+        },
+        {
+            "/pci@i0cf8/pci-bridge@1/pci-bridge@0/scsi@3/disk@0,0",
+            {20, 20, 20}
+        },
+        {NULL, {0, 0, 0} }
+    };
+    CHSResult expected2[] = {
+        {
+            "/pci@i0cf8/pci-bridge@1/pci-bridge@0/scsi@3/disk@0,0",
+            {20, 20, 20}
+        },
+        {NULL, {0, 0, 0} }
+    };
+
+    args->argc = append_arg(args->argc, args->argv, ARGV_SIZE,
+                            g_strdup("-device pcie-root-port,id=p0 "
+                                     "-device pcie-pci-bridge,bus=p0,id=b1 "
+                                     "-machine q35"));
+
+    add_drive_with_mbr(args, empty_mbr, 1);
+    add_drive_with_mbr(args, empty_mbr, 1);
+    add_virtio_disk(args, 0, "b1", 2, 10000, 120, 30);
+    add_virtio_disk(args, 1, "b1", 3, 20, 20, 20);
+
+    test_override_hot_unplug(args, "virtio-disk0", expected, expected2);
+}
+
 int main(int argc, char **argv)
 {
     Backend i;
@@ -1035,11 +1106,14 @@ int main(int argc, char **argv)
                            test_override_virtio_blk_q35);
             qtest_add_func("hd-geo/override/zero_chs_q35",
                            test_override_zero_chs_q35);
-
             if (qtest_has_device("lsi53c895a")) {
                 qtest_add_func("hd-geo/override/scsi_q35",
                                test_override_scsi_q35);
             }
+            qtest_add_func("hd-geo/override/scsi_hot_unplug_q35",
+                           test_override_scsi_hot_unplug_q35);
+            qtest_add_func("hd-geo/override/virtio_hot_unplug_q35",
+                           test_override_virtio_hot_unplug_q35);
         }
     } else {
         g_test_message("QTEST_QEMU_IMG not set or qemu-img missing; "
Signature · 1 line
2.34.1
Acked-by on v5 5/9
#10 lore raw

Re: [PATCH v5 5/9] tests/x86: Add 'q35' machine type to hotplug hd-geo-test

Quoted 103 lines · Michael Labiuk via

Add pci bridge setting to test hotplug.
Duplicate tests for plugging scsi and virtio devices for q35 machine type.

---
  tests/qtest/hd-geo-test.c | 76 ++++++++++++++++++++++++++++++++++++++-
  1 file changed, 75 insertions(+), 1 deletion(-)
tests/qtest/hd-geo-test.c +71 -1
index 278464c379..4a7628077b 100644
@@ -963,6 +963,42 @@ static void test_override_scsi_hot_unplug(void)
      test_override_hot_unplug(args, "scsi-disk0", expected, expected2);
  }
 
+static void test_override_scsi_hot_unplug_q35(void)
+{
+    TestArgs *args = create_args();
+    CHSResult expected[] = {
+        {
+            "/pci@i0cf8/pci-bridge@1/pci-bridge@0/scsi@2/channel@0/disk@0,0",
+            {10000, 120, 30}
+        },
+        {
+            "/pci@i0cf8/pci-bridge@1/pci-bridge@0/scsi@2/channel@0/disk@1,0",
+            {20, 20, 20}
+        },
+        {NULL, {0, 0, 0} }
+    };
+    CHSResult expected2[] = {
+        {
+            "/pci@i0cf8/pci-bridge@1/pci-bridge@0/scsi@2/channel@0/disk@1,0",
+            {20, 20, 20}
+        },
+        {NULL, {0, 0, 0} }
+    };
+
+    args->argc = append_arg(args->argc, args->argv, ARGV_SIZE,
+                            g_strdup("-device pcie-root-port,id=p0 "
+                                     "-device pcie-pci-bridge,bus=p0,id=b1 "
+                                     "-machine q35"));
+
+    add_drive_with_mbr(args, empty_mbr, 1);
+    add_drive_with_mbr(args, empty_mbr, 1);
+    add_scsi_controller(args, "virtio-scsi-pci", "b1", 2);
+    add_scsi_disk(args, 0, 0, 0, 0, 0, 10000, 120, 30);
+    add_scsi_disk(args, 1, 0, 0, 1, 0, 20, 20, 20);
+
+    test_override_hot_unplug(args, "scsi-disk0", expected, expected2);
+}
+
  static void test_override_virtio_hot_unplug(void)
  {
      TestArgs *args = create_args();
@@ -986,6 +1022,41 @@ static void test_override_virtio_hot_unplug(void)
      test_override_hot_unplug(args, "virtio-disk0", expected, expected2);
  }
 
+static void test_override_virtio_hot_unplug_q35(void)
+{
+    TestArgs *args = create_args();
+    CHSResult expected[] = {
+        {
+            "/pci@i0cf8/pci-bridge@1/pci-bridge@0/scsi@2/disk@0,0",
+            {10000, 120, 30}
+        },
+        {
+            "/pci@i0cf8/pci-bridge@1/pci-bridge@0/scsi@3/disk@0,0",
+            {20, 20, 20}
+        },
+        {NULL, {0, 0, 0} }
+    };
+    CHSResult expected2[] = {
+        {
+            "/pci@i0cf8/pci-bridge@1/pci-bridge@0/scsi@3/disk@0,0",
+            {20, 20, 20}
+        },
+        {NULL, {0, 0, 0} }
+    };
+
+    args->argc = append_arg(args->argc, args->argv, ARGV_SIZE,
+                            g_strdup("-device pcie-root-port,id=p0 "
+                                     "-device pcie-pci-bridge,bus=p0,id=b1 "
+                                     "-machine q35"));
+
+    add_drive_with_mbr(args, empty_mbr, 1);
+    add_drive_with_mbr(args, empty_mbr, 1);
+    add_virtio_disk(args, 0, "b1", 2, 10000, 120, 30);
+    add_virtio_disk(args, 1, "b1", 3, 20, 20, 20);
+
+    test_override_hot_unplug(args, "virtio-disk0", expected, expected2);
+}
+
  int main(int argc, char **argv)
  {
      Backend i;
@@ -1035,11 +1106,14 @@ int main(int argc, char **argv)
                             test_override_virtio_blk_q35);
              qtest_add_func("hd-geo/override/zero_chs_q35",
                             test_override_zero_chs_q35);
-
              if (qtest_has_device("lsi53c895a")) {

tests/qtest/hd-geo-test.c int main(int argc, char **argv) · line 1119

Quoted 10 lines
tests/qtest/hd-geo-test.c +4 -0
                  qtest_add_func("hd-geo/override/scsi_q35",
                                 test_override_scsi_q35);
              }
+            qtest_add_func("hd-geo/override/scsi_hot_unplug_q35",
+                           test_override_scsi_hot_unplug_q35);
+            qtest_add_func("hd-geo/override/virtio_hot_unplug_q35",
+                           test_override_virtio_hot_unplug_q35);
          }
      } else {
          g_test_message("QTEST_QEMU_IMG not set or qemu-img missing; "
#11 lore raw

PATCH v5 6/9 tests/x86: Fix comment typo in drive_del-test

In reply to Michael Labiuk via
---
 tests/qtest/drive_del-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qtest/drive_del-test.c +1 -1
index 467e752b0d..44b9578801 100644
@@ -327,7 +327,7 @@ static void test_blockdev_add_device_add_and_del(void)
     qts = qtest_init(machine_addition);
 
     /*
-     * blockdev_add/device_add and device_del.  The it drive is used by a
+     * blockdev_add/device_add and device_del. The drive is used by a
      * device that unplugs after reset, but it doesn't go away.
      */
     blockdev_add_with_media(qts);
Signature · 1 line
2.34.1
Reviewed-by on v5 6/9
#12 lore raw

Re: [PATCH v5 6/9] tests/x86: Fix comment typo in drive_del-test

Quoted 10 lines · Michael Labiuk via
---
  tests/qtest/drive_del-test.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tests/qtest/drive_del-test.c +0 -0
index 467e752b0d..44b9578801 100644

tests/qtest/drive_del-test.c static void test_blockdev_add_device_add_and_del(void) · line 333

Quoted 8 lines
tests/qtest/drive_del-test.c +1 -1
@@ -327,7 +327,7 @@ static void test_blockdev_add_device_add_and_del(void)
      qts = qtest_init(machine_addition);
 
      /*
-     * blockdev_add/device_add and device_del.  The it drive is used by a
+     * blockdev_add/device_add and device_del. The drive is used by a
       * device that unplugs after reset, but it doesn't go away.
       */
      blockdev_add_with_media(qts);
#13 lore raw

PATCH v5 7/9 tests/x86: replace snprint() by g_strdup_printf() in drive_del-test

In reply to Michael Labiuk via

Using g_autofree char* and g_strdup_printf(...) instead of ugly snprintf on stack array.

---
 tests/qtest/drive_del-test.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
tests/qtest/drive_del-test.c +4 -6
index 44b9578801..106c613f4f 100644
@@ -123,12 +123,10 @@ static const char *qvirtio_get_dev_type(void)
 
 static void device_add(QTestState *qts)
 {
-    QDict *response;
-    char driver[32];
-    snprintf(driver, sizeof(driver), "virtio-blk-%s",
-             qvirtio_get_dev_type());
-
-    response = qtest_qmp(qts, "{'execute': 'device_add',"
+    g_autofree char *driver = g_strdup_printf("virtio-blk-%s",
+                                              qvirtio_get_dev_type());
+    QDict *response =
+               qtest_qmp(qts, "{'execute': 'device_add',"
                               " 'arguments': {"
                               "   'driver': %s,"
                               "   'drive': 'drive0',"
Signature · 1 line
2.34.1
Reviewed-by on v5 7/9
#14 lore raw

Re: [PATCH v5 7/9] tests/x86: replace snprint() by g_strdup_printf() in drive_del-test

Quoted 19 lines · Michael Labiuk via

Using g_autofree char* and g_strdup_printf(...) instead of ugly snprintf on stack array.

---
  tests/qtest/drive_del-test.c | 10 ++++------
  1 file changed, 4 insertions(+), 6 deletions(-)
tests/qtest/drive_del-test.c +0 -3
index 44b9578801..106c613f4f 100644
@@ -123,12 +123,10 @@ static const char *qvirtio_get_dev_type(void)
 
  static void device_add(QTestState *qts)
  {
-    QDict *response;
-    char driver[32];
-    snprintf(driver, sizeof(driver), "virtio-blk-%s",

tests/qtest/drive_del-test.c static const char *qvirtio_get_dev_type(void) · line 132

Quoted 10 lines
tests/qtest/drive_del-test.c +4 -3
-             qvirtio_get_dev_type());
-
-    response = qtest_qmp(qts, "{'execute': 'device_add',"
+    g_autofree char *driver = g_strdup_printf("virtio-blk-%s",
+                                              qvirtio_get_dev_type());
+    QDict *response =
+               qtest_qmp(qts, "{'execute': 'device_add',"
                                " 'arguments': {"
                                "   'driver': %s,"
                                "   'drive': 'drive0',"
Reviewed-by on v5 7/9
#15 lore raw

Re: [PATCH v5 7/9] tests/x86: replace snprint() by g_strdup_printf() in drive_del-test

In reply to Michael Labiuk via
Quoted 7 lines · Michael Labiuk via

Using g_autofree char* and g_strdup_printf(...) instead of ugly snprintf on stack array.

---
  tests/qtest/drive_del-test.c | 10 ++++------
  1 file changed, 4 insertions(+), 6 deletions(-)
#16 lore raw

PATCH v5 8/9 tests/x86: Add 'q35' machine type to drive_del-test

In reply to Michael Labiuk via

Configure pci bridge setting to run tests on 'q35' machine type.

---
 tests/qtest/drive_del-test.c | 107 +++++++++++++++++++++++++++++++++++
 1 file changed, 107 insertions(+)
tests/qtest/drive_del-test.c +107 -0
index 106c613f4f..9a750395a9 100644
@@ -252,6 +252,27 @@ static void test_cli_device_del(void)
     qtest_quit(qts);
 }
 
+static void test_cli_device_del_q35(void)
+{
+    QTestState *qts;
+
+    /*
+     * -drive/-device and device_del.  Start with a drive used by a
+     * device that unplugs after reset.
+     */
+    qts = qtest_initf("-drive if=none,id=drive0,file=null-co://,"
+                      "file.read-zeroes=on,format=raw "
+                      "-machine q35 -device pcie-root-port,id=p1 "
+                      "-device pcie-pci-bridge,bus=p1,id=b1 "
+                      "-device virtio-blk-%s,drive=drive0,bus=b1,id=dev0",
+                      qvirtio_get_dev_type());
+
+    device_del(qts, true);
+    g_assert(!has_drive(qts));
+
+    qtest_quit(qts);
+}
+
 static void test_empty_device_del(void)
 {
     QTestState *qts;
@@ -288,6 +309,43 @@ static void test_device_add_and_del(void)
     qtest_quit(qts);
 }
 
+static void device_add_q35(QTestState *qts)
+{
+    g_autofree char *driver = g_strdup_printf("virtio-blk-%s",
+                                              qvirtio_get_dev_type());
+    QDict *response =
+               qtest_qmp(qts, "{'execute': 'device_add',"
+                              " 'arguments': {"
+                              "   'driver': %s,"
+                              "   'drive': 'drive0',"
+                              "   'id': 'dev0',"
+                              "   'bus': 'b1'"
+                              "}}", driver);
+    g_assert(response);
+    g_assert(qdict_haskey(response, "return"));
+    qobject_unref(response);
+}
+
+static void test_device_add_and_del_q35(void)
+{
+    QTestState *qts;
+
+    /*
+     * -drive/device_add and device_del.  Start with a drive used by a
+     * device that unplugs after reset.
+     */
+    qts = qtest_initf("-machine q35 -device pcie-root-port,id=p1 "
+                     "-device pcie-pci-bridge,bus=p1,id=b1 "
+                     "-drive if=none,id=drive0,file=null-co://,"
+                     "file.read-zeroes=on,format=raw");
+
+    device_add_q35(qts);
+    device_del(qts, true);
+    g_assert(!has_drive(qts));
+
+    qtest_quit(qts);
+}
+
 static void test_drive_add_device_add_and_del(void)
 {
     QTestState *qts;
@@ -312,6 +370,25 @@ static void test_drive_add_device_add_and_del(void)
     qtest_quit(qts);
 }
 
+static void test_drive_add_device_add_and_del_q35(void)
+{
+    QTestState *qts;
+
+    qts = qtest_init("-machine q35 -device pcie-root-port,id=p1 "
+                     "-device pcie-pci-bridge,bus=p1,id=b1");
+
+    /*
+     * drive_add/device_add and device_del.  The drive is used by a
+     * device that unplugs after reset.
+     */
+    drive_add_with_media(qts);
+    device_add_q35(qts);
+    device_del(qts, true);
+    g_assert(!has_drive(qts));
+
+    qtest_quit(qts);
+}
+
 static void test_blockdev_add_device_add_and_del(void)
 {
     QTestState *qts;
@@ -336,6 +413,25 @@ static void test_blockdev_add_device_add_and_del(void)
     qtest_quit(qts);
 }
 
+static void test_blockdev_add_device_add_and_del_q35(void)
+{
+    QTestState *qts;
+
+    qts = qtest_init("-machine q35 -device pcie-root-port,id=p1 "
+                     "-device pcie-pci-bridge,bus=p1,id=b1");
+
+    /*
+     * blockdev_add/device_add and device_del. The drive is used by a
+     * device that unplugs after reset, but it doesn't go away.
+     */
+    blockdev_add_with_media(qts);
+    device_add_q35(qts);
+    device_del(qts, true);
+    g_assert(has_blockdev(qts));
+
+    qtest_quit(qts);
+}
+
 int main(int argc, char **argv)
 {
     g_test_init(&argc, &argv, NULL);
@@ -357,6 +453,17 @@ int main(int argc, char **argv)
                        test_empty_device_del);
         qtest_add_func("/device_del/blockdev",
                        test_blockdev_add_device_add_and_del);
+
+        if (qtest_has_machine("q35")) {
+            qtest_add_func("/device_del/drive/cli_device_q35",
+                           test_cli_device_del_q35);
+            qtest_add_func("/device_del/drive/device_add_q35",
+                           test_device_add_and_del_q35);
+            qtest_add_func("/device_del/drive/drive_add_device_add_q35",
+                           test_drive_add_device_add_and_del_q35);
+            qtest_add_func("/device_del/blockdev_q35",
+                           test_blockdev_add_device_add_and_del_q35);
+        }
     }
 
     return g_test_run();
Signature · 1 line
2.34.1
Reviewed-by on v5 8/9
#17 lore raw

Re: [PATCH v5 8/9] tests/x86: Add 'q35' machine type to drive_del-test

Quoted 143 lines · Michael Labiuk via

Configure pci bridge setting to run tests on 'q35' machine type.

---
  tests/qtest/drive_del-test.c | 107 +++++++++++++++++++++++++++++++++++
  1 file changed, 107 insertions(+)
tests/qtest/drive_del-test.c +100 -0
index 106c613f4f..9a750395a9 100644
@@ -252,6 +252,27 @@ static void test_cli_device_del(void)
      qtest_quit(qts);
  }
 
+static void test_cli_device_del_q35(void)
+{
+    QTestState *qts;
+
+    /*
+     * -drive/-device and device_del.  Start with a drive used by a
+     * device that unplugs after reset.
+     */
+    qts = qtest_initf("-drive if=none,id=drive0,file=null-co://,"
+                      "file.read-zeroes=on,format=raw "
+                      "-machine q35 -device pcie-root-port,id=p1 "
+                      "-device pcie-pci-bridge,bus=p1,id=b1 "
+                      "-device virtio-blk-%s,drive=drive0,bus=b1,id=dev0",
+                      qvirtio_get_dev_type());
+
+    device_del(qts, true);
+    g_assert(!has_drive(qts));
+
+    qtest_quit(qts);
+}
+
  static void test_empty_device_del(void)
  {
      QTestState *qts;
@@ -288,6 +309,43 @@ static void test_device_add_and_del(void)
      qtest_quit(qts);
  }
 
+static void device_add_q35(QTestState *qts)
+{
+    g_autofree char *driver = g_strdup_printf("virtio-blk-%s",
+                                              qvirtio_get_dev_type());
+    QDict *response =
+               qtest_qmp(qts, "{'execute': 'device_add',"
+                              " 'arguments': {"
+                              "   'driver': %s,"
+                              "   'drive': 'drive0',"
+                              "   'id': 'dev0',"
+                              "   'bus': 'b1'"
+                              "}}", driver);
+    g_assert(response);
+    g_assert(qdict_haskey(response, "return"));
+    qobject_unref(response);
+}
+
+static void test_device_add_and_del_q35(void)
+{
+    QTestState *qts;
+
+    /*
+     * -drive/device_add and device_del.  Start with a drive used by a
+     * device that unplugs after reset.
+     */
+    qts = qtest_initf("-machine q35 -device pcie-root-port,id=p1 "
+                     "-device pcie-pci-bridge,bus=p1,id=b1 "
+                     "-drive if=none,id=drive0,file=null-co://,"
+                     "file.read-zeroes=on,format=raw");
+
+    device_add_q35(qts);
+    device_del(qts, true);
+    g_assert(!has_drive(qts));
+
+    qtest_quit(qts);
+}
+
  static void test_drive_add_device_add_and_del(void)
  {
      QTestState *qts;
@@ -312,6 +370,25 @@ static void test_drive_add_device_add_and_del(void)
      qtest_quit(qts);
  }
 
+static void test_drive_add_device_add_and_del_q35(void)
+{
+    QTestState *qts;
+
+    qts = qtest_init("-machine q35 -device pcie-root-port,id=p1 "
+                     "-device pcie-pci-bridge,bus=p1,id=b1");
+
+    /*
+     * drive_add/device_add and device_del.  The drive is used by a
+     * device that unplugs after reset.
+     */
+    drive_add_with_media(qts);
+    device_add_q35(qts);
+    device_del(qts, true);
+    g_assert(!has_drive(qts));
+
+    qtest_quit(qts);
+}
+
  static void test_blockdev_add_device_add_and_del(void)
  {
      QTestState *qts;
@@ -336,6 +413,25 @@ static void test_blockdev_add_device_add_and_del(void)
      qtest_quit(qts);
  }
 
+static void test_blockdev_add_device_add_and_del_q35(void)
+{
+    QTestState *qts;
+
+    qts = qtest_init("-machine q35 -device pcie-root-port,id=p1 "
+                     "-device pcie-pci-bridge,bus=p1,id=b1");
+
+    /*
+     * blockdev_add/device_add and device_del. The drive is used by a
+     * device that unplugs after reset, but it doesn't go away.
+     */
+    blockdev_add_with_media(qts);
+    device_add_q35(qts);
+    device_del(qts, true);
+    g_assert(has_blockdev(qts));
+
+    qtest_quit(qts);
+}
+
  int main(int argc, char **argv)
  {
      g_test_init(&argc, &argv, NULL);
@@ -357,6 +453,17 @@ int main(int argc, char **argv)
                         test_empty_device_del);
          qtest_add_func("/device_del/blockdev",
                         test_blockdev_add_device_add_and_del);
+
+        if (qtest_has_machine("q35")) {
+            qtest_add_func("/device_del/drive/cli_device_q35",
+                           test_cli_device_del_q35);

tests/qtest/drive_del-test.c int main(int argc, char **argv) · line 469

Quoted 10 lines
tests/qtest/drive_del-test.c +7 -0
+            qtest_add_func("/device_del/drive/device_add_q35",
+                           test_device_add_and_del_q35);
+            qtest_add_func("/device_del/drive/drive_add_device_add_q35",
+                           test_drive_add_device_add_and_del_q35);
+            qtest_add_func("/device_del/blockdev_q35",
+                           test_blockdev_add_device_add_and_del_q35);
+        }
      }
 
      return g_test_run();
#18 lore raw

PATCH v5 9/9 tests/x86: Add 'q35' machine type to ivshmem-test

In reply to Michael Labiuk via

Configure pci bridge setting to test ivshmem on 'q35'.

---
 tests/qtest/ivshmem-test.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
tests/qtest/ivshmem-test.c +18 -0
index 9611d05eb5..cd550c8935 100644
@@ -378,6 +378,20 @@ static void test_ivshmem_server(void)
     close(thread.pipe[0]);
 }
 
+static void test_ivshmem_hotplug_q35(void)
+{
+    QTestState *qts = qtest_init("-object memory-backend-ram,size=1M,id=mb1 "
+                                 "-device pcie-root-port,id=p1 "
+                                 "-device pcie-pci-bridge,bus=p1,id=b1 "
+                                 "-machine q35");
+
+    qtest_qmp_device_add(qts, "ivshmem-plain", "iv1",
+                         "{'memdev': 'mb1', 'bus': 'b1'}");
+    qtest_qmp_device_del_send(qts, "iv1");
+
+    qtest_quit(qts);
+}
+
 #define PCI_SLOT_HP             0x06
 
 static void test_ivshmem_hotplug(void)
@@ -469,6 +483,7 @@ int main(int argc, char **argv)
 {
     int ret, fd;
     gchar dir[] = "/tmp/ivshmem-test.XXXXXX";
+    const char *arch = qtest_get_arch();
 
     g_test_init(&argc, &argv, NULL);
 
@@ -494,6 +509,9 @@ int main(int argc, char **argv)
         qtest_add_func("/ivshmem/pair", test_ivshmem_pair);
         qtest_add_func("/ivshmem/server", test_ivshmem_server);
     }
+    if (!strcmp(arch, "x86_64") && qtest_has_machine("q35")) {
+        qtest_add_func("/ivshmem/hotplug-q35", test_ivshmem_hotplug_q35);
+    }
 
 out:
     ret = g_test_run();
Signature · 1 line
2.34.1
#20 lore raw

PATCH v5 1/1 Add 'q35' machine type to hotplug tests

In reply to Michael Labiuk via

I would like to ping a patch

https://patchew.org/QEMU/[email protected]/

Quoted 35 lines · Michael Labiuk via

Add pci bridge setting to run hotplug tests on q35 machine type. Hotplug tests was bounded to 'pc' machine type by commit 7b172333f1b

v5 -> v4:

* Unify device removing in tests.
* Using qtest_has_machine("q35") as condition.
* fixed typos.
* Replaced snprintf.

v4 -> v3:

* Moving helper function process_device_remove() to separate commit.
* Refactoring hd-geo-test to avoid code duplication.

Michael Labiuk (9):
tests/x86: add helper qtest_qmp_device_del_send() tests/x86: Add subtest with 'q35' machine type to device-plug-test tests/x86: Refactor hot unplug hd-geo-test
tests/x86: Add 'q35' machine type to override-tests in hd-geo-test tests/x86: Add 'q35' machine type to hotplug hd-geo-test tests/x86: Fix comment typo in drive_del-test
tests/x86: replace snprint() by g_strdup_printf() in drive_del-test tests/x86: Add 'q35' machine type to drive_del-test tests/x86: Add 'q35' machine type to ivshmem-test

  tests/qtest/device-plug-test.c |  56 ++++--
  tests/qtest/drive_del-test.c   | 125 +++++++++++--
  tests/qtest/hd-geo-test.c      | 319 ++++++++++++++++++++++++---------
  tests/qtest/ivshmem-test.c     |  18 ++
  tests/qtest/libqos/pci-pc.c    |   8 +-
  tests/qtest/libqtest.c         |  16 +-
  tests/qtest/libqtest.h         |  10 ++
  7 files changed, 425 insertions(+), 127 deletions(-)
#21 lore raw
Quoted 1 line · Michael Labiuk

I would like to ping a patch

Sorry, it took me a little bit longer to get back to this...

Anyway, patches look fine, and I've queued them now (with the typo fixed in the first patch) to my testing-next branch:

https://gitlab.com/thuth/qemu/-/commits/testing-next

Thomas

Quoted 39 lines · Michael Labiuk via
Quoted 35 lines

Add pci bridge setting to run hotplug tests on q35 machine type. Hotplug tests was bounded to 'pc' machine type by commit 7b172333f1b

v5 -> v4:

* Unify device removing in tests.
* Using qtest_has_machine("q35") as condition.
* fixed typos.
* Replaced snprintf.

v4 -> v3:

* Moving helper function process_device_remove() to separate commit.
* Refactoring hd-geo-test to avoid code duplication.

Michael Labiuk (9):
   tests/x86: add helper qtest_qmp_device_del_send() tests/x86: Add subtest with 'q35' machine type to device-plug-test tests/x86: Refactor hot unplug hd-geo-test
   tests/x86: Add 'q35' machine type to override-tests in hd-geo-test tests/x86: Add 'q35' machine type to hotplug hd-geo-test tests/x86: Fix comment typo in drive_del-test
   tests/x86: replace snprint() by g_strdup_printf() in drive_del-test tests/x86: Add 'q35' machine type to drive_del-test tests/x86: Add 'q35' machine type to ivshmem-test

  tests/qtest/device-plug-test.c |  56 ++++-- tests/qtest/drive_del-test.c   | 125 +++++++++++-- tests/qtest/hd-geo-test.c      | 319 ++++++++++++++++++++++++--------- tests/qtest/ivshmem-test.c     |  18 ++ tests/qtest/libqos/pci-pc.c    |   8 +- tests/qtest/libqtest.c         |  16 +- tests/qtest/libqtest.h         |  10 ++

  7 files changed, 425 insertions(+), 127 deletions(-)