{"id":812508,"url":"http://patchwork.ozlabs.org/api/patches/812508/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20170911172022.4738-19-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-19-eblake@redhat.com>","list_archive_url":null,"date":"2017-09-11T17:20:02","name":"[v7,18/38] ahci-test: Drop dependence on global_qtest","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"2a95c3b281f7b10147c45942a478da6bad529858","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-19-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/812508/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/812508/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-mx06.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx06.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 3xrb9J3dzwz9s7F\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 12 Sep 2017 03:52:20 +1000 (AEST)","from localhost ([::1]:59494 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 1drSsc-0002MT-Ho\n\tfor incoming@patchwork.ozlabs.org; Mon, 11 Sep 2017 13:52:18 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:38688)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <eblake@redhat.com>) id 1drSOc-0007ak-Ax\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 13:21:20 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <eblake@redhat.com>) id 1drSOa-0001JN-H9\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 13:21:18 -0400","from mx1.redhat.com ([209.132.183.28]:57836)\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>)\n\tid 1drSOU-0001GS-3X; Mon, 11 Sep 2017 13:21:10 -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 2C1E718424C;\n\tMon, 11 Sep 2017 17:21:09 +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 160965D9CA;\n\tMon, 11 Sep 2017 17:21:07 +0000 (UTC)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com 2C1E718424C","From":"Eric Blake <eblake@redhat.com>","To":"qemu-devel@nongnu.org","Date":"Mon, 11 Sep 2017 12:20:02 -0500","Message-Id":"<20170911172022.4738-19-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.30]);\n\tMon, 11 Sep 2017 17:21:09 +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 18/38] ahci-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, John Snow <jsnow@redhat.com>,\n\tarmbru@redhat.com, \"open list:IDE\" <qemu-block@nongnu.org>","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; the\nmanagement of global_qtest is even harder to follow because\nit was masked behind set_context().\n\nInstead, explicitly pass QTestState* around (generally, by\nreusing the member already present in ahci->parent QOSState),\nand call explicit qtest_* functions on all places that\ninteract with a monitor.\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\nBonus: there was one spots that was creating a needless temporary\nvariable to execute the 'cont' command, rather than just directly\npassing the literal command through qtest_qmp().  Fixing that\ngets us one step closer to enabling -Wformat checking on\nconstructed JSON.\n\nSigned-off-by: Eric Blake <eblake@redhat.com>\n\n---\nv7: split bulk of libqos changes into earlier patch\n---\n tests/libqos/libqos.h |  1 -\n tests/ahci-test.c     | 83 ++++++++++++++++++++++++---------------------------\n tests/libqos/libqos.c |  9 ------\n 3 files changed, 39 insertions(+), 54 deletions(-)","diff":"diff --git a/tests/libqos/libqos.h b/tests/libqos/libqos.h\nindex 07d4b93d1d..9e020efb10 100644\n--- a/tests/libqos/libqos.h\n+++ b/tests/libqos/libqos.h\n@@ -29,7 +29,6 @@ void qtest_shutdown(QOSState *qs);\n bool have_qemu_img(void);\n void mkimg(const char *file, const char *fmt, unsigned size_mb);\n void mkqcow2(const char *file, unsigned size_mb);\n-void set_context(QOSState *s);\n void migrate(QOSState *from, QOSState *to, const char *uri);\n void prepare_blkdebug_script(const char *debug_fn, const char *event);\n void generate_pattern(void *buffer, size_t len, size_t cycle_len);\ndiff --git a/tests/ahci-test.c b/tests/ahci-test.c\nindex d6696cc370..7c94c4920b 100644\n--- a/tests/ahci-test.c\n+++ b/tests/ahci-test.c\n@@ -157,7 +157,6 @@ static AHCIQState *ahci_vboot(const char *cli, va_list ap)\n\n     s = g_malloc0(sizeof(AHCIQState));\n     s->parent = qtest_pc_vboot(cli, ap);\n-    global_qtest = s->parent->qts;\n     alloc_set_flags(s->parent->alloc, ALLOC_LEAK_ASSERT);\n\n     /* Verify that we have an AHCI device present. */\n@@ -197,7 +196,7 @@ static void ahci_shutdown(AHCIQState *ahci)\n {\n     QOSState *qs = ahci->parent;\n\n-    set_context(qs);\n+    assert(!global_qtest);\n     ahci_clean_mem(ahci);\n     free_ahci_device(ahci->dev);\n     g_free(ahci);\n@@ -870,15 +869,15 @@ static void ahci_test_io_rw_simple(AHCIQState *ahci, unsigned bufsize,\n\n     /* Write some indicative pattern to our buffer. */\n     generate_pattern(tx, bufsize, AHCI_SECTOR_SIZE);\n-    bufwrite(ptr, tx, bufsize);\n+    qtest_bufwrite(ahci->parent->qts, ptr, tx, bufsize);\n\n     /* Write this buffer to disk, then read it back to the DMA buffer. */\n     ahci_guest_io(ahci, port, write_cmd, ptr, bufsize, sector);\n-    qmemset(ptr, 0x00, bufsize);\n+    qtest_memset(ahci->parent->qts, ptr, 0x00, bufsize);\n     ahci_guest_io(ahci, port, read_cmd, ptr, bufsize, sector);\n\n     /*** Read back the Data ***/\n-    bufread(ptr, rx, bufsize);\n+    qtest_bufread(ahci->parent->qts, ptr, rx, bufsize);\n     g_assert_cmphex(memcmp(tx, rx, bufsize), ==, 0);\n\n     ahci_free(ahci, ptr);\n@@ -919,7 +918,7 @@ static void ahci_test_max(AHCIQState *ahci)\n     }\n\n     port = ahci_test_nondata(ahci, cmd);\n-    memread(ahci->port[port].fb + 0x40, d2h, 0x20);\n+    qtest_memread(ahci->parent->qts, ahci->port[port].fb + 0x40, d2h, 0x20);\n     nsect = (uint64_t)d2h->lba_hi[2] << 40 |\n         (uint64_t)d2h->lba_hi[1] << 32 |\n         (uint64_t)d2h->lba_hi[0] << 24 |\n@@ -1037,7 +1036,7 @@ static void test_dma_fragmented(void)\n     /* Create a DMA buffer in guest memory, and write our pattern to it. */\n     ptr = guest_alloc(ahci->parent->alloc, bufsize);\n     g_assert(ptr);\n-    bufwrite(ptr, tx, bufsize);\n+    qtest_bufwrite(ahci->parent->qts, ptr, tx, bufsize);\n\n     cmd = ahci_command_create(CMD_WRITE_DMA);\n     ahci_command_adjust(cmd, 0, ptr, bufsize, 32);\n@@ -1054,7 +1053,7 @@ static void test_dma_fragmented(void)\n     ahci_command_free(cmd);\n\n     /* Read back the guest's receive buffer into local memory */\n-    bufread(ptr, rx, bufsize);\n+    qtest_bufread(ahci->parent->qts, ptr, rx, bufsize);\n     guest_free(ahci->parent->alloc, ptr);\n\n     g_assert_cmphex(memcmp(tx, rx, bufsize), ==, 0);\n@@ -1165,8 +1164,6 @@ static void ahci_migrate_simple(uint8_t cmd_read, uint8_t cmd_write)\n                     \"-drive if=ide,format=%s,file=%s \"\n                     \"-incoming %s\", imgfmt, tmp_path, uri);\n\n-    set_context(src->parent);\n-\n     /* initialize */\n     px = ahci_port_select(src);\n     ahci_port_clear(src, px);\n@@ -1234,7 +1231,7 @@ static void ahci_halted_io_test(uint8_t cmd_read, uint8_t cmd_write)\n     generate_pattern(tx, bufsize, AHCI_SECTOR_SIZE);\n     ptr = ahci_alloc(ahci, bufsize);\n     g_assert(ptr);\n-    memwrite(ptr, tx, bufsize);\n+    qtest_memwrite(ahci->parent->qts, ptr, tx, bufsize);\n\n     /* Attempt to write (and fail) */\n     cmd = ahci_guest_io_halt(ahci, port, cmd_write,\n@@ -1300,8 +1297,6 @@ static void ahci_migrate_halted_io(uint8_t cmd_read, uint8_t cmd_write)\n                     \"-incoming %s\",\n                     tmp_path, imgfmt, uri);\n\n-    set_context(src->parent);\n-\n     /* Initialize and prepare */\n     port = ahci_port_select(src);\n     ahci_port_clear(src, port);\n@@ -1310,7 +1305,7 @@ static void ahci_migrate_halted_io(uint8_t cmd_read, uint8_t cmd_write)\n     /* create DMA source buffer and write pattern */\n     ptr = ahci_alloc(src, bufsize);\n     g_assert(ptr);\n-    memwrite(ptr, tx, bufsize);\n+    qtest_memwrite(src->parent->qts, ptr, tx, bufsize);\n\n     /* Write, trigger the VM to stop, migrate, then resume. */\n     cmd = ahci_guest_io_halt(src, port, cmd_write,\n@@ -1351,7 +1346,6 @@ static void test_flush_migrate(void)\n     AHCIQState *src, *dst;\n     AHCICommand *cmd;\n     uint8_t px;\n-    const char *s;\n     char *uri = g_strdup_printf(\"unix:%s\", mig_socket);\n\n     prepare_blkdebug_script(debug_path, \"flush_to_disk\");\n@@ -1369,8 +1363,6 @@ static void test_flush_migrate(void)\n                     \"-device ide-hd,drive=drive0 \"\n                     \"-incoming %s\", tmp_path, imgfmt, uri);\n\n-    set_context(src->parent);\n-\n     px = ahci_port_select(src);\n     ahci_port_clear(src, px);\n\n@@ -1381,15 +1373,14 @@ static void test_flush_migrate(void)\n     cmd = ahci_command_create(CMD_FLUSH_CACHE);\n     ahci_command_commit(src, cmd, px);\n     ahci_command_issue_async(src, cmd);\n-    qmp_eventwait(\"STOP\");\n+    qtest_qmp_eventwait(src->parent->qts, \"STOP\");\n\n     /* Migrate over */\n     ahci_migrate(src, dst, uri);\n\n     /* Complete the command */\n-    s = \"{'execute':'cont' }\";\n-    qmp_async(s);\n-    qmp_eventwait(\"RESUME\");\n+    qtest_async_qmp(dst->parent->qts, \"{'execute':'cont'}\");\n+    qtest_qmp_eventwait(dst->parent->qts, \"RESUME\");\n     ahci_command_wait(dst, cmd);\n     ahci_command_verify(dst, cmd);\n\n@@ -1481,7 +1472,7 @@ static int ahci_cb_cmp_buff(AHCIQState *ahci, AHCICommand *cmd,\n     }\n\n     rx = g_malloc0(opts->size);\n-    bufread(opts->buffer, rx, opts->size);\n+    qtest_bufread(ahci->parent->qts, opts->buffer, rx, opts->size);\n     g_assert_cmphex(memcmp(tx, rx, opts->size), ==, 0);\n     g_free(rx);\n\n@@ -1556,9 +1547,10 @@ static void test_atapi_bcl(void)\n }\n\n\n-static void atapi_wait_tray(bool open)\n+static void atapi_wait_tray(AHCIQState *ahci, bool open)\n {\n-    QDict *rsp = qmp_eventwait_ref(\"DEVICE_TRAY_MOVED\");\n+    QDict *rsp = qtest_qmp_eventwait_ref(ahci->parent->qts,\n+                                         \"DEVICE_TRAY_MOVED\");\n     QDict *data = qdict_get_qdict(rsp, \"data\");\n     if (open) {\n         g_assert(qdict_get_bool(data, \"tray-open\"));\n@@ -1585,43 +1577,46 @@ static void test_atapi_tray(void)\n     port = ahci_port_select(ahci);\n\n     ahci_atapi_eject(ahci, port);\n-    atapi_wait_tray(true);\n+    atapi_wait_tray(ahci, true);\n\n     ahci_atapi_load(ahci, port);\n-    atapi_wait_tray(false);\n+    atapi_wait_tray(ahci, false);\n\n     /* Remove media */\n-    qmp_async(\"{'execute': 'blockdev-open-tray', \"\n-               \"'arguments': {'device': 'drive0'}}\");\n-    atapi_wait_tray(true);\n-    rsp = qmp_receive();\n+    qtest_async_qmp(ahci->parent->qts, \"{'execute': 'blockdev-open-tray', \"\n+                    \"'arguments': {'device': 'drive0'}}\");\n+    atapi_wait_tray(ahci, true);\n+    rsp = qtest_qmp_receive(ahci->parent->qts);\n     QDECREF(rsp);\n\n-    qmp_discard_response(\"{'execute': 'x-blockdev-remove-medium', \"\n-                         \"'arguments': {'device': 'drive0'}}\");\n+    qtest_qmp_discard_response(ahci->parent->qts,\n+                               \"{'execute': 'x-blockdev-remove-medium', \"\n+                               \"'arguments': {'device': 'drive0'}}\");\n\n     /* Test the tray without a medium */\n     ahci_atapi_load(ahci, port);\n-    atapi_wait_tray(false);\n+    atapi_wait_tray(ahci, false);\n\n     ahci_atapi_eject(ahci, port);\n-    atapi_wait_tray(true);\n+    atapi_wait_tray(ahci, true);\n\n     /* Re-insert media */\n-    qmp_discard_response(\"{'execute': 'blockdev-add', \"\n-                          \"'arguments': {'node-name': 'node0', \"\n+    qtest_qmp_discard_response(ahci->parent->qts,\n+                               \"{'execute': 'blockdev-add', \"\n+                               \"'arguments': {'node-name': 'node0', \"\n                                         \"'driver': 'raw', \"\n                                         \"'file': { 'driver': 'file', \"\n                                                   \"'filename': %s }}}\", iso);\n-    qmp_discard_response(\"{'execute': 'x-blockdev-insert-medium',\"\n-                          \"'arguments': { 'device': 'drive0', \"\n+    qtest_qmp_discard_response(ahci->parent->qts,\n+                               \"{'execute': 'x-blockdev-insert-medium',\"\n+                               \"'arguments': { 'device': 'drive0', \"\n                                          \"'node-name': 'node0' }}\");\n\n     /* Again, the event shows up first */\n-    qmp_async(\"{'execute': 'blockdev-close-tray', \"\n-               \"'arguments': {'device': 'drive0'}}\");\n-    atapi_wait_tray(false);\n-    rsp = qmp_receive();\n+    qtest_async_qmp(ahci->parent->qts, \"{'execute': 'blockdev-close-tray', \"\n+                    \"'arguments': {'device': 'drive0'}}\");\n+    atapi_wait_tray(ahci, false);\n+    rsp = qtest_qmp_receive(ahci->parent->qts);\n     QDECREF(rsp);\n\n     /* Now, to convince ATAPI we understand the media has changed... */\n@@ -1641,10 +1636,10 @@ static void test_atapi_tray(void)\n\n     /* Final tray test. */\n     ahci_atapi_eject(ahci, port);\n-    atapi_wait_tray(true);\n+    atapi_wait_tray(ahci, true);\n\n     ahci_atapi_load(ahci, port);\n-    atapi_wait_tray(false);\n+    atapi_wait_tray(ahci, false);\n\n     /* Cleanup */\n     g_free(tx);\ndiff --git a/tests/libqos/libqos.c b/tests/libqos/libqos.c\nindex 9798e1d027..3ff61246a4 100644\n--- a/tests/libqos/libqos.c\n+++ b/tests/libqos/libqos.c\n@@ -75,11 +75,6 @@ void qtest_shutdown(QOSState *qs)\n     }\n }\n\n-void set_context(QOSState *s)\n-{\n-    global_qtest = s->qts;\n-}\n-\n static QDict *qmp_execute(QTestState *qts, const char *command)\n {\n     return qtest_qmp(qts, \"{ 'execute': %s }\", command);\n@@ -91,8 +86,6 @@ void migrate(QOSState *from, QOSState *to, const char *uri)\n     QDict *rsp, *sub;\n     bool running;\n\n-    set_context(from);\n-\n     /* Is the machine currently running? */\n     rsp = qmp_execute(from->qts, \"query-status\");\n     g_assert(qdict_haskey(rsp, \"return\"));\n@@ -116,7 +109,6 @@ void migrate(QOSState *from, QOSState *to, const char *uri)\n     /* If we were running, we can wait for an event. */\n     if (running) {\n         migrate_allocator(from->alloc, to->alloc);\n-        set_context(to);\n         qtest_qmp_eventwait(to->qts, \"RESUME\");\n         return;\n     }\n@@ -146,7 +138,6 @@ void migrate(QOSState *from, QOSState *to, const char *uri)\n     }\n\n     migrate_allocator(from->alloc, to->alloc);\n-    set_context(to);\n }\n\n bool have_qemu_img(void)\n","prefixes":["v7","18/38"]}