[CRIU] [PATCH v2 2/2] zdtm: Add socket_close_data01 test

Pavel Emelyanov xemul at parallels.com
Mon Nov 30 01:11:26 PST 2015


On 11/26/2015 08:56 PM, Kirill Tkhai wrote:
> This test is for unix sockets open in DGRAM mode.
> Server opens a socket, binds it and waits for a signal.
> Client connects to the socket and sends a message.
> 
> After the signal server checks that data is readable,
> and that it's still possible to connect to the bound
> socket.

What's the difference from socket_close_data01?

> Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
> ---
>  test/zdtm/.gitignore                        |    1 
>  test/zdtm/live/static/Makefile              |    1 
>  test/zdtm/live/static/socket_close_data01.c |  111 +++++++++++++++++++++++++++
>  3 files changed, 113 insertions(+)
>  create mode 100644 test/zdtm/live/static/socket_close_data01.c
> 
> diff --git a/test/zdtm/.gitignore b/test/zdtm/.gitignore
> index 166c26d..097ea26 100644
> --- a/test/zdtm/.gitignore
> +++ b/test/zdtm/.gitignore
> @@ -142,6 +142,7 @@
>  /live/static/socket6_udp
>  /live/static/socket_aio
>  /live/static/socket_close_data
> +/live/static/socket_close_data01
>  /live/static/socket_dgram_data
>  /live/static/socket_listen
>  /live/static/socket_listen6
> diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
> index 66920ca..d710ded 100644
> --- a/test/zdtm/live/static/Makefile
> +++ b/test/zdtm/live/static/Makefile
> @@ -36,6 +36,7 @@ TST_NOFILE	=				\
>  		socket_udplite			\
>  		socket_aio			\
>  		socket_close_data		\
> +		socket_close_data01		\
>  		socket_snd_addr			\
>  		socket_dgram_data		\
>  		packet_sock			\
> diff --git a/test/zdtm/live/static/socket_close_data01.c b/test/zdtm/live/static/socket_close_data01.c
> new file mode 100644
> index 0000000..9539ea5
> --- /dev/null
> +++ b/test/zdtm/live/static/socket_close_data01.c
> @@ -0,0 +1,111 @@
> +#include <errno.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <sys/types.h>
> +#include <sys/socket.h>
> +#include <sys/types.h>
> +#include <sys/wait.h>
> +#include <sys/un.h>
> +
> +#include "zdtmtst.h"
> +
> +const char *test_doc	= "Check data of bound socket and possibility to connect";
> +const char *test_author	= "Kirill Tkhai <ktkhai at virtuozzo";
> +
> +#define MSG "hello"
> +#define NAME "socket_close_data01.sock"
> +
> +static int client(const char *iter)
> +{
> +	struct sockaddr_un addr;
> +	int sk;
> +
> +	sk = socket(AF_UNIX, SOCK_DGRAM, 0);
> +	if (sk < 0) {
> +		pr_perror("open client %s", iter);
> +		return 1;
> +	}
> +
> +	addr.sun_family = AF_UNIX;
> +	strcpy(addr.sun_path, NAME);
> +
> +	if (connect(sk, (void *)&addr, sizeof(struct sockaddr_un)) < 0) {
> +		pr_perror("connect failed %s\n", iter);
> +		return 1;
> +	}
> +
> +	if (send(sk, MSG, sizeof(MSG), 0) != sizeof(MSG)) {
> +		pr_perror("send failed %s\n", iter);
> +		return 1;
> +	}
> +
> +	return 0;
> +}
> +
> +int main(int argc, char **argv)
> +{
> +	struct sockaddr_un addr;
> +	int srv, status, ret;
> +	char buf[1024];
> +
> +	test_init(argc, argv);
> +
> +	srv = socket(AF_UNIX, SOCK_DGRAM | SOCK_NONBLOCK, 0);
> +	if (srv < 0) {
> +		pr_perror("open srv");
> +		exit(1);
> +	}
> +
> +	addr.sun_family = AF_UNIX;
> +	strcpy(addr.sun_path, NAME);
> +
> +	if (bind(srv, (struct sockaddr *) &addr, sizeof(struct sockaddr_un))) {
> +		pr_perror("bind srv");
> +		exit(1);
> +	}
> +
> +	if (fork() == 0) {
> +		close(srv);
> +		client("(iter1)");
> +		exit(0);
> +	}
> +
> +	test_daemon();
> +	test_waitsig();
> +
> +	/* Test1: check we can read client message: */
> +	ret = read(srv, buf, sizeof(MSG));
> +	buf[ret > 0 ? ret : 0] = 0;
> +	if (ret != sizeof(MSG)) {
> +		fail("%d: %s", ret, buf);
> +		ret = 1;
> +		goto unlink;
> +	}
> +
> +	ret = 1;
> +	if (wait(NULL) == -1) {
> +		fail("wait failed");
> +		goto unlink;
> +	}
> +
> +	/* Test2: check it's still possible to connect to the bound socket */
> +	if (fork() == 0) {
> +		exit(client("(iter2)"));
> +	}
> +
> +	if (wait(&status) < 0) {
> +		fail("wait failed");
> +		goto unlink;
> +	}
> +
> +	if (WEXITSTATUS(status) != 0) {
> +		fail("connect failed");
> +		goto unlink;
> +	}
> +
> +	ret = 0;
> +	pass();
> +unlink:
> +	unlink(NAME);
> +	return ret;
> +}
> 
> .
> 



More information about the CRIU mailing list