qtest_qmp provides a convenient way to automatically serialize into the client JSON protocol and to send the command to the QMP socket. Since qtest has a strong dependency to the QMP monitor, a minimal number of function has been added to mcd-test.c for interoperability with MCD's protocol.
Signed-off-by: Mario Fleischmann <mario.fleischm...@lauterbach.com> --- MAINTAINERS | 1 + tests/qtest/mcd-test.c | 82 +++++++++++++++++++++++++++++++++++++++++ tests/qtest/mcd-util.h | 21 +++++++++++ tests/qtest/meson.build | 5 +++ 4 files changed, 109 insertions(+) create mode 100644 tests/qtest/mcd-test.c create mode 100644 tests/qtest/mcd-util.h diff --git a/MAINTAINERS b/MAINTAINERS index 159a38f..cb4f9ab 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3127,6 +3127,7 @@ F: mcd/* F: docs/interop/mcd.rst F: qapi/mcd.json F: include/exec/mcdstub.h +X: tests/qtest/mcd-* Memory API M: Paolo Bonzini <pbonz...@redhat.com> diff --git a/tests/qtest/mcd-test.c b/tests/qtest/mcd-test.c new file mode 100644 index 0000000..b9ee3f4 --- /dev/null +++ b/tests/qtest/mcd-test.c @@ -0,0 +1,82 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * mcdtest - Test suite for the Multi-Core Debug (MCD) API implementation + * + * Copyright (c) 2025 Lauterbach GmbH + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" + +#ifndef _WIN32 +#include <sys/socket.h> +#include <sys/wait.h> +#include <sys/un.h> +#endif /* _WIN32 */ +#ifdef __linux__ +#include <sys/prctl.h> +#endif /* __linux__ */ +#ifdef __FreeBSD__ +#include <sys/procctl.h> +#endif /* __FreeBSD__ */ + +#include "libqtest.h" +#include "mcd-util.h" + +#define QEMU_EXTRA_ARGS "" + +static bool verbose; + +static QTestStateMCD mcdtest_init(const char *extra_args) +{ + QTestStateMCD qts_mcd; + int sock; + + g_autofree gchar *sock_path = g_strdup_printf("%s/qtest-%d.mcd", + g_get_tmp_dir(), getpid()); + + /* remove possible orphan from earlier test run */ + unlink(sock_path); + sock = qtest_socket_server(sock_path); + + g_autoptr(GString) args = g_string_new(extra_args); + g_string_append_printf(args, " -chardev socket,path=%s,id=mcdsock " + "-mcd chardev:mcdsock", + sock_path); + + qts_mcd.qts = qtest_init_without_qmp_handshake(args->str); + g_assert(qts_mcd.qts); + + qts_mcd.mcd_fd = accept(sock, NULL, NULL); + unlink(sock_path); + g_assert(qts_mcd.mcd_fd >= 0); + + return qts_mcd; +} + +static void mcdtest_quit(QTestStateMCD *qts) +{ + qtest_quit(qts->qts); + close(qts->mcd_fd); + + qts->qts = NULL; + qts->mcd_fd = -1; +} + +static void test_initialize_mcdtest(void) +{ + QTestStateMCD qts = mcdtest_init(QEMU_EXTRA_ARGS); + mcdtest_quit(&qts); +} + +int main(int argc, char *argv[]) +{ + char *v_env = getenv("V"); + verbose = v_env && atoi(v_env) >= 1; + g_test_init(&argc, &argv, NULL); + + qtest_add_func("mcd/initialize-mcdtest", test_initialize_mcdtest); + return g_test_run(); +} diff --git a/tests/qtest/mcd-util.h b/tests/qtest/mcd-util.h new file mode 100644 index 0000000..18ff8bd --- /dev/null +++ b/tests/qtest/mcd-util.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * mcdutil - Utility functions for the MCD API test suite + * + * Copyright (c) 2025 Lauterbach GmbH + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#ifndef TEST_MCD_UTILS_H +#define TEST_MCD_UTILS_H + +#include "libqtest.h" + +typedef struct { + QTestState *qts; + int mcd_fd; +} QTestStateMCD; + +#endif /* TEST_MCD_UTILS_H */ diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index 3136d15..3dc9508 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -397,6 +397,11 @@ if dbus_display qtests += {'dbus-display-test': [dbus_display1, gio]} endif +if get_option('mcd').enabled() + qtests += { 'mcd-test': files('mcd-test.c') } + qtests_generic += [ 'mcd-test' ] +endif + qtest_executables = {} foreach dir : target_dirs if not dir.endswith('-softmmu') -- 2.34.1