{"id":812501,"url":"http://patchwork.ozlabs.org/api/patches/812501/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20170911172022.4738-22-eblake@redhat.com/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170911172022.4738-22-eblake@redhat.com>","list_archive_url":null,"date":"2017-09-11T17:20:05","name":"[v7,21/38] vhost-user-test: Drop dependence on global_qtest","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"f0ea5a36acb2a453e7405517c6947dfe463aa951","submitter":{"id":6591,"url":"http://patchwork.ozlabs.org/api/people/6591/?format=json","name":"Eric Blake","email":"eblake@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20170911172022.4738-22-eblake@redhat.com/mbox/","series":[{"id":2534,"url":"http://patchwork.ozlabs.org/api/series/2534/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=2534","date":"2017-09-11T17:19:47","name":"Preliminary libqtest cleanups","version":7,"mbox":"http://patchwork.ozlabs.org/series/2534/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/812501/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/812501/checks/","tags":{},"related":[],"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ext-mx05.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx05.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=eblake@redhat.com"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xrb2N1cg8z9s81\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 12 Sep 2017 03:46:20 +1000 (AEST)","from localhost ([::1]:59459 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1drSmo-0004da-6w\n\tfor incoming@patchwork.ozlabs.org; Mon, 11 Sep 2017 13:46:18 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:38644)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <eblake@redhat.com>) id 1drSOa-0007YK-BQ\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 13:21:17 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <eblake@redhat.com>) id 1drSOX-0001I1-Tt\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 13:21:16 -0400","from mx1.redhat.com ([209.132.183.28]:44512)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <eblake@redhat.com>) id 1drSOX-0001Ho-Ko\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 13:21:13 -0400","from smtp.corp.redhat.com\n\t(int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id BFAF536D05D\n\tfor <qemu-devel@nongnu.org>; Mon, 11 Sep 2017 17:21:12 +0000 (UTC)","from red.redhat.com (ovpn-120-44.rdu2.redhat.com [10.10.120.44])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id EC4535D9CA;\n\tMon, 11 Sep 2017 17:21:11 +0000 (UTC)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com BFAF536D05D","From":"Eric Blake <eblake@redhat.com>","To":"qemu-devel@nongnu.org","Date":"Mon, 11 Sep 2017 12:20:05 -0500","Message-Id":"<20170911172022.4738-22-eblake@redhat.com>","In-Reply-To":"<20170911172022.4738-1-eblake@redhat.com>","References":"<20170911172022.4738-1-eblake@redhat.com>","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.14","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.29]);\n\tMon, 11 Sep 2017 17:21:12 +0000 (UTC)","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","Subject":"[Qemu-devel] [PATCH v7 21/38] vhost-user-test: Drop dependence on\n\tglobal_qtest","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"pbonzini@redhat.com, thuth@redhat.com, armbru@redhat.com","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"},"content":"Managing parallel connections to two different monitors via\nthe implicit global_qtest makes it hard to copy-and-paste code\nto tests that are not aware of the implicit state.  Now that\nlibqos is fully-explicit, it is easy to expand the rest of\nvhost-user-test to also use explicit state everywhere.\n\nWe can assert that the conversion is correct by checking that\nglobal_qtest remains NULL throughout the test (a later patch\nthat changes global_qtest to not be a public global variable\nwill drop the assertions).\n\nSigned-off-by: Eric Blake <eblake@redhat.com>\nReviewed-by: Thomas Huth <thuth@redhat.com>\n---\n tests/vhost-user-test.c | 68 ++++++++++++++++++++++---------------------------\n 1 file changed, 30 insertions(+), 38 deletions(-)","diff":"diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c\nindex b041d2c6a2..d5afc5f9f6 100644\n--- a/tests/vhost-user-test.c\n+++ b/tests/vhost-user-test.c\n@@ -141,6 +141,7 @@ enum {\n };\n\n typedef struct TestServer {\n+    QTestState *qts;\n     QPCIBus *bus;\n     gchar *socket_path;\n     gchar *mig_path;\n@@ -166,7 +167,7 @@ static void init_virtio_dev(TestServer *s)\n     QVirtioPCIDevice *dev;\n     uint32_t features;\n\n-    s->bus = qpci_init_pc(global_qtest, NULL);\n+    s->bus = qpci_init_pc(s->qts, NULL);\n     g_assert_nonnull(s->bus);\n\n     dev = qvirtio_pci_device_find(s->bus, VIRTIO_ID_NET);\n@@ -238,8 +239,11 @@ static void read_guest_mem(const void *data)\n         guest_mem += (s->memory.regions[i].mmap_offset / sizeof(*guest_mem));\n\n         for (j = 0; j < 256; j++) {\n-            uint32_t a = readl(s->memory.regions[i].guest_phys_addr + j*4);\n-            uint32_t b = guest_mem[j];\n+            uint32_t a, b;\n+\n+            a = qtest_readl(s->qts,\n+                            s->memory.regions[i].guest_phys_addr + j * 4);\n+            b = guest_mem[j];\n\n             g_assert_cmpint(a, ==, b);\n         }\n@@ -512,6 +516,12 @@ static gboolean _test_server_free(TestServer *server)\n\n static void test_server_free(TestServer *server)\n {\n+    assert(!global_qtest);\n+    if (server->qts) {\n+        qtest_quit(server->qts);\n+        server->qts = NULL;\n+    }\n+\n     g_idle_add((GSourceFunc)_test_server_free, server);\n }\n\n@@ -623,7 +633,6 @@ static void test_migrate(void)\n     TestServer *s = test_server_new(\"src\");\n     TestServer *dest = test_server_new(\"dest\");\n     char *uri = g_strdup_printf(\"%s%s\", \"unix:\", dest->mig_path);\n-    QTestState *global = global_qtest, *from, *to;\n     GSource *source;\n     gchar *cmd;\n     QDict *rsp;\n@@ -634,7 +643,7 @@ static void test_migrate(void)\n     test_server_listen(dest);\n\n     cmd = GET_QEMU_CMDE(s, 2, \"\", \"\");\n-    from = qtest_start(cmd);\n+    s->qts = qtest_init(cmd);\n     g_free(cmd);\n\n     init_virtio_dev(s);\n@@ -643,7 +652,7 @@ static void test_migrate(void)\n     g_assert_cmpint(size, ==, (2 * 1024 * 1024) / (VHOST_LOG_PAGE * 8));\n\n     cmd = GET_QEMU_CMDE(dest, 2, \"\", \" -incoming %s\", uri);\n-    to = qtest_init(cmd);\n+    dest->qts = qtest_init(cmd);\n     g_free(cmd);\n\n     source = g_source_new(&test_migrate_source_funcs,\n@@ -654,16 +663,13 @@ static void test_migrate(void)\n\n     /* slow down migration to have time to fiddle with log */\n     /* TODO: qtest could learn to break on some places */\n-    rsp = qmp(\"{ 'execute': 'migrate_set_speed',\"\n-              \"'arguments': { 'value': 10 } }\");\n+    rsp = qtest_qmp(s->qts, \"{ 'execute': 'migrate_set_speed',\"\n+                    \"'arguments': { 'value': 10 } }\");\n     g_assert(qdict_haskey(rsp, \"return\"));\n     QDECREF(rsp);\n\n-    cmd = g_strdup_printf(\"{ 'execute': 'migrate',\"\n-                          \"'arguments': { 'uri': '%s' } }\",\n-                          uri);\n-    rsp = qmp(cmd);\n-    g_free(cmd);\n+    rsp = qtest_qmp(s->qts,\n+                    \"{'execute': 'migrate', 'arguments': { 'uri': %s}}\", uri);\n     g_assert(qdict_haskey(rsp, \"return\"));\n     QDECREF(rsp);\n\n@@ -678,28 +684,23 @@ static void test_migrate(void)\n     munmap(log, size);\n\n     /* speed things up */\n-    rsp = qmp(\"{ 'execute': 'migrate_set_speed',\"\n-              \"'arguments': { 'value': 0 } }\");\n+    rsp = qtest_qmp(s->qts, \"{ 'execute': 'migrate_set_speed',\"\n+                    \"'arguments': { 'value': 0 } }\");\n     g_assert(qdict_haskey(rsp, \"return\"));\n     QDECREF(rsp);\n\n-    qmp_eventwait(\"STOP\");\n+    qtest_qmp_eventwait(s->qts, \"STOP\");\n\n-    global_qtest = to;\n-    qmp_eventwait(\"RESUME\");\n+    qtest_qmp_eventwait(dest->qts, \"RESUME\");\n\n     read_guest_mem(dest);\n\n     g_source_destroy(source);\n     g_source_unref(source);\n\n-    qtest_quit(to);\n     test_server_free(dest);\n-    qtest_quit(from);\n     test_server_free(s);\n     g_free(uri);\n-\n-    global_qtest = global;\n }\n\n static void wait_for_rings_started(TestServer *s, size_t count)\n@@ -754,7 +755,7 @@ static void test_reconnect_subprocess(void)\n\n     g_thread_new(\"connect\", connect_thread, s);\n     cmd = GET_QEMU_CMDE(s, 2, \",server\", \"\");\n-    qtest_start(cmd);\n+    s->qts = qtest_init(cmd);\n     g_free(cmd);\n\n     init_virtio_dev(s);\n@@ -768,7 +769,6 @@ static void test_reconnect_subprocess(void)\n     wait_for_fds(s);\n     wait_for_rings_started(s, 2);\n\n-    qtest_end();\n     test_server_free(s);\n     return;\n }\n@@ -790,14 +790,13 @@ static void test_connect_fail_subprocess(void)\n     s->test_fail = true;\n     g_thread_new(\"connect\", connect_thread, s);\n     cmd = GET_QEMU_CMDE(s, 2, \",server\", \"\");\n-    qtest_start(cmd);\n+    s->qts = qtest_init(cmd);\n     g_free(cmd);\n\n     init_virtio_dev(s);\n     wait_for_fds(s);\n     wait_for_rings_started(s, 2);\n\n-    qtest_end();\n     test_server_free(s);\n }\n\n@@ -818,14 +817,13 @@ static void test_flags_mismatch_subprocess(void)\n     s->test_flags = TEST_FLAGS_DISCONNECT;\n     g_thread_new(\"connect\", connect_thread, s);\n     cmd = GET_QEMU_CMDE(s, 2, \",server\", \"\");\n-    qtest_start(cmd);\n+    s->qts = qtest_init(cmd);\n     g_free(cmd);\n\n     init_virtio_dev(s);\n     wait_for_fds(s);\n     wait_for_rings_started(s, 2);\n\n-    qtest_end();\n     test_server_free(s);\n }\n\n@@ -890,13 +888,13 @@ static void test_multiqueue(void)\n                           512, 512, root, s->chr_name,\n                           s->socket_path, \"\", s->chr_name,\n                           queues, queues * 2 + 2);\n-    qtest_start(cmd);\n+    s->qts = qtest_init(cmd);\n     g_free(cmd);\n\n-    bus = qpci_init_pc(global_qtest, NULL);\n+    bus = qpci_init_pc(s->qts, NULL);\n     dev = virtio_net_pci_init(bus, PCI_SLOT);\n\n-    alloc = pc_alloc_init(global_qtest);\n+    alloc = pc_alloc_init(s->qts);\n     for (i = 0; i < queues * 2; i++) {\n         vq[i] = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, alloc, i);\n     }\n@@ -913,14 +911,12 @@ static void test_multiqueue(void)\n     g_free(dev->pdev);\n     g_free(dev);\n     qpci_free_pc(bus);\n-    qtest_end();\n\n     test_server_free(s);\n }\n\n int main(int argc, char **argv)\n {\n-    QTestState *s = NULL;\n     TestServer *server = NULL;\n     const char *hugefs;\n     char *qemu_cmd = NULL;\n@@ -957,7 +953,7 @@ int main(int argc, char **argv)\n\n     qemu_cmd = GET_QEMU_CMD(server);\n\n-    s = qtest_start(qemu_cmd);\n+    server->qts = qtest_init(qemu_cmd);\n     g_free(qemu_cmd);\n     init_virtio_dev(server);\n\n@@ -979,10 +975,6 @@ int main(int argc, char **argv)\n\n     ret = g_test_run();\n\n-    if (s) {\n-        qtest_quit(s);\n-    }\n-\n     /* cleanup */\n     test_server_free(server);\n\n","prefixes":["v7","21/38"]}