Commit 0e4ec776 authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

zdtm: check restore of TCP connections (v2)

The test creates two processes.
A first process creates a tcp server, a second one connects to it.
The first process is dumped and restored.
Then the test checks that the TCP connection is alive.

v2: fix compilation :)
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 689317bf
...@@ -62,6 +62,7 @@ TEST_LIST=$TEST_LIST$(echo $TEST_LIST | tr ' ' '\n' | sed 's#^#ns/#') ...@@ -62,6 +62,7 @@ TEST_LIST=$TEST_LIST$(echo $TEST_LIST | tr ' ' '\n' | sed 's#^#ns/#')
TEST_LIST="$TEST_LIST TEST_LIST="$TEST_LIST
static/file_fown static/file_fown
static/socket-ext static/socket-ext
static/socket-tcp
" "
MNT_TEST_LIST=" MNT_TEST_LIST="
...@@ -226,7 +227,7 @@ EOF ...@@ -226,7 +227,7 @@ EOF
echo Dump $PID echo Dump $PID
mkdir -p $ddump mkdir -p $ddump
save_fds $PID $ddump/dump.fd save_fds $PID $ddump/dump.fd
setsid $CRTOOLS dump -x --evasive-devices -D $ddump -o dump.log -v 4 -t $PID $args $ARGS || { setsid $CRTOOLS dump --tcp-established -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 echo WARNING: process $tname is left running for your debugging needs
return 1 return 1
} }
...@@ -250,7 +251,7 @@ EOF ...@@ -250,7 +251,7 @@ EOF
done done
echo Restore $PID echo Restore $PID
setsid $CRTOOLS restore -x -D $ddump -o restore.log -v 4 -d -t $PID $args || return 2 setsid $CRTOOLS restore --tcp-established -x -D $ddump -o restore.log -v 4 -d -t $PID $args || return 2
for i in `seq 5`; do for i in `seq 5`; do
save_fds $PID $ddump/restore.fd save_fds $PID $ddump/restore.fd
......
...@@ -40,6 +40,7 @@ TST_NOFILE = \ ...@@ -40,6 +40,7 @@ TST_NOFILE = \
sockets_spair \ sockets_spair \
sockets_dgram \ sockets_dgram \
socket_queues \ socket_queues \
socket-tcp \
ipc_namespace \ ipc_namespace \
selfexe00 \ selfexe00 \
sem \ sem \
......
#include "zdtmtst.h"
const char *test_doc = "Check, that a TCP connection can be restored\n";
const char *test_author = "Andrey Vagin <avagin@parallels.com";
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
static int port = 8880;
#define BUF_SIZE 1024
int main(int argc, char **argv)
{
unsigned char buf[BUF_SIZE];
int fd, fd_s;
pid_t extpid;
int res;
uint32_t crc;
int pfd[2];
if (pipe(pfd)) {
err("pipe() failed");
return 1;
}
extpid = fork();
if (extpid < 0) {
err("fork() failed");
return 1;
} else if (extpid == 0) {
test_ext_init(argc, argv);
close(pfd[1]);
if (read(pfd[0], &port, sizeof(port)) != sizeof(port)) {
err("Can't read port\n");
return 1;
}
fd = tcp_init_client("127.0.0.1", port);
if (fd < 0)
return 1;
res = read(fd, buf, BUF_SIZE);
if (res != BUF_SIZE) {
err("read less then have to: %d instead of %d", res, BUF_SIZE);
return 1;
}
if (datachk(buf, BUF_SIZE, &crc))
return 2;
datagen(buf, BUF_SIZE, &crc);
if (write(fd, buf, BUF_SIZE) < BUF_SIZE) {
err("can't write");
return 1;
}
return 0;
}
test_init(argc, argv);
if ((fd_s = tcp_init_server(&port)) < 0) {
err("initializing server failed");
return 1;
}
close(pfd[0]);
if (write(pfd[1], &port, sizeof(port)) != sizeof(port)) {
err("Can't send port");
return 1;
}
close(pfd[1]);
/*
* parent is server of TCP connection
*/
fd = tcp_accept_server(fd_s);
if (fd < 0) {
err("can't accept client connection %m");
return 1;
}
test_daemon();
test_waitsig();
datagen(buf, BUF_SIZE, &crc);
if (write(fd, buf, BUF_SIZE) < BUF_SIZE) {
err("can't write");
return 1;
}
res = read(fd, buf, BUF_SIZE);
if (res != BUF_SIZE) {
err("read less then have to: %d instead of %d", res, BUF_SIZE);
return 1;
}
if (datachk(buf, BUF_SIZE, &crc))
return 2;
pass();
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment