33 #include <sys/types.h>
39 #include <sys/select.h>
46 if (
close(fd) == 0 || errno == EINTR || errno == EINPROGRESS)
63 assert(fd > STDERR_FILENO);
64 unsetenv(
"UV_TEST_RUNNER_FD");
72 setvbuf(
stdout, NULL, _IONBF, 0);
73 setvbuf(
stderr, NULL, _IONBF, 0);
98 if (is_helper == 0 &&
arg != NULL && atoi(
arg) != 0) {
99 args[
n++] =
"valgrind";
100 args[
n++] =
"--quiet";
101 args[
n++] =
"--leak-check=full";
102 args[
n++] =
"--show-reachable=yes";
103 args[
n++] =
"--error-exitcode=125";
111 stdout_file = tmpfile();
112 stdout_fd = fileno(stdout_file);
124 snprintf(fdstr,
sizeof(fdstr),
"%d", pipefd[1]);
125 if (setenv(
"UV_TEST_RUNNER_FD", fdstr, 1)) {
145 dup2(stdout_fd, STDOUT_FILENO);
146 dup2(stdout_fd, STDERR_FILENO);
155 p->stdout_file = stdout_file;
161 unsetenv(
"UV_TEST_RUNNER_FD");
164 rc =
read(pipefd[0], &
n, 1);
165 while (rc == -1 && errno == EINTR);
175 fprintf(
stderr,
"EOF expected but got data.\n");
199 for (
i = 0;
i <
args->n;
i++) {
201 if (
p->terminated)
continue;
202 r = waitpid(
p->pid, &
p->status, 0);
210 if (
args->pipe[1] >= 0) {
216 while (
r == -1 && errno == EINTR);
234 unsigned int elapsed_ms;
256 r = pipe((
int*)&(
args.pipe));
262 if (pthread_attr_init(&
attr))
266 if (pthread_attr_setstacksize(&
attr, 1024 * 1024))
268 if (pthread_attr_setstacksize(&
attr, 256 * 1024))
274 if (pthread_attr_destroy(&
attr))
278 perror(
"pthread_create()");
283 if (gettimeofday(&timebase, NULL))
298 if (elapsed_ms >= (
unsigned)
timeout)
305 FD_SET(
args.pipe[0], &fds);
307 r = select(
args.pipe[0] + 1, &fds, NULL, NULL, &tv);
308 if (!(
r == -1 && errno == EINTR))
311 if (gettimeofday(&tv, NULL))
325 for (
i = 0;
i <
n;
i++) {
327 kill(
p->pid, SIGTERM);
332 if (pthread_join(
tid, NULL))
347 int r = fstat(fileno(
p->stdout_file), &
buf);
352 return (
long)
buf.st_size;
368 while ((
r = fread(
buf, 1,
sizeof(
buf),
p->stdout_file)) != 0)
371 if (ferror(
p->stdout_file)) {
394 while (fgets(
buffer, buffer_len,
p->stdout_file) != NULL) {
400 if (ferror(
p->stdout_file)) {
417 return kill(
p->pid, SIGTERM);
423 if (WIFEXITED(
p->status)) {
424 return WEXITSTATUS(
p->status);
441 fprintf(
stderr,
"\047[2K\r");
443 fprintf(
stderr,
"\033[2K\r");