1/*
2 * Copyright (c) 2008 Apple Inc.  All Rights Reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29
30#ifdef  __sun
31#pragma ident   "@(#)posix_spawn.c  1.0     08/21/08 Apple Inc."
32#endif
33
34/*
35 * posix_spawn benchmark
36 */
37
38#include <unistd.h>
39#include <stdio.h>
40#include <stdlib.h>
41#include <string.h>
42#include <sys/wait.h>
43#include <spawn.h>
44
45#include "../libmicro.h"
46
47static char exec_path[1024];
48static char *argv[3];
49
50int
51benchmark_init()
52{
53	lm_defB = 128;
54	lm_tsdsize = 0;
55
56	(void) sprintf(lm_usage,
57	    "notes: measures posix_spawn time of simple process()\n");
58
59	return (0);
60}
61
62/*ARGSUSED*/
63int
64benchmark_initbatch(void *tsd)
65{
66	char			buffer[80];
67
68	(void) strcpy(exec_path, lm_procpath);
69	(void) strcat(exec_path, "/posix_spawn_bin");
70
71	(void) sprintf(buffer, "%d", lm_optB);
72	argv[0] = exec_path;
73	argv[1] = strdup(buffer);
74	argv[2] = NULL;
75
76	return (0);
77}
78
79/*ARGSUSED*/
80int
81benchmark(void *tsd, result_t *res)
82{
83	int c;
84	int pid;
85	int status;
86
87	if (( c = posix_spawn(&pid, exec_path, NULL, NULL, argv, NULL) != 0))
88	{
89		res->re_errors++;
90	}
91
92	if (waitpid(pid, &status, 0) < 0)
93	{
94		res->re_errors++;
95	}
96
97	if (WIFEXITED(status) && WEXITSTATUS(status) != 0)
98	{
99		res->re_errors++;
100	}
101
102	res->re_count = lm_optB;
103
104	return (0);
105}
106