2011-12-06 12:44:00 +04:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
|
|
|
#include "zdtmtst.h"
|
|
|
|
|
2021-07-19 07:28:38 +00:00
|
|
|
const char *test_doc = "Lock inversion";
|
|
|
|
const char *test_author = "Andrey Vagin <avagin@parallels.com>";
|
2011-12-06 12:44:00 +04:00
|
|
|
|
|
|
|
#define TEST_STRING "Hello world"
|
|
|
|
|
2021-07-19 07:28:38 +00:00
|
|
|
int main(int argc, char **argv)
|
2011-12-06 12:44:00 +04:00
|
|
|
{
|
|
|
|
int pipe1[2];
|
|
|
|
int pipe2[2];
|
|
|
|
int ret;
|
|
|
|
pid_t pid;
|
|
|
|
char buf[sizeof(TEST_STRING)];
|
2015-12-22 15:34:00 +03:00
|
|
|
task_waiter_t t;
|
2011-12-06 12:44:00 +04:00
|
|
|
|
|
|
|
test_init(argc, argv);
|
|
|
|
|
2015-12-22 15:34:00 +03:00
|
|
|
task_waiter_init(&t);
|
|
|
|
|
2011-12-06 12:44:00 +04:00
|
|
|
ret = pipe(pipe1);
|
|
|
|
if (ret)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
ret = pipe(pipe2);
|
|
|
|
if (ret)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
pid = test_fork();
|
|
|
|
if (pid < 0) {
|
2015-10-20 18:10:00 +03:00
|
|
|
pr_perror("Can't fork");
|
2011-12-06 12:44:00 +04:00
|
|
|
exit(1);
|
|
|
|
} else if (pid == 0) {
|
|
|
|
if (dup2(pipe1[1], 11) == -1 || dup2(pipe2[0], 12) == -1) {
|
2015-10-20 18:10:00 +03:00
|
|
|
pr_perror("dup2 failed");
|
2011-12-06 12:44:00 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} else {
|
2021-07-19 07:28:38 +00:00
|
|
|
if (dup2(pipe1[0], 12) == -1 || dup2(pipe2[1], 11) == -1) {
|
2015-10-20 18:10:00 +03:00
|
|
|
pr_perror("dup2 failed");
|
2011-12-06 12:44:00 +04:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
close(pipe2[0]);
|
|
|
|
close(pipe2[1]);
|
|
|
|
close(pipe1[0]);
|
|
|
|
close(pipe1[1]);
|
|
|
|
|
|
|
|
if (pid > 0) {
|
|
|
|
int status;
|
|
|
|
|
2015-12-22 15:34:00 +03:00
|
|
|
task_waiter_wait4(&t, 1);
|
|
|
|
|
2011-12-06 12:44:00 +04:00
|
|
|
test_daemon();
|
|
|
|
|
2012-10-10 17:31:19 +04:00
|
|
|
test_waitsig();
|
2011-12-06 12:44:00 +04:00
|
|
|
|
2012-04-05 20:02:00 +04:00
|
|
|
ret = read(12, buf, sizeof(TEST_STRING));
|
|
|
|
if (ret != sizeof(TEST_STRING)) {
|
2015-10-20 18:10:00 +03:00
|
|
|
pr_perror("read failed: %d", ret);
|
2012-04-05 20:02:00 +04:00
|
|
|
goto err;
|
|
|
|
}
|
2011-12-06 12:44:00 +04:00
|
|
|
ret = write(11, TEST_STRING, sizeof(TEST_STRING));
|
|
|
|
if (ret != sizeof(TEST_STRING)) {
|
2015-10-20 18:10:00 +03:00
|
|
|
pr_perror("write failed: %d", ret);
|
2011-12-06 12:44:00 +04:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
close(11);
|
|
|
|
ret = read(12, buf, sizeof(TEST_STRING));
|
|
|
|
if (ret != sizeof(TEST_STRING)) {
|
2015-10-20 18:10:00 +03:00
|
|
|
pr_perror("read failed: %d", ret);
|
2011-12-06 12:44:00 +04:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
if (strcmp(TEST_STRING, buf)) {
|
2022-03-30 18:45:16 -07:00
|
|
|
pr_perror("data corruption");
|
2011-12-06 12:44:00 +04:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = wait(&status);
|
|
|
|
if (ret == -1 || !WIFEXITED(status) || WEXITSTATUS(status)) {
|
|
|
|
kill(pid, SIGKILL);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
pass();
|
|
|
|
} else {
|
2015-12-22 15:34:00 +03:00
|
|
|
task_waiter_complete(&t, 1);
|
2012-04-05 20:02:00 +04:00
|
|
|
ret = write(11, TEST_STRING, sizeof(TEST_STRING));
|
|
|
|
if (ret != sizeof(TEST_STRING)) {
|
2015-10-20 18:10:00 +03:00
|
|
|
pr_perror("write failed: %d", ret);
|
2012-04-05 20:02:00 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2011-12-06 12:44:00 +04:00
|
|
|
ret = read(12, buf, sizeof(TEST_STRING));
|
|
|
|
if (ret != sizeof(TEST_STRING)) {
|
2015-10-20 18:10:00 +03:00
|
|
|
pr_perror("read failed: %d", ret);
|
2011-12-06 12:44:00 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
ret = write(11, TEST_STRING, sizeof(TEST_STRING));
|
|
|
|
if (ret != sizeof(TEST_STRING)) {
|
2015-10-20 18:10:00 +03:00
|
|
|
pr_perror("write failed: %d", ret);
|
2011-12-06 12:44:00 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
close(11);
|
|
|
|
if (strcmp(TEST_STRING, buf)) {
|
2022-03-30 18:45:16 -07:00
|
|
|
pr_perror("data corruption");
|
2011-12-06 12:44:00 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
err:
|
2015-10-20 18:10:00 +03:00
|
|
|
pr_perror("FAIL");
|
2011-12-06 12:44:00 +04:00
|
|
|
return 1;
|
|
|
|
}
|