1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms
5 * of the Common Development and Distribution License
6 * (the "License").  You may not use this file except
7 * in compliance with the License.
8 *
9 * You can obtain a copy of the license at
10 * src/OPENSOLARIS.LICENSE
11 * or http://www.opensolaris.org/os/licensing.
12 * See the License for the specific language governing
13 * permissions and limitations under the License.
14 *
15 * When distributing Covered Code, include this CDDL
16 * HEADER in each file and include the License file at
17 * usr/src/OPENSOLARIS.LICENSE.  If applicable,
18 * add the following below this CDDL HEADER, with the
19 * fields enclosed by brackets "[]" replaced with your
20 * own identifying information: Portions Copyright [yyyy]
21 * [name of copyright owner]
22 *
23 * CDDL HEADER END
24 */
25
26/*
27 * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
28 * Use is subject to license terms.
29 */
30
31/*
32 * exec benchmark
33 */
34
35#include <unistd.h>
36#include <stdio.h>
37#include <stdlib.h>
38#include <string.h>
39#include <sys/wait.h>
40
41#include "libmicro.h"
42
43static char exec_path[1024];
44static char *argv[3];
45
46int
47benchmark_init()
48{
49	lm_defB = 128;
50	lm_tsdsize = 0;
51
52	(void) sprintf(lm_usage,
53	    "notes: measures execv time of simple process()\n");
54
55	return (0);
56}
57
58/*ARGSUSED*/
59int
60benchmark_initbatch(void *tsd)
61{
62	char			buffer[80];
63
64	(void) strcpy(exec_path, lm_procpath);
65	(void) strcat(exec_path, "/exec_bin");
66
67	(void) sprintf(buffer, "%d", lm_optB);
68	argv[0] = exec_path;
69	argv[1] = strdup(buffer);
70	argv[2] = NULL;
71
72	return (0);
73}
74
75/*ARGSUSED*/
76int
77benchmark(void *tsd, result_t *res)
78{
79	int c;
80	int status;
81
82	switch (c = fork()) {
83	case -1:
84		res->re_errors++;
85		break;
86	default:
87		if (waitpid(c, &status, 0) < 0)
88			res->re_errors++;
89
90		if (WIFEXITED(status) && WEXITSTATUS(status) != 0)
91			res->re_errors++;
92		break;
93	case 0:
94		if (execv(exec_path, argv) < 0)
95			res->re_errors++;
96	}
97
98	res->re_count = lm_optB;
99
100	return (0);
101}
102