6 #include <sys/socket.h>
19 int readbuf_sz
= 0, readbuf_used
= 0;
27 void handler( int s
) {
34 write(1, readbuf
, readbuf_used
);
45 sz
= read(fds
[1], buf
, 2048);
48 if (readbuf_used
+ sz
>= readbuf_sz
) {
49 readbuf_sz
= readbuf_sz
? 2 * readbuf_sz
: 4096;
50 readbuf
= realloc(readbuf
, readbuf_sz
);
54 memcpy(readbuf
+ readbuf_used
, buf
, sz
);
59 void passed(int i
, char *f
) {
65 void skipped(int i
, char *f
) {
71 void failed(int i
, char *f
, int st
) {
75 printf("interrupted.\n");
79 printf("-- FAILED %s ------------------------------------\n", f
);
81 printf("-- FAILED %s (end) ------------------------------\n", f
);
84 void run(int i
, char *f
) {
87 perror("Fork failed.");
89 } else if (pid
== 0) {
93 execlp("bash", "bash", f
, NULL
);
99 snprintf(buf
, 128, "%s ...", f
);
101 printf("Running %-40s ", buf
);
104 while ((w
= waitpid(pid
, &st
, WNOHANG
)) == 0) {
114 if (WEXITSTATUS(st
) == 0) {
116 } else if (WEXITSTATUS(st
) == 200) {
128 int main(int argc
, char **argv
) {
130 status
= alloca(sizeof(int)*argc
);
132 if (socketpair(PF_UNIX
, SOCK_STREAM
, 0, fds
)) {
133 perror("socketpair");
137 if ( fcntl( fds
[1], F_SETFL
, O_NONBLOCK
) == -1 ) {
138 perror("fcntl on socket");
142 /* set up signal handlers */
143 for (i
= 0; i
<= 32; ++i
) {
144 if (i
== SIGCHLD
|| i
== SIGWINCH
|| i
== SIGURG
)
150 for (i
= 1; i
< argc
; ++ i
) {
156 printf("\n## %d tests: %d OK, %d failed, %d skipped\n",
157 npassed
+ nfailed
+ nskipped
, npassed
, nfailed
, nskipped
);
159 /* print out a summary */
160 if (nfailed
|| nskipped
) {
161 for (i
= 1; i
< argc
; ++ i
) {
164 printf("FAILED: %s\n", argv
[i
]);
167 printf("skipped: %s\n", argv
[i
]);
172 return nfailed
> 0 || die
;