]>
git.saurik.com Git - apple/xnu.git/blob - tools/tests/libMicro/apple/getgrnam.c
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"
40 #include <uuid/uuid.h>
43 # define debug(fmt, args...) (void) fprintf(stderr, fmt "\n" , ##args)
45 # define debug(fmt, args...)
51 // getgrnam -E -L -S -W -B 200 -C 10 -r 10
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 // -r is the number of total groups (from "local_test_group1" to "local_test_group#")
63 extern int gL1CacheEnabled
;
66 * Your state variables should live in the tsd_t struct below
71 // temporary buffer size
74 // the number of record lookup to issue is covered by standard option optB
75 static int optRecords
= 10; // the number of total records
77 // This will use local users (local_test_*)
78 static char *default_gprefix
= "ds_test_group";
80 #define GROUPNAME_LEN 30
81 static char *grpname_list
;
86 debug("benchmark_init");
87 (void) sprintf(lm_optstr
, "l:r:g:");
89 lm_tsdsize
= sizeof (tsd_t
);
92 (void) sprintf(lm_usage
,
93 "\n ------- getgrnam specific options (default: *)\n"
94 " [-r total number of group records (10*)]\n"
95 " [-g group prefix(ds_test_group)]\n"
101 * This is where you parse your lower-case arguments.
104 benchmark_optswitch(int opt
, char *optarg
)
106 debug("benchmark_optswitch");
109 case 'r': // total number of records. default is 100
110 optRecords
= atoi(optarg
);
111 debug("optRecords = %d\n", optRecords
);
115 gL1CacheEnabled
= atoi(optarg
);
118 case 'g': // base name for the groups to use
119 default_gprefix
= strdup(optarg
);
120 debug("default_gprefix = %s\n", default_gprefix
);
131 // Initialize all structures that will be used in benchmark()
132 // moved template init from benchmark_initworker -> benchmark_initrun
133 // since username_list is static across threads and processes
140 debug("\nbenchmark_initrun");
142 // create an array of usernames to use in benchmark before their use
143 // realtime generation in benchmark effects performance measurements
144 grpname_list
= malloc( optRecords
* GROUPNAME_LEN
);
146 debug ("malloc error");
150 for (i
= 0; i
< optRecords
; i
++) {
151 sprintf(&grpname_list
[i
*GROUPNAME_LEN
], "%s%d", default_gprefix
, i
+1);
152 debug("creating group name %s", &grpname_list
[i
*GROUPNAME_LEN
]);
160 benchmark(void *tsd
, result_t
*res
)
163 struct group
*grp
= NULL
;
167 debug("in to benchmark - optB = %i", lm_optB
);
170 for (i
= 0; i
< lm_optB
; i
++) {
171 int index
= (random() % optRecords
) * GROUPNAME_LEN
;
175 struct group
*grp_ptr
= &gd
;
176 struct group
*tmp_ptr
;
179 err
= getgrnam_r( &grpname_list
[index
], grp_ptr
, gbuf
, BUFSIZE
, &tmp_ptr
);
180 // non-NULL err means failure and NULL result ptr means no matching
183 debug("error: %s -> %s", &grpname_list
[index
], strerror(err
));
186 else if ( !tmp_ptr
) {
187 debug("not found: %s", &grpname_list
[index
] );
193 grp
= getgrnam( &grpname_list
[index
] );
197 debug("error: %s -> %s", &grpname_list
[index
], strerror(errno
));
201 debug("not found: %s", &grpname_list
[index
] );
212 // We need to release all the structures we allocated in benchmark_initrun()
214 benchmark_finirun(void *tsd
)
216 // tsd_t *ts = (tsd_t *)tsd;
217 debug("benchmark_finiworker: deallocating structures");
227 static char result
= '\0';
228 debug("benchmark_result");