mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-01 14:53:54 -06:00
tests: New helper qtest_qmp_receive_success()
Commit b21373d071
copied wait_command() from tests/migration-test.c
to tests/tpm-util.c. Replace both copies by new libqtest helper
qtest_qmp_receive_success(). Also use it to simplify
qtest_qmp_device_del().
Bonus: gets rid of a non-literal format string. A step towards
compile-time format string checking without triggering
-Wformat-nonliteral.
Cc: Thomas Huth <thuth@redhat.com>
Cc: Juan Quintela <quintela@redhat.com>
Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
Cc: Stefan Berger <stefanb@linux.vnet.ibm.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180806065344.7103-17-armbru@redhat.com>
This commit is contained in:
parent
e145416524
commit
3cd46d42fe
4 changed files with 80 additions and 67 deletions
|
@ -22,8 +22,6 @@
|
|||
#define TIS_REG(LOCTY, REG) \
|
||||
(TPM_TIS_ADDR_BASE + ((LOCTY) << 12) + REG)
|
||||
|
||||
static bool got_stop;
|
||||
|
||||
void tpm_util_crb_transfer(QTestState *s,
|
||||
const unsigned char *req, size_t req_size,
|
||||
unsigned char *rsp, size_t rsp_size)
|
||||
|
@ -247,41 +245,19 @@ void tpm_util_migrate(QTestState *who, const char *uri)
|
|||
qobject_unref(rsp);
|
||||
}
|
||||
|
||||
/*
|
||||
* Events can get in the way of responses we are actually waiting for.
|
||||
*/
|
||||
static QDict *tpm_util_wait_command(QTestState *who, const char *command)
|
||||
{
|
||||
const char *event_string;
|
||||
QDict *response;
|
||||
|
||||
response = qtest_qmp(who, command);
|
||||
|
||||
while (qdict_haskey(response, "event")) {
|
||||
/* OK, it was an event */
|
||||
event_string = qdict_get_str(response, "event");
|
||||
if (!strcmp(event_string, "STOP")) {
|
||||
got_stop = true;
|
||||
}
|
||||
qobject_unref(response);
|
||||
response = qtest_qmp_receive(who);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
void tpm_util_wait_for_migration_complete(QTestState *who)
|
||||
{
|
||||
while (true) {
|
||||
QDict *rsp, *rsp_return;
|
||||
QDict *rsp_return;
|
||||
bool completed;
|
||||
const char *status;
|
||||
|
||||
rsp = tpm_util_wait_command(who, "{ 'execute': 'query-migrate' }");
|
||||
rsp_return = qdict_get_qdict(rsp, "return");
|
||||
qtest_qmp_send(who, "{ 'execute': 'query-migrate' }");
|
||||
rsp_return = qtest_qmp_receive_success(who, NULL, NULL);
|
||||
status = qdict_get_str(rsp_return, "status");
|
||||
completed = strcmp(status, "completed") == 0;
|
||||
g_assert_cmpstr(status, !=, "failed");
|
||||
qobject_unref(rsp);
|
||||
qobject_unref(rsp_return);
|
||||
if (completed) {
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue