mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-31 06:15:24 +00:00
zdtm: check external sockets
Signed-off-by: Andrey Vagin <avagin@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
committed by
Pavel Emelyanov
parent
410345a9d1
commit
fab874bf2f
@@ -59,6 +59,7 @@ TEST_LIST="$TEST_LIST
|
||||
static/zombie00
|
||||
transition/fork
|
||||
static/file_fown
|
||||
static/socket-ext
|
||||
"
|
||||
|
||||
MNT_TEST_LIST="
|
||||
@@ -222,7 +223,7 @@ EOF
|
||||
echo Dump $PID
|
||||
mkdir -p $ddump
|
||||
save_fds $PID $ddump/dump.fd
|
||||
setsid $CRTOOLS dump --evasive-devices -D $ddump -o dump.log -v 4 -t $PID $args $ARGS || {
|
||||
setsid $CRTOOLS dump -x --evasive-devices -D $ddump -o dump.log -v 4 -t $PID $args $ARGS || {
|
||||
echo WARNING: process $tname is left running for your debugging needs
|
||||
return 1
|
||||
}
|
||||
@@ -246,7 +247,7 @@ EOF
|
||||
done
|
||||
|
||||
echo Restore $PID
|
||||
setsid $CRTOOLS restore --log-pid -D $ddump -o restore.log -v 4 -d -t $PID $args || return 2
|
||||
setsid $CRTOOLS restore --log-pid -x -D $ddump -o restore.log -v 4 -d -t $PID $args || return 2
|
||||
|
||||
save_fds $PID $ddump/restore.fd
|
||||
diff_fds $ddump/dump.fd $ddump/restore.fd || return 2
|
||||
|
@@ -56,6 +56,7 @@ TST_NOFILE = \
|
||||
mountpoints \
|
||||
netns \
|
||||
session01 \
|
||||
socket-ext \
|
||||
# jobctl00 \
|
||||
|
||||
TST_FILE = \
|
||||
|
100
test/zdtm/live/static/socket-ext.c
Normal file
100
test/zdtm/live/static/socket-ext.c
Normal file
@@ -0,0 +1,100 @@
|
||||
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#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 <limits.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "zdtmtst.h"
|
||||
|
||||
const char *test_doc = "Test external sockets\n";
|
||||
const char *test_author = "Andrey Vagin <avagin@openvz.org";
|
||||
|
||||
#define SK_DATA "packet"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct sockaddr_un addr;
|
||||
unsigned int addrlen;
|
||||
task_waiter_t lock;
|
||||
|
||||
char path[PATH_MAX] = "/tmp/zdtm.unix.sock.XXXXXX";
|
||||
pid_t pid;
|
||||
int ret, sk;
|
||||
|
||||
mktemp(path);
|
||||
addr.sun_family = AF_UNIX;
|
||||
strncpy(addr.sun_path, path, sizeof(addr.sun_path));
|
||||
addrlen = sizeof(addr.sun_family) + strlen(path);
|
||||
|
||||
task_waiter_init(&lock);
|
||||
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
err("fork() failed");
|
||||
return 1;
|
||||
} else if (pid == 0) {
|
||||
char c;
|
||||
test_ext_init(argc, argv);
|
||||
|
||||
sk = socket(AF_UNIX, SOCK_DGRAM, 0);
|
||||
if (sk < 0) {
|
||||
err("Can't create socket");
|
||||
return 1;
|
||||
}
|
||||
ret = bind(sk, &addr, addrlen);
|
||||
if (ret < 0) {
|
||||
err("Can't bind socket to %s", path);
|
||||
return 1;
|
||||
}
|
||||
test_msg("The external socket %s\n", path);
|
||||
task_waiter_complete(&lock, 1);
|
||||
task_waiter_fini(&lock);
|
||||
|
||||
recv(sk, &c, sizeof(c), 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
test_init(argc, argv);
|
||||
|
||||
task_waiter_wait4(&lock, 1);
|
||||
task_waiter_fini(&lock);
|
||||
|
||||
sk = socket(AF_UNIX, SOCK_DGRAM, 0);
|
||||
if (sk < 0) {
|
||||
err("Can't create socket");
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = connect(sk, &addr, addrlen);
|
||||
if (ret < 0) {
|
||||
err("Can't connect socket");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
test_daemon();
|
||||
test_waitsig();
|
||||
|
||||
unlink(path);
|
||||
|
||||
ret = send(sk, "H", 1, 0);
|
||||
if (ret != 1) {
|
||||
err("Can't send a symbol");
|
||||
fail();
|
||||
return 1;
|
||||
}
|
||||
|
||||
pass();
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user