[PATCH 4/8] tests/qtest/hd-geo-test: Check for availability of "pc" machine before using it

Thomas Huth posted 8 patches 2 months, 2 weeks ago
[PATCH 4/8] tests/qtest/hd-geo-test: Check for availability of "pc" machine before using it
Posted by Thomas Huth 2 months, 2 weeks ago
In case QEMU has been configured with "--without-default-devices", the
"pc" machine type might be missing in the binary. We should check for
its availability before using it.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/qtest/hd-geo-test.c | 71 +++++++++++++++++++++------------------
 1 file changed, 38 insertions(+), 33 deletions(-)

diff --git a/tests/qtest/hd-geo-test.c b/tests/qtest/hd-geo-test.c
index d08bffad91..85eb8d7668 100644
--- a/tests/qtest/hd-geo-test.c
+++ b/tests/qtest/hd-geo-test.c
@@ -1074,17 +1074,26 @@ int main(int argc, char **argv)
         }
     }
 
-    qtest_add_func("hd-geo/ide/none", test_ide_none);
-    qtest_add_func("hd-geo/ide/drive/mbr/blank", test_ide_drive_mbr_blank);
-    qtest_add_func("hd-geo/ide/drive/mbr/lba", test_ide_drive_mbr_lba);
-    qtest_add_func("hd-geo/ide/drive/mbr/chs", test_ide_drive_mbr_chs);
-    qtest_add_func("hd-geo/ide/drive/cd_0", test_ide_drive_cd_0);
-    qtest_add_func("hd-geo/ide/device/mbr/blank", test_ide_device_mbr_blank);
-    qtest_add_func("hd-geo/ide/device/mbr/lba", test_ide_device_mbr_lba);
-    qtest_add_func("hd-geo/ide/device/mbr/chs", test_ide_device_mbr_chs);
-    qtest_add_func("hd-geo/ide/device/user/chs", test_ide_device_user_chs);
-    qtest_add_func("hd-geo/ide/device/user/chst", test_ide_device_user_chst);
-    if (have_qemu_img()) {
+    if (qtest_has_machine("pc")) {
+        qtest_add_func("hd-geo/ide/none", test_ide_none);
+        qtest_add_func("hd-geo/ide/drive/mbr/blank", test_ide_drive_mbr_blank);
+        qtest_add_func("hd-geo/ide/drive/mbr/lba", test_ide_drive_mbr_lba);
+        qtest_add_func("hd-geo/ide/drive/mbr/chs", test_ide_drive_mbr_chs);
+        qtest_add_func("hd-geo/ide/drive/cd_0", test_ide_drive_cd_0);
+        qtest_add_func("hd-geo/ide/device/mbr/blank", test_ide_device_mbr_blank);
+        qtest_add_func("hd-geo/ide/device/mbr/lba", test_ide_device_mbr_lba);
+        qtest_add_func("hd-geo/ide/device/mbr/chs", test_ide_device_mbr_chs);
+        qtest_add_func("hd-geo/ide/device/user/chs", test_ide_device_user_chs);
+        qtest_add_func("hd-geo/ide/device/user/chst", test_ide_device_user_chst);
+    }
+
+    if (!have_qemu_img()) {
+        g_test_message("QTEST_QEMU_IMG not set or qemu-img missing; "
+                       "skipping hd-geo/override/* tests");
+        goto test_add_done;
+    }
+
+    if (qtest_has_machine("pc")) {
         qtest_add_func("hd-geo/override/ide", test_override_ide);
         if (qtest_has_device("lsi53c895a")) {
             qtest_add_func("hd-geo/override/scsi", test_override_scsi);
@@ -1104,30 +1113,26 @@ int main(int argc, char **argv)
             qtest_add_func("hd-geo/override/virtio_blk",
                            test_override_virtio_blk);
         }
+    }
 
-        if (qtest_has_machine("q35")) {
-            qtest_add_func("hd-geo/override/sata", test_override_sata);
-            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);
-            }
-            if (qtest_has_device("virtio-scsi-pci")) {
-                qtest_add_func("hd-geo/override/scsi_hot_unplug_q35",
-                               test_override_scsi_hot_unplug_q35);
-            }
-            if (qtest_has_device("virtio-blk-pci")) {
-                qtest_add_func("hd-geo/override/virtio_hot_unplug_q35",
-                               test_override_virtio_hot_unplug_q35);
-                qtest_add_func("hd-geo/override/virtio_blk_q35",
-                               test_override_virtio_blk_q35);
-            }
-
+    if (qtest_has_machine("q35")) {
+        qtest_add_func("hd-geo/override/sata", test_override_sata);
+        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);
+        }
+        if (qtest_has_device("virtio-scsi-pci")) {
+            qtest_add_func("hd-geo/override/scsi_hot_unplug_q35",
+                           test_override_scsi_hot_unplug_q35);
+        }
+        if (qtest_has_device("virtio-blk-pci")) {
+            qtest_add_func("hd-geo/override/virtio_hot_unplug_q35",
+                           test_override_virtio_hot_unplug_q35);
+            qtest_add_func("hd-geo/override/virtio_blk_q35",
+                           test_override_virtio_blk_q35);
         }
-    } else {
-        g_test_message("QTEST_QEMU_IMG not set or qemu-img missing; "
-                       "skipping hd-geo/override/* tests");
     }
 
 test_add_done:
-- 
2.46.0
Re: [PATCH 4/8] tests/qtest/hd-geo-test: Check for availability of "pc" machine before using it
Posted by Philippe Mathieu-Daudé 2 months, 2 weeks ago
On 5/9/24 21:14, Thomas Huth wrote:
> In case QEMU has been configured with "--without-default-devices", the
> "pc" machine type might be missing in the binary. We should check for
> its availability before using it.
> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>   tests/qtest/hd-geo-test.c | 71 +++++++++++++++++++++------------------
>   1 file changed, 38 insertions(+), 33 deletions(-)
> 
> diff --git a/tests/qtest/hd-geo-test.c b/tests/qtest/hd-geo-test.c
> index d08bffad91..85eb8d7668 100644
> --- a/tests/qtest/hd-geo-test.c
> +++ b/tests/qtest/hd-geo-test.c
> @@ -1074,17 +1074,26 @@ int main(int argc, char **argv)
>           }
>       }
>   
> -    qtest_add_func("hd-geo/ide/none", test_ide_none);
> -    qtest_add_func("hd-geo/ide/drive/mbr/blank", test_ide_drive_mbr_blank);
> -    qtest_add_func("hd-geo/ide/drive/mbr/lba", test_ide_drive_mbr_lba);
> -    qtest_add_func("hd-geo/ide/drive/mbr/chs", test_ide_drive_mbr_chs);
> -    qtest_add_func("hd-geo/ide/drive/cd_0", test_ide_drive_cd_0);
> -    qtest_add_func("hd-geo/ide/device/mbr/blank", test_ide_device_mbr_blank);
> -    qtest_add_func("hd-geo/ide/device/mbr/lba", test_ide_device_mbr_lba);
> -    qtest_add_func("hd-geo/ide/device/mbr/chs", test_ide_device_mbr_chs);
> -    qtest_add_func("hd-geo/ide/device/user/chs", test_ide_device_user_chs);
> -    qtest_add_func("hd-geo/ide/device/user/chst", test_ide_device_user_chst);
> -    if (have_qemu_img()) {
> +    if (qtest_has_machine("pc")) {
> +        qtest_add_func("hd-geo/ide/none", test_ide_none);
> +        qtest_add_func("hd-geo/ide/drive/mbr/blank", test_ide_drive_mbr_blank);
> +        qtest_add_func("hd-geo/ide/drive/mbr/lba", test_ide_drive_mbr_lba);
> +        qtest_add_func("hd-geo/ide/drive/mbr/chs", test_ide_drive_mbr_chs);
> +        qtest_add_func("hd-geo/ide/drive/cd_0", test_ide_drive_cd_0);
> +        qtest_add_func("hd-geo/ide/device/mbr/blank", test_ide_device_mbr_blank);
> +        qtest_add_func("hd-geo/ide/device/mbr/lba", test_ide_device_mbr_lba);
> +        qtest_add_func("hd-geo/ide/device/mbr/chs", test_ide_device_mbr_chs);
> +        qtest_add_func("hd-geo/ide/device/user/chs", test_ide_device_user_chs);
> +        qtest_add_func("hd-geo/ide/device/user/chst", test_ide_device_user_chst);

Just wondering, could a qtest_add_machine_func() method be helpful?
Maybe not if we want to check for multiple machines?
Re: [PATCH 4/8] tests/qtest/hd-geo-test: Check for availability of "pc" machine before using it
Posted by Thomas Huth 2 months, 2 weeks ago
On 06/09/2024 09.50, Philippe Mathieu-Daudé wrote:
> On 5/9/24 21:14, Thomas Huth wrote:
>> In case QEMU has been configured with "--without-default-devices", the
>> "pc" machine type might be missing in the binary. We should check for
>> its availability before using it.
>>
>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>> ---
>>   tests/qtest/hd-geo-test.c | 71 +++++++++++++++++++++------------------
>>   1 file changed, 38 insertions(+), 33 deletions(-)
>>
>> diff --git a/tests/qtest/hd-geo-test.c b/tests/qtest/hd-geo-test.c
>> index d08bffad91..85eb8d7668 100644
>> --- a/tests/qtest/hd-geo-test.c
>> +++ b/tests/qtest/hd-geo-test.c
>> @@ -1074,17 +1074,26 @@ int main(int argc, char **argv)
>>           }
>>       }
>> -    qtest_add_func("hd-geo/ide/none", test_ide_none);
>> -    qtest_add_func("hd-geo/ide/drive/mbr/blank", test_ide_drive_mbr_blank);
>> -    qtest_add_func("hd-geo/ide/drive/mbr/lba", test_ide_drive_mbr_lba);
>> -    qtest_add_func("hd-geo/ide/drive/mbr/chs", test_ide_drive_mbr_chs);
>> -    qtest_add_func("hd-geo/ide/drive/cd_0", test_ide_drive_cd_0);
>> -    qtest_add_func("hd-geo/ide/device/mbr/blank", 
>> test_ide_device_mbr_blank);
>> -    qtest_add_func("hd-geo/ide/device/mbr/lba", test_ide_device_mbr_lba);
>> -    qtest_add_func("hd-geo/ide/device/mbr/chs", test_ide_device_mbr_chs);
>> -    qtest_add_func("hd-geo/ide/device/user/chs", test_ide_device_user_chs);
>> -    qtest_add_func("hd-geo/ide/device/user/chst", 
>> test_ide_device_user_chst);
>> -    if (have_qemu_img()) {
>> +    if (qtest_has_machine("pc")) {
>> +        qtest_add_func("hd-geo/ide/none", test_ide_none);
>> +        qtest_add_func("hd-geo/ide/drive/mbr/blank", 
>> test_ide_drive_mbr_blank);
>> +        qtest_add_func("hd-geo/ide/drive/mbr/lba", test_ide_drive_mbr_lba);
>> +        qtest_add_func("hd-geo/ide/drive/mbr/chs", test_ide_drive_mbr_chs);
>> +        qtest_add_func("hd-geo/ide/drive/cd_0", test_ide_drive_cd_0);
>> +        qtest_add_func("hd-geo/ide/device/mbr/blank", 
>> test_ide_device_mbr_blank);
>> +        qtest_add_func("hd-geo/ide/device/mbr/lba", 
>> test_ide_device_mbr_lba);
>> +        qtest_add_func("hd-geo/ide/device/mbr/chs", 
>> test_ide_device_mbr_chs);
>> +        qtest_add_func("hd-geo/ide/device/user/chs", 
>> test_ide_device_user_chs);
>> +        qtest_add_func("hd-geo/ide/device/user/chst", 
>> test_ide_device_user_chst);
> 
> Just wondering, could a qtest_add_machine_func() method be helpful?
> Maybe not if we want to check for multiple machines?

For adding multiple tests, I think a check at the beginning of the block is 
better than checking it over and over again.

  Thomas