From: Jianwen Ji <jijianwen@gmail.com>
To: linux-sctp@vger.kernel.org
Subject: [PATCH v2 lksctp-tools] testlib: improve test_bind function
Date: Wed, 24 Jul 2019 10:39:30 +0000 [thread overview]
Message-ID: <20190724103930.13727-1-jijianwen@gmail.com> (raw)
Try to bind again if the errno is EADDRINUSE.
Some tests failed to run sometimes, here is one snapshot:
...
test_sockopt.c 25 PASS : setsockopt(SCTP_PEER_ADDR_PARAMS) - one-to-many style invalid hb demand
test_sockopt.c 26 BROK : bind: Address already in use
DUMP_CORE ../../src/testlib/sctputil.h: 145
...
test_1_to_1_sendmsg.c 10 PASS : sendmsg() on a closed association - EPIPE
test_1_to_1_sendmsg.c 11 BROK : bind: Address already in use
DUMP_CORE ../../src/testlib/sctputil.h: 145
The reason is that it closed a socket and then created a new socket
to bind the same socket address as before, which was not released
yet.
Signed-off-by: Jianwen Ji <jijianwen@gmail.com>
---
src/testlib/sctputil.h | 24 +++++++++++++++++++++---
1 file changed, 21 insertions(+), 3 deletions(-)
diff --git a/src/testlib/sctputil.h b/src/testlib/sctputil.h
index 9dbabd4..5b807c7 100644
--- a/src/testlib/sctputil.h
+++ b/src/testlib/sctputil.h
@@ -54,6 +54,7 @@
#endif
#include <string.h>
+#include <unistd.h>
typedef union {
struct sockaddr_in v4;
@@ -72,6 +73,10 @@ typedef union {
#endif
#define SCTP_TESTPORT_2 (SCTP_TESTPORT_1+1)
+#ifndef MAX_BIND_RETRYS
+#define MAX_BIND_RETRYS 10
+#endif
+
#define SCTP_IP_BCAST htonl(0xffffffff)
#define SCTP_IP_LOOPBACK htonl(0x7f000001)
@@ -140,9 +145,22 @@ static inline int test_socket(int domain, int type, int protocol)
static inline int test_bind(int sk, struct sockaddr *addr, socklen_t addrlen)
{
- int error = bind(sk, addr, addrlen);
- if (-1 = error)
- tst_brkm(TBROK, tst_exit, "bind: %s", strerror(errno));
+ int error = 0, i = 0;
+
+ do {
+ if (i > 0) sleep(1); /* sleep a while before new try... */
+
+ error = bind(sk, addr, addrlen);
+ if (-1 = error && errno != EADDRINUSE) {
+ tst_brkm(TBROK, tst_exit, "bind: %s", strerror(errno));
+ }
+
+ i++;
+ if (i >= MAX_BIND_RETRYS) {
+ tst_brkm(TBROK, tst_exit, "bind: %s", strerror(errno));
+ }
+ } while (error < 0 && i < MAX_BIND_RETRYS);
+
return error;
}
--
2.14.5
next reply other threads:[~2019-07-24 10:39 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-24 10:39 Jianwen Ji [this message]
2019-07-24 11:38 ` [PATCH v2 lksctp-tools] testlib: improve test_bind function Neil Horman
2019-07-24 12:40 ` Marcelo Ricardo Leitner
2019-07-25 1:04 ` Ji Jianwen
2019-07-25 2:12 ` Marcelo Ricardo Leitner
2019-07-25 2:39 ` Marcelo Ricardo Leitner
2019-07-25 7:12 ` Ji Jianwen
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=20190724103930.13727-1-jijianwen@gmail.com \
--to=jijianwen@gmail.com \
--cc=linux-sctp@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.