summary refs log tree commit diff stats
path: root/tests/qtest/libqtest.c
diff options
context:
space:
mode:
authorThomas Huth <thuth@redhat.com>2021-12-01 11:43:47 +0100
committerThomas Huth <thuth@redhat.com>2021-12-15 08:08:59 +0100
commit719051ca3fd0ee765d8a80670df1a0292aa566f0 (patch)
treee51fcebb99953a8c34bbe22bdb85fd8db6479450 /tests/qtest/libqtest.c
parent5516a3b592def4de7fa78153912470f160814e5a (diff)
downloadfocaccia-qemu-719051ca3fd0ee765d8a80670df1a0292aa566f0.tar.gz
focaccia-qemu-719051ca3fd0ee765d8a80670df1a0292aa566f0.zip
tests/qtest: Add a function to check whether a machine is available
It is nowadays possible to build QEMU with a reduced set of machines
in each binary. However, the qtests still hard-code the expected
machines and fail if the binary does not feature the required machine.
Let's get a little bit more flexible here: Add a function that can be
used to query whether a certain machine is available or not, and use
it in some tests as an example (more work has to be done in other
tests which will follow later).

Message-Id: <20211201104347.51922-5-thuth@redhat.com>
Acked-by: John Snow <jsnow@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
Diffstat (limited to 'tests/qtest/libqtest.c')
-rw-r--r--tests/qtest/libqtest.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 7ae2dc4e1d..65ed949685 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -1401,6 +1401,23 @@ void qtest_cb_for_every_machine(void (*cb)(const char *machine),
     }
 }
 
+bool qtest_has_machine(const char *machine)
+{
+    struct MachInfo *machines;
+    int i;
+
+    machines = qtest_get_machines();
+
+    for (i = 0; machines[i].name != NULL; i++) {
+        if (g_str_equal(machine, machines[i].name) ||
+            (machines[i].alias && g_str_equal(machine, machines[i].alias))) {
+            return true;
+        }
+    }
+
+    return false;
+}
+
 /*
  * Generic hot-plugging test via the device_add QMP commands.
  */