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>
g_test_init(&argc, &argv, NULL);
for (i = 0; tests[i].arch != NULL; i++) {
- if (strcmp(arch, tests[i].arch) == 0) {
+ if (g_str_equal(arch, tests[i].arch) &&
+ qtest_has_machine(tests[i].machine)) {
char *name = g_strdup_printf("boot-serial/%s", tests[i].machine);
qtest_add_data_func(name, &tests[i], test_machine);
g_free(name);
static void add_cdrom_param_tests(const char **machines)
{
while (*machines) {
- char *testname = g_strdup_printf("cdrom/param/%s", *machines);
- qtest_add_data_func(testname, *machines, test_cdrom_param);
- g_free(testname);
+ if (qtest_has_machine(*machines)) {
+ char *testname = g_strdup_printf("cdrom/param/%s", *machines);
+ qtest_add_data_func(testname, *machines, test_cdrom_param);
+ g_free(testname);
+ }
machines++;
}
}
void qtest_cb_for_every_machine(void (*cb)(const char *machine),
bool skip_old_versioned);
+/**
+ * qtest_has_machine:
+ * @machine: The machine to look for
+ *
+ * Returns: true if the machine is available in the target binary.
+ */
+bool qtest_has_machine(const char *machine);
+
/**
* qtest_qmp_device_add_qdict:
* @qts: QTestState instance to operate on
}
}
+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.
*/
char *name;
for (i = 0; machines[i] != NULL; i++) {
- name = g_strdup_printf("prom-env/%s", machines[i]);
- qtest_add_data_func(name, machines[i], test_machine);
- g_free(name);
+ if (qtest_has_machine(machines[i])) {
+ name = g_strdup_printf("prom-env/%s", machines[i]);
+ qtest_add_data_func(name, machines[i], test_machine);
+ g_free(name);
+ }
}
}