From 246069e850327b3d5c7f460461fc0bbf0f817654 Mon Sep 17 00:00:00 2001 From: Vladimir Sementsov-Ogievskiy Date: Thu, 10 Apr 2025 19:22:50 +0300 Subject: [PATCH 1/3] qtest: introduce qtest_init_ext MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Merge qtest_init_with_env_and_capabilities() and qtest_init_with_env() into one qtest_init_ext(). Reasons: 1. qtest_init_with_env() is just wrong: it gets do_connect parameter but always pass true to qtest_init_with_env_and_capabilities(). Happily, all qtest_init_with_env() callers pass true as well. 2. qtest_init_with_env() is not used outside of libqtest.c, so no reason to keep it as public function 3. and in libqtest.c it's used not often, so no problem to use more generic function instead. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Steve Sistare Reviewed-by: Fabiano Rosas Message-ID: <20250410162250.329941-1-vsementsov@yandex-team.ru> Signed-off-by: Fabiano Rosas --- tests/qtest/libqtest.c | 18 +++++------------- tests/qtest/libqtest.h | 30 +++++++----------------------- tests/qtest/migration/framework.c | 7 +++---- 3 files changed, 15 insertions(+), 40 deletions(-) diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index 358580361d..94526b7f9c 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -574,10 +574,8 @@ void qtest_qmp_handshake(QTestState *s, QList *capabilities) } } -QTestState *qtest_init_with_env_and_capabilities(const char *var, - const char *extra_args, - QList *capabilities, - bool do_connect) +QTestState *qtest_init_ext(const char *var, const char *extra_args, + QList *capabilities, bool do_connect) { QTestState *s = qtest_init_internal(qtest_qemu_binary(var), extra_args, do_connect); @@ -594,15 +592,9 @@ QTestState *qtest_init_with_env_and_capabilities(const char *var, return s; } -QTestState *qtest_init_with_env(const char *var, const char *extra_args, - bool do_connect) -{ - return qtest_init_with_env_and_capabilities(var, extra_args, NULL, true); -} - QTestState *qtest_init(const char *extra_args) { - return qtest_init_with_env(NULL, extra_args, true); + return qtest_init_ext(NULL, extra_args, NULL, true); } QTestState *qtest_vinitf(const char *fmt, va_list ap) @@ -1662,7 +1654,7 @@ static struct MachInfo *qtest_get_machines(const char *var) silence_spawn_log = !g_test_verbose(); - qts = qtest_init_with_env(qemu_var, "-machine none", true); + qts = qtest_init_ext(qemu_var, "-machine none", NULL, true); response = qtest_qmp(qts, "{ 'execute': 'query-machines' }"); g_assert(response); list = qdict_get_qlist(response, "return"); @@ -1717,7 +1709,7 @@ static struct CpuModel *qtest_get_cpu_models(void) silence_spawn_log = !g_test_verbose(); - qts = qtest_init_with_env(NULL, "-machine none", true); + qts = qtest_init_ext(NULL, "-machine none", NULL, true); response = qtest_qmp(qts, "{ 'execute': 'query-cpu-definitions' }"); g_assert(response); list = qdict_get_qlist(response, "return"); diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h index 930a91dcb7..b3f2e7fbef 100644 --- a/tests/qtest/libqtest.h +++ b/tests/qtest/libqtest.h @@ -57,37 +57,21 @@ QTestState *qtest_vinitf(const char *fmt, va_list ap) G_GNUC_PRINTF(1, 0); QTestState *qtest_init(const char *extra_args); /** - * qtest_init_with_env: - * @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. - * @do_connect: connect to qemu monitor and qtest socket. - * - * Like qtest_init(), but use a different environment variable for the - * QEMU binary. - * - * Returns: #QTestState instance. - */ -QTestState *qtest_init_with_env(const char *var, const char *extra_args, - bool do_connect); - -/** - * qtest_init_with_env_and_capabilities: + * qtest_init_ext: * @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 * @do_connect: connect to qemu monitor and qtest socket. * - * Like qtest_init_with_env(), but enable specified capabilities during - * hadshake. + * Like qtest_init(), but use a different environment variable for the + * QEMU binary, allow specify capabilities and skip connecting + * to QEMU monitor. * * Returns: #QTestState instance. */ -QTestState *qtest_init_with_env_and_capabilities(const char *var, - const char *extra_args, - QList *capabilities, - bool do_connect); +QTestState *qtest_init_ext(const char *var, const char *extra_args, + QList *capabilities, bool do_connect); /** * qtest_init_without_qmp_handshake: @@ -102,7 +86,7 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args); * qtest_connect * @s: #QTestState instance to connect * Connect to qemu monitor and qtest socket, after skipping them in - * qtest_init_with_env. Does not handshake with the monitor. + * qtest_init_ext. Does not handshake with the monitor. */ void qtest_connect(QTestState *s); diff --git a/tests/qtest/migration/framework.c b/tests/qtest/migration/framework.c index e48b80a127..407c9023c0 100644 --- a/tests/qtest/migration/framework.c +++ b/tests/qtest/migration/framework.c @@ -382,8 +382,7 @@ 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_and_capabilities(QEMU_ENV_SRC, cmd_source, - capabilities, true); + *from = qtest_init_ext(QEMU_ENV_SRC, cmd_source, capabilities, true); qtest_qmp_set_event_callback(*from, migrate_watch_for_events, &src_state); @@ -411,8 +410,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_and_capabilities(QEMU_ENV_DST, cmd_target, - capabilities, !args->defer_target_connect); + *to = qtest_init_ext(QEMU_ENV_DST, cmd_target, capabilities, + !args->defer_target_connect); qtest_qmp_set_event_callback(*to, migrate_watch_for_events, &dst_state); From 3008224ca8a7415323f67d58d8c03e69bde49092 Mon Sep 17 00:00:00 2001 From: Thomas Huth Date: Wed, 30 Apr 2025 15:28:17 +0200 Subject: [PATCH 2/3] tests/qtest/libqos: Avoid double swapping when using modern virtio MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The logic in the qvirtio_read/write function is rather a headache, involving byte-swapping when the target is big endian, just to maybe involve another byte-swapping in the qtest_read/write function immediately afterwards (on the QEMU side). Let's do it in a more obvious way here: For virtio 1.0, we know that the values have to be little endian, so let's read/write the bytes in that well known order here. Signed-off-by: Thomas Huth Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Alex Bennée Tested-by: Alex Bennée Message-ID: <20250430132817.610903-1-thuth@redhat.com> Signed-off-by: Fabiano Rosas --- tests/qtest/libqos/virtio.c | 44 ++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/tests/qtest/libqos/virtio.c b/tests/qtest/libqos/virtio.c index 2e7979652f..5a709d0bc5 100644 --- a/tests/qtest/libqos/virtio.c +++ b/tests/qtest/libqos/virtio.c @@ -25,49 +25,63 @@ */ static uint16_t qvirtio_readw(QVirtioDevice *d, QTestState *qts, uint64_t addr) { - uint16_t val = qtest_readw(qts, addr); + uint16_t val; - if (d->features & (1ull << VIRTIO_F_VERSION_1) && qtest_big_endian(qts)) { - val = bswap16(val); + if (d->features & (1ull << VIRTIO_F_VERSION_1)) { + qtest_memread(qts, addr, &val, sizeof(val)); + val = le16_to_cpu(val); + } else { + val = qtest_readw(qts, addr); } + return val; } static uint32_t qvirtio_readl(QVirtioDevice *d, QTestState *qts, uint64_t addr) { - uint32_t val = qtest_readl(qts, addr); + uint32_t val; - if (d->features & (1ull << VIRTIO_F_VERSION_1) && qtest_big_endian(qts)) { - val = bswap32(val); + if (d->features & (1ull << VIRTIO_F_VERSION_1)) { + qtest_memread(qts, addr, &val, sizeof(val)); + val = le32_to_cpu(val); + } else { + val = qtest_readl(qts, addr); } + return val; } static void qvirtio_writew(QVirtioDevice *d, QTestState *qts, uint64_t addr, uint16_t val) { - if (d->features & (1ull << VIRTIO_F_VERSION_1) && qtest_big_endian(qts)) { - val = bswap16(val); + if (d->features & (1ull << VIRTIO_F_VERSION_1)) { + val = cpu_to_le16(val); + qtest_memwrite(qts, addr, &val, sizeof(val)); + } else { + qtest_writew(qts, addr, val); } - qtest_writew(qts, addr, val); } static void qvirtio_writel(QVirtioDevice *d, QTestState *qts, uint64_t addr, uint32_t val) { - if (d->features & (1ull << VIRTIO_F_VERSION_1) && qtest_big_endian(qts)) { - val = bswap32(val); + if (d->features & (1ull << VIRTIO_F_VERSION_1)) { + val = cpu_to_le32(val); + qtest_memwrite(qts, addr, &val, sizeof(val)); + } else { + qtest_writel(qts, addr, val); } - qtest_writel(qts, addr, val); } static void qvirtio_writeq(QVirtioDevice *d, QTestState *qts, uint64_t addr, uint64_t val) { - if (d->features & (1ull << VIRTIO_F_VERSION_1) && qtest_big_endian(qts)) { - val = bswap64(val); + if (d->features & (1ull << VIRTIO_F_VERSION_1)) { + val = cpu_to_le64(val); + qtest_memwrite(qts, addr, &val, sizeof(val)); + } else { + qtest_writeq(qts, addr, val); } - qtest_writeq(qts, addr, val); } uint8_t qvirtio_config_readb(QVirtioDevice *d, uint64_t addr) From 98008aa41b93b2477782205dcbd9ce5978f26a7e Mon Sep 17 00:00:00 2001 From: Bibo Mao Date: Fri, 14 Mar 2025 16:51:30 +0800 Subject: [PATCH 3/3] tests/qtest/cpu-plug-test: Add cpu hotplug support for LoongArch Add cpu hotplug testcase support for LoongArch system, it passes to run with command "make check-qtest-loongarch64" as following: qemu:qtest+qtest-loongarch64 / qtest-loongarch64/cpu-plug-test OK 0.38s 1 subtests passed Signed-off-by: Bibo Mao Reviewed-by: Thomas Huth Message-ID: <20250314085130.4184272-1-maobibo@loongson.cn> Signed-off-by: Fabiano Rosas --- tests/qtest/cpu-plug-test.c | 24 ++++++++++++++++++++++++ tests/qtest/meson.build | 3 ++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/tests/qtest/cpu-plug-test.c b/tests/qtest/cpu-plug-test.c index 6633abfc10..44d704680b 100644 --- a/tests/qtest/cpu-plug-test.c +++ b/tests/qtest/cpu-plug-test.c @@ -156,6 +156,28 @@ static void add_s390x_test_case(const char *mname) g_free(path); } +static void add_loongarch_test_case(const char *mname) +{ + char *path; + PlugTestData *data; + + data = g_new(PlugTestData, 1); + data->machine = g_strdup(mname); + data->cpu_model = "la464"; + data->device_model = g_strdup("la464-loongarch-cpu"); + data->sockets = 1; + data->cores = 3; + data->threads = 1; + data->maxcpus = data->sockets * data->cores * data->threads; + + path = g_strdup_printf("cpu-plug/%s/device-add/%ux%ux%u&maxcpus=%u", + mname, data->sockets, data->cores, + data->threads, data->maxcpus); + qtest_add_data_func_full(path, data, test_plug_with_device_add, + test_data_free); + g_free(path); +} + int main(int argc, char **argv) { const char *arch = qtest_get_arch(); @@ -168,6 +190,8 @@ int main(int argc, char **argv) qtest_cb_for_every_machine(add_pseries_test_case, g_test_quick()); } else if (g_str_equal(arch, "s390x")) { qtest_cb_for_every_machine(add_s390x_test_case, g_test_quick()); + } else if (g_str_equal(arch, "loongarch64")) { + add_loongarch_test_case("virt"); } return g_test_run(); diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index 3136d15e0f..7daf619845 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -148,7 +148,8 @@ qtests_hppa = \ qtests_loongarch64 = qtests_filter + \ (config_all_devices.has_key('CONFIG_LOONGARCH_VIRT') ? ['numa-test'] : []) + \ - ['boot-serial-test'] + ['boot-serial-test', + 'cpu-plug-test'] qtests_m68k = ['boot-serial-test'] + \ qtests_filter