aboutsummaryrefslogtreecommitdiff
path: root/tests/qmp-test.c
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2018-09-24 12:28:36 +0100
committerPeter Maydell <peter.maydell@linaro.org>2018-09-24 12:28:37 +0100
commit09d8277eb0cc40e7b29c5d4795bb9aaa7d8bbdcc (patch)
tree050199ca9486e0885c24b033dc5d01f80a75bb9e /tests/qmp-test.c
parent2fde22f8ae1a69253dff5c7a73c39d3a72fa94a1 (diff)
parentae6bf766048ecaeef90b85c4fb2b4db2aa0c094c (diff)
Merge remote-tracking branch 'remotes/huth-gitlab/tags/pull-request-2018-08-31' into staging
Removal of deprecated options and improvements for the qtests # gpg: Signature made Fri 31 Aug 2018 09:10:23 BST # gpg: using RSA key 2ED9D774FE702DB5 # gpg: Good signature from "Thomas Huth <th.huth@gmx.de>" # gpg: aka "Thomas Huth <thuth@redhat.com>" # gpg: aka "Thomas Huth <huth@tuxfamily.org>" # gpg: aka "Thomas Huth <th.huth@posteo.de>" # Primary key fingerprint: 27B8 8847 EEE0 2501 18F3 EAB9 2ED9 D774 FE70 2DB5 * remotes/huth-gitlab/tags/pull-request-2018-08-31: tests: add a qmp success-response test tests: add qmp/qom-set-without-value test tests: add qmp/object-add-without-props test tests: add qmp_assert_error_class() tests/libqos: Utilize newer glib spawn check net: Remove the deprecated -tftp, -bootp, -redir and -smb options Remove the deprecated options -startdate, -localtime and -rtc-td-hack Remove the deprecated -nodefconfig option Remove the deprecated -balloon option Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'tests/qmp-test.c')
-rw-r--r--tests/qmp-test.c87
1 files changed, 37 insertions, 50 deletions
diff --git a/tests/qmp-test.c b/tests/qmp-test.c
index 4ae2245484..2b923f02db 100644
--- a/tests/qmp-test.c
+++ b/tests/qmp-test.c
@@ -21,15 +21,6 @@
const char common_args[] = "-nodefaults -machine none";
-static const char *get_error_class(QDict *resp)
-{
- QDict *error = qdict_get_qdict(resp, "error");
- const char *desc = qdict_get_try_str(error, "desc");
-
- g_assert(desc);
- return error ? qdict_get_try_str(error, "class") : NULL;
-}
-
static void test_version(QObject *version)
{
Visitor *v;
@@ -42,15 +33,12 @@ static void test_version(QObject *version)
visit_free(v);
}
-static bool recovered(QTestState *qts)
+static void assert_recovered(QTestState *qts)
{
QDict *resp;
- bool ret;
resp = qtest_qmp(qts, "{ 'execute': 'no-such-cmd' }");
- ret = !strcmp(get_error_class(resp), "CommandNotFound");
- qobject_unref(resp);
- return ret;
+ qmp_assert_error_class(resp, "CommandNotFound");
}
static void test_malformed(QTestState *qts)
@@ -60,73 +48,61 @@ static void test_malformed(QTestState *qts)
/* syntax error */
qtest_qmp_send_raw(qts, "{]\n");
resp = qtest_qmp_receive(qts);
- g_assert_cmpstr(get_error_class(resp), ==, "GenericError");
- qobject_unref(resp);
- g_assert(recovered(qts));
+ qmp_assert_error_class(resp, "GenericError");
+ assert_recovered(qts);
/* lexical error: impossible byte outside string */
qtest_qmp_send_raw(qts, "{\xFF");
resp = qtest_qmp_receive(qts);
- g_assert_cmpstr(get_error_class(resp), ==, "GenericError");
- qobject_unref(resp);
- g_assert(recovered(qts));
+ qmp_assert_error_class(resp, "GenericError");
+ assert_recovered(qts);
/* lexical error: funny control character outside string */
qtest_qmp_send_raw(qts, "{\x01");
resp = qtest_qmp_receive(qts);
- g_assert_cmpstr(get_error_class(resp), ==, "GenericError");
- qobject_unref(resp);
- g_assert(recovered(qts));
+ qmp_assert_error_class(resp, "GenericError");
+ assert_recovered(qts);
/* lexical error: impossible byte in string */
qtest_qmp_send_raw(qts, "{'bad \xFF");
resp = qtest_qmp_receive(qts);
- g_assert_cmpstr(get_error_class(resp), ==, "GenericError");
- qobject_unref(resp);
- g_assert(recovered(qts));
+ qmp_assert_error_class(resp, "GenericError");
+ assert_recovered(qts);
/* lexical error: control character in string */
qtest_qmp_send_raw(qts, "{'execute': 'nonexistent', 'id':'\n");
resp = qtest_qmp_receive(qts);
- g_assert_cmpstr(get_error_class(resp), ==, "GenericError");
- qobject_unref(resp);
- g_assert(recovered(qts));
+ qmp_assert_error_class(resp, "GenericError");
+ assert_recovered(qts);
/* lexical error: interpolation */
qtest_qmp_send_raw(qts, "%%p\n");
/* two errors, one for "%", one for "p" */
resp = qtest_qmp_receive(qts);
- g_assert_cmpstr(get_error_class(resp), ==, "GenericError");
- qobject_unref(resp);
+ qmp_assert_error_class(resp, "GenericError");
resp = qtest_qmp_receive(qts);
- g_assert_cmpstr(get_error_class(resp), ==, "GenericError");
- qobject_unref(resp);
- g_assert(recovered(qts));
+ qmp_assert_error_class(resp, "GenericError");
+ assert_recovered(qts);
/* Not even a dictionary */
resp = qtest_qmp(qts, "null");
- g_assert_cmpstr(get_error_class(resp), ==, "GenericError");
- qobject_unref(resp);
+ qmp_assert_error_class(resp, "GenericError");
/* No "execute" key */
resp = qtest_qmp(qts, "{}");
- g_assert_cmpstr(get_error_class(resp), ==, "GenericError");
- qobject_unref(resp);
+ qmp_assert_error_class(resp, "GenericError");
/* "execute" isn't a string */
resp = qtest_qmp(qts, "{ 'execute': true }");
- g_assert_cmpstr(get_error_class(resp), ==, "GenericError");
- qobject_unref(resp);
+ qmp_assert_error_class(resp, "GenericError");
/* "arguments" isn't a dictionary */
resp = qtest_qmp(qts, "{ 'execute': 'no-such-cmd', 'arguments': [] }");
- g_assert_cmpstr(get_error_class(resp), ==, "GenericError");
- qobject_unref(resp);
+ qmp_assert_error_class(resp, "GenericError");
/* extra key */
resp = qtest_qmp(qts, "{ 'execute': 'no-such-cmd', 'extra': true }");
- g_assert_cmpstr(get_error_class(resp), ==, "GenericError");
- qobject_unref(resp);
+ qmp_assert_error_class(resp, "GenericError");
}
static void test_qmp_protocol(void)
@@ -148,8 +124,7 @@ static void test_qmp_protocol(void)
/* Test valid command before handshake */
resp = qtest_qmp(qts, "{ 'execute': 'query-version' }");
- g_assert_cmpstr(get_error_class(resp), ==, "CommandNotFound");
- qobject_unref(resp);
+ qmp_assert_error_class(resp, "CommandNotFound");
/* Test malformed commands before handshake */
test_malformed(qts);
@@ -162,8 +137,7 @@ static void test_qmp_protocol(void)
/* Test repeated handshake */
resp = qtest_qmp(qts, "{ 'execute': 'qmp_capabilities' }");
- g_assert_cmpstr(get_error_class(resp), ==, "CommandNotFound");
- qobject_unref(resp);
+ qmp_assert_error_class(resp, "CommandNotFound");
/* Test valid command */
resp = qtest_qmp(qts, "{ 'execute': 'query-version' }");
@@ -182,9 +156,8 @@ static void test_qmp_protocol(void)
/* Test command failure with 'id' */
resp = qtest_qmp(qts, "{ 'execute': 'human-monitor-command', 'id': 2 }");
- g_assert_cmpstr(get_error_class(resp), ==, "GenericError");
g_assert_cmpint(qdict_get_int(resp, "id"), ==, 2);
- qobject_unref(resp);
+ qmp_assert_error_class(resp, "GenericError");
qtest_quit(qts);
}
@@ -348,6 +321,19 @@ static void test_qmp_preconfig(void)
qtest_quit(qs);
}
+static void test_qom_set_without_value(void)
+{
+ QTestState *qts;
+ QDict *resp;
+
+ qts = qtest_init(common_args);
+ resp = qtest_qmp(qts, "{'execute': 'qom-set', 'arguments':"
+ " { 'path': '/machine', 'property': 'rtc-time' } }");
+ g_assert_nonnull(resp);
+ qmp_assert_error_class(resp, "GenericError");
+ qtest_quit(qts);
+}
+
int main(int argc, char *argv[])
{
g_test_init(&argc, &argv, NULL);
@@ -355,6 +341,7 @@ int main(int argc, char *argv[])
qtest_add_func("qmp/protocol", test_qmp_protocol);
qtest_add_func("qmp/oob", test_qmp_oob);
qtest_add_func("qmp/preconfig", test_qmp_preconfig);
+ qtest_add_func("qmp/qom-set-without-value", test_qom_set_without_value);
return g_test_run();
}