qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH v3 6/9] tests: extend qmp test with pereconfig check


From: Igor Mammedov
Subject: [Qemu-devel] [PATCH v3 6/9] tests: extend qmp test with pereconfig checks
Date: Fri, 16 Feb 2018 13:37:18 +0100

Add permission checks for commands in 'preconfig' state.

It should work for all targets, but won't work with
machine 'none' as it's limited to -smp 1 only.
So use PC machine for testing preconfig and 'runstate'
parameter.

Signed-off-by: Igor Mammedov <address@hidden>
---
 tests/qmp-test.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/tests/qmp-test.c b/tests/qmp-test.c
index 5808483..3adc485 100644
--- a/tests/qmp-test.c
+++ b/tests/qmp-test.c
@@ -304,8 +304,54 @@ static void add_query_tests(QmpSchema *schema)
     }
 }
 
+static bool is_err(QDict *rsp)
+{
+    const char *desc = NULL;
+    QDict *error = qdict_get_qdict(rsp, "error");
+    if (error) {
+        desc = qdict_get_try_str(error, "desc");
+    }
+    QDECREF(rsp);
+    return !!desc;
+}
+
+static void test_qmp_preconfig(void)
+{
+    QDict *rsp, *ret;
+    QTestState *qs = qtest_startf("-nodefaults -preconfig -smp 2");
+
+    /* preconfig state */
+    /* enabled commands, no error expected  */
+    g_assert(!is_err(qtest_qmp(qs, "{ 'execute': 'query-commands' }")));
+
+    /* forbidden commands, expected error */
+    g_assert(is_err(qtest_qmp(qs, "{ 'execute': 'query-cpus' }")));
+
+    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");
+    QDECREF(rsp);
+
+    /* exit preconfig state */
+    g_assert(!is_err(qtest_qmp(qs, "{ 'execute': 'cont' }")));
+    qtest_qmp_eventwait(qs, "RESUME");
+
+    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");
+    QDECREF(rsp);
+
+    /* enabled commands, no error expected  */
+    g_assert(!is_err(qtest_qmp(qs, "{ 'execute': 'query-cpus' }")));
+
+    qtest_quit(qs);
+}
+
 int main(int argc, char *argv[])
 {
+    const char *arch = qtest_get_arch();
     QmpSchema schema;
     int ret;
 
@@ -314,6 +360,9 @@ int main(int argc, char *argv[])
     qtest_add_func("qmp/protocol", test_qmp_protocol);
     qmp_schema_init(&schema);
     add_query_tests(&schema);
+    if (!strcmp(arch, "i386") || !strcmp(arch, "x86_64")) {
+        qtest_add_func("qmp/preconfig", test_qmp_preconfig);
+    }
 
     ret = g_test_run();
 
-- 
2.7.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]