1*433d6423SLionel Sambuc /* Test40.c
2*433d6423SLionel Sambuc *
3*433d6423SLionel Sambuc * Test select(...) system call
4*433d6423SLionel Sambuc *
5*433d6423SLionel Sambuc */
6*433d6423SLionel Sambuc
7*433d6423SLionel Sambuc #include <sys/types.h>
8*433d6423SLionel Sambuc #include <sys/wait.h>
9*433d6423SLionel Sambuc #include <sys/syslimits.h>
10*433d6423SLionel Sambuc #include <stdio.h>
11*433d6423SLionel Sambuc #include <stdlib.h>
12*433d6423SLionel Sambuc #include <unistd.h>
13*433d6423SLionel Sambuc #include <stdarg.h>
14*433d6423SLionel Sambuc
15*433d6423SLionel Sambuc int max_error = 5;
16*433d6423SLionel Sambuc #include "common.h"
17*433d6423SLionel Sambuc
18*433d6423SLionel Sambuc
main(int argc,char ** argv)19*433d6423SLionel Sambuc int main(int argc, char **argv) {
20*433d6423SLionel Sambuc char *tests[] = {"t40a", "t40b", "t40c", "t40d", "t40e", "t40f", "t40g"};
21*433d6423SLionel Sambuc char copy_command[8+PATH_MAX+1];
22*433d6423SLionel Sambuc int no_tests, i, forkres, status = 0;
23*433d6423SLionel Sambuc
24*433d6423SLionel Sambuc no_tests = sizeof(tests) / sizeof(char *);
25*433d6423SLionel Sambuc
26*433d6423SLionel Sambuc start(40);
27*433d6423SLionel Sambuc
28*433d6423SLionel Sambuc for(i = 0; i < no_tests; i++) {
29*433d6423SLionel Sambuc char subtest[2];
30*433d6423SLionel Sambuc snprintf(subtest, 2, "%d", i+1);
31*433d6423SLionel Sambuc
32*433d6423SLionel Sambuc /* Copy subtest */
33*433d6423SLionel Sambuc snprintf(copy_command, 8 + PATH_MAX, "cp ../%s .", tests[i]);
34*433d6423SLionel Sambuc system(copy_command);
35*433d6423SLionel Sambuc
36*433d6423SLionel Sambuc forkres = fork();
37*433d6423SLionel Sambuc if(forkres == 0) { /* Child */
38*433d6423SLionel Sambuc execl(tests[i], tests[i], subtest, (char *) 0);
39*433d6423SLionel Sambuc printf("Failed to execute subtest %s\n", tests[i]);
40*433d6423SLionel Sambuc exit(-2);
41*433d6423SLionel Sambuc } else if(forkres > 0) { /* Parent */
42*433d6423SLionel Sambuc if(waitpid(forkres, &status, 0) > 0 && WEXITSTATUS(status) < 20) {
43*433d6423SLionel Sambuc errct += WEXITSTATUS(status); /* Count errors */
44*433d6423SLionel Sambuc }
45*433d6423SLionel Sambuc status = 0; /* Reset */
46*433d6423SLionel Sambuc } else {
47*433d6423SLionel Sambuc printf("Failed to fork\n");
48*433d6423SLionel Sambuc exit(-2);
49*433d6423SLionel Sambuc }
50*433d6423SLionel Sambuc }
51*433d6423SLionel Sambuc
52*433d6423SLionel Sambuc quit();
53*433d6423SLionel Sambuc
54*433d6423SLionel Sambuc return (-1); /* Impossible */
55*433d6423SLionel Sambuc }
56*433d6423SLionel Sambuc
57