1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
** file: inrval.c
** description: Interval conversion test.
** Modification History:
** 15-May-97 AGarcia- Converted the test to accomodate the debug_mode flag.
** The debug mode will print all of the printfs associated with this test.
** The regress mode will be the default mode. Since the regress tool limits
** the output to a one line status:PASS or FAIL,all of the printf statements
** have been handled with an if (debug_mode) statement.
** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to
** recognize the return code from tha main program.
**/
/***********************************************************************
** Includes
***********************************************************************/
/* Used to get the command line option */
#include "plgetopt.h"
#include "prinit.h"
#include "obsolete/pralarm.h"
#include "prio.h"
#include "prprf.h"
#include "prlock.h"
#include "prlong.h"
#include "prcvar.h"
#include "prinrval.h"
#include "prtime.h"
#include "plgetopt.h"
#include <stdio.h>
#include <stdlib.h>
static PRIntn debug_mode;
static PRFileDesc *output;
static void TestConversions(void)
{
PRIntervalTime ticks = PR_TicksPerSecond();
if (debug_mode) {
PR_fprintf(output, "PR_TicksPerSecond: %ld\n\n", ticks);
PR_fprintf(output, "PR_SecondsToInterval(1): %ld\n", PR_SecondsToInterval(1));
PR_fprintf(output, "PR_MillisecondsToInterval(1000): %ld\n", PR_MillisecondsToInterval(1000));
PR_fprintf(output, "PR_MicrosecondsToInterval(1000000): %ld\n\n", PR_MicrosecondsToInterval(1000000));
PR_fprintf(output, "PR_SecondsToInterval(3): %ld\n", PR_SecondsToInterval(3));
PR_fprintf(output, "PR_MillisecondsToInterval(3000): %ld\n", PR_MillisecondsToInterval(3000));
PR_fprintf(output, "PR_MicrosecondsToInterval(3000000): %ld\n\n", PR_MicrosecondsToInterval(3000000));
PR_fprintf(output, "PR_IntervalToSeconds(%ld): %ld\n", ticks, PR_IntervalToSeconds(ticks));
PR_fprintf(output, "PR_IntervalToMilliseconds(%ld): %ld\n", ticks, PR_IntervalToMilliseconds(ticks));
PR_fprintf(output, "PR_IntervalToMicroseconds(%ld): %ld\n\n", ticks, PR_IntervalToMicroseconds(ticks));
ticks *= 3;
PR_fprintf(output, "PR_IntervalToSeconds(%ld): %ld\n", ticks, PR_IntervalToSeconds(ticks));
PR_fprintf(output, "PR_IntervalToMilliseconds(%ld): %ld\n", ticks, PR_IntervalToMilliseconds(ticks));
PR_fprintf(output, "PR_IntervalToMicroseconds(%ld): %ld\n\n", ticks, PR_IntervalToMicroseconds(ticks));
} /*end debug mode */
} /* TestConversions */
static void TestIntervalOverhead(void)
{
/* Hopefully the optimizer won't delete this function */
PRUint32 elapsed, per_call, loops = 1000000;
PRIntervalTime timeout, timein = PR_IntervalNow();
while (--loops > 0)
timeout = PR_IntervalNow();
elapsed = 1000U * PR_IntervalToMicroseconds(timeout - timein);
per_call = elapsed / 1000000U;
PR_fprintf(
output, "Overhead of 'PR_IntervalNow()' is %u nsecs\n\n", per_call);
} /* TestIntervalOverhead */
static void TestNowOverhead(void)
{
PRTime timeout, timein;
PRInt32 overhead, loops = 1000000;
PRInt64 elapsed, per_call, ten23rd, ten26th;
LL_I2L(ten23rd, 1000);
LL_I2L(ten26th, 1000000);
timein = PR_Now();
while (--loops > 0)
timeout = PR_Now();
LL_SUB(elapsed, timeout, timein);
LL_MUL(elapsed, elapsed, ten23rd);
LL_DIV(per_call, elapsed, ten26th);
LL_L2I(overhead, per_call);
PR_fprintf(
output, "Overhead of 'PR_Now()' is %u nsecs\n\n", overhead);
} /* TestNowOverhead */
static void TestIntervals(void)
{
PRStatus rv;
PRUint32 delta;
PRInt32 seconds;
PRUint64 elapsed, thousand;
PRTime timein, timeout;
PRLock *ml = PR_NewLock();
PRCondVar *cv = PR_NewCondVar(ml);
for (seconds = 0; seconds < 10; ++seconds)
{
PRIntervalTime ticks = PR_SecondsToInterval(seconds);
PR_Lock(ml);
timein = PR_Now();
rv = PR_WaitCondVar(cv, ticks);
timeout = PR_Now();
PR_Unlock(ml);
LL_SUB(elapsed, timeout, timein);
LL_I2L(thousand, 1000);
LL_DIV(elapsed, elapsed, thousand);
LL_L2UI(delta, elapsed);
if (debug_mode) PR_fprintf(output,
"TestIntervals: %swaiting %ld seconds took %ld msecs\n",
((rv == PR_SUCCESS) ? "" : "FAILED "), seconds, delta);
}
PR_DestroyCondVar(cv);
PR_DestroyLock(ml);
if (debug_mode) PR_fprintf(output, "\n");
} /* TestIntervals */
static PRIntn PR_CALLBACK RealMain(int argc, char** argv)
{
PRUint32 vcpu, cpus = 0, loops = 1000;
/* The command line argument: -d is used to determine if the test is being run
in debug mode. The regress tool requires only one line output:PASS or FAIL.
All of the printfs associated with this test has been handled with a if (debug_mode)
test.
Usage: test_name -d
*/
/* main test */
PLOptStatus os;
PLOptState *opt = PL_CreateOptState(argc, argv, "dl:c:");
while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
{
if (PL_OPT_BAD == os) continue;
switch (opt->option)
{
case 'd': /* debug mode */
debug_mode = 1;
break;
case 'c': /* concurrency counter */
cpus = atoi(opt->value);
break;
case 'l': /* loop counter */
loops = atoi(opt->value);
break;
default:
break;
}
}
PL_DestroyOptState(opt);
output = PR_GetSpecialFD(PR_StandardOutput);
PR_fprintf(output, "inrval: Examine stdout to determine results.\n");
if (cpus == 0) cpus = 8;
if (loops == 0) loops = 1000;
if (debug_mode > 0)
{
PR_fprintf(output, "Inrval: Using %d loops\n", loops);
PR_fprintf(output, "Inrval: Using 1 and %d cpu(s)\n", cpus);
}
for (vcpu = 1; vcpu <= cpus; vcpu += cpus - 1)
{
if (debug_mode)
PR_fprintf(output, "\nInrval: Using %d CPU(s)\n\n", vcpu);
PR_SetConcurrency(vcpu);
TestNowOverhead();
TestIntervalOverhead();
TestConversions();
TestIntervals();
}
return 0;
}
int main(int argc, char **argv)
{
PRIntn rv;
PR_STDIO_INIT();
rv = PR_Initialize(RealMain, argc, argv, 0);
return rv;
} /* main */
|