diff options
author | Igor Mammedov <imammedo@redhat.com> | 2018-05-17 13:28:44 +0200 |
---|---|---|
committer | Eduardo Habkost <ehabkost@redhat.com> | 2018-05-30 13:19:14 -0300 |
commit | fb1e58f72ba8daf7446ac46b00b5d1853486d28b (patch) | |
tree | 0bb6de771cbe332e7a7253ef62027c6a3ac82818 /tests/qmp-test.c | |
parent | 047f7038f586d2150f16c6d9ba9cfd0479f0f6ac (diff) | |
download | qemu-fb1e58f72ba8daf7446ac46b00b5d1853486d28b.zip qemu-fb1e58f72ba8daf7446ac46b00b5d1853486d28b.tar.gz qemu-fb1e58f72ba8daf7446ac46b00b5d1853486d28b.tar.bz2 |
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>
Diffstat (limited to 'tests/qmp-test.c')
-rw-r--r-- | tests/qmp-test.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/qmp-test.c b/tests/qmp-test.c index 88f867f..2ee441c 100644 --- a/tests/qmp-test.c +++ b/tests/qmp-test.c @@ -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(); |