25
25
#include <stdlib.h>
26
26
#include <unistd.h>
27
27
#include <signal.h>
28
+ #ifdef __APPLE__
28
29
#include <mach/clock_types.h>
29
30
#include <mach-o/arch.h>
31
+ #endif
30
32
#include <sys/resource.h>
31
33
#include <sys/time.h>
32
34
33
35
#include <bsdtests.h>
34
36
35
37
extern char * * environ ;
36
38
39
+ #ifdef __linux__
40
+ // FIXME: LINUX_PORT_HDD
41
+ // For initial bringup, don't use libdispatch to test libdispatch!
42
+ #define SIMPLE_TEST_HARNESS 1
43
+ #else
44
+ #define SIMPLE_TEST_HARNESS 0
45
+ #endif
46
+
37
47
int
38
48
main (int argc , char * argv [])
39
49
{
@@ -46,10 +56,15 @@ main(int argc, char *argv[])
46
56
exit (1 );
47
57
}
48
58
59
+ #ifdef __APPLE__
49
60
short spawnflags = POSIX_SPAWN_START_SUSPENDED ;
50
61
#if TARGET_OS_EMBEDDED
51
62
spawnflags |= POSIX_SPAWN_SETEXEC ;
52
63
#endif
64
+ #else
65
+ #define POSIX_SPAWN_SETEXEC 0 /* ignore... */
66
+ short spawnflags = 0 ;
67
+ #endif
53
68
54
69
posix_spawnattr_t attr ;
55
70
res = posix_spawnattr_init (& attr );
@@ -58,6 +73,7 @@ main(int argc, char *argv[])
58
73
assert (res == 0 );
59
74
60
75
uint64_t to = 0 ;
76
+ #ifdef __APPLE__
61
77
char * tos = getenv ("BSDTEST_TIMEOUT" );
62
78
if (tos ) {
63
79
to = strtoul (tos , NULL , 0 );
@@ -73,6 +89,7 @@ main(int argc, char *argv[])
73
89
}
74
90
}
75
91
92
+ #endif
76
93
int i ;
77
94
char * * newargv = calloc (argc , sizeof (void * ));
78
95
for (i = 1 ; i < argc ; ++ i ) {
@@ -98,6 +115,29 @@ main(int argc, char *argv[])
98
115
//fprintf(stderr, "pid = %d\n", pid);
99
116
assert (pid > 0 );
100
117
118
+ #if SIMPLE_TEST_HARNESS
119
+ int status ;
120
+ struct rusage usage ;
121
+ struct timeval tv_stop , tv_wall ;
122
+
123
+ gettimeofday (& tv_stop , NULL );
124
+ tv_wall .tv_sec = tv_stop .tv_sec - tv_start .tv_sec ;
125
+ tv_wall .tv_sec -= (tv_stop .tv_usec < tv_start .tv_usec );
126
+ tv_wall .tv_usec = abs (tv_stop .tv_usec - tv_start .tv_usec );
127
+
128
+ int res2 = wait4 (pid , & status , 0 , & usage );
129
+ assert (res2 != -1 );
130
+ test_long ("Process exited" , (WIFEXITED (status ) && WEXITSTATUS (status ) && WEXITSTATUS (status ) != 0xff ) || WIFSIGNALED (status ), 0 );
131
+ printf ("[PERF]\twall time: %ld.%06d\n" , tv_wall .tv_sec , tv_wall .tv_usec );
132
+ printf ("[PERF]\tuser time: %ld.%06d\n" , usage .ru_utime .tv_sec , usage .ru_utime .tv_usec );
133
+ printf ("[PERF]\tsystem time: %ld.%06d\n" , usage .ru_stime .tv_sec , usage .ru_stime .tv_usec );
134
+ printf ("[PERF]\tmax resident set size: %ld\n" , usage .ru_maxrss );
135
+ printf ("[PERF]\tpage faults: %ld\n" , usage .ru_majflt );
136
+ printf ("[PERF]\tswaps: %ld\n" , usage .ru_nswap );
137
+ printf ("[PERF]\tvoluntary context switches: %ld\n" , usage .ru_nvcsw );
138
+ printf ("[PERF]\tinvoluntary context switches: %ld\n" , usage .ru_nivcsw );
139
+ exit ((WIFEXITED (status ) && WEXITSTATUS (status )) || WIFSIGNALED (status ));
140
+ #else
101
141
dispatch_queue_t main_q = dispatch_get_main_queue ();
102
142
103
143
tmp_ds = dispatch_source_create (DISPATCH_SOURCE_TYPE_PROC , pid , DISPATCH_PROC_EXIT , main_q );
@@ -155,6 +195,7 @@ main(int argc, char *argv[])
155
195
kill (pid , SIGCONT );
156
196
157
197
dispatch_main ();
198
+ #endif // SIMPLE_TEST_HARNESS
158
199
159
200
return 0 ;
160
201
}
0 commit comments