mirror of
https://github.com/qemu/qemu.git
synced 2024-12-13 22:43:32 +08:00
tests: extend qmp test with preconfig checks
Add permission checks for commands at 'preconfig' stage. Signed-off-by: Igor Mammedov <imammedo@redhat.com> Message-Id: <1526556524-267991-1-git-send-email-imammedo@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
This commit is contained in:
parent
047f7038f5
commit
fb1e58f72b
@ -392,6 +392,52 @@ static void add_query_tests(QmpSchema *schema)
|
||||
}
|
||||
}
|
||||
|
||||
static bool qmp_rsp_is_err(QDict *rsp)
|
||||
{
|
||||
QDict *error = qdict_get_qdict(rsp, "error");
|
||||
qobject_unref(rsp);
|
||||
return !!error;
|
||||
}
|
||||
|
||||
static void test_qmp_preconfig(void)
|
||||
{
|
||||
QDict *rsp, *ret;
|
||||
QTestState *qs = qtest_startf("%s --preconfig", common_args);
|
||||
|
||||
/* preconfig state */
|
||||
/* enabled commands, no error expected */
|
||||
g_assert(!qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'query-commands' }")));
|
||||
|
||||
/* forbidden commands, expected error */
|
||||
g_assert(qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'query-cpus' }")));
|
||||
|
||||
/* check that query-status returns preconfig state */
|
||||
rsp = qtest_qmp(qs, "{ 'execute': 'query-status' }");
|
||||
ret = qdict_get_qdict(rsp, "return");
|
||||
g_assert(ret);
|
||||
g_assert_cmpstr(qdict_get_try_str(ret, "status"), ==, "preconfig");
|
||||
qobject_unref(rsp);
|
||||
|
||||
/* exit preconfig state */
|
||||
g_assert(!qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'exit-preconfig' }")));
|
||||
qtest_qmp_eventwait(qs, "RESUME");
|
||||
|
||||
/* check that query-status returns running state */
|
||||
rsp = qtest_qmp(qs, "{ 'execute': 'query-status' }");
|
||||
ret = qdict_get_qdict(rsp, "return");
|
||||
g_assert(ret);
|
||||
g_assert_cmpstr(qdict_get_try_str(ret, "status"), ==, "running");
|
||||
qobject_unref(rsp);
|
||||
|
||||
/* check that exit-preconfig returns error after exiting preconfig */
|
||||
g_assert(qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'exit-preconfig' }")));
|
||||
|
||||
/* enabled commands, no error expected */
|
||||
g_assert(!qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'query-cpus' }")));
|
||||
|
||||
qtest_quit(qs);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QmpSchema schema;
|
||||
@ -403,6 +449,7 @@ int main(int argc, char *argv[])
|
||||
qtest_add_func("qmp/oob", test_qmp_oob);
|
||||
qmp_schema_init(&schema);
|
||||
add_query_tests(&schema);
|
||||
qtest_add_func("qmp/preconfig", test_qmp_preconfig);
|
||||
|
||||
ret = g_test_run();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user