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 * Portions Copyright (c) 2006, Apple Inc.
32 */
33
34#ifdef	__sun
35#pragma ident	"@(#)lmbench_stat.c	1.4	06/21/06 Apple Inc."
36#endif
37
38
39#include <unistd.h>
40#include <stdlib.h>
41#include <stdio.h>
42#include <sys/types.h>
43#include <sys/stat.h>
44
45#include "../libmicro.h"
46
47#define	DEFF			"/dev/null"
48static char			*optf = DEFF;
49
50int
51benchmark_init()
52{
53
54	(void) sprintf(lm_optstr, "f:");
55
56	lm_tsdsize = 0;
57
58	(void) sprintf(lm_usage,
59	    "       [-f file-to-stat (default %s)]\n"
60	    "notes: measures stat()\n",
61	    DEFF);
62
63	return (0);
64}
65
66int
67benchmark_optswitch(int opt, char *optarg)
68{
69	switch (opt) {
70	case 'f':
71		optf = optarg;
72		break;
73	default:
74		return (-1);
75	}
76	return (0);
77}
78
79/*ARGSUSED*/
80int
81benchmark(void *tsd, result_t *res)
82{
83	int			i;
84	struct stat		sbuf;
85
86	res->re_errors = 0;
87
88/*
89 * The libmicro test uses a for loop as below:
90 *   for (i = 0; i < lm_optB; i++) {
91 *
92 * we can probably get away with using lm_optB
93 * in the while loop below
94 *
95 */
96 	i = 0;
97
98	while (i++ < lm_optB) {
99		if (stat(optf, &sbuf) == -1)
100			res->re_errors++;
101	}
102
103	res->re_count += lm_optB;
104
105	return (0);
106}
107