[15/15] test: pty05 -- Add testing of multiple devpts instance

Submitted by Andrey Vagin on Sept. 26, 2018, 7:37 p.m.

Details

Message ID 20180926193743.GC19690@outlook.office365.com
State New
Series "tty: Add support for multiple devtps instances"
Headers show

Commit Message

Andrey Vagin Sept. 26, 2018, 7:37 p.m.
[root@fc24 criu]# python test/zdtm.py run -t zdtm/static/pty05  --iter 1
Checking feature mnt_id
=== Run 1/1 ================ zdtm/static/pty05
========================= Run zdtm/static/pty05 in ns ==========================
Start test
Test is SUID
./pty05 --pidfile=pty05.pid --outfile=pty05.out --dirname=pty05.test
Run criu dump
=[log]=> dump/zdtm/static/pty05/43/1/dump.log
------------------------ grep Error ------------------------
(00.011803) mnt: Inspecting sharing on 232 shared_id 0 master_id -1 (@./)
(00.011809) Collecting netns 9/43
(00.011814) Switching to 43's net for collecting sockets
(00.011990) unix: 	Collected: ino 39566 peer_ino 0 family    1 type    5 state  7 name (null)
(00.012175) Error (criu/libnetlink.c:27): ERROR -2 reported by netlink (No such file or directory)
(00.012182) Warn  (criu/sockets.c:791): sockets: The current kernel doesn't support ipv4 raw_diag module
(00.012380) Error (criu/libnetlink.c:27): ERROR -2 reported by netlink (No such file or directory)
(00.024245) tty: Dumping tty ./zdtm/static/pty05.test/lvl1/1 fd 7 (mnt_id 193 st_dev 0x34) with id 0x11
(00.024254) mnt: tty: resolving path ./zdtm/static/pty05.test/lvl1/1 mnt_id 193 s_dev 0x34
(00.024261) mnt: tty: pre-resolved path ./zdtm/static/pty05.test/lvl1/1 to mnt_id 193 root / ns_mountpoint ./zdtm/static/pty05.test/lvl1 source devpts fstype devpts 6
(00.024269) mnt: tty: bindmount on mnt_id 193 root / ns_mountpoint ./zdtm/static/pty05.test/lvl1 source devpts fstype devpts 6
(00.024276) Error (criu/mount.c:387): mnt: tty: Can't resolve devpts for s_dev 0x34
(00.024282) Error (criu/tty.c:2235): tty: Can't obtain mnt_id on tty 27 id 0x11
(00.024294) ----------------------------------------
(00.024325) Error (criu/cr-dump.c:1348): Dump files (pid: 46) failed with -1
(00.025250) Running network-unlock scripts
(00.029799) Unfreezing tasks into 1
(00.029824) 	Unseizing 43 into 1
(00.029841) 	Unseizing 46 into 1
(00.029867) Error (criu/cr-dump.c:1744): Dumping FAILED.
------------------------ ERROR OVER ------------------------
################### Test zdtm/static/pty05 FAIL at CRIU dump ###################
Send the 9 signal to  43
Wait for zdtm/static/pty05(43) to die for 0.100000
##################################### FAIL #####################################


On Fri, Sep 07, 2018 at 07:18:36PM +0300, Cyrill Gorcunov wrote:
> Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
> ---
>  test/zdtm/static/Makefile   |   1 +
>  test/zdtm/static/pty05.c    | 183 ++++++++++++++++++++++++++++++++++++
>  test/zdtm/static/pty05.desc |   1 +
>  3 files changed, 185 insertions(+)
>  create mode 100644 test/zdtm/static/pty05.c
>  create mode 100644 test/zdtm/static/pty05.desc
> 
> diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
> index fe67747db954..416c3d2bb11c 100644
> --- a/test/zdtm/static/Makefile
> +++ b/test/zdtm/static/Makefile
> @@ -340,6 +340,7 @@ TST_DIR		=				\
>  		shared_slave_mount_children	\
>  		non_uniform_share_propagation	\
>  		private_bind_propagation	\
> +		pty05				\
>  
>  TST_DIR_FILE	=				\
>  		chroot				\
> diff --git a/test/zdtm/static/pty05.c b/test/zdtm/static/pty05.c
> new file mode 100644
> index 000000000000..f900e559f204
> --- /dev/null
> +++ b/test/zdtm/static/pty05.c
> @@ -0,0 +1,183 @@
> +#define _XOPEN_SOURCE 500
> +
> +#include <termios.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <unistd.h>
> +#include <signal.h>
> +#include <limits.h>
> +#include <fcntl.h>
> +
> +#include <sys/types.h>
> +#include <sys/stat.h>
> +#include <sys/ioctl.h>
> +#include <sys/mount.h>
> +
> +#include "zdtmtst.h"
> +
> +const char *test_doc	= "Test multiple PTYs with different session leaders";
> +const char *test_author	= "Cyrill Gorcunov <gorcunov@openvz.org>";
> +
> +char *dirname;
> +TEST_OPTION(dirname, string, "directory name", 1);
> +
> +static int pty_get_index(int fd)
> +{
> +	int index;
> +
> +	if (ioctl(fd, TIOCGPTN, &index)) {
> +		pr_perror("Can't fetch ptmx index");
> +		return -1;
> +	}
> +
> +	return index;
> +}
> +
> +static int open_pty_pair(char *dir, int *fdm, int *fds)
> +{
> +	char path[PATH_MAX];
> +	int index;
> +
> +	snprintf(path, sizeof(path), "%s/ptmx", dir);
> +	*fdm = open(path, O_RDWR);
> +	if (*fdm < 0) {
> +		pr_perror("Can't open %s", path);
> +		return -1;
> +	}
> +
> +	grantpt(*fdm);
> +	unlockpt(*fdm);
> +
> +	index = pty_get_index(*fdm);
> +	if (index < 0) {
> +		close(*fdm);
> +		return -1;
> +	}
> +
> +	snprintf(path, sizeof(path), "%s/%d", dir, index);
> +	*fds = open(path, O_RDWR);
> +	if (*fds < 0) {
> +		pr_perror("Can't open %s\n", path);
> +		close(*fdm);
> +		return -1;
> +	}
> +
> +	test_msg("Created pair %d/%d index %d\n", *fdm, *fds, index);
> +	return 0;
> +}
> +
> +int main(int argc, char *argv[])
> +{
> +	char path[PATH_MAX], *dir1, *dir2;
> +	struct peer_s {
> +		char	*str;
> +		int	size;
> +		int	fdm;
> +		int	fds;
> +	} peers[2] = {
> +		{ .str = "hello1\n", .size = 7, },
> +		{ .str = "hello2\n", .size = 7, } };
> +	int ret, retval = 1, i;
> +	char buf[64];
> +
> +	test_init(argc, argv);
> +
> +	if (mkdir(dirname, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) {
> +		pr_perror("Can't create testing directory %s", dirname);
> +		exit(1);
> +	}
> +
> +	snprintf(path, sizeof(path), "%s/%s", dirname, "lvl1");
> +	dir1 = strdup(path);
> +
> +	if (!dir1 || mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) {
> +		pr_perror("Can't create testing directory %s", path);
> +		exit(1);
> +	}
> +	test_msg("Mounting first devpts at %s\n", dir1);
> +	if (mount("devpts", path, "devpts", 0, "newinstance,ptmxmode=0666")) {
> +		pr_perror("Can't mount testing directory %s", path);
> +		exit(1);
> +	}
> +
> +	snprintf(path, sizeof(path), "%s/%s", dirname, "lvl2");
> +	dir2 = strdup(path);
> +	if (!dir2 || mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) {
> +		umount2(dir1, MNT_DETACH);
> +		pr_perror("Can't create testing directory %s", path);
> +		exit(1);
> +	}
> +	test_msg("Mounting second devpts at %s\n", dir2);
> +	if (mount("devpts", path, "devpts", 0, "newinstance,ptmxmode=0666")) {
> +		umount2(dir1, MNT_DETACH);
> +		pr_perror("Can't mount testing directory %s", path);
> +		exit(1);
> +	}
> +
> +	if (open_pty_pair(dir1, &peers[0].fdm, &peers[0].fds) ||
> +	    open_pty_pair(dir2, &peers[1].fdm, &peers[1].fds)) {
> +		umount2(dir1, MNT_DETACH);
> +		umount2(dir2, MNT_DETACH);
> +		exit(1);
> +	}
> +
> +	for (i = 0; i < ARRAY_SIZE(peers); i++) {
> +		test_msg("Writting %d bytes into fds %d\n", peers[i].size, peers[i].fds);
> +		ret = write(peers[i].fds, peers[i].str, peers[i].size);
> +		if (ret != peers[i].size) {
> +			pr_perror("Can't write into fds %d, "
> +				  "%d bytes but %d expected",
> +				  peers[i].fds, ret, peers[i].size);
> +			exit(1);
> +		}
> +	}
> +
> +	test_daemon();
> +	test_waitsig();
> +
> +	signal(SIGHUP, SIG_IGN);
> +
> +	for (i = 0; i < ARRAY_SIZE(peers); i++) {
> +		memset(buf, 0, sizeof(buf));
> +		test_msg("Reading %d bytes from fdm %d\n", peers[i].size, peers[i].fdm);
> +		ret = read(peers[i].fdm, buf, peers[i].size);
> +		if (ret != peers[i].size) {
> +			fail("Can't read from fdm %d, "
> +			     "got %d bytes but %d expected",
> +			     peers[i].fdm, ret, peers[i].size);
> +			goto out;
> +		}
> +
> +		if (strncmp(buf, peers[i].str, peers[i].size - 1)) {
> +			fail("Data mismatch on fdm %d (got %s but %s expected)",
> +			     peers[i].fdm, buf, peers[i].str);
> +			goto out;
> +		}
> +	}
> +
> +	retval = 0;
> +out:
> +	for (i = 0; i < ARRAY_SIZE(peers); i++) {
> +		close(peers[i].fds);
> +		close(peers[i].fdm);
> +	}
> +
> +	if (umount2(dir1, MNT_DETACH))
> +		pr_perror("Can't unmount %s\n", dir1);
> +	if (umount2(dir2, MNT_DETACH))
> +		pr_perror("Can't unmount %s\n", dir2);
> +	if (rmdir(dir1))
> +		pr_perror("Can't remove %s", dir1);
> +	if (rmdir(dir2))
> +		pr_perror("Can't remove %s", dir2);
> +	if (rmdir(dirname))
> +		pr_perror("Can't remove %s", dirname);
> +
> +	free(dir1);
> +	free(dir2);
> +
> +	if (retval == 0)
> +		pass();
> +
> +	return retval;
> +}
> diff --git a/test/zdtm/static/pty05.desc b/test/zdtm/static/pty05.desc
> new file mode 100644
> index 000000000000..3fd8e03f7ed7
> --- /dev/null
> +++ b/test/zdtm/static/pty05.desc
> @@ -0,0 +1 @@
> +{'flavor': 'ns', 'flags': 'suid', 'feature': 'mnt_id'}
> -- 
> 2.17.1
>

Patch hide | download patch | download mbox

diff --git a/test/zdtm/static/pty05.c b/test/zdtm/static/pty05.c
index f900e559f..e242b3964 100644
--- a/test/zdtm/static/pty05.c
+++ b/test/zdtm/static/pty05.c
@@ -74,9 +74,12 @@  int main(int argc, char *argv[])
                int     size;
                int     fdm;
                int     fds;
-       } peers[2] = {
+       } peers[4] = {
                { .str = "hello1\n", .size = 7, },
-               { .str = "hello2\n", .size = 7, } };
+               { .str = "hello2\n", .size = 7, },
+               { .str = "hello3\n", .size = 7, },
+               { .str = "hello4\n", .size = 7, },
+       };
        int ret, retval = 1, i;
        char buf[64];
 
@@ -114,7 +117,10 @@  int main(int argc, char *argv[])
                exit(1);
        }
 
-       if (open_pty_pair(dir1, &peers[0].fdm, &peers[0].fds) ||
+       if (
+               open_pty_pair(dir1, &peers[0].fdm, &peers[0].fds) ||
+               open_pty_pair(dir1, &peers[2].fdm, &peers[2].fds) ||
+               open_pty_pair(dir2, &peers[3].fdm, &peers[3].fds) ||
            open_pty_pair(dir2, &peers[1].fdm, &peers[1].fds)) {
                umount2(dir1, MNT_DETACH);
                umount2(dir2, MNT_DETACH);

Comments

Cyrill Gorcunov Sept. 26, 2018, 9:06 p.m.
On Wed, Sep 26, 2018 at 07:37:51PM +0000, Andrey Vagin wrote:
> diff --git a/test/zdtm/static/pty05.c b/test/zdtm/static/pty05.c
> index f900e559f..e242b3964 100644
> --- a/test/zdtm/static/pty05.c
> +++ b/test/zdtm/static/pty05.c
> @@ -74,9 +74,12 @@ int main(int argc, char *argv[])
>                 int     size;
>                 int     fdm;
>                 int     fds;
> -       } peers[2] = {
> +       } peers[4] = {
>                 { .str = "hello1\n", .size = 7, },
> -               { .str = "hello2\n", .size = 7, } };
> +               { .str = "hello2\n", .size = 7, },
> +               { .str = "hello3\n", .size = 7, },
> +               { .str = "hello4\n", .size = 7, },
> +       };

Thanks a lot! I'll take a look! And indeed the former reason
we've started to support this multiple devtps was docker running
inside our container. It is under the question now if we even
need this code.