]> git.saurik.com Git - apple/xnu.git/blame - tools/tests/libMicro/apple/geekbench_stdlib_write.c
xnu-4570.41.2.tar.gz
[apple/xnu.git] / tools / tests / libMicro / apple / geekbench_stdlib_write.c
CommitLineData
b0d623f7
A
1/*
2 * Copyright (c) 2006 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29
30/*
31 * Order of Execution
32 *
33 * benchmark_init
34 *
35 * benchmark_optswitch
36 *
37 * benchmark_initrun
38 *
39 * benchmark_initworker
40 * benchmark_initbatch
41 * benchmark
42 * benchmark_finibatch
43 * benchmark_initbatch
44 * benchmark
45 * benchmark_finibatch, etc.
46 * benchmark_finiworker
47 *
48 * benchmark_result
49 *
50 * benchmark_finirun
51 *
52 * benchmark_fini
53 */
54
55
56
57#ifdef __sun
58#pragma ident "@(#)geekbench_stdlib_write.c 1.0 08/17/06 Apple Inc."
59#endif
60
61
62
63#include <unistd.h>
64#include <stdlib.h>
65#include <stdio.h>
66#include <string.h>
67
68#include "../libmicro.h"
69
70/*
71 * Your state variables should live in the tsd_t struct below
72 */
73typedef struct {
74 int ts_once;
75} tsd_t;
76
77unsigned char * arena;
78unsigned int arenaSize = 1048576;
79
80static int optt = 1;
81
82/*ARGSUSED*/
83int
84benchmark_initbatch(void *tsd)
85{
86 /*
87 * initialize your state variables here second
88 */
89 //tsd_t *ts = (tsd_t *)tsd;
90 //(void) fprintf(stderr, "benchmark_initbatch: ts_once = %i\n",ts->ts_once);
91 return (0);
92}
93
94int
95benchmark_finirun()
96{
97 (void) fprintf(stderr, "benchmark_finirun\n");
98 return (0);
99}
100
101int
102benchmark_init()
103{
104 (void) fprintf(stderr, "benchmark_init\n");
105 /*
106 * the lm_optstr must be defined here or no options for you
107 *
108 * ...and the framework will throw an error
109 *
110 */
111 (void) sprintf(lm_optstr, "t:");
112 /*
113 * working hypothesis:
114 *
115 * tsd_t is the struct that we can pass around our
116 * state info in
117 *
118 * lm_tsdsize will allocate the space we need for this
119 * structure throughout the rest of the framework
120 */
121 lm_tsdsize = sizeof (tsd_t);
122
123 (void) sprintf(lm_usage,
124 " [-t int (default 1)]\n"
125 "notes: measures nothing\n");
126 return (0);
127}
128
129int
130benchmark_fini()
131{
132 (void) fprintf(stderr, "benchmark_fini\n");
133 return (0);
134}
135
136int
137benchmark_finibatch(void *tsd)
138{
139 tsd_t *ts = (tsd_t *)tsd;
140 /*
141 * more proof of state passing
142 */
143 ts->ts_once = optt;
144 //(void) fprintf(stderr, "benchmark_finibatch: ts_once = %i\n",ts->ts_once);
145 return (0);
146}
147
148char *
149benchmark_result()
150{
151 static char result = '\0';
152 (void) fprintf(stderr, "benchmark_result\n");
153 return (&result);
154}
155
156int
157benchmark_finiworker(void *tsd)
158{
159 //tsd_t *ts = (tsd_t *)tsd;
160 //(void) fprintf(stderr, "benchmark_finiworker: ts_once = %i\n",ts->ts_once);
161 return (0);
162}
163
164int
165benchmark_optswitch(int opt, char *optarg)
166{
167 (void) fprintf(stderr, "benchmark_optswitch\n");
168
169 switch (opt) {
170 case 't':
171 optt = sizetoint(optarg);
172 break;
173 default:
174 return (-1);
175 }
176 return (0);
177}
178
179int
180benchmark_initworker(void *tsd)
181{
182 /*
183 * initialize your state variables here first
184 */
185 //tsd_t *ts = (tsd_t *)tsd;
186 //ts->ts_once = optt;
187 //(void) fprintf(stderr, "benchmark_initworker: ts_once = %i\n",ts->ts_once);
188 arena = ( unsigned char * )malloc( arenaSize);
189 return (0);
190}
191
192int
193benchmark_initrun()
194{
195 //(void) fprintf(stderr, "benchmark_initrun\n");
196 return (0);
197}
198
199int
200benchmark(void *tsd, result_t *res)
201{
202 /*
203 * initialize your state variables here last
204 *
205 * and realize that you are paying for your initialization here
206 * and it is really a bad idea
207 */
208 //tsd_t *ts = (tsd_t *)tsd;
209 int i;
210
211 //(void) fprintf(stderr, "in to benchmark - optB = %i : ts_once = %i\n", lm_optB, ts->ts_once);
212 for (i = 0; i < lm_optB; i++) {
213 /*
214 * just to show that ts really contains state
215 */
216 //(void) fprintf(stderr, "i is %i\n",i);
217 memset( arena, 0, arenaSize );
218 }
219 res->re_count = i;
220 //(void) fprintf(stderr, "out of benchmark - optB = %i : ts_once = %i\n", lm_optB, ts->ts_once);
221
222 return (0);
223}