qtest patches for binaries with reduced machines
cover qtest patches for binaries with reduced machines
First patch extends the ppc64 tests as we used them before the conversion to meson.
The other patches improve the usage of the qtests with target binaries that have a reduced set of machines (since this is possible now e.g. by using the --with-devices-<arch>=... config switch).
Thomas Huth (4):
tests/qtest: Run the PPC 32-bit tests with the 64-bit target binary,
too
tests/qtest: Fence the tests that need xlnx-zcu102 with
CONFIG_XLNX_ZYNQMP_ARM
tests/qtest: Add a function that gets a list with available machine
types
tests/qtest: Add a function to check whether a machine is available
tests/qtest/boot-serial-test.c | 3 +- tests/qtest/cdrom-test.c | 8 ++-- tests/qtest/libqos/libqtest.h | 8 ++++ tests/qtest/libqtest.c | 79 +++++++++++++++++++++++++++++----- tests/qtest/meson.build | 4 +- tests/qtest/prom-env-test.c | 8 ++-- 6 files changed, 91 insertions(+), 19 deletions(-)
Signature · 1 line
2.27.0
PATCH 2/4 tests/qtest: Fence the tests that need xlnx-zcu102 with CONFIG_XLNX_ZYNQMP_ARM
The 'xlnx-can-test' and the 'fuzz-xlnx-dp-test' need the "xlnx-zcu102" machine and thus should only be built and run if CONFIG_XLNX_ZYNQMP_ARM is enabled.
--- tests/qtest/meson.build | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
tests/qtest/meson.build +1 -2
@@ -184,11 +184,10 @@ qtests_aarch64 = \ (cpu != 'arm' and unpack_edk2_blobs ? ['bios-tables-test'] : []) + \ (config_all_devices.has_key('CONFIG_TPM_TIS_SYSBUS') ? ['tpm-tis-device-test'] : []) + \ (config_all_devices.has_key('CONFIG_TPM_TIS_SYSBUS') ? ['tpm-tis-device-swtpm-test'] : []) + \ + (config_all_devices.has_key('CONFIG_XLNX_ZYNQMP_ARM') ? ['xlnx-can-test', 'fuzz-xlnx-dp-test'] : []) + \ ['arm-cpu-features', 'numa-test', 'boot-serial-test', - 'xlnx-can-test', - 'fuzz-xlnx-dp-test', 'migration-test'] qtests_s390x = \
Signature · 1 line
2.27.0
PATCH 3/4 tests/qtest: Add a function that gets a list with available machine types
In reply to Thomas HuthFor the upcoming patches, we will need a way to gets a list with all available machine types. Refactor the qtest_cb_for_every_machine() to split the related code out into a separate new function, and gather the aliases of the various machine types, too.
--- tests/qtest/libqtest.c | 64 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 11 deletions(-)
tests/qtest/libqtest.c +53 -11
@@ -1321,16 +1321,29 @@ static bool qtest_is_old_versioned_machine(const char *mname)return res; } -void qtest_cb_for_every_machine (void (*cb)(const char *machine), -bool skip_old_versioned) +struct MachInfo { +char *name; +char *alias; +}; + +/* +* Returns an array with pointers to the available machine names. +* The terminating entry has the name set to NULL. +*/ +static struct MachInfo *qtest_get_machines (void ) { +static struct MachInfo *machines;QDict *response, *minfo;QList *list;const QListEntry *p;QObject *qobj;QString *qstr; -const char *mname;QTestState *qts; +int idx; + +if (machines) { +return machines; + } qts =qtest_init ("-machine none" ); response =qtest_qmp (qts,"{ 'execute': 'query-machines' }" );
@@ -1338,25 +1351,54 @@ void qtest_cb_for_every_machine(void (*cb)(const char *machine), list =qdict_get_qlist (response,"return" );g_assert (list); -for (p =qlist_first (list); p; p =qlist_next (p)) { + machines = g_new(struct MachInfo, qlist_size(list) + 1); + +for (p =qlist_first (list), idx =0 ; p; p =qlist_next (p), idx++) { minfo =qobject_to (QDict,qlist_entry_obj (p));g_assert (minfo); + qobj =qdict_get (minfo,"name" );g_assert (qobj); qstr =qobject_to (QString, qobj);g_assert (qstr); - mname =qstring_get_str (qstr); -/* Ignore machines that cannot be used for qtests */ -if (!strncmp ("xenfv" , mname,5 ) ||g_str_equal ("xenpv" , mname)) { -continue ; - } -if (!skip_old_versioned || !qtest_is_old_versioned_machine (mname)) { -cb (mname); + machines[idx].name =g_strdup (qstring_get_str (qstr)); + + qobj =qdict_get (minfo,"alias" ); +if (qobj) {/* The alias is optional */ + qstr =qobject_to (QString, qobj); +g_assert (qstr); + machines[idx].alias =g_strdup (qstring_get_str (qstr)); + }else { + machines[idx].alias =NULL ; } }qtest_quit (qts);qobject_unref (response); + +memset (&machines[idx],0 ,sizeof (struct MachInfo ));/* Terminating entry */ +return machines; +} + +void qtest_cb_for_every_machine (void (*cb)(const char *machine), +bool skip_old_versioned) +{ +struct MachInfo *machines; +int i; + + machines =qtest_get_machines (); + +for (i =0 ; machines[i].name !=NULL ; i++) { +/* Ignore machines that cannot be used for qtests */ +if (!strncmp ("xenfv" , machines[i].name,5 ) || +g_str_equal ("xenpv" , machines[i].name)) { +continue ; + } +if (!skip_old_versioned || + !qtest_is_old_versioned_machine (machines[i].name)) { +cb (machines[i].name); + } + } }/*
Signature · 1 line
2.27.0
PATCH 1/4 tests/qtest: Run the PPC 32-bit tests with the 64-bit target binary, too
In reply to Thomas HuthThe ppc64 target is a superset of the 32-bit target, so we should include the tests here, too. This used to be done in the past already, but it got lost during the conversion to meson.
--- tests/qtest/meson.build | 1 + 1 file changed, 1 insertion(+)
tests/qtest/meson.build +1 -0
@@ -134,6 +134,7 @@ qtests_ppc = \ ['boot-order-test', 'prom-env-test', 'boot-serial-test'] \ qtests_ppc64 = \ + qtests_ppc + \ (config_all_devices.has_key('CONFIG_PSERIES') ? ['device-plug-test'] : []) + \ (config_all_devices.has_key('CONFIG_POWERNV') ? ['pnv-xscom-test'] : []) + \ (config_all_devices.has_key('CONFIG_PSERIES') ? ['rtas-test'] : []) + \
Signature · 1 line
2.27.0
PATCH 4/4 tests/qtest: Add a function to check whether a machine is available
In reply to Thomas HuthIt 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).
--- tests/qtest/boot-serial-test.c | 3 ++- tests/qtest/cdrom-test.c | 8 +++++--- tests/qtest/libqos/libqtest.h | 8 ++++++++ tests/qtest/libqtest.c | 17 +++++++++++++++++ tests/qtest/prom-env-test.c | 8 +++++--- 5 files changed, 37 insertions(+), 7 deletions(-)
tests/qtest/boot-serial-test.c +2 -1
@@ -285,7 +285,8 @@ int main(int argc, char *argv[])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);
tests/qtest/cdrom-test.c +5 -3
@@ -109,9 +109,11 @@ static void test_cdrom_param(gconstpointer data)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++; } }
tests/qtest/libqos/libqtest.h +8 -0
@@ -710,6 +710,14 @@ QDict *qmp_fd(int fd, const char *fmt, ...) GCC_FMT_ATTR(2, 3);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
tests/qtest/libqtest.c +17 -0
@@ -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. */
tests/qtest/prom-env-test.c +5 -3
@@ -71,9 +71,11 @@ static void add_tests(const char *machines[])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); + } } }
Signature · 1 line
2.27.0
Re: [PATCH for-7.0 4/4] tests/qtest: Add a function to check whether a machine is available
Quoted 112 lines · Thomas Huth
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).
Signed-off-by Thomas Huth <[email protected]>--- tests/qtest/boot-serial-test.c | 3 ++- tests/qtest/cdrom-test.c | 8 +++++--- tests/qtest/libqos/libqtest.h | 8 ++++++++ tests/qtest/libqtest.c | 17 +++++++++++++++++ tests/qtest/prom-env-test.c | 8 +++++--- 5 files changed, 37 insertions(+), 7 deletions(-)tests/qtest/boot-serial-test.c +2
-1@@ -285,7 +285,8 @@ int main(int argc, char *argv[])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);tests/qtest/cdrom-test.c +5
-3@@ -109,9 +109,11 @@ static void test_cdrom_param(gconstpointer data)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++; } }tests/qtest/libqos/libqtest.h +8
-0@@ -710,6 +710,14 @@ QDict *qmp_fd(int fd, const char *fmt, ...)GCC_FMT_ATTR (2 ,3 );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
tests/qtest/libqtest.c +17
-0@@ -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_addQMP commands. */tests/qtest/prom-env-test.c +0
-1@@ -71,9 +71,11 @@ static void add_tests(const char *machines[])char *name;for (i =0 ; machines[i] !=NULL ; i++) { - name =g_strdup_printf ("prom-env/%s" , machines[i]);
tests/qtest/prom-env-test.c static void add_tests(const char *machines[]) · line 81
Quoted 10 lines
tests/qtest/prom-env-test.c +5
-2-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); + } } }
I wonder if the arch-specific CDROM tests should be split out into their own file, because IIRC it's not really about testing the *cdrom* itself, it's just a test that uses the CDROM.
Eh.
cdrom test bits: Acked-by: John Snow <[email protected]>
--js