]>
git.saurik.com Git - apple/xnu.git/blob - tools/tests/execperf/run.c
10 extern char **environ
;
12 char * const *newargv
;
18 int main(int argc
, char *argv
[]) {
20 int i
, count
, threadcount
;
28 threadcount
= atoi(argv
[1]);
29 count
= atoi(argv
[2]);
33 threads
= (pthread_t
*)calloc(threadcount
, sizeof(pthread_t
));
34 for (i
=0; i
< threadcount
; i
++) {
35 ret
= pthread_create(&threads
[i
], NULL
, work
, (void *)(intptr_t)count
);
37 err(1, "pthread_create");
41 for (i
=0; i
< threadcount
; i
++) {
42 ret
= pthread_join(threads
[i
], NULL
);
44 err(1, "pthread_join");
52 fprintf(stderr
, "Usage: %s <threadcount> <count> <program> [<arg1> [<arg2> ...]]\n",
59 int count
= (int)(intptr_t)arg
;
64 for (i
=0; i
< count
; i
++) {
65 ret
= posix_spawn(&pid
, newargv
[0], NULL
, NULL
, newargv
, environ
);
67 errc(1, ret
, "posix_spawn(%s)", newargv
[0]);
70 while (-1 == waitpid(pid
, &ret
, 0)) {
72 err(1, "waitpid(%d)", pid
);
76 if (WIFSIGNALED(ret
)) {
77 errx(1, "process exited with signal %d", WTERMSIG(ret
));
78 } else if (WIFSTOPPED(ret
)) {
79 errx(1, "process stopped with signal %d", WSTOPSIG(ret
));
80 } else if (WIFEXITED(ret
)) {
81 if (WEXITSTATUS(ret
) != 42) {
82 errx(1, "process exited with unexpected exit code %d", WEXITSTATUS(ret
));
85 errx(1, "unknown exit condition %x", ret
);