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#include <unistd.h>
30#include <stdlib.h>
31#include <stdio.h>
32#include <stdbool.h>
33#include <errno.h>
34#include <string.h>
35#include <netdb.h>
36
37// add additional headers needed here.
38
39#include "../libmicro.h"
40
41#if DEBUG
42# define debug(fmt, args...)    (void) fprintf(stderr, fmt "\n" , ##args)
43#else
44# define debug(fmt, args...)
45#endif
46
47
48// This exercises "ssh" port
49//
50// Correct use case
51//
52//    getaddrinfo_port -E  -L -S -W -B 200 -C 100
53//
54//      libMicro default benchmark run options are "-E -L -S -W -C 200"
55//
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
61//                          runs in libMicro.
62//
63
64extern int gL1CacheEnabled;
65
66/*
67 *    Your state variables should live in the tsd_t struct below
68 */
69typedef struct {
70} tsd_t;
71
72
73int
74benchmark_init()
75{
76    debug("benchmark_init");
77
78    (void) sprintf(lm_optstr,  "l:");
79    lm_tsdsize = sizeof (tsd_t);
80    lm_defB = 100;
81
82    return (0);
83}
84
85
86/*
87 * This is where you parse your lower-case arguments.
88 */
89int
90benchmark_optswitch(int opt, char *optarg)
91{
92    debug("benchmark_optswitch");
93
94    switch (opt) {
95        case 'l':
96            gL1CacheEnabled = atoi(optarg);
97            break;
98    }
99
100    return 0;
101}
102
103
104// Initialize all structures that will be used in benchmark()
105//
106int
107benchmark_initrun()
108{
109    debug("\nbenchmark_initrun");
110
111    return (0);
112}
113
114
115int
116benchmark(void *tsd, result_t *res)
117{
118    int         i, err;
119    struct addrinfo *addi;
120
121    res->re_errors = 0;
122
123    debug("in to benchmark - optB = %i", lm_optB);
124    for (i = 0; i < lm_optB; i++) {
125
126        err = getaddrinfo(NULL, "ssh", NULL, &addi);
127
128        if (err) {
129            debug("error: %s", gai_strerror(err));
130            res->re_errors++;
131        }
132
133        freeaddrinfo (addi);
134    }
135    res->re_count = i;
136
137    return (0);
138}
139
140// We need to release all the structures we allocated in benchmark_initrun()
141int
142benchmark_finirun(void *tsd)
143{
144    // tsd_t    *ts = (tsd_t *)tsd;
145    debug("benchmark_finirun ");
146
147    return (0);
148}
149
150char *
151benchmark_result()
152{
153    static char    result = '\0';
154    debug("benchmark_result");
155    return (&result);
156}
157
158