[CRIU] [PATCH 5/5] zdtm: add a new test to check netlink sockets with queued data

Andrey Vagin avagin at openvz.org
Mon Jun 13 16:35:35 PDT 2016


From: Andrew Vagin <avagin at virtuozzo.com>

Signed-off-by: Andrew Vagin <avagin at virtuozzo.com>
---
 test/zdtm/static/Makefile          |  2 ++
 test/zdtm/static/sk-netlink.c      | 53 +++++++++++++++++++++++++++++++++-----
 test/zdtm/static/sk-netlink02.c    |  1 +
 test/zdtm/static/sk-netlink02.desc |  1 +
 4 files changed, 50 insertions(+), 7 deletions(-)
 create mode 120000 test/zdtm/static/sk-netlink02.c
 create mode 100644 test/zdtm/static/sk-netlink02.desc

diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index b1a6312..e51fcf5 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -120,6 +120,7 @@ TST_NOFILE	=				\
 		sigpending			\
 		sigaltstack			\
 		sk-netlink			\
+		sk-netlink02			\
 		mem-touch			\
 		grow_map			\
 		grow_map02			\
@@ -398,6 +399,7 @@ sk-freebind-false:	override CFLAGS += -DZDTM_FREEBIND_FALSE
 stopped01:	override CFLAGS += -DZDTM_STOPPED_KILL
 stopped02:	override CFLAGS += -DZDTM_STOPPED_TKILL
 stopped12:	override CFLAGS += -DZDTM_STOPPED_KILL -DZDTM_STOPPED_TKILL
+sk-netlink02:	override CFLAGS += -DZDTM_NETLINK_DATA
 
 $(LIB):	force
 	$(Q) $(MAKE) -C $(LIBDIR)
diff --git a/test/zdtm/static/sk-netlink.c b/test/zdtm/static/sk-netlink.c
index f334246..976a140 100644
--- a/test/zdtm/static/sk-netlink.c
+++ b/test/zdtm/static/sk-netlink.c
@@ -76,6 +76,13 @@ int main(int argc, char ** argv)
 		return 1;
 	}
 
+	addr.nl_groups = 1 << (UDEV_MONITOR_TEST - 2);
+	addr.nl_pid = getpid() * 10;
+	if (bind(dsk, (struct sockaddr *) &addr, sizeof(struct sockaddr_nl))) {
+		pr_perror("bind");
+		return 1;
+	}
+
 	addr.nl_pid = getpid();;
 	addr.nl_groups = 1 << (UDEV_MONITOR_TEST - 1);
 	if (connect(csk, (struct sockaddr *) &addr, sizeof(struct sockaddr_nl))) {
@@ -83,10 +90,6 @@ int main(int argc, char ** argv)
 		return 1;
 	}
 
-	test_daemon();
-
-	test_waitsig();
-
 	req.hdr.nlmsg_len       = sizeof(req);
 	req.hdr.nlmsg_type      = 0x1234;
 	req.hdr.nlmsg_flags     = NLM_F_DUMP | NLM_F_REQUEST;
@@ -123,6 +126,11 @@ int main(int argc, char ** argv)
 		return 1;
 	}
 
+#ifndef ZDTM_NETLINK_DATA
+	test_daemon();
+	test_waitsig();
+#endif
+
 	addr.nl_family = AF_NETLINK;
 	addr.nl_groups = 0;
 	addr.nl_pid = getpid();
@@ -134,7 +142,7 @@ int main(int argc, char ** argv)
 	msg.msg_iovlen  = 1;
 
 	iov.iov_base    = (void *) &req;
-	iov.iov_len     = sizeof(req);;
+	iov.iov_len     = sizeof(req);
 
 	if (sendmsg(dsk, &msg, 0) < 0) {
 		pr_perror("Can't send request message");
@@ -142,14 +150,45 @@ int main(int argc, char ** argv)
 	}
 
 	memset(&msg, 0, sizeof(msg));
-	msg.msg_namelen = 0;
+	msg.msg_namelen = sizeof(addr);
+	msg.msg_name	= &addr;
+	msg.msg_iov     = &iov;
+	msg.msg_iovlen  = 1;
+
+	iov.iov_base    = (void *) &req;
+	iov.iov_len     = sizeof(req) - 1;
+
+	if (sendmsg(dsk, &msg, 0) < 0) {
+		pr_perror("Can't send request message");
+		return 1;
+	}
+
+#ifdef ZDTM_NETLINK_DATA
+	test_daemon();
+	test_waitsig();
+#endif
+
+	memset(&msg, 0, sizeof(msg));
+	memset(&addr, 0, sizeof(addr));
+	msg.msg_namelen = sizeof(addr);
+	msg.msg_name	= &addr;
 	msg.msg_iov     = &iov;
 	msg.msg_iovlen  = 1;
 
 	iov.iov_base    = buf;
 	iov.iov_len     = sizeof(buf);
 
-	if (recvmsg(ssk, &msg, 0) < 0) {
+	if (recvmsg(ssk, &msg, 0) != sizeof(req)) {
+		pr_perror("Can't recv request message");
+		return 1;
+	}
+
+	if (addr.nl_pid != getpid() * 10) {
+		fail("address mismatch: %x != %x size %d", addr.nl_pid, getpid(), msg.msg_namelen);
+		return 1;
+	}
+
+	if (recvmsg(ssk, &msg, 0) != sizeof(req) - 1) {
 		pr_perror("Can't recv request message");
 		return 1;
 	}
diff --git a/test/zdtm/static/sk-netlink02.c b/test/zdtm/static/sk-netlink02.c
new file mode 120000
index 0000000..7a4b40b
--- /dev/null
+++ b/test/zdtm/static/sk-netlink02.c
@@ -0,0 +1 @@
+sk-netlink.c
\ No newline at end of file
diff --git a/test/zdtm/static/sk-netlink02.desc b/test/zdtm/static/sk-netlink02.desc
new file mode 100644
index 0000000..9239fb3
--- /dev/null
+++ b/test/zdtm/static/sk-netlink02.desc
@@ -0,0 +1 @@
+{'flags': 'suid', 'feature' : 'nl_repair'}
-- 
2.7.4



More information about the CRIU mailing list