]> git.saurik.com Git - apple/xnu.git/blob - tools/tests/libMicro/apple/lmbench_fstat.c
xnu-1699.22.81.tar.gz
[apple/xnu.git] / tools / tests / libMicro / apple / lmbench_fstat.c
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 #ifdef __sun
31 #pragma ident "@(#)lmbench_fstat.c 1.4 06/21/06 Apple Inc."
32 #endif
33
34
35 #include <unistd.h>
36 #include <stdlib.h>
37 #include <stdio.h>
38 #include <sys/types.h>
39 #include <sys/stat.h>
40 #include <fcntl.h>
41
42 #include "../libmicro.h"
43
44 typedef struct {
45 char *ts_buf;
46 int ts_fd;
47 } tsd_t;
48
49
50 #define DEFF "/dev/null"
51 #define DEFS 1024
52
53 static char *optf = DEFF;
54 // static long long opts = DEFS;
55
56 int
57 benchmark_init()
58 {
59
60 (void) sprintf(lm_optstr, "f:");
61
62 lm_tsdsize = 0;
63
64 (void) sprintf(lm_usage,
65 " [-f file-to-stat (default %s)]\n"
66 "notes: measures lmbench_fstat()\n",
67 DEFF);
68
69 return (0);
70 }
71
72 int
73 benchmark_optswitch(int opt, char *optarg)
74 {
75 switch (opt) {
76 case 'f':
77 optf = optarg;
78 break;
79 default:
80 return (-1);
81 }
82 return (0);
83 }
84
85 /*
86 * This initbatch stolen from lmbench_read.c
87 */
88 int
89 benchmark_initbatch(void *tsd)
90 {
91 tsd_t *ts = (tsd_t *)tsd;
92
93 if (ts->ts_buf == NULL) {
94 /* ts->ts_buf = malloc(opts); */
95 ts->ts_fd = open(optf, O_RDONLY);
96 }
97
98 /* (void) lseek(ts->ts_fd, 0, SEEK_SET); */
99
100 return (0);
101 }
102
103
104 /*ARGSUSED*/
105 int
106 benchmark(void *tsd, result_t *res)
107 {
108 int i;
109 struct stat sbuf;
110 tsd_t *ts = (tsd_t *)tsd;
111
112 res->re_errors = 0;
113
114 /*
115 * The libmicro test uses a for loop as below:
116 * for (i = 0; i < lm_optB; i++) {
117 *
118 * we can probably get away with using lm_optB
119 * in the while loop below
120 *
121 */
122 i = 0;
123
124 // while (i++ < lm_optB) {
125 for (i = 0; i < lm_optB; i++) {
126 if (fstat(ts->ts_fd, &sbuf) == -1)
127 res->re_errors++;
128 }
129
130 res->re_count += lm_optB;
131
132 return (0);
133 }