[01/16] zdtm: Test descriptor sent over unix and kept open

Submitted by Pavel Emelianov on July 6, 2017, 4:14 p.m.

Details

Message ID aa68da4b-16fb-ce4e-d0ab-a31137ff4ad8@virtuozzo.com
State Accepted
Series "Support descriptors sent over unix sockets"
Commit 0a9a76ac4af7ec00139f51edefeb1b2c00456c18
Headers show

Commit Message

Pavel Emelianov July 6, 2017, 4:14 p.m.
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
---
 test/zdtm/static/Makefile   |  2 ++
 test/zdtm/static/scm00.c    | 26 +++++++++++++++++++++-----
 test/zdtm/static/scm01.c    |  1 +
 test/zdtm/static/scm01.desc |  1 +
 4 files changed, 25 insertions(+), 5 deletions(-)
 create mode 120000 test/zdtm/static/scm01.c
 create mode 100644 test/zdtm/static/scm01.desc

Patch hide | download patch | download mbox

diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index 6947e05..661ff7f 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -154,6 +154,7 @@  TST_NOFILE	:=				\
 		remap_dead_pid			\
 		remap_dead_pid_root			\
 		scm00				\
+		scm01				\
 		aio00				\
 		aio01				\
 		fd				\
@@ -442,6 +443,7 @@  socket-tcp-closed-last-ack:	CFLAGS += -D ZDTM_TCP_LAST_ACK
 mnt_ext_manual:		CFLAGS += -D ZDTM_EXTMAP_MANUAL
 sigpending:		LDLIBS += -lrt
 vdso01:			LDLIBS += -lrt
+scm01:			CFLAGS += -DKEEP_SENT_FD
 mntns_link_remap:	CFLAGS += -DZDTM_LINK_REMAP
 mntns_shared_bind02:	CFLAGS += -DSHARED_BIND02
 mntns_root_bind02:	CFLAGS += -DROOT_BIND02
diff --git a/test/zdtm/static/scm00.c b/test/zdtm/static/scm00.c
index 6f0c7b7..39c1473 100644
--- a/test/zdtm/static/scm00.c
+++ b/test/zdtm/static/scm00.c
@@ -68,7 +68,7 @@  static int recv_fd(int via)
 
 int main(int argc, char **argv)
 {
-	int sk[2], p[2];
+	int sk[2], p[2], rfd;
 #define MSG "HELLO"
 	char buf[8]; /* bigger than the MSG to check boundaries */
 
@@ -89,6 +89,7 @@  int main(int argc, char **argv)
 		exit(1);
 	}
 
+#ifndef KEEP_SENT_FD
 	close(p[0]);
 
 	/* Swap pipe ends to make scm recv put pipe into different place */
@@ -96,22 +97,29 @@  int main(int argc, char **argv)
 	close(p[1]);
 	p[1] = p[0];
 	p[0] = -1;
+#endif
 
 	test_daemon();
 	test_waitsig();
 
-	p[0] = recv_fd(sk[1]);
-	if (p[0] < 0) {
+	rfd = recv_fd(sk[1]);
+	if (rfd < 0) {
 		fail("Can't recv pipe back (%d)", p[0]);
 		goto out;
 	}
-
+#ifdef KEEP_SENT_FD
+	if (rfd == p[0]) {
+		fail("Original descriptor not kept");
+		goto out;
+	}
+again:
+#endif
 	if (write(p[1], MSG, sizeof(MSG)) != sizeof(MSG)) {
 		fail("Pipe write-broken");
 		goto out;
 	}
 
-	if (read(p[0], buf, sizeof(buf)) != sizeof(MSG)) {
+	if (read(rfd, buf, sizeof(buf)) != sizeof(MSG)) {
 		fail("Pipe read-broken");
 		goto out;
 	}
@@ -122,6 +130,14 @@  int main(int argc, char **argv)
 		goto out;
 	}
 
+#ifdef KEEP_SENT_FD
+	if (rfd != p[0]) {
+		test_msg("Check kept\n");
+		rfd = p[0];
+		goto again;
+	}
+#endif
+
 	pass();
 out:
 	return 0;
diff --git a/test/zdtm/static/scm01.c b/test/zdtm/static/scm01.c
new file mode 120000
index 0000000..4cab0ed
--- /dev/null
+++ b/test/zdtm/static/scm01.c
@@ -0,0 +1 @@ 
+scm00.c
\ No newline at end of file
diff --git a/test/zdtm/static/scm01.desc b/test/zdtm/static/scm01.desc
new file mode 100644
index 0000000..ded8987
--- /dev/null
+++ b/test/zdtm/static/scm01.desc
@@ -0,0 +1 @@ 
+{'flags': 'crfail'}