]>
git.saurik.com Git - apple/xnu.git/blob - tools/tests/libMicro/apple/mbr_check_service_membership.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"
39 #include <membership.h>
41 #include <uuid/uuid.h>
44 # define debug(fmt, args...) (void) fprintf(stderr, fmt "\n" , ##args)
46 # define debug(fmt, args...)
52 // mbr_check_service_membership -E -L -S -W -B 200 -C 10 -r 100 -s "SACL" -u user_prefix
54 // libMicro default benchmark run options are "-E -C 200 -L -S -W"
56 // -B is batch size: loop iteration per each benchmark run. Needs to match # of
57 // real lookups. This is total number of lookups to issue.
58 // -C is min sample number: how many benchmark needs to run to get proper sample
59 // 1 is mimumum, but you get at least 3 benchmark run
60 // samples. Do not set to zero. Default is 200 for most
62 // -r is the number of total records.
63 // -s is SACL string: ie. "ssh"
64 // -u user_prefix that preceeds the user number
70 // the number of record lookup to issue is covered by standard option optB
71 static int optRecords
= 100; // the number of total records
72 static int optSACL
= 0; // option SACL specified?
74 static char **sacl
= NULL
;
75 static char *default_sacl
[] = { "com.apple.access_dsproxy",
76 "com.apple.access_screensharing",
77 "com.apple.access_ssh",
79 static int numSACL
= 3; // number of SACLs
82 // This will use local users (local_test_*)
83 static char *default_uprefix
= "local_test_";
88 debug("benchmark_init");
89 (void) sprintf(lm_optstr
, "r:s:u:");
91 lm_tsdsize
= sizeof(tsd_t
);
94 (void) sprintf(lm_usage
,
95 "\n ------- mbr_check_service_membership specific options (default: *)\n"
96 " [-r total number of records (100*)]\n"
104 * This is where you parse your lower-case arguments.
107 benchmark_optswitch(int opt
, char *optarg
)
109 debug("benchmark_optswitch");
112 case 'r': // total number of records. default is 100
113 optRecords
= atoi(optarg
);
114 debug("optRecords = %d\n", optRecords
);
119 printf("SACL already specified. Skipping");
122 sacl
= malloc(2 * sizeof(char *));
124 printf("Error: no memory available for strdup\n");
127 sacl
[0] = strdup(optarg
);
135 default_uprefix
= strdup(optarg
);
136 debug("default_uprefix = %s\n", default_uprefix
);
151 debug("benchmark_initrun");
157 for (i
=0; strcmp(sacl
[i
], "") && i
<= numSACL
; i
++) {
158 debug("SACL = %s", sacl
[i
]);
164 // Initialize all structures that will be used in benchmark()
165 // 1. make local or network node for OD query
166 // 2. create user key
168 benchmark_initworker(void *tsd
)
171 tsd_t
*ts
= (tsd_t
*)tsd
;
172 char *uprefix
= default_uprefix
; // local user is default
173 char username
[30] = "";
174 struct passwd
*info
= NULL
;
176 debug("benchmark_initworker");
178 // create an array of usernames to use in benchmark before their use
179 // realtime generation in benchmark effects performance measurements
181 ts
->uuid_list
= calloc(optRecords
, sizeof(uuid_t
));
183 for (i
= 0; i
< optRecords
; i
++) {
185 sprintf(username
, "%s%d", uprefix
, i
+1);
186 info
= getpwnam(username
);
188 debug ("error converting username %s to uuid", username
);
192 (void) mbr_uid_to_uuid(info
->pw_uid
, ts
->uuid_list
[i
]);
198 uuid_unparse(ts
->uuid_list
[i
], buf
);
199 mbr_uuid_to_id(ts
->uuid_list
[i
], &uid
, &id_type
);
200 debug ("username (%s), uid %d, uuid %s, back to uid %d", username
, info
->pw_uid
, buf
, uid
);
204 // if batch size (one benchmark run) is less than the number records, adjust
205 // it to match the number record lookups in one batch run
206 if (optRecords
< lm_optB
) {
207 lm_optB
= optRecords
;
208 debug("Reducing batch size to %d to match the record #\n", lm_optB
);
211 debug("benchmark_initworker");
216 benchmark(void *tsd
, result_t
*res
)
218 tsd_t
*ts
= (tsd_t
*)tsd
;
231 debug("in to benchmark - optB = %i", lm_optB
);
232 for (i
= 0; i
< lm_optB
; i
++) {
234 sacl_chosen
= sacl
[random() % numSACL
];
235 err
= mbr_check_service_membership(ts
->uuid_list
[i
], sacl_chosen
, &isMember
);
238 mbr_uuid_to_id(ts
->uuid_list
[i
], &uid
, &id_type
);
239 debug ("loop %d: uid %d is %s a member of %s", i
, uid
, (isMember
) ? "" : "not", sacl_chosen
);
243 debug("error: %s", strerror(err
));
253 // We need to release all the structures we allocated in benchmark_initworker()
255 benchmark_finiworker(void *tsd
)
257 tsd_t
*ts
= (tsd_t
*)tsd
;
258 debug("benchmark_result: deallocating structures");
266 benchmark_finirun(void *tsd
)
277 static char result
= '\0';
278 debug("benchmark_result");