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.38.99]) by gnuweeb.org (Postfix) with ESMTPSA id 9845180C38; Fri, 2 Sep 2022 01:18:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1662081521; bh=t/yUsttRItt9nJsTr0VDOU9oV2/pORcRDTd/UkdXK9A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kgdaJl8nJKsOHeAosLmWiJ0jW0j6Rp+rplNHPKonbTVmaIejhTVQzqlzlcYpnKWzq Azyx086+VxseuQx2gVQIyzZCt+ssc6TTQ57E1d5kQiG3/KTkRa9DN5mJ8fGYeKWujn KBbxTjIQpvVUjP6ApRN3hffmM5IStYNcRnnXjzAqhrK21Ne287LvyeVnmFo97QioBE +OhmYWG1iYYBryUFE0bxkgD1P3PCrubEFn/hjDz0Ay+H9Ep0ECFLB8fsPdabtowK41 /saiYsxEa3N+KRqnZWNrPwQO5LjZpG+UVujaJQNBYYiaacNaX69acILu+PSbjKgGpn +TxWg++PCTMNA== 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 Subject: [RESEND PATCH liburing v1 11/12] t/232c93d07b74: Don't use a static port number Date: Fri, 2 Sep 2022 08:17:51 +0700 Message-Id: <20220902011548.2506938-12-ammar.faizi@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220902011548.2506938-1-ammar.faizi@intel.com> References: <20220902011548.2506938-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 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 @@ -18,29 +18,28 @@ #include #include #include #include #include #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) { pthread_mutex_lock(&mutex); rcv_ready = 1; pthread_cond_signal(&cond); @@ -68,28 +67,27 @@ static void *rcv(void *arg) int val = 1; s0 = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP); res = setsockopt(s0, SOL_SOCKET, SO_REUSEPORT, &val, sizeof(val)); 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)); addr.sun_family = AF_UNIX; memcpy(addr.sun_path, "\0sock", 6); res = bind(s0, (struct sockaddr *) &addr, sizeof(addr)); assert(res != -1); } @@ -183,25 +181,25 @@ static void *snd(void *arg) wait_for_rcv_ready(); if (p->tcp) { int val = 1; 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); struct sockaddr_un addr; memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; memcpy(addr.sun_path, "\0sock", 6); -- Ammar Faizi