QTest patches for 2025-01-17
Subsystems (2)
[PULL 1/5] target/riscv: Add RISC-V CSR qtest support
In reply to Fabiano RosasFrom: Ivan Klokov <[email protected]>
The RISC-V architecture supports the creation of custom CSR-mapped devices. It would be convenient to test them in the same way as MMIO-mapped devices. To do this, a new call has been added to read/write CSR registers.
--- hw/riscv/riscv_hart.c | 55 ++++++++++++++++++++++++++++++++++++++++++ tests/qtest/libqtest.c | 27 +++++++++++++++++++++ tests/qtest/libqtest.h | 14 +++++++++++ 3 files changed, 96 insertions(+)
hw/riscv/riscv_hart.c +55 -0
@@ -22,6 +22,8 @@#include "qapi/error.h" #include "qemu/module.h" #include "system/reset.h" +#include "system/qtest.h" +#include "qemu/cutils.h" #include "hw/sysbus.h" #include "target/riscv/cpu.h" #include "hw/qdev-properties.h"
@@ -41,6 +43,55 @@ static void riscv_harts_cpu_reset(void *opaque)cpu_reset (CPU (cpu)); } +#ifndef CONFIG_USER_ONLY +static void csr_call (char *cmd,uint64_t cpu_num,int csrno,uint64_t *val) +{ +RISCVCPU *cpu =RISCV_CPU (cpu_by_arch_id (cpu_num)); +CPURISCVState *env = &cpu->env; + +int ret =RISCV_EXCP_NONE ; +if (strcmp (cmd,"get_csr" ) ==0 ) { + ret =riscv_csrr (env, csrno, (target_ulong *)val); + }else if (strcmp (cmd,"set_csr" ) ==0 ) { + ret =riscv_csrrw (env, csrno,NULL , *(target_ulong *)val, +MAKE_64BIT_MASK (0 ,TARGET_LONG_BITS )); + } + +g_assert (ret ==RISCV_EXCP_NONE ); +} + +static bool csr_qtest_callback (CharBackend *chr,gchar **words) +{ +if (strcmp (words[0 ],"csr" ) ==0 ) { + +uint64_t cpu; +uint64_t val; +int rc, csr; + + rc =qemu_strtou64 (words[2 ],NULL ,0 , &cpu); +g_assert (rc ==0 ); + rc =qemu_strtoi (words[3 ],NULL ,0 , &csr); +g_assert (rc ==0 ); + rc =qemu_strtou64 (words[4 ],NULL ,0 , &val); +g_assert (rc ==0 ); +csr_call (words[1 ], cpu, csr, &val); + +qtest_send_prefix (chr); +qtest_sendf (chr,"OK 0 " TARGET_FMT_lx"\n" , (target_ulong )val); + +return true; + } + +return false; +} + +static void riscv_cpu_register_csr_qtest_callback (void ) +{ +static GOnce once; +g_once (&once, (GThreadFunc )qtest_set_command_cb, csr_qtest_callback); +} +#endif +static bool riscv_hart_realize (RISCVHartArrayState *s,int idx,char *cpu_type,Error **errp) {
@@ -58,6 +109,10 @@ static void riscv_harts_realize(DeviceState *dev, Error **errp) s->harts =g_new0 (RISCVCPU , s->num_harts); +#ifndef CONFIG_USER_ONLY +riscv_cpu_register_csr_qtest_callback (); +#endif +for (n =0 ; n < s->num_harts; n++) {if (!riscv_hart_realize (s, n, s->cpu_type, errp)) {return ;
tests/qtest/libqtest.c +27 -0
@@ -1218,6 +1218,33 @@ uint64_t qtest_rtas_call(QTestState *s, const char *name,return 0 ; } +static void qtest_rsp_csr (QTestState *s,uint64_t *val) +{ +gchar **args; +uint64_t ret; +int rc; + + args =qtest_rsp_args (s,3 ); + + rc =qemu_strtou64 (args[1 ],NULL ,16 , &ret); +g_assert (rc ==0 ); + rc =qemu_strtou64 (args[2 ],NULL ,16 , val); +g_assert (rc ==0 ); + +g_strfreev (args); +} + +uint64_t qtest_csr_call (QTestState *s,const char *name, +uint64_t cpu,int csr, +uint64_t *val) +{ +qtest_sendf (s,"csr %s 0x%" PRIx64" %d 0x%" PRIx64"\n" , + name, cpu, csr, *val); + +qtest_rsp_csr (s, val); +return 0 ; +} +void qtest_add_func (const char *str,void (*fn)(void )) {gchar *path =g_strdup_printf ("/%s/%s" ,qtest_get_arch (), str);
tests/qtest/libqtest.h +14 -0
@@ -600,6 +600,20 @@ uint64_t qtest_rtas_call(QTestState *s, const char *name, uint32_t nargs, uint64_t args, uint32_t nret, uint64_t ret); +/** +* qtest_csr_call: +* @s: #QTestState instance to operate on. +* @name: name of the command to call. +* @cpu: hart number. +* @csr: CSR number. +* @val: Value for reading/writing. +* +* Call an RISC-V CSR read/write function +*/ +uint64_t qtest_csr_call (QTestState *s,const char *name, +uint64_t cpu,int csr, +uint64_t *val); +/** * qtest_bufread: * @s: #QTestState instance to operate on.
Signature · 1 line
2.35.3
[PULL 5/5] tests/qtest/test-x86-cpuid-compat: Remove tests related to pc-i440fx-2.3
In reply to Fabiano RosasFrom: Thomas Huth <[email protected]>
The pc-i440fx-2.3 machine type has been removed in commit 46a2bd5257 ("hw/i386/pc: Remove deprecated pc-i440fx-2.3 machine") already, so these tests are just dead code by now.
--- tests/qtest/test-x86-cpuid-compat.c | 18 ------------------ 1 file changed, 18 deletions(-)
tests/qtest/test-x86-cpuid-compat.c +0 -18
@@ -357,19 +357,6 @@ int main(int argc, char **argv)"486" ,"xstore=on" ,"pc-i440fx-2.7" , "xlevel2", 0); } -/* -* QEMU 2.3.0 had auto-level enabled for CPUID[7], already, -* and the compat code that sets default level shouldn't -* disable the auto-level=7 code: -*/ -if (qtest_has_machine ("pc-i440fx-2.3" )) { -add_cpuid_test ("x86/cpuid/auto-level7/pc-i440fx-2.3/off" , -"Penryn" ,NULL ,"pc-i440fx-2.3" , -"level" ,4 ); -add_cpuid_test ("x86/cpuid/auto-level7/pc-i440fx-2.3/on" , -"Penryn" ,"erms=on" ,"pc-i440fx-2.3" , -"level" ,7 ); - }if (qtest_has_machine ("pc-i440fx-2.9" )) { add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-2.9/off", "Conroe", NULL, "pc-i440fx-2.9",
@@ -384,11 +371,6 @@ int main(int argc, char **argv)* code on old machine-types. Just check that the compat code * is working correctly: */ -if (qtest_has_machine ("pc-i440fx-2.3" )) { -add_cpuid_test ("x86/cpuid/xlevel-compat/pc-i440fx-2.3" , -"SandyBridge" ,NULL ,"pc-i440fx-2.3" , -"xlevel" ,0x8000000a ); - }if (qtest_has_machine ("pc-i440fx-2.4" )) { add_cpuid_test("x86/cpuid/xlevel-compat/pc-i440fx-2.4/npt-off", "SandyBridge", NULL, "pc-i440fx-2.4",
Signature · 1 line
2.35.3
The following changes since commit 4d5d933bbc7cc52f6cc6b9021f91fa06266222d5:
Merge tag 'pull-xenfv-20250116' of git://git.infradead.org/users/dwmw2/qemu into staging (2025-01-16 09:03:43 -0500)
are available in the Git repository at:
https://gitlab.com/farosas/qemu.git tags/qtest-20250117-pull-request
for you to fetch changes up to aa601bd4f1208d85906f7778679c57d91cef6c70:
tests/qtest/test-x86-cpuid-compat: Remove tests related to pc-i440fx-2.3 (2025-01-17 11:48:44 -0300)
----------------------------------------------------------------
Qtest pull request
- RISCV CSR test
- migration recover changed to OOB
- removal of dead code in test-x86-cpuid-compat
----------------------------------------------------------------
Ivan Klokov (2):
target/riscv: Add RISC-V CSR qtest support tests/qtest: QTest example for RISC-V CSR register
Juraj Marcin (2):
tests/qtest: Introduce qtest_init_with_env_and_capabilities() tests/qtest/migration: Use out-of-band execution for migrate-recover
Thomas Huth (1):
tests/qtest/test-x86-cpuid-compat: Remove tests related to
pc-i440fx-2.3
hw/riscv/riscv_hart.c | 55 ++++++++++++++++++++++++++ tests/qtest/libqtest.c | 45 ++++++++++++++++++++- tests/qtest/libqtest.h | 31 +++++++++++++++ tests/qtest/meson.build | 2 +- tests/qtest/migration/framework.c | 23 ++++++++++- tests/qtest/migration/framework.h | 2 + tests/qtest/migration/migration-qmp.c | 2 +- tests/qtest/riscv-csr-test.c | 56 +++++++++++++++++++++++++++ tests/qtest/test-x86-cpuid-compat.c | 18 --------- 9 files changed, 210 insertions(+), 24 deletions(-) create mode 100644 tests/qtest/riscv-csr-test.c
Signature · 1 line
2.35.3
[PULL 2/5] tests/qtest: QTest example for RISC-V CSR register
From: Ivan Klokov <[email protected]>
Added demo for reading CSR register from qtest environment.
--- tests/qtest/meson.build | 2 +- tests/qtest/riscv-csr-test.c | 56 ++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 tests/qtest/riscv-csr-test.c
tests/qtest/meson.build +1 -1
@@ -274,7 +274,7 @@ qtests_s390x = \ qtests_riscv32 = \ (config_all_devices.has_key('CONFIG_SIFIVE_E_AON') ? ['sifive-e-aon-watchdog-test'] : []) -qtests_riscv64 = \ +qtests_riscv64 = ['riscv-csr-test'] + \ (unpack_edk2_blobs ? ['bios-tables-test'] : []) qos_test_ss = ss.source_set()
tests/qtest/riscv-csr-test.c new file +56 -0
56 lines not on this page · raw message
Signature · 1 line
2.35.3
[PULL 3/5] tests/qtest: Introduce qtest_init_with_env_and_capabilities()
In reply to Fabiano RosasFrom: Juraj Marcin <[email protected]>
This patch adds a new version of qtest_init_with_env() that allows specifying QMP capabilities that should be enabled during handshake. This is useful for example if a test needs out-of-band execution of QMP commands, it can initialize with the oob capability.
--- tests/qtest/libqtest.c | 18 ++++++++++++++++-- tests/qtest/libqtest.h | 17 +++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-)
tests/qtest/libqtest.c +16 -2
@@ -543,7 +543,9 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)return qtest_init_internal (qtest_qemu_binary (NULL ), extra_args); } -QTestState *qtest_init_with_env (const char *var,const char *extra_args) +QTestState *qtest_init_with_env_and_capabilities (const char *var, +const char *extra_args, +QList *capabilities) {QTestState *s =qtest_init_internal (qtest_qemu_binary (var), extra_args);QDict *greeting;
@@ -551,11 +553,23 @@ QTestState *qtest_init_with_env(const char *var, const char *extra_args)/* Read the QMP greeting and then do the handshake */ greeting =qtest_qmp_receive (s);qobject_unref (greeting); -qobject_unref (qtest_qmp (s,"{ 'execute': 'qmp_capabilities' }" )); +if (capabilities) { +qtest_qmp_assert_success (s, +"{ 'execute': 'qmp_capabilities', " +"'arguments': { 'enable': %p } }" , +qobject_ref (capabilities)); + }else { +qtest_qmp_assert_success (s,"{ 'execute': 'qmp_capabilities' }" ); + }return s; } +QTestState *qtest_init_with_env (const char *var,const char *extra_args) +{ +return qtest_init_with_env_and_capabilities (var, extra_args,NULL ); +} +QTestState *qtest_init (const char *extra_args) {return qtest_init_with_env (NULL , extra_args);
tests/qtest/libqtest.h +17 -0
@@ -19,6 +19,7 @@#include "qapi/qmp/qobject.h" #include "qapi/qmp/qdict.h" +#include "qapi/qmp/qlist.h" #include "libqmp.h" typedef struct QTestState QTestState ;
@@ -68,6 +69,22 @@ QTestState *qtest_init(const char *extra_args);*/ QTestState *qtest_init_with_env (const char *var,const char *extra_args); +/** +* qtest_init_with_env_and_capabilities: +* @var: Environment variable from where to take the QEMU binary +* @extra_args: Other arguments to pass to QEMU. CAUTION: these +* arguments are subject to word splitting and shell evaluation. +* @capabilities: list of QMP capabilities (strings) to enable +* +* Like qtest_init_with_env(), but enable specified capabilities during +* hadshake. +* +* Returns: #QTestState instance. +*/ +QTestState *qtest_init_with_env_and_capabilities (const char *var, +const char *extra_args, +QList *capabilities); +/** * qtest_init_without_qmp_handshake: * @extra_args: other arguments to pass to QEMU. CAUTION: these
Signature · 1 line
2.35.3
[PULL 4/5] tests/qtest/migration: Use out-of-band execution for migrate-recover
In reply to Fabiano RosasFrom: Juraj Marcin <[email protected]>
In real use cases, the migrate-recover command requires out-of-band execution, because the thread processing normal commands is blocked by a page fault in the guest memory. With this change, the tests will be closer to real use cases and could help detect regressions and other bugs in migration recovery.
--- tests/qtest/migration/framework.c | 23 +++++++++++++++++++++-- tests/qtest/migration/framework.h | 2 ++ tests/qtest/migration/migration-qmp.c | 2 +- 3 files changed, 24 insertions(+), 3 deletions(-)
tests/qtest/migration/framework.c +21 -2
@@ -194,6 +194,16 @@ static void cleanup(const char *filename)unlink (path); } +static QList *migrate_start_get_qmp_capabilities (const MigrateStart *args) +{ +QList *capabilities =qlist_new (); + +if (args->oob) { +qlist_append_str (capabilities,"oob" ); + } +return capabilities; +} +int migrate_start (QTestState **from,QTestState **to,const char *uri,MigrateStart *args) {
@@ -210,6 +220,7 @@ int migrate_start(QTestState **from, QTestState **to, const char *uri,const char *machine_alias, *machine_opts ="" ; g_autofree char *machine = NULL;const char *bootpath; +g_autoptr (QList) capabilities =migrate_start_get_qmp_capabilities (args);if (args->use_shmem) {if (!g_file_test ("/dev/shm" ,G_FILE_TEST_IS_DIR )) {
@@ -314,7 +325,8 @@ int migrate_start(QTestState **from, QTestState **to, const char *uri, args->opts_source ? args->opts_source :"" , ignore_stderr);if (!args->only_target) { - *from =qtest_init_with_env (QEMU_ENV_SRC , cmd_source); + *from =qtest_init_with_env_and_capabilities (QEMU_ENV_SRC , cmd_source, + capabilities);qtest_qmp_set_event_callback (*from, migrate_watch_for_events, &src_state);
@@ -334,7 +346,8 @@ int migrate_start(QTestState **from, QTestState **to, const char *uri, shmem_opts ? shmem_opts :"" , args->opts_target ? args->opts_target :"" , ignore_stderr); - *to =qtest_init_with_env (QEMU_ENV_DST , cmd_target); + *to =qtest_init_with_env_and_capabilities (QEMU_ENV_DST , cmd_target, + capabilities);qtest_qmp_set_event_callback (*to, migrate_watch_for_events, &dst_state);
@@ -601,6 +614,12 @@ void test_postcopy_recovery_common(MigrateCommon *args)QTestState *from, *to; g_autofree char *uri = NULL; +/* +* Always enable OOB QMP capability for recovery tests, migrate-recover is +* executed out-of-band +*/ + args->start.oob = true; +/* Always hide errors for postcopy recover tests since they're expected */ args->start.hide_stderr = true;
tests/qtest/migration/framework.h +2 -0
@@ -109,6 +109,8 @@ typedef struct {const char *opts_target;/* suspend the src before migrating to dest. */ bool suspend_me; +/* enable OOB QMP capability */ +bool oob; } MigrateStart; typedef enum PostcopyRecoveryFailStage {
tests/qtest/migration/migration-qmp.c +1 -1
@@ -464,7 +464,7 @@ void migrate_continue(QTestState *who, const char *state)void migrate_recover (QTestState *who,const char *uri) {qtest_qmp_assert_success (who, -"{ 'execute': 'migrate-recover', " +"{ 'exec-oob': 'migrate-recover', " " 'id': 'recover-cmd', " " 'arguments': { 'uri': %s } }" , uri);
Signature · 1 line
2.35.3
Stefan Hajnoczi
AppliedApplied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/10.0 for any user-visible changes.