qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org
Cc: Igor Mammedov <imammedo@redhat.com>
Subject: [Qemu-devel] [PULL 09/12] tests: extend qmp test with preconfig checks
Date: Wed, 30 May 2018 20:05:25 -0300	[thread overview]
Message-ID: <20180530230528.30166-10-ehabkost@redhat.com> (raw)
In-Reply-To: <20180530230528.30166-1-ehabkost@redhat.com>

From: Igor Mammedov <imammedo@redhat.com>

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>
---
 tests/qmp-test.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/tests/qmp-test.c b/tests/qmp-test.c
index 88f867f8c0..2ee441cdb3 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();
 
-- 
2.17.1

  parent reply	other threads:[~2018-05-30 23:05 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-30 23:05 [Qemu-devel] [PULL 00/12] NUMA queue, 2018-05-30 Eduardo Habkost
2018-05-30 23:05 ` [Qemu-devel] [PULL 01/12] numa: clarify error message when node index is out of range in -numa dist, Eduardo Habkost
2018-05-30 23:05 ` [Qemu-devel] [PULL 02/12] numa: postpone options post-processing till machine_run_board_init() Eduardo Habkost
2018-05-30 23:05 ` [Qemu-devel] [PULL 03/12] numa: split out NumaOptions parsing into set_numa_options() Eduardo Habkost
2018-05-30 23:05 ` [Qemu-devel] [PULL 04/12] qapi: introduce preconfig runstate Eduardo Habkost
2018-05-30 23:05 ` [Qemu-devel] [PULL 05/12] hmp: disable monitor in preconfig state Eduardo Habkost
2018-05-30 23:05 ` [Qemu-devel] [PULL 06/12] qapi: introduce new cmd option "allow-preconfig" Eduardo Habkost
2018-05-30 23:05 ` [Qemu-devel] [PULL 07/12] tests: qapi-schema tests for allow-preconfig Eduardo Habkost
2018-05-30 23:05 ` [Qemu-devel] [PULL 08/12] cli: add --preconfig option Eduardo Habkost
2018-05-30 23:05 ` Eduardo Habkost [this message]
2018-05-30 23:05 ` [Qemu-devel] [PULL 10/12] qmp: permit query-hotpluggable-cpus in preconfig state Eduardo Habkost
2018-05-30 23:05 ` [Qemu-devel] [PULL 11/12] qmp: add set-numa-node command Eduardo Habkost
2018-05-30 23:05 ` [Qemu-devel] [PULL 12/12] tests: functional tests for QMP command set-numa-node Eduardo Habkost
2018-05-31 13:40 ` [Qemu-devel] [PULL 00/12] NUMA queue, 2018-05-30 Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180530230528.30166-10-ehabkost@redhat.com \
    --to=ehabkost@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).