]> granicus.if.org Git - strace/blob - tests/filter-unavailable.c
Use printnum_int64 instead of print_loff_t
[strace] / tests / filter-unavailable.c
1 #include <assert.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <pthread.h>
5 #include <sys/wait.h>
6
7 #define P 16
8 #define T 7
9
10 static void *
11 thread(void *arg)
12 {
13         assert(write(1, "", 1) == 1);
14         pause();
15         return arg;
16 }
17
18 static int
19 process(void)
20 {
21         int i;
22         int fds[2];
23         pthread_t t;
24         struct timespec ts = { .tv_nsec = 10000000 };
25
26         (void) close(0);
27         (void) close(1);
28         assert(pipe(fds) == 0 && fds[0] == 0 && fds[1] == 1);
29
30         for (i = 0; i < T; ++i)
31                 assert(pthread_create(&t, NULL, thread, NULL) == 0);
32         for (i = 0; i < T; ++i)
33                 assert(read(0, fds, 1) == 1);
34
35         (void) nanosleep(&ts, 0);
36         return 0;
37 }
38
39 int
40 main(void)
41 {
42         int i, s;
43         pid_t p;
44
45         for (i = 0; i < P; ++i) {
46                 assert((p = fork()) >= 0);
47                 if (p == 0)
48                         return process();
49                 assert(waitpid(p, &s, 0) == p && WIFEXITED(s));
50                 if (WEXITSTATUS(s))
51                         return WEXITSTATUS(s);
52         }
53         return 0;
54 }