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 * test getenv
33 */
34
35#include <unistd.h>
36#include <stdio.h>
37#include <stdlib.h>
38#include <pthread.h>
39#include <string.h>
40
41#include "libmicro.h"
42
43#define	DEFS			100
44
45static int			opts = DEFS;
46
47int
48benchmark_init()
49{
50	(void) sprintf(lm_optstr, "s:");
51
52	lm_tsdsize = 0;
53
54	(void) sprintf(lm_usage,
55	    "       [-s search-size (default = %d)]\n"
56	    "notes: measures time to search env for missing string\n",
57	    DEFS);
58
59	lm_nsecs_per_op = 200;
60
61	return (0);
62}
63
64int
65benchmark_optswitch(int opt, char *optarg)
66{
67	switch (opt) {
68	case 's':
69		opts = atoi(optarg);
70		break;
71	default:
72		return (-1);
73	}
74	return (0);
75}
76
77int
78benchmark_initrun()
79{
80	extern char **		environ;
81	int			i, j;
82
83	/* count environment strings */
84
85	for (i = 0; environ[i++]; )
86		;
87
88	/*
89	 * pad to desired count
90	 */
91
92	if (opts < i)
93		opts = i;
94
95	for (j = i; j < opts; j++) {
96		char buf[80];
97		(void) sprintf(buf, "VAR_%d=%d", j, j);
98		(void) putenv(strdup(buf));
99	}
100
101	return (0);
102}
103
104/*ARGSUSED*/
105int
106benchmark(void *tsd, result_t *res)
107{
108	int			i;
109	char 			*search = "RUMPLSTILTSKIN";
110
111	for (i = 0; i < lm_optB; i += 10) {
112		(void) getenv(search);
113		(void) getenv(search);
114		(void) getenv(search);
115		(void) getenv(search);
116		(void) getenv(search);
117		(void) getenv(search);
118		(void) getenv(search);
119		(void) getenv(search);
120		(void) getenv(search);
121		(void) getenv(search);
122	}
123	res->re_count = i;
124
125	return (0);
126}
127