Skip to contentSkip to conversation

tests/x86: Add 'q35' machine type to hotplug tests

PATCH Superseded Michael Labiuk via 3 participants 3 messages Aug 26, 2022 – Aug 31, 2022

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/x86: 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

---
 tests/qtest/device-plug-test.c |  26 ++++++
 tests/qtest/drive_del-test.c   | 111 +++++++++++++++++++++++++
 tests/qtest/hd-geo-test.c      | 148 +++++++++++++++++++++++++++++++++
 tests/qtest/ivshmem-test.c     |  30 +++++++
 4 files changed, 315 insertions(+)
tests/qtest/device-plug-test.c +26 -0
index 2e3137843e..2f07b37ba1 100644
@@ -165,6 +165,26 @@ static void test_spapr_phb_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");
+
+    /*
+     * Request device removal. As the guest is not running, the request won't
+     * be processed. However during system reset, the removal will be
+     * handled, removing the device.
+     */
+    device_del(qtest, "dev0");
+    system_reset(qtest);
+    wait_device_deleted_event(qtest, "dev0");
+
+    qtest_quit(qtest);
+}
+
 int main(int argc, char **argv)
 {
     const char *arch = qtest_get_arch();
@@ -195,5 +215,11 @@ int main(int argc, char **argv)
                        test_spapr_phb_unplug_request);
     }
 
+    if (!strcmp(arch, "x86_64")) {
+        qtest_add_func("/device-plug/q35-pci-unplug-request",
+                   test_q35_pci_unplug_request);
+
+    }
+
     return g_test_run();
 }
tests/qtest/drive_del-test.c +111 -0

143 lines not on this page · raw message

tests/qtest/hd-geo-test.c +148 -0

168 lines not on this page · raw message

tests/qtest/ivshmem-test.c +30 -0
index e23a97fa8e..c4ca7efc62 100644
@@ -378,6 +378,32 @@ static void test_ivshmem_server(void)
     close(thread.pipe[0]);
 }
 
+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 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'}");
+    device_del(qts, "iv1");
+
+    qtest_quit(qts);
+}
+
 #define PCI_SLOT_HP             0x06
 
 static void test_ivshmem_hotplug(void)
@@ -469,6 +495,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 +521,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_add_func("/ivshmem/hotplug-q35", test_ivshmem_hotplug_q35);
+    }
 
 out:
     ret = g_test_run();
Signature · 1 line
2.34.1
#1 lore raw
Quoted 16 lines · Michael Labiuk

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

---
  tests/qtest/device-plug-test.c |  26 ++++++
  tests/qtest/drive_del-test.c   | 111 +++++++++++++++++++++++++
  tests/qtest/hd-geo-test.c      | 148 +++++++++++++++++++++++++++++++++
  tests/qtest/ivshmem-test.c     |  30 +++++++
  4 files changed, 315 insertions(+)
tests/qtest/device-plug-test.c +0 -0
index 2e3137843e..2f07b37ba1 100644

tests/qtest/device-plug-test.c static void test_spapr_phb_unplug_request(void) · line 168

Quoted 4 lines
tests/qtest/device-plug-test.c +1 -0
@@ -165,6 +165,26 @@ static void test_spapr_phb_unplug_request(void)
      qtest_quit(qtest);
  }
 
+static void test_q35_pci_unplug_request(void)

that seems a little bit wrong. we have pcie test and thus the naming should be appropriate.

What about test_pcie_unplug_request()?

Quoted 9 lines
tests/qtest/device-plug-test.c +9 -0
+{
+
+    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");
+
+    /*
+     * Request device removal. As the guest is not running, the request won't

tests/qtest/device-plug-test.c static void test_spapr_phb_unplug_request(void) · line 187

Quoted 10 lines
tests/qtest/device-plug-test.c +10 -0
+     * be processed. However during system reset, the removal will be
+     * handled, removing the device.
+     */
+    device_del(qtest, "dev0");
+    system_reset(qtest);
+    wait_device_deleted_event(qtest, "dev0");
+
+    qtest_quit(qtest);
+}
+

this is better to be placed near 'pci' testcases I think

tests/qtest/device-plug-test.c int main(int argc, char **argv) · line 220

Quoted 10 lines
tests/qtest/device-plug-test.c +3 -0
  int main(int argc, char **argv)
  {
      const char *arch = qtest_get_arch();
@@ -195,5 +215,11 @@ int main(int argc, char **argv)
                         test_spapr_phb_unplug_request);
      }
 
+    if (!strcmp(arch, "x86_64")) {
+        qtest_add_func("/device-plug/q35-pci-unplug-request",
+                   test_q35_pci_unplug_request);

for me JSON version of the test would also be good to be added

tests/qtest/drive_del-test.c static void test_cli_device_del(void) · line 260

Quoted 13 lines
tests/qtest/device-plug-test.c +3 -0
+
+    }
+
      return g_test_run();
  }
tests/qtest/drive_del-test.c +0 -0
index 5e6d58b4dd..3a2ddecf22 100644
@@ -258,6 +258,27 @@ static void test_cli_device_del(void)
      qtest_quit(qts);
  }
 

this patch seems trashes the internal structure of the test. originally it was unified for all archs through qvirtio_get_dev_type(void)
and this change makes the test non-uniform.
This should be rethinked

Quoted 306 lines
tests/qtest/drive_del-test.c +111 -0
+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;
@@ -294,6 +315,45 @@ static void test_device_add_and_del(void)
      qtest_quit(qts);
  }
 
+static void device_add_q35(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',"
+                              " '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;
@@ -318,6 +378,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;
@@ -342,8 +421,29 @@ 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 it 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)
  {
+    const char *arch = qtest_get_arch();
+
      g_test_init(&argc, &argv, NULL);
 
      qtest_add_func("/drive_del/without-dev", test_drive_without_dev);
@@ -363,6 +463,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 (!strcmp(arch, "x86_64")) {
+            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();
tests/qtest/hd-geo-test.c +143 -0
index 413cf964c0..256450729f 100644
@@ -874,6 +874,78 @@ static void test_override_scsi_hot_unplug(void)
      g_free(args);
  }
 
+static void test_override_scsi_hot_unplug_q35(void)
+{
+    QTestState *qts;
+    char *joined_args;
+    QFWCFG *fw_cfg;
+    QDict *response;
+    int i;
+    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} }
+    };
+    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);
+
+    joined_args = g_strjoinv(" ", args->argv);
+
+    qts = qtest_initf("-device pcie-root-port,id=p0 "
+                      "-device pcie-pci-bridge,bus=p0,id=b1 "
+                      "-machine q35 %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]);
+        free(args->drives[i]);
+    }
+    g_free(args->drives);
+    g_strfreev(args->argv);
+    g_free(args);
+}
+
  static void test_override_virtio_hot_unplug(void)
  {
      QTestState *qts;
@@ -934,6 +1006,77 @@ static void test_override_virtio_hot_unplug(void)
      g_free(args);
  }
 
+static void test_override_virtio_hot_unplug_q35(void)
+{
+    QTestState *qts;
+    char *joined_args;
+    QFWCFG *fw_cfg;
+    QDict *response;
+    int i;
+    TestArgs *args = create_args();
+    CHSResult expected[] = {
+        {
+            "/pci@i0cf8/pci-bridge@2/pci-bridge@0/scsi@2/disk@0,0",
+            {10000, 120, 30}
+        },
+        {
+            "/pci@i0cf8/pci-bridge@2/pci-bridge@0/scsi@3/disk@0,0",
+            {20, 20, 20}
+        },
+        {NULL, {0, 0, 0} }
+    };
+    CHSResult expected2[] = {
+        {
+            "/pci@i0cf8/pci-bridge@2/pci-bridge@0/scsi@3/disk@0,0",
+            {20, 20, 20}
+        },
+        {NULL, {0, 0, 0} }
+    };
+    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);
+
+    joined_args = g_strjoinv(" ", args->argv);
+
+    qts = qtest_initf("-device pcie-root-port,id=p0 "
+                      "-device pcie-pci-bridge,bus=p0,id=b1 "
+                      "-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]);
+        free(args->drives[i]);
+    }
+    g_free(args->drives);
+    g_strfreev(args->argv);
+    g_free(args);
+}
+
  int main(int argc, char **argv)
  {
      Backend i;

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

Quoted 10 lines
tests/qtest/hd-geo-test.c +5 -0
@@ -974,8 +1117,13 @@ int main(int argc, char **argv)
          qtest_add_func("hd-geo/override/zero_chs", test_override_zero_chs);
          qtest_add_func("hd-geo/override/scsi_hot_unplug",
                         test_override_scsi_hot_unplug);
+        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",
                         test_override_virtio_hot_unplug);
+        qtest_add_func("hd-geo/override/virtio_hot_unplug_q35",
+                       test_override_virtio_hot_unplug_q35);
+

we should add SATA tests here too

Quoted 27 lines
tests/qtest/hd-geo-test.c +0 -0
      } else {
          g_test_message("QTEST_QEMU_IMG not set or qemu-img missing; "
                         "skipping hd-geo/override/* tests");
tests/qtest/ivshmem-test.c +16 -0
index e23a97fa8e..c4ca7efc62 100644
@@ -378,6 +378,32 @@ static void test_ivshmem_server(void)
      close(thread.pipe[0]);
  }
 
+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 test_ivshmem_hotplug_q35(void)
+{
+    QTestState *qts = qtest_init("-object memory-backend-ram,size=1M,id=mb1 "
+                                 "-device pcie-root-port,id=p1 "

tests/qtest/ivshmem-test.c static void test_ivshmem_server(void) · line 406

Quoted 10 lines
tests/qtest/ivshmem-test.c +10 -0
+                                 "-device pcie-pci-bridge,bus=p1,id=b1 "
+                                 "-machine q35");
+
+    qtest_qmp_device_add(qts, "ivshmem-plain", "iv1",
+                         "{'memdev': 'mb1', 'bus': 'b1'}");
+    device_del(qts, "iv1");
+
+    qtest_quit(qts);
+}
+

I think that we need something like we have observed in tests/qtest/drive_del-test.c to avoid copy/pasted code

Quoted 12 lines
tests/qtest/ivshmem-test.c +1 -0
  #define PCI_SLOT_HP             0x06
 
  static void test_ivshmem_hotplug(void)
@@ -469,6 +495,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);
 

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

Quoted 9 lines
tests/qtest/ivshmem-test.c +3 -0
@@ -494,6 +521,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_add_func("/ivshmem/hotplug-q35", test_ivshmem_hotplug_q35);
+    }
 
  out:
      ret = g_test_run();

In general, this patchset should be split as such approach violates "patch should do only one thing" approach. There are too many items to discuss and fix.

Den

#2 lore raw
Quoted 6 lines · Denis V. Lunev
Quoted 1 line · Michael Labiuk

+static void test_q35_pci_unplug_request(void)

that seems a little bit wrong. we have pcie test and thus the naming should be appropriate.

What about test_pcie_unplug_request()?

I don't think so. Device type remains PCI. Only bridge configuration to allow hotplug.

Quoted 5 lines
Quoted 5 lines
tests/qtest/drive_del-test.c +0 -0
index 5e6d58b4dd..3a2ddecf22 100644
@@ -258,6 +258,27 @@ static void test_cli_device_del(void)
Quoted 8 lines

tests/qtest/drive_del-test.c static void test_cli_device_del(void) · line 259

Quoted 2 lines
tests/qtest/drive_del-test.c +0 -0
       qtest_quit(qts);
   }

this patch seems trashes the internal structure of the test. originally it was unified for all archs through
  qvirtio_get_dev_type(void)
and this change makes the test non-uniform.
This should be rethinked

We have to add test with explicit machine type. Existing test works fine but use default machine type. Type returned by qvirtio_get_dev_type(void) is the same for 'pc' and 'q35' machine types. May be better to create a new test instead of extending drive-del-test. Can you make suggestion?

Quoted 28 lines
Quoted 28 lines
tests/qtest/ivshmem-test.c +15 -0
index e23a97fa8e..c4ca7efc62 100644
@@ -378,6 +378,32 @@ static void test_ivshmem_server(void)
       close(thread.pipe[0]);
   }
+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 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",

Quoted 9 lines

tests/qtest/ivshmem-test.c

Quoted 6 lines

+                         "{'memdev': 'mb1', 'bus': 'b1'}"); +    device_del(qts, "iv1");

tests/qtest/ivshmem-test.c +4 -0
+
+    qtest_quit(qts);
+}
+

I think that we need something like we have observed in tests/qtest/drive_del-test.c to avoid copy/pasted code

Could you explain where you find duplicate?
We can't select behavior because we do not want to replace test for default machine type. Needed new test for 'q35'.

Thanks,
Michael