[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v2 04/10] tests: Don't abuse global_qtest
From: |
Dr. David Alan Gilbert |
Subject: |
Re: [Qemu-devel] [PATCH v2 04/10] tests: Don't abuse global_qtest |
Date: |
Fri, 27 Oct 2017 03:37:08 +0100 |
User-agent: |
Mutt/1.9.1 (2017-09-22) |
* Juan Quintela (address@hidden) wrote:
> As we have two guests running, just pass always who we want to send a
> message to. Once there, refactor return_or_event() into wait_command.
>
> Signed-off-by: Juan Quintela <address@hidden>
Hmm was there anything else anywhere that relied on global_qtest?
Hopefully not.
Reviewed-by: Dr. David Alan Gilbert <address@hidden>
> ---
> tests/migration-test.c | 55
> +++++++++++++++++++++++++-------------------------
> 1 file changed, 27 insertions(+), 28 deletions(-)
>
> diff --git a/tests/migration-test.c b/tests/migration-test.c
> index 91fb0277d6..c429a13403 100644
> --- a/tests/migration-test.c
> +++ b/tests/migration-test.c
> @@ -223,20 +223,23 @@ static void wait_for_serial(const char *side)
> /*
> * Events can get in the way of responses we are actually waiting for.
> */
> -static QDict *return_or_event(QDict *response)
> +static QDict *wait_command(QTestState *who, const char *command)
> {
> const char *event_string;
> - if (!qdict_haskey(response, "event")) {
> - return response;
> - }
> + QDict *response;
> +
> + response = qtest_qmp(who, command);
>
> - /* OK, it was an event */
> - event_string = qdict_get_str(response, "event");
> - if (!strcmp(event_string, "STOP")) {
> - got_stop = true;
> + 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;
> + }
> + QDECREF(response);
> + response = qtest_qmp_receive(who);
> }
> - QDECREF(response);
> - return return_or_event(qtest_qmp_receive(global_qtest));
> + return response;
> }
>
>
> @@ -245,12 +248,12 @@ static QDict *return_or_event(QDict *response)
> * events suddenly appearing confuse the qmp()/hmp() responses.
> */
>
> -static uint64_t get_migration_pass(void)
> +static uint64_t get_migration_pass(QTestState *who)
> {
> QDict *rsp, *rsp_return, *rsp_ram;
> uint64_t result;
>
> - rsp = return_or_event(qmp("{ 'execute': 'query-migrate' }"));
> + rsp = wait_command(who, "{ 'execute': 'query-migrate' }");
> rsp_return = qdict_get_qdict(rsp, "return");
> if (!qdict_haskey(rsp_return, "ram")) {
> /* Still in setup */
> @@ -263,7 +266,7 @@ static uint64_t get_migration_pass(void)
> return result;
> }
>
> -static void wait_for_migration_complete(void)
> +static void wait_for_migration_complete(QTestState *who)
> {
> QDict *rsp, *rsp_return;
> bool completed;
> @@ -271,7 +274,7 @@ static void wait_for_migration_complete(void)
> do {
> const char *status;
>
> - rsp = return_or_event(qmp("{ 'execute': 'query-migrate' }"));
> + rsp = wait_command(who, "{ 'execute': 'query-migrate' }");
> rsp_return = qdict_get_qdict(rsp, "return");
> status = qdict_get_str(rsp_return, "status");
> completed = strcmp(status, "completed") == 0;
> @@ -281,14 +284,14 @@ static void wait_for_migration_complete(void)
> } while (!completed);
> }
>
> -static void wait_for_migration_pass(void)
> +static void wait_for_migration_pass(QTestState *who)
> {
> - uint64_t initial_pass = get_migration_pass();
> + uint64_t initial_pass = get_migration_pass(who);
> uint64_t pass;
>
> /* Wait for the 1st sync */
> do {
> - initial_pass = get_migration_pass();
> + initial_pass = get_migration_pass(who);
> if (got_stop || initial_pass) {
> break;
> }
> @@ -297,7 +300,7 @@ static void wait_for_migration_pass(void)
>
> do {
> usleep(1000 * 100);
> - pass = get_migration_pass();
> + pass = get_migration_pass(who);
> } while (pass == initial_pass && !got_stop);
> }
>
> @@ -493,7 +496,7 @@ static void test_migrate_end(QTestState *from, QTestState
> *to)
> static void test_migrate(void)
> {
> char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
> - QTestState *global = global_qtest, *from, *to;
> + QTestState *from, *to;
> QDict *rsp;
>
> test_migrate_start(&from, &to, uri);
> @@ -513,26 +516,22 @@ static void test_migrate(void)
>
> migrate(from, uri);
>
> - global_qtest = from;
> - wait_for_migration_pass();
> + wait_for_migration_pass(from);
>
> - rsp = return_or_event(qmp("{ 'execute': 'migrate-start-postcopy' }"));
> + rsp = wait_command(from, "{ 'execute': 'migrate-start-postcopy' }");
> g_assert(qdict_haskey(rsp, "return"));
> QDECREF(rsp);
>
> if (!got_stop) {
> - qmp_eventwait("STOP");
> + qtest_qmp_eventwait(from, "STOP");
> }
>
> - global_qtest = to;
> - qmp_eventwait("RESUME");
> + qtest_qmp_eventwait(to, "RESUME");
>
> wait_for_serial("dest_serial");
> - global_qtest = from;
> - wait_for_migration_complete();
> + wait_for_migration_complete(from);
>
> g_free(uri);
> - global_qtest = global;
>
> test_migrate_end(from, to);
> }
> --
> 2.13.6
>
--
Dr. David Alan Gilbert / address@hidden / Manchester, UK
- [Qemu-devel] [PATCH v2 00/10] Add make check tests for Migration, Juan Quintela, 2017/10/26
- [Qemu-devel] [PATCH v2 01/10] tests: rename postcopy-test to migration-test, Juan Quintela, 2017/10/26
- [Qemu-devel] [PATCH v2 02/10] tests: Refactor setting of parameters/capabilities, Juan Quintela, 2017/10/26
- [Qemu-devel] [PATCH v2 04/10] tests: Don't abuse global_qtest, Juan Quintela, 2017/10/26
- Re: [Qemu-devel] [PATCH v2 04/10] tests: Don't abuse global_qtest,
Dr. David Alan Gilbert <=
- [Qemu-devel] [PATCH v2 03/10] tests: Factorize out migrate_test_start/end, Juan Quintela, 2017/10/26
- [Qemu-devel] [PATCH v2 05/10] tests: check that migration parameters are really assigned, Juan Quintela, 2017/10/26
- [Qemu-devel] [PATCH v2 07/10] tests: Add basic migration precopy tcp test, Juan Quintela, 2017/10/26
- [Qemu-devel] [PATCH v2 06/10] tests: Add migration precopy test, Juan Quintela, 2017/10/26