@@ -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();
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 <imammedo@redhat.com> --- tests/qmp-test.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+)