qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: qemu-devel@nongnu.org, Richard Henderson <richard.henderson@linaro.org>
Cc: Laurent Vivier <lvivier@redhat.com>
Subject: [PULL 03/21] net: stream: test reconnect option with an unix socket
Date: Mon, 15 May 2023 15:02:15 +0200	[thread overview]
Message-ID: <20230515130233.418183-4-thuth@redhat.com> (raw)
In-Reply-To: <20230515130233.418183-1-thuth@redhat.com>

From: Laurent Vivier <lvivier@redhat.com>

We can have failure with the inet type test because the port address
is not allocated atomically and can be taken by another test between its
selection and the start of QEMU. To avoid that, use an unix socket with
a path that is unique

Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Message-Id: <20230503094109.1198248-1-lvivier@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/qtest/netdev-socket.c | 39 +++++++++++++++++--------------------
 1 file changed, 18 insertions(+), 21 deletions(-)

diff --git a/tests/qtest/netdev-socket.c b/tests/qtest/netdev-socket.c
index 9cf1b0698e..097abc0230 100644
--- a/tests/qtest/netdev-socket.c
+++ b/tests/qtest/netdev-socket.c
@@ -189,28 +189,26 @@ static void wait_stream_disconnected(QTestState *qts, const char *id)
     qobject_unref(resp);
 }
 
-static void test_stream_inet_reconnect(void)
+static void test_stream_unix_reconnect(void)
 {
     QTestState *qts0, *qts1;
-    int port;
     SocketAddress *addr;
+    gchar *path;
 
-    port = inet_get_free_port(false);
+    path = g_strconcat(tmpdir, "/stream_unix_reconnect", NULL);
     qts0 = qtest_initf("-nodefaults -M none "
-                       "-netdev stream,id=st0,server=true,addr.type=inet,"
-                       "addr.ipv4=on,addr.ipv6=off,"
-                       "addr.host=127.0.0.1,addr.port=%d", port);
+                       "-netdev stream,id=st0,server=true,addr.type=unix,"
+                       "addr.path=%s", path);
 
     EXPECT_STATE(qts0, "st0: index=0,type=stream,\r\n", 0);
 
     qts1 = qtest_initf("-nodefaults -M none "
-                       "-netdev stream,server=false,id=st0,addr.type=inet,"
-                       "addr.ipv4=on,addr.ipv6=off,reconnect=1,"
-                       "addr.host=127.0.0.1,addr.port=%d", port);
+                       "-netdev stream,server=false,id=st0,addr.type=unix,"
+                       "addr.path=%s,reconnect=1", path);
 
     wait_stream_connected(qts0, "st0", &addr);
-    g_assert_cmpint(addr->type, ==, SOCKET_ADDRESS_TYPE_INET);
-    g_assert_cmpstr(addr->u.inet.host, ==, "127.0.0.1");
+    g_assert_cmpint(addr->type, ==, SOCKET_ADDRESS_TYPE_UNIX);
+    g_assert_cmpstr(addr->u.q_unix.path, ==, path);
     qapi_free_SocketAddress(addr);
 
     /* kill server */
@@ -221,24 +219,23 @@ static void test_stream_inet_reconnect(void)
 
     /* restart server */
     qts0 = qtest_initf("-nodefaults -M none "
-                       "-netdev stream,id=st0,server=true,addr.type=inet,"
-                       "addr.ipv4=on,addr.ipv6=off,"
-                       "addr.host=127.0.0.1,addr.port=%d", port);
+                       "-netdev stream,id=st0,server=true,addr.type=unix,"
+                       "addr.path=%s", path);
 
     /* wait connection events*/
     wait_stream_connected(qts0, "st0", &addr);
-    g_assert_cmpint(addr->type, ==, SOCKET_ADDRESS_TYPE_INET);
-    g_assert_cmpstr(addr->u.inet.host, ==, "127.0.0.1");
+    g_assert_cmpint(addr->type, ==, SOCKET_ADDRESS_TYPE_UNIX);
+    g_assert_cmpstr(addr->u.q_unix.path, ==, path);
     qapi_free_SocketAddress(addr);
 
     wait_stream_connected(qts1, "st0", &addr);
-    g_assert_cmpint(addr->type, ==, SOCKET_ADDRESS_TYPE_INET);
-    g_assert_cmpstr(addr->u.inet.host, ==, "127.0.0.1");
-    g_assert_cmpint(atoi(addr->u.inet.port), ==, port);
+    g_assert_cmpint(addr->type, ==, SOCKET_ADDRESS_TYPE_UNIX);
+    g_assert_cmpstr(addr->u.q_unix.path, ==, path);
     qapi_free_SocketAddress(addr);
 
     qtest_quit(qts1);
     qtest_quit(qts0);
+    g_free(path);
 }
 
 static void test_stream_inet_ipv6(void)
@@ -517,8 +514,6 @@ int main(int argc, char **argv)
 #ifndef _WIN32
         qtest_add_func("/netdev/dgram/mcast", test_dgram_mcast);
 #endif
-        qtest_add_func("/netdev/stream/inet/reconnect",
-                       test_stream_inet_reconnect);
     }
     if (has_ipv6) {
         qtest_add_func("/netdev/stream/inet/ipv6", test_stream_inet_ipv6);
@@ -530,6 +525,8 @@ int main(int argc, char **argv)
         qtest_add_func("/netdev/dgram/unix", test_dgram_unix);
 #endif
         qtest_add_func("/netdev/stream/unix", test_stream_unix);
+        qtest_add_func("/netdev/stream/unix/reconnect",
+                       test_stream_unix_reconnect);
 #ifdef CONFIG_LINUX
         qtest_add_func("/netdev/stream/unix/abstract",
                        test_stream_unix_abstract);
-- 
2.31.1



  parent reply	other threads:[~2023-05-15 13:03 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-15 13:02 [PULL 00/21] Tests, docs, s390x and misc patches Thomas Huth
2023-05-15 13:02 ` [PULL 01/21] tests/avocado/virtio-gpu: Fix the URLs of the test_virtio_vga_virgl test Thomas Huth
2023-05-15 13:02 ` [PULL 02/21] sysemu/kvm: Remove unused headers Thomas Huth
2023-05-15 13:02 ` Thomas Huth [this message]
2023-05-15 13:02 ` [PULL 04/21] tests/qtest: replace qmp_discard_response with qtest_qmp_assert_success Thomas Huth
2023-05-15 13:02 ` [PULL 05/21] hw/pci-bridge: Fix release ordering by embedding PCIBridgeWindows within PCIBridge Thomas Huth
2023-05-15 13:02 ` [PULL 06/21] Add information how to fix common build error on Windows in symlink-install-tree Thomas Huth
2023-05-15 13:02 ` [PULL 07/21] tests: libvirt-ci: Update to commit 'c8971e90ac' to pull in mformat and xorriso Thomas Huth
2023-05-15 13:02 ` [PULL 08/21] tests/lcitool: Add mtools and xorriso and remove genisoimage as dependencies Thomas Huth
2023-05-15 13:02 ` [PULL 09/21] util/async-teardown: wire up query-command-line-options Thomas Huth
2023-05-15 13:02 ` [PULL 10/21] s390x/pv: Fix spurious warning with asynchronous teardown Thomas Huth
2023-05-15 13:02 ` [PULL 11/21] docs/devel: remind developers to run CI container pipeline when updating images Thomas Huth
2023-05-15 13:02 ` [PULL 12/21] docs/about/emulation: fix typo Thomas Huth
2023-05-15 13:02 ` [PULL 13/21] hw/core: Use a callback for target specific query-cpus-fast information Thomas Huth
2023-05-15 13:02 ` [PULL 14/21] cpu: Introduce a wrapper for being able to use TARGET_NAME in common code Thomas Huth
2023-05-15 13:02 ` [PULL 15/21] hw/core: Move machine-qmp-cmds.c into the target independent source set Thomas Huth
2023-05-15 13:02 ` [PULL 16/21] hw/net: Move xilinx_ethlite.c to the target-independent " Thomas Huth
2023-05-15 13:02 ` [PULL 17/21] s390x/tcg: Fix LDER instruction format Thomas Huth
2023-05-15 13:02 ` [PULL 18/21] tests/tcg/multiarch: Make the system memory test work on big-endian Thomas Huth
2023-05-15 13:02 ` [PULL 19/21] tests/tcg/s390x: Enable the multiarch system tests Thomas Huth
2023-05-15 13:02 ` [PULL 20/21] target/s390x: Fix EXECUTE of relative branches Thomas Huth
2023-05-15 13:02 ` [PULL 21/21] tests/tcg/s390x: Test " Thomas Huth
2023-05-15 20:53 ` [PULL 00/21] Tests, docs, s390x and misc patches Richard Henderson
2023-05-16  7:11   ` Thomas Huth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230515130233.418183-4-thuth@redhat.com \
    --to=thuth@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).