mirror of
https://github.com/checkpoint-restore/criu
synced 2025-09-01 23:05:39 +00:00
zdtm: add new test case for "pipe inversion"
Probably all of you know about "lock inversion". We have a similar problem on restoring pipes. This test case creates two process and two pipes. process 1: 11: pipe1 (w) 12: pipe2 (r) process 2: 11: pipe2 (r) 12: pipe1 (w) Signed-off-by: Andrey Vagin <avagin@openvz.org> Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
This commit is contained in:
committed by
Cyrill Gorcunov
parent
d924a240ff
commit
a5439d5fed
@@ -23,6 +23,7 @@ TST_NOFILE = \
|
|||||||
inotify_system_nodel \
|
inotify_system_nodel \
|
||||||
shm \
|
shm \
|
||||||
ptrace_sig \
|
ptrace_sig \
|
||||||
|
pipe00 \
|
||||||
# jobctl00 \
|
# jobctl00 \
|
||||||
|
|
||||||
TST_FILE = \
|
TST_FILE = \
|
||||||
|
106
test/zdtm/live/static/pipe00.c
Normal file
106
test/zdtm/live/static/pipe00.c
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
|
||||||
|
#include "zdtmtst.h"
|
||||||
|
|
||||||
|
const char *test_doc = "Lock inversion";
|
||||||
|
const char *test_author = "Andrey Vagin <avagin@parallels.com>";
|
||||||
|
|
||||||
|
#define TEST_STRING "Hello world"
|
||||||
|
|
||||||
|
int main(int argc, char ** argv)
|
||||||
|
{
|
||||||
|
int pipe1[2];
|
||||||
|
int pipe2[2];
|
||||||
|
int ret;
|
||||||
|
pid_t pid;
|
||||||
|
char buf[sizeof(TEST_STRING)];
|
||||||
|
|
||||||
|
test_init(argc, argv);
|
||||||
|
|
||||||
|
ret = pipe(pipe1);
|
||||||
|
if (ret)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
ret = pipe(pipe2);
|
||||||
|
if (ret)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
pid = test_fork();
|
||||||
|
if (pid < 0) {
|
||||||
|
err("Can't fork");
|
||||||
|
exit(1);
|
||||||
|
} else if (pid == 0) {
|
||||||
|
if (dup2(pipe1[1], 11) == -1 || dup2(pipe2[0], 12) == -1) {
|
||||||
|
err("dup2 failed");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (dup2(pipe1[0], 12) == -1 || dup2(pipe2[1], 11) == -1) {
|
||||||
|
err("dup2 failed");
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
close(pipe2[0]);
|
||||||
|
close(pipe2[1]);
|
||||||
|
close(pipe1[0]);
|
||||||
|
close(pipe1[1]);
|
||||||
|
|
||||||
|
if (pid > 0) {
|
||||||
|
int status;
|
||||||
|
|
||||||
|
test_daemon();
|
||||||
|
|
||||||
|
while (test_go())
|
||||||
|
;
|
||||||
|
|
||||||
|
ret = write(11, TEST_STRING, sizeof(TEST_STRING));
|
||||||
|
if (ret != sizeof(TEST_STRING)) {
|
||||||
|
err("write failed: %d", ret);
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
close(11);
|
||||||
|
ret = read(12, buf, sizeof(TEST_STRING));
|
||||||
|
if (ret != sizeof(TEST_STRING)) {
|
||||||
|
err("read failed: %d", ret);
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
if (strcmp(TEST_STRING, buf)) {
|
||||||
|
err("data curruption");
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = wait(&status);
|
||||||
|
if (ret == -1 || !WIFEXITED(status) || WEXITSTATUS(status)) {
|
||||||
|
kill(pid, SIGKILL);
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
pass();
|
||||||
|
} else {
|
||||||
|
ret = read(12, buf, sizeof(TEST_STRING));
|
||||||
|
if (ret != sizeof(TEST_STRING)) {
|
||||||
|
err("read failed: %d", ret);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
ret = write(11, TEST_STRING, sizeof(TEST_STRING));
|
||||||
|
if (ret != sizeof(TEST_STRING)) {
|
||||||
|
err("write failed: %d", ret);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
close(11);
|
||||||
|
if (strcmp(TEST_STRING, buf)) {
|
||||||
|
err("data curruption");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
err:
|
||||||
|
err("FAIL");
|
||||||
|
return 1;
|
||||||
|
}
|
Reference in New Issue
Block a user