]>
git.saurik.com Git - apple/xnu.git/blob - tools/tests/libMicro/apple/trivial.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@
39 * benchmark_initworker
45 * benchmark_finibatch, etc.
46 * benchmark_finiworker
58 #pragma ident "@(#)trivial.c 1.0 08/17/06 Apple Inc."
68 // add additional headers needed here.
70 #include "../libmicro.h"
73 # define debug(fmt, args...) (void) fprintf(stderr, fmt "\n" , ##args)
75 # define debug(fmt, args...)
79 * Your state variables should live in the tsd_t struct below
86 * You can have any lower-case option you want to define.
87 * options are specified in the lm_optstr as either a
88 * single lower-case letter, or a single lower case letter
89 * with a colon after it. In this example, you can optionally
90 * specify -c {str} -e or -t {number}
91 * -c takes a string (quote the string if blanks)
96 static char * optc
; // allocated in benchmark_init, freed in benchmark_fini.
97 static bool opte
= false;
104 debug("benchmark_init\n");
106 * the lm_optstr must be defined here or no options for you
108 * ...and the framework will throw an error
111 (void) sprintf(lm_optstr
, "c:et:");
113 * tsd_t is the state info struct that we pass around
115 * lm_tsdsize will allocate the space we need for this
116 * structure throughout the rest of the framework
118 lm_tsdsize
= sizeof (tsd_t
);
120 (void) sprintf(lm_usage
,
122 " [-e] optional parameter\n"
123 " [-t int (default 1)]\n"
124 "notes: measures nothing\n");
131 * This is where you parse your lower-case arguments.
132 * the format was defined in the lm_optstr assignment
136 benchmark_optswitch(int opt
, char *optarg
)
138 debug("benchmark_optswitch\n");
142 strncpy(optc
, optarg
, 20);
143 debug("optc = %s\n", optc
);
147 debug("opte = %s\n", opte
? "true": "false");
150 optt
= sizetoint(optarg
);
151 debug("optt = %d\n", optt
);
162 debug("benchmark_initrun\n");
167 benchmark_initworker(void *tsd
)
170 * initialize your state variables here first
172 tsd_t
*ts
= (tsd_t
*)tsd
;
174 debug("benchmark_initworker: ts_once = %i\n",ts
->ts_once
);
180 benchmark_initbatch(void *tsd
)
183 * initialize your state variables here second
185 tsd_t
*ts
= (tsd_t
*)tsd
;
186 // useless code to show what you can do.
189 debug("benchmark_initbatch: ts_once = %i\n",ts
->ts_once
);
194 benchmark(void *tsd
, result_t
*res
)
197 * try not to initialize things here. This is the main
198 * loop of things to get timed. Start a server in
199 * benchmark_initbatch
201 tsd_t
*ts
= (tsd_t
*)tsd
;
204 debug("in to benchmark - optB = %i : ts_once = %i\n", lm_optB
, ts
->ts_once
);
205 for (i
= 0; i
< lm_optB
; i
++) {
207 * just to show that ts really contains state
212 debug("out of benchmark - optB = %i : ts_once = %i\n", lm_optB
, ts
->ts_once
);
218 benchmark_finibatch(void *tsd
)
220 tsd_t
*ts
= (tsd_t
*)tsd
;
222 * more proof of state passing
225 debug("benchmark_finibatch: ts_once = %i\n",ts
->ts_once
);
230 benchmark_finiworker(void *tsd
)
232 tsd_t
*ts
= (tsd_t
*)tsd
;
233 // useless code to show what you can do.
236 debug("benchmark_finiworker: ts_once = %i\n",ts
->ts_once
);
243 static char result
= '\0';
244 debug("benchmark_result\n");
251 debug("benchmark_finirun\n");
259 debug("benchmark_fini\n");