[CRIU] Re: [PATCH 7/7] zdtm: Add socket6_udp test

Cyrill Gorcunov gorcunov at openvz.org
Fri Apr 20 18:58:36 EDT 2012


On Sat, Apr 21, 2012 at 02:56:40AM +0400, Cyrill Gorcunov wrote:
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---

The code itself escaped git index. See enveloped.

	Cyrill
-------------- next part --------------
>From cdce29d6e16a34bf3747a6323176027bc3a29393 Mon Sep 17 00:00:00 2001
From: Cyrill Gorcunov <gorcunov at openvz.org>
Date: Sat, 21 Apr 2012 02:57:38 +0400
Subject: [PATCH] zdtm: Add socket6_udp test

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 test/zdtm.sh                        |    1 +
 test/zdtm/live/static/Makefile      |    1 +
 test/zdtm/live/static/socket6_udp.c |  124 +++++++++++++++++++++++++++++++++++
 3 files changed, 126 insertions(+), 0 deletions(-)
 create mode 100644 test/zdtm/live/static/socket6_udp.c

diff --git a/test/zdtm.sh b/test/zdtm.sh
index f33a61e..6b8faa7 100644
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -35,6 +35,7 @@ static/caps00
 static/cmdlinenv00
 static/socket_listen
 static/socket_udp
+static/socket6_udp
 static/socket_udplite
 static/selfexe00
 static/file_fown
diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index 0f1e0df..373ede7 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -20,6 +20,7 @@ TST_NOFILE	=				\
 		unbound_sock			\
 		socket_listen			\
 		socket_udp			\
+		socket6_udp			\
 		socket_udplite			\
 		socket_aio			\
 		msgque				\
diff --git a/test/zdtm/live/static/socket6_udp.c b/test/zdtm/live/static/socket6_udp.c
new file mode 100644
index 0000000..c9fd2fa
--- /dev/null
+++ b/test/zdtm/live/static/socket6_udp.c
@@ -0,0 +1,124 @@
+#include "zdtmtst.h"
+
+const char *test_doc = "Static test for IP6/UDP socket\n";
+const char *test_author = "Cyrill Gorcunov <gorcunov at openvz.org>\n";
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>  /* for sockaddr_in and inet_ntoa() */
+#include <wait.h>
+
+static int port = 8880;
+static char buf[64];
+
+#define MSG1 "msg1"
+#define MSG2 "msg_2"
+
+int main(int argc, char **argv)
+{
+	int ret, sk1, sk2;
+	socklen_t len = sizeof(struct sockaddr_in6);
+	struct sockaddr_in6 addr1, addr2, addr;
+
+	test_init(argc, argv);
+
+	sk1 = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
+	if (sk1 < 0) {
+		err("Can't create socket");
+		return 1;
+	}
+
+	memset(&addr1, 0, sizeof(addr1));
+	addr1.sin6_family = AF_INET6;
+	addr1.sin6_port = htons(port);
+	inet_pton(AF_INET6, "::1", &addr1.sin6_addr);
+
+	ret = bind(sk1, (struct sockaddr *)&addr1, len);
+	if (ret < 0) {
+		err("Can't bind socket");
+		return 1;
+	}
+
+	sk2 = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
+	if (sk2 < 0) {
+		err("Can't create socket");
+		return 1;
+	}
+
+	memset(&addr2, 0, sizeof(addr2));
+	addr2.sin6_family = AF_INET6;
+	addr2.sin6_port = htons(port+1);
+	inet_pton(AF_INET6, "::1", &addr2.sin6_addr);
+
+	ret = bind(sk2, (struct sockaddr *)&addr2, len);
+	if (ret < 0) {
+		err("Can't bind socket");
+		return 1;
+	}
+
+	ret = connect(sk2, (struct sockaddr *)&addr1, len);
+	if (ret < 0) {
+		err("Can't connect");
+		return 1;
+	}
+
+	test_daemon();
+	test_waitsig();
+
+	ret = sendto(sk1, MSG1, sizeof(MSG1), 0,
+			(struct sockaddr *)&addr2, len);
+	if (ret < 0) {
+		fail("Can't send");
+		return 1;
+	}
+
+	ret = send(sk2, MSG2, sizeof(MSG2), 0);
+	if (ret < 0) {
+		fail("Can't send C");
+		return 1;
+	}
+
+	ret = recvfrom(sk1, buf, sizeof(buf), MSG_DONTWAIT,
+			(struct sockaddr *)&addr, &len);
+	if (ret <= 0) {
+		fail("Can't recv C");
+		return 1;
+	}
+
+	if (len != sizeof(struct sockaddr_in6) || memcmp(&addr2, &addr, len)) {
+		fail("Wrong peer C");
+		return 1;
+	}
+
+	if (ret != sizeof(MSG2) || memcmp(buf, MSG2, ret)) {
+		fail("Wrong message C");
+		return 1;
+	}
+
+	ret = recvfrom(sk2, buf, sizeof(buf), MSG_DONTWAIT,
+			(struct sockaddr *)&addr, &len);
+	if (ret <= 0) {
+		fail("Can't recv");
+		return 1;
+	}
+
+	if (len != sizeof(struct sockaddr_in6) || memcmp(&addr1, &addr, len)) {
+		fail("Wrong peer");
+		return 1;
+	}
+
+	if (ret != sizeof(MSG1) || memcmp(buf, MSG1, ret)) {
+		fail("Wrong message");
+		return 1;
+	}
+
+	pass();
+	return 0;
+}
-- 
1.7.7.6



More information about the CRIU mailing list