From acadb12c26165825d357499e946875fc33f62344 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 21 Oct 2006 06:44:36 +0000 Subject: r19435: fixed the subunit code on platforms with small pipe buffers, and use pipe() on all platforms, not socket pairs (stdin/out are not sockets) also show the output while its happening, so the tests become useful again for non-automated usage. I still really dislike running tests like the TALLOC one as child processes (This used to be commit b621999c59fc56a32ff574523204355c5e0382c0) --- source4/torture/subunit.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'source4/torture/subunit.c') diff --git a/source4/torture/subunit.c b/source4/torture/subunit.c index b7d2ad405c..e417b45306 100644 --- a/source4/torture/subunit.c +++ b/source4/torture/subunit.c @@ -94,12 +94,12 @@ static pid_t piped_child(char* const command[], int *f_stdout, int *f_stderr) pid_t pid; int sock_out[2], sock_err[2]; - if (socketpair(AF_UNIX, SOCK_STREAM, 0, sock_out) == -1) { + if (pipe(sock_out) == -1) { DEBUG(0, ("socketpair: %s", strerror(errno))); return -1; } - if (socketpair(AF_UNIX, SOCK_STREAM, 0, sock_err) == -1) { + if (pipe(sock_err) == -1) { DEBUG(0, ("socketpair: %s", strerror(errno))); return -1; } @@ -107,9 +107,6 @@ static pid_t piped_child(char* const command[], int *f_stdout, int *f_stderr) *f_stdout = sock_out[0]; *f_stderr = sock_err[0]; - fcntl(sock_out[0], F_SETFL, O_NONBLOCK); - fcntl(sock_err[0], F_SETFL, O_NONBLOCK); - pid = fork(); if (pid == -1) { @@ -124,7 +121,7 @@ static pid_t piped_child(char* const command[], int *f_stdout, int *f_stderr) close(sock_out[0]); close(sock_err[0]); - dup2(sock_out[1], 0); + open("/dev/null", O_RDONLY); dup2(sock_out[1], 1); dup2(sock_err[1], 2); execvp(command[0], command); @@ -195,20 +192,12 @@ bool torture_subunit_run_suite(struct torture_context *context, if (pid == -1) return false; - if (waitpid(pid, &status, 0) == -1) { - torture_result(context, TORTURE_ERROR, "waitpid(%d) failed\n", pid); - return false; - } - - if (WEXITSTATUS(status) != 0) { - torture_result(context, TORTURE_ERROR, "failed with status %d\n", WEXITSTATUS(status)); - return false; - } - while ((size = read(fd_out, buffer+offset, sizeof(buffer-offset) > 0))) { char *eol; buffer[offset+size] = '\0'; + write(1, buffer+offset, size); + for (p = buffer; p; p = eol+1) { eol = strchr(p, '\n'); if (eol == NULL) @@ -263,6 +252,16 @@ bool torture_subunit_run_suite(struct torture_context *context, memcpy(buffer, p, offset); } + if (waitpid(pid, &status, 0) == -1) { + torture_result(context, TORTURE_ERROR, "waitpid(%d) failed\n", pid); + return false; + } + + if (WEXITSTATUS(status) != 0) { + torture_result(context, TORTURE_ERROR, "failed with status %d\n", WEXITSTATUS(status)); + return false; + } + if (name != NULL) { torture_result(context, TORTURE_ERROR, "Interrupted during %s\n", name); return false; -- cgit