]>
git.saurik.com Git - apple/xnu.git/blob - tools/tests/libMicro/apple/getgrgid.c
f49925d18bc98c880d37d3c4759b34078c91ffa7
2 * Copyright (c) 2006 Apple Inc. All Rights Reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
36 // add additional headers needed here.
38 #include "../libmicro.h"
39 #include <membership.h>
43 # define debug(fmt, args...) (void) fprintf(stderr, fmt "\n" , ##args)
45 # define debug(fmt, args...)
51 // getgrgid -E -L -S -W -B 200 -C 10 -g 1211-1213
53 // libMicro default benchmark run options are "-E -L -S -W -C 200"
55 // -B is batch size: loop iteration per each benchmark run. Needs to match # of
56 // real lookups. This is total number of lookups to issue.
57 // -C is min sample number: how many benchmark needs to run to get proper sample
58 // 1 is mimumum, but you get at least 3 benchmark run
59 // samples. Do not set to zero. Default is 200 for most
61 // -g gid range in the form of "min-max". For example, -g 1211-1213
64 extern int gL1CacheEnabled
;
67 * Your state variables should live in the tsd_t struct below
72 // temporary buffer size
76 static gid_t gid_min
= INVALID_ID
;
77 static int gid_range
= 0; // gid_max = gid_min + gid_range
82 debug("benchmark_init");
83 (void) sprintf(lm_optstr
, "l:g:");
85 lm_tsdsize
= sizeof (tsd_t
);
88 (void) sprintf(lm_usage
,
89 "\n ------- getgrgid specific options (default: *)\n"
90 " [-g GID range (min-max)]\n"
97 parse_range(gid_t
*min
, int *offset
, char *buf
)
99 char *value
, *tmp_ptr
= strdup(buf
);
101 debug("parse_range");
103 value
= strsep(&tmp_ptr
, "-");
105 debug("min = %d", *min
);
107 value
= strsep(&tmp_ptr
, "-");
110 printf("max id should be larger than min id\n");
113 *offset
= range
- *min
+ 1;
114 debug("range = %d", *offset
);
117 printf("argument should be in the form of min-max\n");
126 * This is where you parse your lower-case arguments.
129 benchmark_optswitch(int opt
, char *optarg
)
131 debug("benchmark_optswitch");
135 gL1CacheEnabled
= atoi(optarg
);
138 case 'g': // GID range
139 return parse_range( &gid_min
, &gid_range
, optarg
);
150 // Initialize all structures that will be used in benchmark()
151 // moved template init from benchmark_initworker -> benchmark_initrun
156 debug("\nbenchmark_initrun");
163 benchmark(void *tsd
, result_t
*res
)
166 struct group
*grp
= NULL
;
170 debug("in to benchmark - optB = %i", lm_optB
);
171 for (i
= 0; i
< lm_optB
; i
++) {
172 gid_t gid
= gid_min
+ random() % gid_range
;
176 struct group
*grp_ptr
= &gd
;
177 struct group
*tmp_ptr
;
180 err
= getgrgid_r( gid
, grp_ptr
, gbuf
, BUFSIZE
, &tmp_ptr
);
182 debug("error: GID %d -> %s", gid
, strerror(err
));
186 debug("not found: GID %d", gid
);
192 grp
= getgrgid( gid
);
196 debug("error: GID %d -> %s", gid
, strerror(errno
));
200 debug("not found: GID %d", gid
);
211 // We need to release all the structures we allocated in benchmark_initrun()
213 benchmark_finirun(void *tsd
)
215 // tsd_t *ts = (tsd_t *)tsd;
216 debug("benchmark_finirun ");
224 static char result
= '\0';
225 debug("benchmark_result");