tests/qtest: Introduce qtest_init_with_env_and_capabilities()

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.

Signed-off-by: Juraj Marcin <jmarcin@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Fabiano Rosas <farosas@suse.de>
This commit is contained in:
Juraj Marcin 2025-01-07 17:31:53 +01:00 committed by Fabiano Rosas
parent b4a91c5e71
commit 99baa5d921
2 changed files with 33 additions and 2 deletions

View File

@ -543,7 +543,9 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
return qtest_init_internal(qtest_qemu_binary(NULL), 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); QTestState *s = qtest_init_internal(qtest_qemu_binary(var), extra_args);
QDict *greeting; 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 */ /* Read the QMP greeting and then do the handshake */
greeting = qtest_qmp_receive(s); greeting = qtest_qmp_receive(s);
qobject_unref(greeting); 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; 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) QTestState *qtest_init(const char *extra_args)
{ {
return qtest_init_with_env(NULL, extra_args); return qtest_init_with_env(NULL, extra_args);

View File

@ -19,6 +19,7 @@
#include "qapi/qmp/qobject.h" #include "qapi/qmp/qobject.h"
#include "qapi/qmp/qdict.h" #include "qapi/qmp/qdict.h"
#include "qapi/qmp/qlist.h"
#include "libqmp.h" #include "libqmp.h"
typedef struct QTestState QTestState; 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); 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: * qtest_init_without_qmp_handshake:
* @extra_args: other arguments to pass to QEMU. CAUTION: these * @extra_args: other arguments to pass to QEMU. CAUTION: these