Introduce helpers to query migration states and use it.
Signed-off-by: Peter Xu <peterx@redhat.com>
---
tests/migration-test.c | 64 ++++++++++++++++++++++++++++--------------
1 file changed, 43 insertions(+), 21 deletions(-)
diff --git a/tests/migration-test.c b/tests/migration-test.c
index af82a04789..1d85ccbef1 100644
--- a/tests/migration-test.c
+++ b/tests/migration-test.c
@@ -168,6 +168,37 @@ static QDict *wait_command(QTestState *who, const char *command)
return response;
}
+/*
+ * Note: caller is responsible to free the returned object via
+ * qobject_unref() after use
+ */
+static QDict *migrate_query(QTestState *who)
+{
+ QDict *rsp, *rsp_return;
+
+ rsp = wait_command(who, "{ 'execute': 'query-migrate' }");
+ rsp_return = qdict_get_qdict(rsp, "return");
+ g_assert(rsp_return);
+ qobject_ref(rsp_return);
+ qobject_unref(rsp);
+
+ return rsp_return;
+}
+
+/*
+ * Note: caller is responsible to free the returned object via
+ * g_free() after use
+ */
+static gchar *migrate_query_status(QTestState *who)
+{
+ QDict *rsp_return = migrate_query(who);
+ gchar *status = g_strdup(qdict_get_str(rsp_return, "status"));
+
+ g_assert(status);
+ qobject_unref(rsp_return);
+
+ return status;
+}
/*
* It's tricky to use qemu's migration event capability with qtest,
@@ -176,11 +207,10 @@ static QDict *wait_command(QTestState *who, const char *command)
static uint64_t get_migration_pass(QTestState *who)
{
- QDict *rsp, *rsp_return, *rsp_ram;
+ QDict *rsp_return, *rsp_ram;
uint64_t result;
- rsp = wait_command(who, "{ 'execute': 'query-migrate' }");
- rsp_return = qdict_get_qdict(rsp, "return");
+ rsp_return = migrate_query(who);
if (!qdict_haskey(rsp_return, "ram")) {
/* Still in setup */
result = 0;
@@ -188,33 +218,29 @@ static uint64_t get_migration_pass(QTestState *who)
rsp_ram = qdict_get_qdict(rsp_return, "ram");
result = qdict_get_try_int(rsp_ram, "dirty-sync-count", 0);
}
- qobject_unref(rsp);
+ qobject_unref(rsp_return);
return result;
}
static void read_blocktime(QTestState *who)
{
- QDict *rsp, *rsp_return;
+ QDict *rsp_return;
- rsp = wait_command(who, "{ 'execute': 'query-migrate' }");
- rsp_return = qdict_get_qdict(rsp, "return");
+ rsp_return = migrate_query(who);
g_assert(qdict_haskey(rsp_return, "postcopy-blocktime"));
- qobject_unref(rsp);
+ qobject_unref(rsp_return);
}
static void wait_for_migration_complete(QTestState *who)
{
while (true) {
- QDict *rsp, *rsp_return;
bool completed;
- const char *status;
+ char *status;
- rsp = wait_command(who, "{ 'execute': 'query-migrate' }");
- rsp_return = qdict_get_qdict(rsp, "return");
- status = qdict_get_str(rsp_return, "status");
+ status = migrate_query_status(who);
completed = strcmp(status, "completed") == 0;
g_assert_cmpstr(status, !=, "failed");
- qobject_unref(rsp);
+ g_free(status);
if (completed) {
return;
}
@@ -569,20 +595,16 @@ static void test_baddest(void)
{
QTestState *from, *to;
QDict *rsp, *rsp_return;
- const char *status;
+ char *status;
bool failed;
test_migrate_start(&from, &to, "tcp:0:0", true);
migrate(from, "tcp:0:0", NULL);
do {
- rsp = wait_command(from, "{ 'execute': 'query-migrate' }");
- rsp_return = qdict_get_qdict(rsp, "return");
-
- status = qdict_get_str(rsp_return, "status");
-
+ status = migrate_query_status(from);
g_assert(!strcmp(status, "setup") || !(strcmp(status, "failed")));
failed = !strcmp(status, "failed");
- qobject_unref(rsp);
+ g_free(status);
} while (!failed);
/* Is the machine currently running? */
--
2.17.1
* Peter Xu (peterx@redhat.com) wrote:
> Introduce helpers to query migration states and use it.
>
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
> tests/migration-test.c | 64 ++++++++++++++++++++++++++++--------------
> 1 file changed, 43 insertions(+), 21 deletions(-)
>
> diff --git a/tests/migration-test.c b/tests/migration-test.c
> index af82a04789..1d85ccbef1 100644
> --- a/tests/migration-test.c
> +++ b/tests/migration-test.c
> @@ -168,6 +168,37 @@ static QDict *wait_command(QTestState *who, const char *command)
> return response;
> }
>
> +/*
> + * Note: caller is responsible to free the returned object via
> + * qobject_unref() after use
> + */
> +static QDict *migrate_query(QTestState *who)
> +{
> + QDict *rsp, *rsp_return;
> +
> + rsp = wait_command(who, "{ 'execute': 'query-migrate' }");
having a 'migrate_query' function that issues 'query-migrate' is a bit
odd; I think I'd have called it query_migrate just to match; however
that's just a nit-pick:
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> + rsp_return = qdict_get_qdict(rsp, "return");
> + g_assert(rsp_return);
> + qobject_ref(rsp_return);
> + qobject_unref(rsp);
> +
> + return rsp_return;
> +}
> +
> +/*
> + * Note: caller is responsible to free the returned object via
> + * g_free() after use
> + */
> +static gchar *migrate_query_status(QTestState *who)
> +{
> + QDict *rsp_return = migrate_query(who);
> + gchar *status = g_strdup(qdict_get_str(rsp_return, "status"));
> +
> + g_assert(status);
> + qobject_unref(rsp_return);
> +
> + return status;
> +}
>
> /*
> * It's tricky to use qemu's migration event capability with qtest,
> @@ -176,11 +207,10 @@ static QDict *wait_command(QTestState *who, const char *command)
>
> static uint64_t get_migration_pass(QTestState *who)
> {
> - QDict *rsp, *rsp_return, *rsp_ram;
> + QDict *rsp_return, *rsp_ram;
> uint64_t result;
>
> - rsp = wait_command(who, "{ 'execute': 'query-migrate' }");
> - rsp_return = qdict_get_qdict(rsp, "return");
> + rsp_return = migrate_query(who);
> if (!qdict_haskey(rsp_return, "ram")) {
> /* Still in setup */
> result = 0;
> @@ -188,33 +218,29 @@ static uint64_t get_migration_pass(QTestState *who)
> rsp_ram = qdict_get_qdict(rsp_return, "ram");
> result = qdict_get_try_int(rsp_ram, "dirty-sync-count", 0);
> }
> - qobject_unref(rsp);
> + qobject_unref(rsp_return);
> return result;
> }
>
> static void read_blocktime(QTestState *who)
> {
> - QDict *rsp, *rsp_return;
> + QDict *rsp_return;
>
> - rsp = wait_command(who, "{ 'execute': 'query-migrate' }");
> - rsp_return = qdict_get_qdict(rsp, "return");
> + rsp_return = migrate_query(who);
> g_assert(qdict_haskey(rsp_return, "postcopy-blocktime"));
> - qobject_unref(rsp);
> + qobject_unref(rsp_return);
> }
>
> static void wait_for_migration_complete(QTestState *who)
> {
> while (true) {
> - QDict *rsp, *rsp_return;
> bool completed;
> - const char *status;
> + char *status;
>
> - rsp = wait_command(who, "{ 'execute': 'query-migrate' }");
> - rsp_return = qdict_get_qdict(rsp, "return");
> - status = qdict_get_str(rsp_return, "status");
> + status = migrate_query_status(who);
> completed = strcmp(status, "completed") == 0;
> g_assert_cmpstr(status, !=, "failed");
> - qobject_unref(rsp);
> + g_free(status);
> if (completed) {
> return;
> }
> @@ -569,20 +595,16 @@ static void test_baddest(void)
> {
> QTestState *from, *to;
> QDict *rsp, *rsp_return;
> - const char *status;
> + char *status;
> bool failed;
>
> test_migrate_start(&from, &to, "tcp:0:0", true);
> migrate(from, "tcp:0:0", NULL);
> do {
> - rsp = wait_command(from, "{ 'execute': 'query-migrate' }");
> - rsp_return = qdict_get_qdict(rsp, "return");
> -
> - status = qdict_get_str(rsp_return, "status");
> -
> + status = migrate_query_status(from);
> g_assert(!strcmp(status, "setup") || !(strcmp(status, "failed")));
> failed = !strcmp(status, "failed");
> - qobject_unref(rsp);
> + g_free(status);
> } while (!failed);
>
> /* Is the machine currently running? */
> --
> 2.17.1
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
"Dr. David Alan Gilbert" <dgilbert@redhat.com> wrote:
> * Peter Xu (peterx@redhat.com) wrote:
>> Introduce helpers to query migration states and use it.
>>
>> Signed-off-by: Peter Xu <peterx@redhat.com>
>> ---
>> tests/migration-test.c | 64 ++++++++++++++++++++++++++++--------------
>> 1 file changed, 43 insertions(+), 21 deletions(-)
>>
>> diff --git a/tests/migration-test.c b/tests/migration-test.c
>> index af82a04789..1d85ccbef1 100644
>> --- a/tests/migration-test.c
>> +++ b/tests/migration-test.c
>> @@ -168,6 +168,37 @@ static QDict *wait_command(QTestState *who, const char *command)
>> return response;
>> }
>>
>> +/*
>> + * Note: caller is responsible to free the returned object via
>> + * qobject_unref() after use
>> + */
>> +static QDict *migrate_query(QTestState *who)
>> +{
>> + QDict *rsp, *rsp_return;
>> +
>> + rsp = wait_command(who, "{ 'execute': 'query-migrate' }");
>
> having a 'migrate_query' function that issues 'query-migrate' is a bit
> odd; I think I'd have called it query_migrate just to match; however
> that's just a nit-pick:
I guess he is trying to get almost everything to be migrate_<foo>.
Not that the whole file is consistent at all, but well.
>
>
> Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
>
>> + rsp_return = qdict_get_qdict(rsp, "return");
>> + g_assert(rsp_return);
>> + qobject_ref(rsp_return);
>> + qobject_unref(rsp);
>> +
>> + return rsp_return;
>> +}
>> +
>> +/*
>> + * Note: caller is responsible to free the returned object via
>> + * g_free() after use
>> + */
>> +static gchar *migrate_query_status(QTestState *who)
>> +{
>> + QDict *rsp_return = migrate_query(who);
>> + gchar *status = g_strdup(qdict_get_str(rsp_return, "status"));
>> +
>> + g_assert(status);
>> + qobject_unref(rsp_return);
>> +
>> + return status;
>> +}
>>
>> /*
>> * It's tricky to use qemu's migration event capability with qtest,
>> @@ -176,11 +207,10 @@ static QDict *wait_command(QTestState *who, const char *command)
>>
>> static uint64_t get_migration_pass(QTestState *who)
>> {
>> - QDict *rsp, *rsp_return, *rsp_ram;
>> + QDict *rsp_return, *rsp_ram;
>> uint64_t result;
>>
>> - rsp = wait_command(who, "{ 'execute': 'query-migrate' }");
>> - rsp_return = qdict_get_qdict(rsp, "return");
>> + rsp_return = migrate_query(who);
>> if (!qdict_haskey(rsp_return, "ram")) {
>> /* Still in setup */
>> result = 0;
>> @@ -188,33 +218,29 @@ static uint64_t get_migration_pass(QTestState *who)
>> rsp_ram = qdict_get_qdict(rsp_return, "ram");
>> result = qdict_get_try_int(rsp_ram, "dirty-sync-count", 0);
>> }
>> - qobject_unref(rsp);
>> + qobject_unref(rsp_return);
>> return result;
>> }
>>
>> static void read_blocktime(QTestState *who)
>> {
>> - QDict *rsp, *rsp_return;
>> + QDict *rsp_return;
>>
>> - rsp = wait_command(who, "{ 'execute': 'query-migrate' }");
>> - rsp_return = qdict_get_qdict(rsp, "return");
>> + rsp_return = migrate_query(who);
>> g_assert(qdict_haskey(rsp_return, "postcopy-blocktime"));
>> - qobject_unref(rsp);
>> + qobject_unref(rsp_return);
>> }
>>
>> static void wait_for_migration_complete(QTestState *who)
>> {
>> while (true) {
>> - QDict *rsp, *rsp_return;
>> bool completed;
>> - const char *status;
>> + char *status;
>>
>> - rsp = wait_command(who, "{ 'execute': 'query-migrate' }");
>> - rsp_return = qdict_get_qdict(rsp, "return");
>> - status = qdict_get_str(rsp_return, "status");
>> + status = migrate_query_status(who);
>> completed = strcmp(status, "completed") == 0;
>> g_assert_cmpstr(status, !=, "failed");
>> - qobject_unref(rsp);
>> + g_free(status);
>> if (completed) {
>> return;
>> }
>> @@ -569,20 +595,16 @@ static void test_baddest(void)
>> {
>> QTestState *from, *to;
>> QDict *rsp, *rsp_return;
>> - const char *status;
>> + char *status;
>> bool failed;
>>
>> test_migrate_start(&from, &to, "tcp:0:0", true);
>> migrate(from, "tcp:0:0", NULL);
>> do {
>> - rsp = wait_command(from, "{ 'execute': 'query-migrate' }");
>> - rsp_return = qdict_get_qdict(rsp, "return");
>> -
>> - status = qdict_get_str(rsp_return, "status");
>> -
>> + status = migrate_query_status(from);
>> g_assert(!strcmp(status, "setup") || !(strcmp(status, "failed")));
>> failed = !strcmp(status, "failed");
>> - qobject_unref(rsp);
>> + g_free(status);
>> } while (!failed);
>>
>> /* Is the machine currently running? */
>> --
>> 2.17.1
>>
> --
> Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
On Thu, Jul 05, 2018 at 11:17:52AM +0800, Peter Xu wrote:
> Introduce helpers to query migration states and use it.
>
> Signed-off-by: Peter Xu <peterx@redhat.com>
Looks good to me.
Reviewed-by: Balamuruhan S <bala24@linux.vnet.ibm.com>
> ---
> tests/migration-test.c | 64 ++++++++++++++++++++++++++++--------------
> 1 file changed, 43 insertions(+), 21 deletions(-)
>
> diff --git a/tests/migration-test.c b/tests/migration-test.c
> index af82a04789..1d85ccbef1 100644
> --- a/tests/migration-test.c
> +++ b/tests/migration-test.c
> @@ -168,6 +168,37 @@ static QDict *wait_command(QTestState *who, const char *command)
> return response;
> }
>
> +/*
> + * Note: caller is responsible to free the returned object via
> + * qobject_unref() after use
> + */
> +static QDict *migrate_query(QTestState *who)
> +{
> + QDict *rsp, *rsp_return;
> +
> + rsp = wait_command(who, "{ 'execute': 'query-migrate' }");
> + rsp_return = qdict_get_qdict(rsp, "return");
> + g_assert(rsp_return);
> + qobject_ref(rsp_return);
> + qobject_unref(rsp);
> +
> + return rsp_return;
> +}
> +
> +/*
> + * Note: caller is responsible to free the returned object via
> + * g_free() after use
> + */
> +static gchar *migrate_query_status(QTestState *who)
> +{
> + QDict *rsp_return = migrate_query(who);
> + gchar *status = g_strdup(qdict_get_str(rsp_return, "status"));
> +
> + g_assert(status);
> + qobject_unref(rsp_return);
> +
> + return status;
> +}
>
> /*
> * It's tricky to use qemu's migration event capability with qtest,
> @@ -176,11 +207,10 @@ static QDict *wait_command(QTestState *who, const char *command)
>
> static uint64_t get_migration_pass(QTestState *who)
> {
> - QDict *rsp, *rsp_return, *rsp_ram;
> + QDict *rsp_return, *rsp_ram;
> uint64_t result;
>
> - rsp = wait_command(who, "{ 'execute': 'query-migrate' }");
> - rsp_return = qdict_get_qdict(rsp, "return");
> + rsp_return = migrate_query(who);
> if (!qdict_haskey(rsp_return, "ram")) {
> /* Still in setup */
> result = 0;
> @@ -188,33 +218,29 @@ static uint64_t get_migration_pass(QTestState *who)
> rsp_ram = qdict_get_qdict(rsp_return, "ram");
> result = qdict_get_try_int(rsp_ram, "dirty-sync-count", 0);
> }
> - qobject_unref(rsp);
> + qobject_unref(rsp_return);
> return result;
> }
>
> static void read_blocktime(QTestState *who)
> {
> - QDict *rsp, *rsp_return;
> + QDict *rsp_return;
>
> - rsp = wait_command(who, "{ 'execute': 'query-migrate' }");
> - rsp_return = qdict_get_qdict(rsp, "return");
> + rsp_return = migrate_query(who);
> g_assert(qdict_haskey(rsp_return, "postcopy-blocktime"));
> - qobject_unref(rsp);
> + qobject_unref(rsp_return);
> }
>
> static void wait_for_migration_complete(QTestState *who)
> {
> while (true) {
> - QDict *rsp, *rsp_return;
> bool completed;
> - const char *status;
> + char *status;
>
> - rsp = wait_command(who, "{ 'execute': 'query-migrate' }");
> - rsp_return = qdict_get_qdict(rsp, "return");
> - status = qdict_get_str(rsp_return, "status");
> + status = migrate_query_status(who);
> completed = strcmp(status, "completed") == 0;
> g_assert_cmpstr(status, !=, "failed");
> - qobject_unref(rsp);
> + g_free(status);
> if (completed) {
> return;
> }
> @@ -569,20 +595,16 @@ static void test_baddest(void)
> {
> QTestState *from, *to;
> QDict *rsp, *rsp_return;
> - const char *status;
> + char *status;
> bool failed;
>
> test_migrate_start(&from, &to, "tcp:0:0", true);
> migrate(from, "tcp:0:0", NULL);
> do {
> - rsp = wait_command(from, "{ 'execute': 'query-migrate' }");
> - rsp_return = qdict_get_qdict(rsp, "return");
> -
> - status = qdict_get_str(rsp_return, "status");
> -
> + status = migrate_query_status(from);
> g_assert(!strcmp(status, "setup") || !(strcmp(status, "failed")));
> failed = !strcmp(status, "failed");
> - qobject_unref(rsp);
> + g_free(status);
> } while (!failed);
>
> /* Is the machine currently running? */
> --
> 2.17.1
>
>
Peter Xu <peterx@redhat.com> wrote: > Introduce helpers to query migration states and use it. > > Signed-off-by: Peter Xu <peterx@redhat.com> Reviewed-by: Juan Quintela <quintela@redhat.com>
© 2016 - 2025 Red Hat, Inc.