[CRIU] [PATCH 1/2] zdtm: check that data in unix dgram sockets are restored correctly

Tycho Andersen tycho.andersen at canonical.com
Mon Aug 3 06:36:51 PDT 2015


On Mon, Aug 03, 2015 at 03:47:15PM +0300, Pavel Emelyanov wrote:
> On 08/01/2015 10:26 PM, Andrey Vagin wrote:
> 
> We already have test titled static/sockets03 doing approximately
> the same. Can we somehow merge these two?

Sure, I think it should just check to make sure the messages are
what it sent; I can send a patch for that.

Tycho

> > Signed-off-by: Andrey Vagin <avagin at openvz.org>
> > ---
> >  test/zdtm/live/static/Makefile            |  1 +
> >  test/zdtm/live/static/socket-dgram-data.c | 82 +++++++++++++++++++++++++++++++
> >  2 files changed, 83 insertions(+)
> >  create mode 100644 test/zdtm/live/static/socket-dgram-data.c
> > 
> > diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
> > index 7575f7d..4f14793 100644
> > --- a/test/zdtm/live/static/Makefile
> > +++ b/test/zdtm/live/static/Makefile
> > @@ -34,6 +34,7 @@ TST_NOFILE	=				\
> >  		socket_udplite			\
> >  		socket_aio			\
> >  		socket_close_data		\
> > +		socket-dgram-data		\
> >  		packet_sock			\
> >  		packet_sock_mmap		\
> >  		sock_filter			\
> > diff --git a/test/zdtm/live/static/socket-dgram-data.c b/test/zdtm/live/static/socket-dgram-data.c
> > new file mode 100644
> > index 0000000..aa41792
> > --- /dev/null
> > +++ b/test/zdtm/live/static/socket-dgram-data.c
> > @@ -0,0 +1,82 @@
> > +#define _GNU_SOURCE
> > +#include <errno.h>
> > +#include <stdlib.h>
> > +#include <string.h>
> > +#include <sys/types.h>
> > +#include <sys/socket.h>
> > +#include <sys/un.h>
> > +
> > +#include "zdtmtst.h"
> > +
> > +const char *test_doc	= "Check that data in dgram socket are restored correctly";
> > +const char *test_author	= "Andrew Vagin <avagin at openvz.org";
> > +
> > +#define SK_SRV "\0socket_snd_srv"
> > +
> > +#define MSG "hello"
> > +int main(int argc, char **argv)
> > +{
> > +	struct sockaddr_un addr;
> > +	unsigned int addrlen;
> > +	int srv, clnt1, clnt2, ret;
> > +	char buf[1024];
> > +
> > +	test_init(argc, argv);
> > +
> > +	srv = socket(PF_UNIX, SOCK_DGRAM | SOCK_NONBLOCK, 0);
> > +	if (srv < 0) {
> > +		err("socket");
> > +		return 1;
> > +	}
> > +	clnt1 = socket(PF_UNIX, SOCK_DGRAM | SOCK_NONBLOCK, 0);
> > +	if (clnt1 < 0) {
> > +		err("socket");
> > +		return 1;
> > +	}
> > +	clnt2 = socket(PF_UNIX, SOCK_DGRAM | SOCK_NONBLOCK, 0);
> > +	if (clnt2 < 0) {
> > +		err("socket");
> > +		return 1;
> > +	}
> > +
> > +	addr.sun_family = AF_UNIX;
> > +	memcpy(addr.sun_path, SK_SRV, sizeof(SK_SRV));
> > +	addrlen = sizeof(addr.sun_family) + sizeof(SK_SRV);
> > +
> > +	if (bind(srv, &addr, addrlen)) {
> > +		fail("bind\n");
> > +		exit(1);
> > +	}
> > +	if (connect(clnt1, &addr, addrlen)) {
> > +		fail("connect\n");
> > +		exit(1);
> > +	}
> > +	if (connect(clnt2, &addr, addrlen)) {
> > +		fail("connect\n");
> > +		exit(1);
> > +	}
> > +
> > +	if (write(clnt1, MSG, sizeof(MSG)) != sizeof(MSG)) {
> > +		err("write");
> > +		return 1;
> > +	}
> > +
> > +	test_daemon();
> > +	test_waitsig();
> > +
> > +	ret = read(srv, buf, sizeof(buf));
> > +	buf[ret > 0 ? ret : 0] = 0;
> > +	if (ret != sizeof(MSG)) {
> > +		fail("%d: %s", ret, buf);
> > +		return 1;
> > +	}
> > +
> > +	ret = read(srv, buf, sizeof(buf));
> > +	if (ret != -1 || errno != EAGAIN) {
> > +		fail("unexpected data: %d", ret);
> > +		return 1;
> > +	}
> > +
> > +	pass();
> > +	return 0;
> > +}
> > 
> 


More information about the CRIU mailing list