2525#include <stdlib.h>
2626#include <unistd.h>
2727#include <signal.h>
28+ #ifdef __APPLE__
2829#include <mach/clock_types.h>
2930#include <mach-o/arch.h>
31+ #endif
3032#include <sys/resource.h>
3133#include <sys/time.h>
3234
3335#include <bsdtests.h>
3436
3537extern char * * environ ;
3638
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+
3747int
3848main (int argc , char * argv [])
3949{
@@ -46,10 +56,15 @@ main(int argc, char *argv[])
4656 exit (1 );
4757 }
4858
59+ #ifdef __APPLE__
4960 short spawnflags = POSIX_SPAWN_START_SUSPENDED ;
5061#if TARGET_OS_EMBEDDED
5162 spawnflags |= POSIX_SPAWN_SETEXEC ;
5263#endif
64+ #else
65+ #define POSIX_SPAWN_SETEXEC 0 /* ignore... */
66+ short spawnflags = 0 ;
67+ #endif
5368
5469 posix_spawnattr_t attr ;
5570 res = posix_spawnattr_init (& attr );
@@ -58,6 +73,7 @@ main(int argc, char *argv[])
5873 assert (res == 0 );
5974
6075 uint64_t to = 0 ;
76+ #ifdef __APPLE__
6177 char * tos = getenv ("BSDTEST_TIMEOUT" );
6278 if (tos ) {
6379 to = strtoul (tos , NULL , 0 );
@@ -73,6 +89,7 @@ main(int argc, char *argv[])
7389 }
7490 }
7591
92+ #endif
7693 int i ;
7794 char * * newargv = calloc (argc , sizeof (void * ));
7895 for (i = 1 ; i < argc ; ++ i ) {
@@ -98,6 +115,29 @@ main(int argc, char *argv[])
98115 //fprintf(stderr, "pid = %d\n", pid);
99116 assert (pid > 0 );
100117
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
101141 dispatch_queue_t main_q = dispatch_get_main_queue ();
102142
103143 tmp_ds = dispatch_source_create (DISPATCH_SOURCE_TYPE_PROC , pid , DISPATCH_PROC_EXIT , main_q );
@@ -155,6 +195,7 @@ main(int argc, char *argv[])
155195 kill (pid , SIGCONT );
156196
157197 dispatch_main ();
198+ #endif // SIMPLE_TEST_HARNESS
158199
159200 return 0 ;
160201}
0 commit comments