diff mbox series

[07/12] tests/qtest: drive_del-test: Skip tests that require missing devices

Message ID 20230206150416.4604-8-farosas@suse.de
State New
Headers show
Series qtests vs. default devices | expand

Commit Message

Fabiano Rosas Feb. 6, 2023, 3:04 p.m. UTC
Signed-off-by: Fabiano Rosas <farosas@suse.de>
---
 tests/qtest/drive_del-test.c | 70 ++++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)

Comments

Thomas Huth Feb. 7, 2023, 2:20 p.m. UTC | #1
On 06/02/2023 16.04, Fabiano Rosas wrote:
> Signed-off-by: Fabiano Rosas <farosas@suse.de>
> ---
>   tests/qtest/drive_del-test.c | 70 ++++++++++++++++++++++++++++++++++++
>   1 file changed, 70 insertions(+)
> 
> diff --git a/tests/qtest/drive_del-test.c b/tests/qtest/drive_del-test.c
> index 9a750395a9..6fa96fa94a 100644
> --- a/tests/qtest/drive_del-test.c
> +++ b/tests/qtest/drive_del-test.c
> @@ -16,6 +16,21 @@
>   #include "qapi/qmp/qdict.h"
>   #include "qapi/qmp/qlist.h"
>   
> +static const char *qvirtio_get_dev_type(void);
> +
> +/*
> + * This covers the possible absence of a device due to QEMU build
> + * options.
> + */
> +static bool look_for_device_builtin(const char *prefix, const char *suffix)
> +{
> +    gchar *device = g_strdup_printf("%s-%s", prefix, suffix);
> +    bool rc = qtest_has_device(device);
> +
> +    g_free(device);
> +    return rc;
> +}

I think I'd rather merge the above code into the has_device_builtin() 
function below ... or is there a reason for keeping this separate?

>   static bool look_for_drive0(QTestState *qts, const char *command, const char *key)
>   {
>       QDict *response;
> @@ -40,6 +55,11 @@ static bool look_for_drive0(QTestState *qts, const char *command, const char *ke
>       return found;
>   }
>   
> +static bool has_device_builtin(const char *dev)
> +{
> +    return look_for_device_builtin(dev, qvirtio_get_dev_type());
> +}
> +
>   static bool has_drive(QTestState *qts)
>   {
>       return look_for_drive0(qts, "query-block", "device");
> @@ -208,6 +228,11 @@ static void test_drive_del_device_del(void)
>   {
>       QTestState *qts;
>   
> +    if (!has_device_builtin("virtio-scsi")) {
> +        g_test_skip(NULL);

Having a short message for the skip would be nice.

> +        return;
> +    }

  Thomas
Fabiano Rosas Feb. 7, 2023, 2:32 p.m. UTC | #2
Thomas Huth <thuth@redhat.com> writes:

> On 06/02/2023 16.04, Fabiano Rosas wrote:
>> Signed-off-by: Fabiano Rosas <farosas@suse.de>
>> ---
>>   tests/qtest/drive_del-test.c | 70 ++++++++++++++++++++++++++++++++++++
>>   1 file changed, 70 insertions(+)
>> 
>> diff --git a/tests/qtest/drive_del-test.c b/tests/qtest/drive_del-test.c
>> index 9a750395a9..6fa96fa94a 100644
>> --- a/tests/qtest/drive_del-test.c
>> +++ b/tests/qtest/drive_del-test.c
>> @@ -16,6 +16,21 @@
>>   #include "qapi/qmp/qdict.h"
>>   #include "qapi/qmp/qlist.h"
>>   
>> +static const char *qvirtio_get_dev_type(void);
>> +
>> +/*
>> + * This covers the possible absence of a device due to QEMU build
>> + * options.
>> + */
>> +static bool look_for_device_builtin(const char *prefix, const char *suffix)
>> +{
>> +    gchar *device = g_strdup_printf("%s-%s", prefix, suffix);
>> +    bool rc = qtest_has_device(device);
>> +
>> +    g_free(device);
>> +    return rc;
>> +}
>
> I think I'd rather merge the above code into the has_device_builtin() 
> function below ... or is there a reason for keeping this separate?

No reason, I'll merge them.

>>   static bool look_for_drive0(QTestState *qts, const char *command, const char *key)
>>   {
>>       QDict *response;
>> @@ -40,6 +55,11 @@ static bool look_for_drive0(QTestState *qts, const char *command, const char *ke
>>       return found;
>>   }
>>   
>> +static bool has_device_builtin(const char *dev)
>> +{
>> +    return look_for_device_builtin(dev, qvirtio_get_dev_type());
>> +}
>> +
>>   static bool has_drive(QTestState *qts)
>>   {
>>       return look_for_drive0(qts, "query-block", "device");
>> @@ -208,6 +228,11 @@ static void test_drive_del_device_del(void)
>>   {
>>       QTestState *qts;
>>   
>> +    if (!has_device_builtin("virtio-scsi")) {
>> +        g_test_skip(NULL);
>
> Having a short message for the skip would be nice.

ok.
diff mbox series

Patch

diff --git a/tests/qtest/drive_del-test.c b/tests/qtest/drive_del-test.c
index 9a750395a9..6fa96fa94a 100644
--- a/tests/qtest/drive_del-test.c
+++ b/tests/qtest/drive_del-test.c
@@ -16,6 +16,21 @@ 
 #include "qapi/qmp/qdict.h"
 #include "qapi/qmp/qlist.h"
 
+static const char *qvirtio_get_dev_type(void);
+
+/*
+ * This covers the possible absence of a device due to QEMU build
+ * options.
+ */
+static bool look_for_device_builtin(const char *prefix, const char *suffix)
+{
+    gchar *device = g_strdup_printf("%s-%s", prefix, suffix);
+    bool rc = qtest_has_device(device);
+
+    g_free(device);
+    return rc;
+}
+
 static bool look_for_drive0(QTestState *qts, const char *command, const char *key)
 {
     QDict *response;
@@ -40,6 +55,11 @@  static bool look_for_drive0(QTestState *qts, const char *command, const char *ke
     return found;
 }
 
+static bool has_device_builtin(const char *dev)
+{
+    return look_for_device_builtin(dev, qvirtio_get_dev_type());
+}
+
 static bool has_drive(QTestState *qts)
 {
     return look_for_drive0(qts, "query-block", "device");
@@ -208,6 +228,11 @@  static void test_drive_del_device_del(void)
 {
     QTestState *qts;
 
+    if (!has_device_builtin("virtio-scsi")) {
+        g_test_skip(NULL);
+        return;
+    }
+
     /* Start with a drive used by a device that unplugs instantaneously */
     qts = qtest_initf("-drive if=none,id=drive0,file=null-co://,"
                       "file.read-zeroes=on,format=raw"
@@ -232,6 +257,11 @@  static void test_cli_device_del(void)
     const char *arch = qtest_get_arch();
     const char *machine_addition = "";
 
+    if (!has_device_builtin("virtio-blk")) {
+        g_test_skip(NULL);
+        return;
+    }
+
     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
         machine_addition = "-machine pc";
     }
@@ -256,6 +286,11 @@  static void test_cli_device_del_q35(void)
 {
     QTestState *qts;
 
+    if (!has_device_builtin("virtio-blk")) {
+        g_test_skip(NULL);
+        return;
+    }
+
     /*
      * -drive/-device and device_del.  Start with a drive used by a
      * device that unplugs after reset.
@@ -277,6 +312,11 @@  static void test_empty_device_del(void)
 {
     QTestState *qts;
 
+    if (!has_device_builtin("virtio-scsi")) {
+        g_test_skip(NULL);
+        return;
+    }
+
     /* device_del with no drive plugged.  */
     qts = qtest_initf("-device virtio-scsi-%s -device scsi-cd,id=dev0",
                       qvirtio_get_dev_type());
@@ -291,6 +331,11 @@  static void test_device_add_and_del(void)
     const char *arch = qtest_get_arch();
     const char *machine_addition = "";
 
+    if (!has_device_builtin("virtio-blk")) {
+        g_test_skip(NULL);
+        return;
+    }
+
     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
         machine_addition = "-machine pc";
     }
@@ -330,6 +375,11 @@  static void test_device_add_and_del_q35(void)
 {
     QTestState *qts;
 
+    if (!has_device_builtin("virtio-blk")) {
+        g_test_skip(NULL);
+        return;
+    }
+
     /*
      * -drive/device_add and device_del.  Start with a drive used by a
      * device that unplugs after reset.
@@ -352,6 +402,11 @@  static void test_drive_add_device_add_and_del(void)
     const char *arch = qtest_get_arch();
     const char *machine_addition = "";
 
+    if (!has_device_builtin("virtio-blk")) {
+        g_test_skip(NULL);
+        return;
+    }
+
     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
         machine_addition = "-machine pc";
     }
@@ -374,6 +429,11 @@  static void test_drive_add_device_add_and_del_q35(void)
 {
     QTestState *qts;
 
+    if (!has_device_builtin("virtio-blk")) {
+        g_test_skip(NULL);
+        return;
+    }
+
     qts = qtest_init("-machine q35 -device pcie-root-port,id=p1 "
                      "-device pcie-pci-bridge,bus=p1,id=b1");
 
@@ -395,6 +455,11 @@  static void test_blockdev_add_device_add_and_del(void)
     const char *arch = qtest_get_arch();
     const char *machine_addition = "";
 
+    if (!has_device_builtin("virtio-blk")) {
+        g_test_skip(NULL);
+        return;
+    }
+
     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
         machine_addition = "-machine pc";
     }
@@ -417,6 +482,11 @@  static void test_blockdev_add_device_add_and_del_q35(void)
 {
     QTestState *qts;
 
+    if (!has_device_builtin("virtio-blk")) {
+        g_test_skip(NULL);
+        return;
+    }
+
     qts = qtest_init("-machine q35 -device pcie-root-port,id=p1 "
                      "-device pcie-pci-bridge,bus=p1,id=b1");