Skip to content

Commit d003f7a

Browse files
xzpeterebblake
authored andcommitted
tests: qmp-test: add oob test
Test the new OOB capability. Here we used the new "x-oob-test" command. First, we send a lock=true and oob=false command to hang the main thread. Then send another lock=false and oob=true command (which will be run inside parser this time) to free that hanged command. Reviewed-by: Stefan Hajnoczi <[email protected]> Signed-off-by: Peter Xu <[email protected]> Message-Id: <[email protected]> Reviewed-by: Eric Blake <[email protected]> [eblake: grammar tweaks] Signed-off-by: Eric Blake <[email protected]>
1 parent 91ad450 commit d003f7a

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

tests/qmp-test.c

+65
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,70 @@ static void test_qmp_protocol(void)
164164
qtest_quit(qts);
165165
}
166166

167+
/* Tests for Out-Of-Band support. */
168+
static void test_qmp_oob(void)
169+
{
170+
QDict *resp;
171+
int acks = 0;
172+
const char *cmd_id;
173+
174+
global_qtest = qtest_init_without_qmp_handshake(common_args);
175+
176+
/* Ignore the greeting message. */
177+
resp = qmp_receive();
178+
g_assert(qdict_get_qdict(resp, "QMP"));
179+
QDECREF(resp);
180+
181+
/* Try a fake capability, it should fail. */
182+
resp = qmp("{ 'execute': 'qmp_capabilities', "
183+
" 'arguments': { 'enable': [ 'cap-does-not-exist' ] } }");
184+
g_assert(qdict_haskey(resp, "error"));
185+
QDECREF(resp);
186+
187+
/* Now, enable OOB in current QMP session, it should succeed. */
188+
resp = qmp("{ 'execute': 'qmp_capabilities', "
189+
" 'arguments': { 'enable': [ 'oob' ] } }");
190+
g_assert(qdict_haskey(resp, "return"));
191+
QDECREF(resp);
192+
193+
/*
194+
* Try any command that does not support OOB but with OOB flag. We
195+
* should get failure.
196+
*/
197+
resp = qmp("{ 'execute': 'query-cpus',"
198+
" 'control': { 'run-oob': true } }");
199+
g_assert(qdict_haskey(resp, "error"));
200+
QDECREF(resp);
201+
202+
/*
203+
* First send the "x-oob-test" command with lock=true and
204+
* oob=false, it should hang the dispatcher and main thread;
205+
* later, we send another lock=false with oob=true to continue
206+
* that thread processing. Finally we should receive replies from
207+
* both commands.
208+
*/
209+
qmp_async("{ 'execute': 'x-oob-test',"
210+
" 'arguments': { 'lock': true }, "
211+
" 'id': 'lock-cmd'}");
212+
qmp_async("{ 'execute': 'x-oob-test', "
213+
" 'arguments': { 'lock': false }, "
214+
" 'control': { 'run-oob': true }, "
215+
" 'id': 'unlock-cmd' }");
216+
217+
/* Ignore all events. Wait for 2 acks */
218+
while (acks < 2) {
219+
resp = qmp_receive();
220+
cmd_id = qdict_get_str(resp, "id");
221+
if (!g_strcmp0(cmd_id, "lock-cmd") ||
222+
!g_strcmp0(cmd_id, "unlock-cmd")) {
223+
acks++;
224+
}
225+
QDECREF(resp);
226+
}
227+
228+
qtest_end();
229+
}
230+
167231
static int query_error_class(const char *cmd)
168232
{
169233
static struct {
@@ -348,6 +412,7 @@ int main(int argc, char *argv[])
348412
g_test_init(&argc, &argv, NULL);
349413

350414
qtest_add_func("qmp/protocol", test_qmp_protocol);
415+
qtest_add_func("qmp/oob", test_qmp_oob);
351416
qmp_schema_init(&schema);
352417
add_query_tests(&schema);
353418

0 commit comments

Comments
 (0)