Commit 5f7933e3 authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

zdtm/fork: create 10 process concurrently

Currently this test creates one process and wait it. So most part of the
time this test has only one process without children.
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent b37ce2f1
......@@ -15,47 +15,79 @@
const char *test_doc = "Tests that forking tasks are handled properly";
const char *test_author = "Pavel Emelyanov <xemul@parallels.com>";
char children[] = "0123456789";
int main(int argc, char **argv)
{
int pid, wpid, status;
int p[2];
test_init(argc, argv);
if (pipe(p)) {
err("pipe");
return -1;
}
if (write(p[1], children, sizeof(children)) != sizeof(children)) {
err("write");
return -1;
}
test_daemon();
while (test_go()) {
pid = fork();
if (pid < 0) {
fail("Can't fork");
goto out;
char c = 0;
int ret;
ret = read(p[0], &children, sizeof(children));
if (ret <= 0) {
err("read");
return 1;
}
if (pid == 0) {
for (; ret > 0; ret--) {
pid = fork();
if (pid < 0) {
fail("Can't fork");
goto out;
}
if (pid == 0) {
#ifdef FORK2
usleep(10000);
usleep(10000);
#endif
exit(0);
if (write(p[1], &c, 1) != 1) {
err("write");
return 1;
}
exit(0);
}
}
while ((wpid = wait(&status)) == -1 && errno == EINTR);
while (1) {
wpid = waitpid(-1, &status, WNOHANG);
if (wpid < 0) {
if (errno == ECHILD)
break;
err("waitpid");
return -1;
}
if (wpid == 0)
break;
if (wpid != pid) {
fail("Pids do not match: expected %d "
"instead of %d (errno=%d status=%x)",
pid, wpid, errno, status);
goto out;
}
if (!WIFEXITED(status)) {
fail("Task %d didn't exit", wpid);
goto out;
}
if (!WIFEXITED(status)) {
fail("Task didn't exit");
goto out;
if (WEXITSTATUS(status) != 0) {
fail("Task %d exited with wrong code", wpid);
goto out;
}
}
if (WEXITSTATUS(status) != 0) {
fail("Task exited with wrong code");
goto out;
}
}
test_waitsig();
pass();
out:
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