Skip to content

Commit 99baa5d

Browse files
JurajMarcinFabiano Rosas
authored andcommitted
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>
1 parent b4a91c5 commit 99baa5d

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

tests/qtest/libqtest.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,19 +543,33 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
543543
return qtest_init_internal(qtest_qemu_binary(NULL), extra_args);
544544
}
545545

546-
QTestState *qtest_init_with_env(const char *var, const char *extra_args)
546+
QTestState *qtest_init_with_env_and_capabilities(const char *var,
547+
const char *extra_args,
548+
QList *capabilities)
547549
{
548550
QTestState *s = qtest_init_internal(qtest_qemu_binary(var), extra_args);
549551
QDict *greeting;
550552

551553
/* Read the QMP greeting and then do the handshake */
552554
greeting = qtest_qmp_receive(s);
553555
qobject_unref(greeting);
554-
qobject_unref(qtest_qmp(s, "{ 'execute': 'qmp_capabilities' }"));
556+
if (capabilities) {
557+
qtest_qmp_assert_success(s,
558+
"{ 'execute': 'qmp_capabilities', "
559+
"'arguments': { 'enable': %p } }",
560+
qobject_ref(capabilities));
561+
} else {
562+
qtest_qmp_assert_success(s, "{ 'execute': 'qmp_capabilities' }");
563+
}
555564

556565
return s;
557566
}
558567

568+
QTestState *qtest_init_with_env(const char *var, const char *extra_args)
569+
{
570+
return qtest_init_with_env_and_capabilities(var, extra_args, NULL);
571+
}
572+
559573
QTestState *qtest_init(const char *extra_args)
560574
{
561575
return qtest_init_with_env(NULL, extra_args);

tests/qtest/libqtest.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "qapi/qmp/qobject.h"
2121
#include "qapi/qmp/qdict.h"
22+
#include "qapi/qmp/qlist.h"
2223
#include "libqmp.h"
2324

2425
typedef struct QTestState QTestState;
@@ -68,6 +69,22 @@ QTestState *qtest_init(const char *extra_args);
6869
*/
6970
QTestState *qtest_init_with_env(const char *var, const char *extra_args);
7071

72+
/**
73+
* qtest_init_with_env_and_capabilities:
74+
* @var: Environment variable from where to take the QEMU binary
75+
* @extra_args: Other arguments to pass to QEMU. CAUTION: these
76+
* arguments are subject to word splitting and shell evaluation.
77+
* @capabilities: list of QMP capabilities (strings) to enable
78+
*
79+
* Like qtest_init_with_env(), but enable specified capabilities during
80+
* hadshake.
81+
*
82+
* Returns: #QTestState instance.
83+
*/
84+
QTestState *qtest_init_with_env_and_capabilities(const char *var,
85+
const char *extra_args,
86+
QList *capabilities);
87+
7188
/**
7289
* qtest_init_without_qmp_handshake:
7390
* @extra_args: other arguments to pass to QEMU. CAUTION: these

0 commit comments

Comments
 (0)