From: Geliang Tang <tanggeliang@kylinos.cn>
In shutdown_reuse tests, add a delay after shutdown to wait for
MPTCP sockets to reach TCP_CLOSE state before reuse via bind(),
avoiding the following errors:
# RUN tls.12_aes_gcm_mptcp.shutdown_reuse ...
# tls.c:1790:shutdown_reuse:Expected ret (-1) == 0 (0)
# shutdown_reuse: Test failed
# FAIL tls.12_aes_gcm_mptcp.shutdown_reuse
not ok 14 tls.12_aes_gcm_mptcp.shutdown_reuse
# RUN tls.13_aes_gcm_mptcp.shutdown_reuse ...
# tls.c:1790:shutdown_reuse:Expected ret (-1) == 0 (0)
# shutdown_reuse: Test failed
# FAIL tls.13_aes_gcm_mptcp.shutdown_reuse
not ok 15 tls.13_aes_gcm_mptcp.shutdown_reuse
# RUN tls.12_chacha_mptcp.shutdown_reuse ...
# OK tls.12_chacha_mptcp.shutdown_reuse
ok 16 tls.12_chacha_mptcp.shutdown_reuse
# RUN tls.13_chacha_mptcp.shutdown_reuse ...
# OK tls.13_chacha_mptcp.shutdown_reuse
ok 17 tls.13_chacha_mptcp.shutdown_reuse
# RUN tls.13_sm4_gcm_mptcp.shutdown_reuse ...
# tls.c:1790:shutdown_reuse:Expected ret (-1) == 0 (0)
# shutdown_reuse: Test failed
# FAIL tls.13_sm4_gcm_mptcp.shutdown_reuse
not ok 18 tls.13_sm4_gcm_mptcp.shutdown_reuse
Co-developed-by: Gang Yan <yangang@kylinos.cn>
Signed-off-by: Gang Yan <yangang@kylinos.cn>
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
tools/testing/selftests/net/tls.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/tools/testing/selftests/net/tls.c b/tools/testing/selftests/net/tls.c
index 534c4ffd8fd1..45cbdfe8aed4 100644
--- a/tools/testing/selftests/net/tls.c
+++ b/tools/testing/selftests/net/tls.c
@@ -30,6 +30,10 @@
#define IPPROTO_MPTCP 262
#endif
+#ifndef TCP_CLOSE
+#define TCP_CLOSE 7
+#endif
+
static int fips_enabled;
struct tls_crypto_info_keys {
@@ -1671,6 +1675,25 @@ TEST_F(tls, shutdown_unsent)
shutdown(self->cfd, SHUT_RDWR);
}
+static int wait_for_tcp_close(struct __test_metadata *_metadata,
+ int fd, int max)
+{
+ struct tcp_info info;
+ socklen_t len;
+ int i, ret;
+
+ len = sizeof(info);
+ for (i = 0; i < max; i++) {
+ ret = getsockopt(fd, IPPROTO_TCP, TCP_INFO, &info, &len);
+ EXPECT_EQ(ret, 0);
+ if (info.tcpi_state == TCP_CLOSE)
+ return 0;
+ usleep(1000);
+ }
+
+ return -1;
+}
+
TEST_F(tls, shutdown_reuse)
{
struct sockaddr_in addr;
@@ -1680,6 +1703,9 @@ TEST_F(tls, shutdown_reuse)
shutdown(self->cfd, SHUT_RDWR);
close(self->cfd);
+ if (variant->mptcp)
+ EXPECT_EQ(wait_for_tcp_close(_metadata, self->fd, 1000), 0);
+
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_ANY);
addr.sin_port = 0;
--
2.53.0