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

Submitted by Pavel Emelyanov on July 10, 2017, 9:37 a.m.

Details

Message ID 6229dbad-4666-78f6-7fed-0780de10d148@virtuozzo.com
State New
Series "Support descriptors sent over unix sockets"
Headers show

Commit Message

Pavel Emelyanov July 10, 2017, 9:37 a.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'}

Comments

Andrei Vagin Aug. 8, 2017, 1:02 a.m.
On Mon, Jul 10, 2017 at 12:37:50PM +0300, Pavel Emelyanov wrote:
> 
> 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
> 
> 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'}

Why do we need crfail here?

> -- 
> 2.1.4
> 
> _______________________________________________
> CRIU mailing list
> CRIU@openvz.org
> https://lists.openvz.org/mailman/listinfo/criu
Pavel Emelyanov Aug. 8, 2017, 9:55 a.m.
On 08/08/2017 04:02 AM, Andrei Vagin wrote:
> On Mon, Jul 10, 2017 at 12:37:50PM +0300, Pavel Emelyanov wrote:
>>
>> 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
>>
>> 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'}
> 
> Why do we need crfail here?

Because by this patch SCMs are not C/R-able :) I'll send patch #19 that removes
these things.

-- Pavel