Skip to contentSkip to conversation

tests/qtest: Check for devices and machines before adding tests

PATCH In review Thomas Huth 3 participants 10 messages Dec 20, 2021 – Jan 11, 2022

lore
Share & tools
lore
#0 lore raw

cover tests/qtest: Check for devices and machines before adding tests

Devices might not always be compiled into the QEMU target binaries. We already have the libqos framework that is good for handling such situations, but some of the qtests are not a real good fit for the libqos framework. This patch series adds a new function to check whether a device is available in the target binary or not, so that tests can be run or skipped accordingly (also adding some additional checks for the availability of machines in the target binaries).

Thomas Huth (4):
tests/qtest: Add a function that checks whether a device is available tests/qtest: Improve endianness-test to work with missing machines and
devices
tests/qtest/cdrom-test: Check whether devices are available before
using them
tests/qtest/boot-order-test: Check whether machines are available

 tests/qtest/boot-order-test.c |  5 +++
 tests/qtest/cdrom-test.c      | 60 +++++++++++++++++++++++------------
 tests/qtest/endianness-test.c |  5 ++-
 tests/qtest/libqos/libqtest.h |  8 +++++
 tests/qtest/libqtest.c        | 44 +++++++++++++++++++++++++
 5 files changed, 100 insertions(+), 22 deletions(-)
Signature · 1 line
2.27.0
#1 lore raw

PATCH 1/4 tests/qtest: Add a function that checks whether a device is available

Devices might not always be compiled into the QEMU target binaries. We already have the libqos framework that is good for handling such situations, but some of the qtests are not a real good fit for the libqos framework. Let's add a qtest_has_device() function for such tests instead.

---
 tests/qtest/libqos/libqtest.h |  8 +++++++
 tests/qtest/libqtest.c        | 44 +++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)
tests/qtest/libqos/libqtest.h +8 -0
index dff6b31cf0..2df9397519 100644
@@ -718,6 +718,14 @@ void qtest_cb_for_every_machine(void (*cb)(const char *machine),
  */
 bool qtest_has_machine(const char *machine);
 
+/**
+ * qtest_has_device:
+ * @device: The device to look for
+ *
+ * Returns: true if the device is available in the target binary.
+ */
+bool qtest_has_device(const char *device);
+
 /**
  * qtest_qmp_device_add_qdict:
  * @qts: QTestState instance to operate on
tests/qtest/libqtest.c +44 -0

50 lines not on this page · raw message

Signature · 1 line
2.27.0
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] tests/qtest: Add a function that checks whether a device is available

Quoted 11 lines · Thomas Huth

Devices might not always be compiled into the QEMU target binaries. We already have the libqos framework that is good for handling such situations, but some of the qtests are not a real good fit for the libqos framework. Let's add a qtest_has_device() function for such tests instead.

---
  tests/qtest/libqos/libqtest.h |  8 +++++++
  tests/qtest/libqtest.c        | 44 +++++++++++++++++++++++++++++++++++
  2 files changed, 52 insertions(+)
#3 lore raw

PATCH 2/4 tests/qtest: Improve endianness-test to work with missing machines and devices

In reply to Thomas Huth

The users might have built QEMU with less machines or without the i82378 superio device. Add some checks to the endianess-test so that it is able to deal with such stripped down QEMU versions, too.

---
 tests/qtest/endianness-test.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tests/qtest/endianness-test.c +4 -1
index 09ecb531f1..9c03b72dc9 100644
@@ -281,7 +281,10 @@ int main(int argc, char **argv)
 
     for (i = 0; test_cases[i].arch; i++) {
         gchar *path;
-        if (strcmp(test_cases[i].arch, arch) != 0) {
+
+        if (!g_str_equal(test_cases[i].arch, arch) ||
+            !qtest_has_machine(test_cases[i].machine) ||
+            (test_cases[i].superio && !qtest_has_device(test_cases[i].superio))) {
             continue;
         }
         path = g_strdup_printf("endianness/%s",
Signature · 1 line
2.27.0
#4 lore raw

Re: [PATCH 2/4] tests/qtest: Improve endianness-test to work with missing machines and devices

Quoted 8 lines · Thomas Huth

The users might have built QEMU with less machines or without the i82378 superio device. Add some checks to the endianess-test so that it is able to deal with such stripped down QEMU versions, too.

---
  tests/qtest/endianness-test.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)

The i82378 should work regardless the guest endianess...

#5 lore raw

PATCH 3/4 tests/qtest/cdrom-test: Check whether devices are available before using them

In reply to Thomas Huth

Downstream users might want to disable legacy devices in their binaries, so we should not blindly assume that they are available. Add some proper checks before using them.

---
 tests/qtest/cdrom-test.c | 60 ++++++++++++++++++++++++++--------------
 1 file changed, 39 insertions(+), 21 deletions(-)
tests/qtest/cdrom-test.c +39 -21
index c1fcac5c45..cfca24fa94 100644
@@ -142,21 +142,36 @@ static void add_x86_tests(void)
         qtest_add_data_func("cdrom/boot/isapc", "-M isapc "
                             "-drive if=ide,media=cdrom,file=", test_cdboot);
     }
-    qtest_add_data_func("cdrom/boot/am53c974",
-                        "-device am53c974 -device scsi-cd,drive=cd1 "
-                        "-drive if=none,id=cd1,format=raw,file=", test_cdboot);
-    qtest_add_data_func("cdrom/boot/dc390",
-                        "-device dc390 -device scsi-cd,drive=cd1 "
-                        "-blockdev file,node-name=cd1,filename=", test_cdboot);
-    qtest_add_data_func("cdrom/boot/lsi53c895a",
-                        "-device lsi53c895a -device scsi-cd,drive=cd1 "
-                        "-blockdev file,node-name=cd1,filename=", test_cdboot);
-    qtest_add_data_func("cdrom/boot/megasas", "-M q35 "
-                        "-device megasas -device scsi-cd,drive=cd1 "
-                        "-blockdev file,node-name=cd1,filename=", test_cdboot);
-    qtest_add_data_func("cdrom/boot/megasas-gen2", "-M q35 "
-                        "-device megasas-gen2 -device scsi-cd,drive=cd1 "
-                        "-blockdev file,node-name=cd1,filename=", test_cdboot);
+    if (qtest_has_device("am53c974")) {
+        qtest_add_data_func("cdrom/boot/am53c974",
+                            "-device am53c974 -device scsi-cd,drive=cd1 "
+                            "-drive if=none,id=cd1,format=raw,file=",
+                            test_cdboot);
+    }
+    if (qtest_has_device("dc390")) {
+        qtest_add_data_func("cdrom/boot/dc390",
+                            "-device dc390 -device scsi-cd,drive=cd1 "
+                            "-blockdev file,node-name=cd1,filename=",
+                            test_cdboot);
+    }
+    if (qtest_has_device("lsi53c895a")) {
+        qtest_add_data_func("cdrom/boot/lsi53c895a",
+                            "-device lsi53c895a -device scsi-cd,drive=cd1 "
+                            "-blockdev file,node-name=cd1,filename=",
+                            test_cdboot);
+    }
+    if (qtest_has_device("megasas")) {
+        qtest_add_data_func("cdrom/boot/megasas", "-M q35 "
+                            "-device megasas -device scsi-cd,drive=cd1 "
+                            "-blockdev file,node-name=cd1,filename=",
+                            test_cdboot);
+    }
+    if (qtest_has_device("megasas-gen2")) {
+        qtest_add_data_func("cdrom/boot/megasas-gen2", "-M q35 "
+                            "-device megasas-gen2 -device scsi-cd,drive=cd1 "
+                            "-blockdev file,node-name=cd1,filename=",
+                            test_cdboot);
+    }
 }
 
 static void add_s390x_tests(void)
@@ -171,12 +186,15 @@ static void add_s390x_tests(void)
                         "-drive driver=null-co,read-zeroes=on,if=none,id=d1 "
                         "-device virtio-blk,drive=d2,bootindex=1 "
                         "-drive if=none,id=d2,media=cdrom,file=", test_cdboot);
-    qtest_add_data_func("cdrom/boot/without-bootindex",
-                        "-device virtio-scsi -device virtio-serial "
-                        "-device x-terminal3270 -device virtio-blk,drive=d1 "
-                        "-drive driver=null-co,read-zeroes=on,if=none,id=d1 "
-                        "-device virtio-blk,drive=d2 "
-                        "-drive if=none,id=d2,media=cdrom,file=", test_cdboot);
+    if (qtest_has_device("x-terminal3270")) {
+        qtest_add_data_func("cdrom/boot/without-bootindex",
+                            "-device virtio-scsi -device virtio-serial "
+                            "-device x-terminal3270 -device virtio-blk,drive=d1 "
+                            "-drive driver=null-co,read-zeroes=on,if=none,id=d1 "
+                            "-device virtio-blk,drive=d2 "
+                            "-drive if=none,id=d2,media=cdrom,file=",
+                            test_cdboot);
+    }
 }
 
 int main(int argc, char **argv)
Signature · 1 line
2.27.0
Acked-by on v1 3/4
#6 lore raw

Re: [PATCH 3/4] tests/qtest/cdrom-test: Check whether devices are available before using them

Quoted 103 lines · Thomas Huth

Downstream users might want to disable legacy devices in their binaries, so we should not blindly assume that they are available. Add some proper checks before using them.

---
 tests/qtest/cdrom-test.c | 60 ++++++++++++++++++++++++++--------------
 1 file changed, 39 insertions(+), 21 deletions(-)
tests/qtest/cdrom-test.c +0 -15
index c1fcac5c45..cfca24fa94 100644
@@ -142,21 +142,36 @@ static void add_x86_tests(void)
         qtest_add_data_func("cdrom/boot/isapc", "-M isapc "
                             "-drive if=ide,media=cdrom,file=",
 test_cdboot);
     }
-    qtest_add_data_func("cdrom/boot/am53c974",
-                        "-device am53c974 -device scsi-cd,drive=cd1 "
-                        "-drive if=none,id=cd1,format=raw,file=",
 test_cdboot);
-    qtest_add_data_func("cdrom/boot/dc390",
-                        "-device dc390 -device scsi-cd,drive=cd1 "
-                        "-blockdev file,node-name=cd1,filename=",
 test_cdboot);
-    qtest_add_data_func("cdrom/boot/lsi53c895a",
-                        "-device lsi53c895a -device scsi-cd,drive=cd1 "
-                        "-blockdev file,node-name=cd1,filename=",
 test_cdboot);
-    qtest_add_data_func("cdrom/boot/megasas", "-M q35 "
-                        "-device megasas -device scsi-cd,drive=cd1 "
-                        "-blockdev file,node-name=cd1,filename=",
 test_cdboot);
-    qtest_add_data_func("cdrom/boot/megasas-gen2", "-M q35 "
-                        "-device megasas-gen2 -device scsi-cd,drive=cd1 "
-                        "-blockdev file,node-name=cd1,filename=",

test_cdboot);

tests/qtest/cdrom-test.c +15 -0
+    if (qtest_has_device("am53c974")) {
+        qtest_add_data_func("cdrom/boot/am53c974",
+                            "-device am53c974 -device scsi-cd,drive=cd1 "
+                            "-drive if=none,id=cd1,format=raw,file=",
+                            test_cdboot);
+    }
+    if (qtest_has_device("dc390")) {
+        qtest_add_data_func("cdrom/boot/dc390",
+                            "-device dc390 -device scsi-cd,drive=cd1 "
+                            "-blockdev file,node-name=cd1,filename=",
+                            test_cdboot);
+    }
+    if (qtest_has_device("lsi53c895a")) {
+        qtest_add_data_func("cdrom/boot/lsi53c895a",
+                            "-device lsi53c895a -device scsi-cd,drive=cd1

"

tests/qtest/cdrom-test.c +12 -0
+                            "-blockdev file,node-name=cd1,filename=",
+                            test_cdboot);
+    }
+    if (qtest_has_device("megasas")) {
+        qtest_add_data_func("cdrom/boot/megasas", "-M q35 "
+                            "-device megasas -device scsi-cd,drive=cd1 "
+                            "-blockdev file,node-name=cd1,filename=",
+                            test_cdboot);
+    }
+    if (qtest_has_device("megasas-gen2")) {
+        qtest_add_data_func("cdrom/boot/megasas-gen2", "-M q35 "
+                            "-device megasas-gen2 -device

scsi-cd,drive=cd1 "

tests/qtest/cdrom-test.c +3 -0
+                            "-blockdev file,node-name=cd1,filename=",
+                            test_cdboot);
+    }
 }
 
 static void add_s390x_tests(void)
@@ -171,12 +186,15 @@ static void add_s390x_tests(void)
                         "-drive

driver=null-co,read-zeroes=on,if=none,id=d1 "
"-device virtio-blk,drive=d2,bootindex=1 " "-drive if=none,id=d2,media=cdrom,file=",
test_cdboot);

tests/qtest/cdrom-test.c +0 -3
-    qtest_add_data_func("cdrom/boot/without-bootindex",
-                        "-device virtio-scsi -device virtio-serial "
-                        "-device x-terminal3270 -device

virtio-blk,drive=d1 "
- "-drive
driver=null-co,read-zeroes=on,if=none,id=d1 "

tests/qtest/cdrom-test.c +0 -2
-                        "-device virtio-blk,drive=d2 "
-                        "-drive if=none,id=d2,media=cdrom,file=",

test_cdboot);

tests/qtest/cdrom-test.c +4 -0
+    if (qtest_has_device("x-terminal3270")) {
+        qtest_add_data_func("cdrom/boot/without-bootindex",
+                            "-device virtio-scsi -device virtio-serial "
+                            "-device x-terminal3270 -device

virtio-blk,drive=d1 "
+ "-drive
driver=null-co,read-zeroes=on,if=none,id=d1 "

tests/qtest/cdrom-test.c +4 -1
+                            "-device virtio-blk,drive=d2 "
+                            "-drive if=none,id=d2,media=cdrom,file=",
+                            test_cdboot);
+    }
 }
 
 int main(int argc, char **argv)
--
Quoted 3 lines

2.27.0

These are really more your tests than mine :)

--js

Reviewed-by on v1 3/4
#7 lore raw

Re: [PATCH 3/4] tests/qtest/cdrom-test: Check whether devices are available before using them

In reply to Thomas Huth
Quoted 8 lines · Thomas Huth

Downstream users might want to disable legacy devices in their binaries, so we should not blindly assume that they are available. Add some proper checks before using them.

---
  tests/qtest/cdrom-test.c | 60 ++++++++++++++++++++++++++--------------
  1 file changed, 39 insertions(+), 21 deletions(-)
#8 lore raw

PATCH 4/4 tests/qtest/boot-order-test: Check whether machines are available

In reply to Thomas Huth

Machines might not always be compiled into the QEMU binary, so we should skip the test instead of failing if it is not available.

---
 tests/qtest/boot-order-test.c | 5 +++++
 1 file changed, 5 insertions(+)
tests/qtest/boot-order-test.c +5 -0
index fac580d6c4..f1f59b1261 100644
@@ -34,6 +34,11 @@ static void test_a_boot_order(const char *machine,
     uint64_t actual;
     QTestState *qts;
 
+    if (machine && !qtest_has_machine(machine)) {
+        g_test_skip("Machine is not available");
+        return;
+    }
+
     qts = qtest_initf("-nodefaults%s%s %s", machine ? " -M " : "",
                       machine ?: "", test_args);
     actual = read_boot_order(qts);
Signature · 1 line
2.27.0
#9 lore raw
In reply to Thomas Huth
Quoted 7 lines · Thomas Huth

Devices might not always be compiled into the QEMU target binaries. We already have the libqos framework that is good for handling such situations, but some of the qtests are not a real good fit for the libqos framework. This patch series adds a new function to check whether a device is available in the target binary or not, so that tests can be run or skipped accordingly (also adding some additional checks for the availability of machines in the target binaries).

What happens if a device or machine is inadvertently removed from the build? We won't notice it directly anymore, right?