From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from localhost.localdomain (unknown [182.2.70.226]) by gnuweeb.org (Postfix) with ESMTPSA id C570880C32; Fri, 2 Sep 2022 07:16:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1662102974; bh=T126dCp9v3ZoM12a5j/AAdc4YvfYF7qFFa3/xP4/m7g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XIaZsJ17zV9TcQ9MTYvuBQppOFeD3JAkzQIYiLG/od27uLq4mk3ExJIXqALhOwfP3 tLH9Usz+RJyNVGEOFhYyTt4NBJGi4hCXKi+z78fNYYFChsJBcJIZwc2c8+11YHojWs QzUUsSymKabZoMvPeOplVGdpTTZtALUOjR9eQckoytrnTN2RuuGvMLFH6hCsBTos7u VPs9uFSVPKIwswMkvV0WtE07dB6DpnNr7A/VP1FzqYAUaCQWLpymucCmDRy4Dvqdks RdcRZFJ4eksWktL6lcqotNmfhPW5ROlZ6TLPXCXBeMHvOGD0tIJOyHDiSmlxbckF8q TBDRphZmlOhFg== From: Ammar Faizi To: Jens Axboe Cc: Ammar Faizi , Dylan Yudaken , Facebook Kernel Team , Pavel Begunkov , io-uring Mailing List , GNU/Weeb Mailing List , Kanna Scarlet , Muhammad Rizki , Alviro Iskandar Setiawan Subject: [PATCH liburing v2 11/12] t/232c93d07b74: Don't use a static port number Date: Fri, 2 Sep 2022 14:15:04 +0700 Message-Id: <20220902071153.3168814-12-ammar.faizi@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220902071153.3168814-1-ammar.faizi@intel.com> References: <20220902071153.3168814-1-ammar.faizi@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: From: Ammar Faizi Don't use a static port number. It might already be in use, resulting in a test failure. Use an ephemeral port to make this test reliable. Cc: Dylan Yudaken Cc: Facebook Kernel Team Cc: Pavel Begunkov Reviewed-by: Alviro Iskandar Setiawan Tested-by: Alviro Iskandar Setiawan Signed-off-by: Ammar Faizi --- test/232c93d07b74.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/test/232c93d07b74.c b/test/232c93d07b74.c index c99491f..74cc063 100644 --- a/test/232c93d07b74.c +++ b/test/232c93d07b74.c @@ -23,19 +23,18 @@ #include "helpers.h" #include "liburing.h" #define RECV_BUFF_SIZE 2 #define SEND_BUFF_SIZE 3 -#define PORT 0x1234 - struct params { int tcp; int non_blocking; + __be16 bind_port; }; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t cond = PTHREAD_COND_INITIALIZER; int rcv_ready = 0; static void set_rcv_ready(void) @@ -73,18 +72,17 @@ static void *rcv(void *arg) assert(res != -1); res = setsockopt(s0, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)); assert(res != -1); struct sockaddr_in addr; addr.sin_family = AF_INET; - addr.sin_port = htons(PORT); addr.sin_addr.s_addr = inet_addr("127.0.0.1"); - res = bind(s0, (struct sockaddr *) &addr, sizeof(addr)); - assert(res != -1); + assert(t_bind_ephemeral_port(s0, &addr) == 0); + p->bind_port = addr.sin_port; } else { s0 = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); assert(s0 != -1); struct sockaddr_un addr; memset(&addr, 0, sizeof(addr)); @@ -188,15 +186,15 @@ static void *snd(void *arg) s0 = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP); ret = setsockopt(s0, IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val)); assert(ret != -1); struct sockaddr_in addr; addr.sin_family = AF_INET; - addr.sin_port = htons(PORT); + addr.sin_port = p->bind_port; addr.sin_addr.s_addr = inet_addr("127.0.0.1"); ret = connect(s0, (struct sockaddr*) &addr, sizeof(addr)); assert(ret != -1); } else { s0 = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); assert(s0 != -1); -- Ammar Faizi