mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-08-04 07:43:23 +00:00
test/unix: check C/R of unix listen queues
Check that CRIU handles non-empty listen queues properly. Signed-off-by: Andrei Vagin <avagin@gmail.com> [mclapinski@google.com: update test_doc and test_author] Signed-off-by: Michal Clapinski <mclapinski@google.com>
This commit is contained in:
parent
83c606e023
commit
aeaff64452
8 changed files with 131 additions and 0 deletions
|
|
@ -352,6 +352,10 @@ TST_FILE = \
|
|||
socket_close_data01 \
|
||||
fifo_upon_unix_socket00 \
|
||||
fifo_upon_unix_socket01 \
|
||||
sk-unix-listen01 \
|
||||
sk-unix-listen02 \
|
||||
sk-unix-listen03 \
|
||||
sk-unix-listen04 \
|
||||
|
||||
TST_DIR = \
|
||||
cwd00 \
|
||||
|
|
@ -670,6 +674,10 @@ bpf_array: LDLIBS += -lbpf
|
|||
|
||||
fifo_upon_unix_socket01: CFLAGS += -DFIFO_UPON_UNIX01
|
||||
|
||||
sk-unix-listen02: CFLAGS += -DSK_UNIX_LISTEN02
|
||||
sk-unix-listen03: CFLAGS += -DSK_UNIX_LISTEN03
|
||||
sk-unix-listen04: CFLAGS += -DSK_UNIX_LISTEN02 -DSK_UNIX_LISTEN03
|
||||
|
||||
$(LIB): force
|
||||
$(Q) $(MAKE) -C $(LIBDIR)
|
||||
|
||||
|
|
|
|||
117
test/zdtm/static/sk-unix-listen01.c
Normal file
117
test/zdtm/static/sk-unix-listen01.c
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mount.h>
|
||||
#include <limits.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "zdtmtst.h"
|
||||
|
||||
const char *test_doc = "Test in-flight unix sockets with data in them\n";
|
||||
const char *test_author = "Andrei Vagin <avagin@gmail.com>";
|
||||
|
||||
#define SK_DATA "packet"
|
||||
|
||||
char *filename;
|
||||
TEST_OPTION(filename, string, "socket file name", 1);
|
||||
|
||||
#define TEST_MODE 0640
|
||||
|
||||
#ifdef ZDTM_UNIX_SEQPACKET
|
||||
#define SOCK_TYPE SOCK_SEQPACKET
|
||||
#else
|
||||
#define SOCK_TYPE SOCK_STREAM
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct sockaddr_un addr;
|
||||
unsigned int addrlen;
|
||||
int ssk, sk;
|
||||
|
||||
char path[PATH_MAX];
|
||||
char *cwd;
|
||||
int ret;
|
||||
|
||||
test_init(argc, argv);
|
||||
|
||||
cwd = get_current_dir_name();
|
||||
if (!cwd)
|
||||
return pr_perror("get_current_dir_name");
|
||||
|
||||
snprintf(path, sizeof(path), "%s/%s", cwd, filename);
|
||||
unlink(path);
|
||||
|
||||
addr.sun_family = AF_UNIX;
|
||||
addrlen = strlen(filename);
|
||||
if (addrlen > sizeof(addr.sun_path))
|
||||
return pr_err("address is too long");
|
||||
memcpy(addr.sun_path, filename, addrlen);
|
||||
addrlen += sizeof(addr.sun_family);
|
||||
|
||||
ssk = socket(AF_UNIX, SOCK_TYPE, 0);
|
||||
if (ssk == -1)
|
||||
return pr_perror("socket");
|
||||
|
||||
sk = socket(AF_UNIX, SOCK_TYPE, 0);
|
||||
if (sk < 0)
|
||||
return pr_perror("socket");
|
||||
|
||||
ret = bind(ssk, (struct sockaddr *)&addr, addrlen);
|
||||
if (ret)
|
||||
return pr_perror("bind");
|
||||
|
||||
ret = listen(ssk, 16);
|
||||
if (ret)
|
||||
return pr_perror("listen");
|
||||
|
||||
if (connect(sk, (struct sockaddr *)&addr, addrlen))
|
||||
return pr_perror("connect");
|
||||
|
||||
#ifdef SK_UNIX_LISTEN02
|
||||
{
|
||||
char buf[64];
|
||||
memset(buf, 0, sizeof(buf));
|
||||
write(sk, SK_DATA, sizeof(SK_DATA));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SK_UNIX_LISTEN03
|
||||
close(sk);
|
||||
sk = -1;
|
||||
#endif
|
||||
|
||||
test_daemon();
|
||||
test_waitsig();
|
||||
|
||||
if (sk != -1)
|
||||
close(sk);
|
||||
|
||||
ret = accept(ssk, NULL, NULL);
|
||||
if (ret < 0)
|
||||
return fail("accept");
|
||||
|
||||
#ifdef SK_UNIX_LISTEN02
|
||||
{
|
||||
char buf[64];
|
||||
if (read(ret, &buf, sizeof(buf)) != sizeof(SK_DATA))
|
||||
return pr_perror("read");
|
||||
|
||||
if (strcmp(buf, SK_DATA))
|
||||
return fail("data corrupted");
|
||||
}
|
||||
#endif
|
||||
|
||||
close(ssk);
|
||||
unlink(path);
|
||||
|
||||
pass();
|
||||
return 0;
|
||||
}
|
||||
1
test/zdtm/static/sk-unix-listen02.c
Symbolic link
1
test/zdtm/static/sk-unix-listen02.c
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
sk-unix-listen01.c
|
||||
1
test/zdtm/static/sk-unix-listen02.desc
Normal file
1
test/zdtm/static/sk-unix-listen02.desc
Normal file
|
|
@ -0,0 +1 @@
|
|||
{'flags': 'crfail'}
|
||||
1
test/zdtm/static/sk-unix-listen03.c
Symbolic link
1
test/zdtm/static/sk-unix-listen03.c
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
sk-unix-listen01.c
|
||||
1
test/zdtm/static/sk-unix-listen03.desc
Normal file
1
test/zdtm/static/sk-unix-listen03.desc
Normal file
|
|
@ -0,0 +1 @@
|
|||
{'flags': 'crfail'}
|
||||
1
test/zdtm/static/sk-unix-listen04.c
Symbolic link
1
test/zdtm/static/sk-unix-listen04.c
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
sk-unix-listen01.c
|
||||
1
test/zdtm/static/sk-unix-listen04.desc
Normal file
1
test/zdtm/static/sk-unix-listen04.desc
Normal file
|
|
@ -0,0 +1 @@
|
|||
{'flags': 'crfail'}
|
||||
Loading…
Add table
Add a link
Reference in a new issue