[CRIU] [PATCH] test/static: Add test for --skip-in-flight

Radostin Stoyanov rstoyanov1 at gmail.com
Fri Dec 28 03:00:49 MSK 2018


Signed-off-by: Radostin Stoyanov <rstoyanov1 at gmail.com>
---
 test/zdtm/static/Makefile                     |  2 +
 test/zdtm/static/socket-tcp-skip-in-flight.c  | 93 +++++++++++++++++++
 .../static/socket-tcp-skip-in-flight.desc     |  1 +
 3 files changed, 96 insertions(+)
 create mode 100644 test/zdtm/static/socket-tcp-skip-in-flight.c
 create mode 100644 test/zdtm/static/socket-tcp-skip-in-flight.desc

diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index 7b8d6637..2d13e7d2 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -104,6 +104,7 @@ TST_NOFILE	:=				\
 		socket-tcp-unconn		\
 		socket-tcp6-unconn		\
 		socket-tcp-syn-sent		\
+		socket-tcp-skip-in-flight       \
 		sock_opts00			\
 		sock_opts01			\
 		sk-unix-unconn			\
@@ -486,6 +487,7 @@ socket_listen4v6:	CFLAGS += -D ZDTM_IPV4V6
 socket-tcp6-closed:	CFLAGS += -D ZDTM_IPV6
 socket-tcp6-closed:	CFLAGS += -D ZDTM_IPV4V6
 socket-tcp-closed-last-ack:	CFLAGS += -D ZDTM_TCP_LAST_ACK
+socket-tcp-skip-in-flight:	CFLAGS += -D ZDTM_IPV4V6
 tun_ns:			CFLAGS += -DTUN_NS
 mnt_ext_manual:		CFLAGS += -D ZDTM_EXTMAP_MANUAL
 sigpending:		LDLIBS += -lrt
diff --git a/test/zdtm/static/socket-tcp-skip-in-flight.c b/test/zdtm/static/socket-tcp-skip-in-flight.c
new file mode 100644
index 00000000..d9b4e3dd
--- /dev/null
+++ b/test/zdtm/static/socket-tcp-skip-in-flight.c
@@ -0,0 +1,93 @@
+#include "zdtmtst.h"
+
+#ifdef ZDTM_IPV4V6
+#define ZDTM_FAMILY AF_INET
+#define ZDTM_SRV_FAMILY AF_INET6
+#elif defined(ZDTM_IPV6)
+#define ZDTM_FAMILY AF_INET6
+#define ZDTM_SRV_FAMILY AF_INET6
+#else
+#define ZDTM_FAMILY AF_INET
+#define ZDTM_SRV_FAMILY AF_INET
+#endif
+
+const char *test_doc = "Check that in-flight TCP connections are ignored\n";
+const char *test_author = "Radostin Stoyanov <rstoyanov1 at gmail.com";
+
+/* Description:
+ * Initialise server and client tcp sockets and verify that
+ * in-flight TCP connections are closed after restore.
+ */
+
+#include <linux/types.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/tcp.h>
+#include <netinet/in.h>
+
+static int port = 8880;
+
+static int check_socket_state(int sk, int state)
+{
+        int err;
+        struct {
+                __u8    tcpi_state;
+        } info;
+        socklen_t len = sizeof(info);
+
+        err = getsockopt(sk, IPPROTO_TCP, TCP_INFO, (void *)&info, &len);
+        if (err != 0) {
+                pr_perror("Can't get socket state\n");
+                return -1;
+        } else if (info.tcpi_state != state) {
+                pr_err("Invalid socket state (%i)\n", (int)info.tcpi_state);
+                return -1;
+        }
+
+        return 0;
+}
+
+int main(int argc, char **argv)
+{
+    int fd_s;
+    int clt;
+
+    test_init(argc, argv);
+
+    if ((fd_s = tcp_init_server(ZDTM_SRV_FAMILY, &port)) < 0) {
+        pr_perror("Failed to initialize server");
+        return 1;
+    }
+    clt = tcp_init_client(ZDTM_FAMILY, "localhost", port);
+    if (clt < 0) {
+        pr_perror("Unable to create a client socket");
+        return 1;
+    }
+
+    if (check_socket_state(fd_s, TCP_LISTEN)) {
+            fail("Server socket state isn't TCP_LISTEN\n");
+            return 1;
+    }
+    if (check_socket_state(clt, TCP_ESTABLISHED)) {
+            fail("Client socket isn't TCP_ESTABLISHED\n");
+            return 1;
+    }
+
+    test_daemon();
+    test_waitsig();
+
+    if (check_socket_state(fd_s, TCP_LISTEN)) {
+            fail("Server socket state isn't TCP_LISTEN\n");
+            return 1;
+    }
+    if (check_socket_state(clt, TCP_CLOSE)) {
+            fail("Client socket state isn't TCP_CLOSE\n");
+            return 1;
+    }
+
+    close(fd_s);
+    close(clt);
+
+    pass();
+    return 0;
+}
diff --git a/test/zdtm/static/socket-tcp-skip-in-flight.desc b/test/zdtm/static/socket-tcp-skip-in-flight.desc
new file mode 100644
index 00000000..b76d811d
--- /dev/null
+++ b/test/zdtm/static/socket-tcp-skip-in-flight.desc
@@ -0,0 +1 @@
+{'flavor': 'h ns uns', 'opts': '--tcp-established --skip-in-flight'}
--
2.20.1



More information about the CRIU mailing list