libqtest: Rename qmp_assert_error_class() to qmp_expect_error_and_unref()

qmp_assert_error_class() does more than just assert: it also unrefs
the @rsp argument.  Rename to qmp_expect_error_and_unref() to reduce
confusion.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200902115733.1229537-1-armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
This commit is contained in:
Markus Armbruster 2020-09-02 13:57:33 +02:00 committed by Thomas Huth
parent 978382b453
commit 3bc1b8ee8c
6 changed files with 29 additions and 29 deletions

View File

@ -103,7 +103,7 @@ static void test_after_failed_device_add(void)
" 'drive': 'drive0'" " 'drive': 'drive0'"
"}}", driver); "}}", driver);
g_assert(response); g_assert(response);
qmp_assert_error_class(response, "GenericError"); qmp_expect_error_and_unref(response, "GenericError");
/* Delete the drive */ /* Delete the drive */
drive_del(qts); drive_del(qts);

View File

@ -704,13 +704,13 @@ void qtest_qmp_device_del(QTestState *qts, const char *id);
bool qmp_rsp_is_err(QDict *rsp); bool qmp_rsp_is_err(QDict *rsp);
/** /**
* qmp_assert_error_class: * qmp_expect_error_and_unref:
* @rsp: QMP response to check for error * @rsp: QMP response to check for error
* @class: an error class * @class: an error class
* *
* Assert the response has the given error class and discard @rsp. * Assert the response has the given error class and discard @rsp.
*/ */
void qmp_assert_error_class(QDict *rsp, const char *class); void qmp_expect_error_and_unref(QDict *rsp, const char *class);
/** /**
* qtest_probe_child: * qtest_probe_child:

View File

@ -1359,7 +1359,7 @@ bool qmp_rsp_is_err(QDict *rsp)
return !!error; return !!error;
} }
void qmp_assert_error_class(QDict *rsp, const char *class) void qmp_expect_error_and_unref(QDict *rsp, const char *class)
{ {
QDict *error = qdict_get_qdict(rsp, "error"); QDict *error = qdict_get_qdict(rsp, "error");

View File

@ -210,19 +210,19 @@ static void test_object_add_failure_modes(void)
resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':" resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':"
" {'qom-type': 'memory-backend-ram', 'id': 'ram1' } }"); " {'qom-type': 'memory-backend-ram', 'id': 'ram1' } }");
g_assert_nonnull(resp); g_assert_nonnull(resp);
qmp_assert_error_class(resp, "GenericError"); qmp_expect_error_and_unref(resp, "GenericError");
/* attempt to create an object without qom-type */ /* attempt to create an object without qom-type */
resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':" resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':"
" {'id': 'ram1' } }"); " {'id': 'ram1' } }");
g_assert_nonnull(resp); g_assert_nonnull(resp);
qmp_assert_error_class(resp, "GenericError"); qmp_expect_error_and_unref(resp, "GenericError");
/* attempt to delete an object that does not exist */ /* attempt to delete an object that does not exist */
resp = qtest_qmp(qts, "{'execute': 'object-del', 'arguments':" resp = qtest_qmp(qts, "{'execute': 'object-del', 'arguments':"
" {'id': 'ram1' } }"); " {'id': 'ram1' } }");
g_assert_nonnull(resp); g_assert_nonnull(resp);
qmp_assert_error_class(resp, "GenericError"); qmp_expect_error_and_unref(resp, "GenericError");
/* attempt to create 2 objects with duplicate id */ /* attempt to create 2 objects with duplicate id */
resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':" resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':"
@ -236,7 +236,7 @@ static void test_object_add_failure_modes(void)
" {'qom-type': 'memory-backend-ram', 'id': 'ram1'," " {'qom-type': 'memory-backend-ram', 'id': 'ram1',"
" 'props': {'size': 1048576 } } }"); " 'props': {'size': 1048576 } } }");
g_assert_nonnull(resp); g_assert_nonnull(resp);
qmp_assert_error_class(resp, "GenericError"); qmp_expect_error_and_unref(resp, "GenericError");
/* delete ram1 object */ /* delete ram1 object */
resp = qtest_qmp(qts, "{'execute': 'object-del', 'arguments':" resp = qtest_qmp(qts, "{'execute': 'object-del', 'arguments':"
@ -251,7 +251,7 @@ static void test_object_add_failure_modes(void)
" 'props': {'size': '1048576' } } }"); " 'props': {'size': '1048576' } } }");
g_assert_nonnull(resp); g_assert_nonnull(resp);
/* now do it right */ /* now do it right */
qmp_assert_error_class(resp, "GenericError"); qmp_expect_error_and_unref(resp, "GenericError");
resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':" resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':"
" {'qom-type': 'memory-backend-ram', 'id': 'ram1'," " {'qom-type': 'memory-backend-ram', 'id': 'ram1',"
@ -272,7 +272,7 @@ static void test_object_add_failure_modes(void)
" {'qom-type': 'memory-backend-ram'," " {'qom-type': 'memory-backend-ram',"
" 'props': {'size': 1048576 } } }"); " 'props': {'size': 1048576 } } }");
g_assert_nonnull(resp); g_assert_nonnull(resp);
qmp_assert_error_class(resp, "GenericError"); qmp_expect_error_and_unref(resp, "GenericError");
/* now do it right */ /* now do it right */
resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':" resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':"
@ -294,7 +294,7 @@ static void test_object_add_failure_modes(void)
" {'qom-type': 'memory-backend-ram', 'id': 'ram1'," " {'qom-type': 'memory-backend-ram', 'id': 'ram1',"
" 'props': {'sized': 1048576 } } }"); " 'props': {'sized': 1048576 } } }");
g_assert_nonnull(resp); g_assert_nonnull(resp);
qmp_assert_error_class(resp, "GenericError"); qmp_expect_error_and_unref(resp, "GenericError");
/* now do it right */ /* now do it right */
resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':" resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':"
@ -321,7 +321,7 @@ static void test_object_add_failure_modes(void)
resp = qtest_qmp(qts, "{'execute': 'object-del', 'arguments':" resp = qtest_qmp(qts, "{'execute': 'object-del', 'arguments':"
" {'id': 'ram1' } }"); " {'id': 'ram1' } }");
g_assert_nonnull(resp); g_assert_nonnull(resp);
qmp_assert_error_class(resp, "GenericError"); qmp_expect_error_and_unref(resp, "GenericError");
qtest_quit(qts); qtest_quit(qts);
} }

View File

@ -38,7 +38,7 @@ static void assert_recovered(QTestState *qts)
QDict *resp; QDict *resp;
resp = qtest_qmp(qts, "{ 'execute': 'no-such-cmd' }"); resp = qtest_qmp(qts, "{ 'execute': 'no-such-cmd' }");
qmp_assert_error_class(resp, "CommandNotFound"); qmp_expect_error_and_unref(resp, "CommandNotFound");
} }
static void test_malformed(QTestState *qts) static void test_malformed(QTestState *qts)
@ -48,58 +48,58 @@ static void test_malformed(QTestState *qts)
/* syntax error */ /* syntax error */
qtest_qmp_send_raw(qts, "{]\n"); qtest_qmp_send_raw(qts, "{]\n");
resp = qtest_qmp_receive(qts); resp = qtest_qmp_receive(qts);
qmp_assert_error_class(resp, "GenericError"); qmp_expect_error_and_unref(resp, "GenericError");
assert_recovered(qts); assert_recovered(qts);
/* lexical error: impossible byte outside string */ /* lexical error: impossible byte outside string */
qtest_qmp_send_raw(qts, "{\xFF"); qtest_qmp_send_raw(qts, "{\xFF");
resp = qtest_qmp_receive(qts); resp = qtest_qmp_receive(qts);
qmp_assert_error_class(resp, "GenericError"); qmp_expect_error_and_unref(resp, "GenericError");
assert_recovered(qts); assert_recovered(qts);
/* lexical error: funny control character outside string */ /* lexical error: funny control character outside string */
qtest_qmp_send_raw(qts, "{\x01"); qtest_qmp_send_raw(qts, "{\x01");
resp = qtest_qmp_receive(qts); resp = qtest_qmp_receive(qts);
qmp_assert_error_class(resp, "GenericError"); qmp_expect_error_and_unref(resp, "GenericError");
assert_recovered(qts); assert_recovered(qts);
/* lexical error: impossible byte in string */ /* lexical error: impossible byte in string */
qtest_qmp_send_raw(qts, "{'bad \xFF"); qtest_qmp_send_raw(qts, "{'bad \xFF");
resp = qtest_qmp_receive(qts); resp = qtest_qmp_receive(qts);
qmp_assert_error_class(resp, "GenericError"); qmp_expect_error_and_unref(resp, "GenericError");
assert_recovered(qts); assert_recovered(qts);
/* lexical error: control character in string */ /* lexical error: control character in string */
qtest_qmp_send_raw(qts, "{'execute': 'nonexistent', 'id':'\n"); qtest_qmp_send_raw(qts, "{'execute': 'nonexistent', 'id':'\n");
resp = qtest_qmp_receive(qts); resp = qtest_qmp_receive(qts);
qmp_assert_error_class(resp, "GenericError"); qmp_expect_error_and_unref(resp, "GenericError");
assert_recovered(qts); assert_recovered(qts);
/* lexical error: interpolation */ /* lexical error: interpolation */
qtest_qmp_send_raw(qts, "%%p"); qtest_qmp_send_raw(qts, "%%p");
resp = qtest_qmp_receive(qts); resp = qtest_qmp_receive(qts);
qmp_assert_error_class(resp, "GenericError"); qmp_expect_error_and_unref(resp, "GenericError");
assert_recovered(qts); assert_recovered(qts);
/* Not even a dictionary */ /* Not even a dictionary */
resp = qtest_qmp(qts, "null"); resp = qtest_qmp(qts, "null");
qmp_assert_error_class(resp, "GenericError"); qmp_expect_error_and_unref(resp, "GenericError");
/* No "execute" key */ /* No "execute" key */
resp = qtest_qmp(qts, "{}"); resp = qtest_qmp(qts, "{}");
qmp_assert_error_class(resp, "GenericError"); qmp_expect_error_and_unref(resp, "GenericError");
/* "execute" isn't a string */ /* "execute" isn't a string */
resp = qtest_qmp(qts, "{ 'execute': true }"); resp = qtest_qmp(qts, "{ 'execute': true }");
qmp_assert_error_class(resp, "GenericError"); qmp_expect_error_and_unref(resp, "GenericError");
/* "arguments" isn't a dictionary */ /* "arguments" isn't a dictionary */
resp = qtest_qmp(qts, "{ 'execute': 'no-such-cmd', 'arguments': [] }"); resp = qtest_qmp(qts, "{ 'execute': 'no-such-cmd', 'arguments': [] }");
qmp_assert_error_class(resp, "GenericError"); qmp_expect_error_and_unref(resp, "GenericError");
/* extra key */ /* extra key */
resp = qtest_qmp(qts, "{ 'execute': 'no-such-cmd', 'extra': true }"); resp = qtest_qmp(qts, "{ 'execute': 'no-such-cmd', 'extra': true }");
qmp_assert_error_class(resp, "GenericError"); qmp_expect_error_and_unref(resp, "GenericError");
} }
static void test_qmp_protocol(void) static void test_qmp_protocol(void)
@ -121,7 +121,7 @@ static void test_qmp_protocol(void)
/* Test valid command before handshake */ /* Test valid command before handshake */
resp = qtest_qmp(qts, "{ 'execute': 'query-version' }"); resp = qtest_qmp(qts, "{ 'execute': 'query-version' }");
qmp_assert_error_class(resp, "CommandNotFound"); qmp_expect_error_and_unref(resp, "CommandNotFound");
/* Test malformed commands before handshake */ /* Test malformed commands before handshake */
test_malformed(qts); test_malformed(qts);
@ -134,7 +134,7 @@ static void test_qmp_protocol(void)
/* Test repeated handshake */ /* Test repeated handshake */
resp = qtest_qmp(qts, "{ 'execute': 'qmp_capabilities' }"); resp = qtest_qmp(qts, "{ 'execute': 'qmp_capabilities' }");
qmp_assert_error_class(resp, "CommandNotFound"); qmp_expect_error_and_unref(resp, "CommandNotFound");
/* Test valid command */ /* Test valid command */
resp = qtest_qmp(qts, "{ 'execute': 'query-version' }"); resp = qtest_qmp(qts, "{ 'execute': 'query-version' }");
@ -154,7 +154,7 @@ static void test_qmp_protocol(void)
/* Test command failure with 'id' */ /* Test command failure with 'id' */
resp = qtest_qmp(qts, "{ 'execute': 'human-monitor-command', 'id': 2 }"); resp = qtest_qmp(qts, "{ 'execute': 'human-monitor-command', 'id': 2 }");
g_assert_cmpint(qdict_get_int(resp, "id"), ==, 2); g_assert_cmpint(qdict_get_int(resp, "id"), ==, 2);
qmp_assert_error_class(resp, "GenericError"); qmp_expect_error_and_unref(resp, "GenericError");
qtest_quit(qts); qtest_quit(qts);
} }
@ -327,7 +327,7 @@ static void test_qmp_missing_any_arg(void)
resp = qtest_qmp(qts, "{'execute': 'qom-set', 'arguments':" resp = qtest_qmp(qts, "{'execute': 'qom-set', 'arguments':"
" { 'path': '/machine', 'property': 'rtc-time' } }"); " { 'path': '/machine', 'property': 'rtc-time' } }");
g_assert_nonnull(resp); g_assert_nonnull(resp);
qmp_assert_error_class(resp, "GenericError"); qmp_expect_error_and_unref(resp, "GenericError");
qtest_quit(qts); qtest_quit(qts);
} }

View File

@ -246,7 +246,7 @@ static void test_qga_invalid_oob(gconstpointer fix)
ret = qmp_fd(fixture->fd, "{'exec-oob': 'guest-ping'}"); ret = qmp_fd(fixture->fd, "{'exec-oob': 'guest-ping'}");
g_assert_nonnull(ret); g_assert_nonnull(ret);
qmp_assert_error_class(ret, "GenericError"); qmp_expect_error_and_unref(ret, "GenericError");
} }
static void test_qga_invalid_args(gconstpointer fix) static void test_qga_invalid_args(gconstpointer fix)