1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is the Netscape Portable Runtime (NSPR).
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-2000
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
40 ** description: Interval conversion test.
41 ** Modification History:
42 ** 15-May-97 AGarcia- Converted the test to accomodate the debug_mode flag.
43 ** The debug mode will print all of the printfs associated with this test.
44 ** The regress mode will be the default mode. Since the regress tool limits
45 ** the output to a one line status:PASS or FAIL,all of the printf statements
46 ** have been handled with an if (debug_mode) statement.
47 ** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to
48 ** recognize the return code from tha main program.
50 /***********************************************************************
52 ***********************************************************************/
53 /* Used to get the command line option */
60 #include "obsolete/pralarm.h"
76 static PRIntn debug_mode
;
77 static PRFileDesc
*output
;
80 static void TestConversions(void)
82 PRIntervalTime ticks
= PR_TicksPerSecond();
85 PR_fprintf(output
, "PR_TicksPerSecond: %ld\n\n", ticks
);
86 PR_fprintf(output
, "PR_SecondsToInterval(1): %ld\n", PR_SecondsToInterval(1));
87 PR_fprintf(output
, "PR_MillisecondsToInterval(1000): %ld\n", PR_MillisecondsToInterval(1000));
88 PR_fprintf(output
, "PR_MicrosecondsToInterval(1000000): %ld\n\n", PR_MicrosecondsToInterval(1000000));
90 PR_fprintf(output
, "PR_SecondsToInterval(3): %ld\n", PR_SecondsToInterval(3));
91 PR_fprintf(output
, "PR_MillisecondsToInterval(3000): %ld\n", PR_MillisecondsToInterval(3000));
92 PR_fprintf(output
, "PR_MicrosecondsToInterval(3000000): %ld\n\n", PR_MicrosecondsToInterval(3000000));
94 PR_fprintf(output
, "PR_IntervalToSeconds(%ld): %ld\n", ticks
, PR_IntervalToSeconds(ticks
));
95 PR_fprintf(output
, "PR_IntervalToMilliseconds(%ld): %ld\n", ticks
, PR_IntervalToMilliseconds(ticks
));
96 PR_fprintf(output
, "PR_IntervalToMicroseconds(%ld): %ld\n\n", ticks
, PR_IntervalToMicroseconds(ticks
));
99 PR_fprintf(output
, "PR_IntervalToSeconds(%ld): %ld\n", ticks
, PR_IntervalToSeconds(ticks
));
100 PR_fprintf(output
, "PR_IntervalToMilliseconds(%ld): %ld\n", ticks
, PR_IntervalToMilliseconds(ticks
));
101 PR_fprintf(output
, "PR_IntervalToMicroseconds(%ld): %ld\n\n", ticks
, PR_IntervalToMicroseconds(ticks
));
102 } /*end debug mode */
103 } /* TestConversions */
105 static void TestIntervalOverhead(void)
107 /* Hopefully the optimizer won't delete this function */
108 PRUint32 elapsed
, per_call
, loops
= 1000000;
110 PRIntervalTime timeout
, timein
= PR_IntervalNow();
112 timeout
= PR_IntervalNow();
114 elapsed
= 1000U * PR_IntervalToMicroseconds(timeout
- timein
);
115 per_call
= elapsed
/ 1000000U;
117 output
, "Overhead of 'PR_IntervalNow()' is %u nsecs\n\n", per_call
);
118 } /* TestIntervalOverhead */
120 static void TestNowOverhead(void)
122 PRTime timeout
, timein
;
123 PRInt32 overhead
, loops
= 1000000;
124 PRInt64 elapsed
, per_call
, ten23rd
, ten26th
;
126 LL_I2L(ten23rd
, 1000);
127 LL_I2L(ten26th
, 1000000);
133 LL_SUB(elapsed
, timeout
, timein
);
134 LL_MUL(elapsed
, elapsed
, ten23rd
);
135 LL_DIV(per_call
, elapsed
, ten26th
);
136 LL_L2I(overhead
, per_call
);
138 output
, "Overhead of 'PR_Now()' is %u nsecs\n\n", overhead
);
139 } /* TestNowOverhead */
141 static void TestIntervals(void)
146 PRUint64 elapsed
, thousand
;
147 PRTime timein
, timeout
;
148 PRLock
*ml
= PR_NewLock();
149 PRCondVar
*cv
= PR_NewCondVar(ml
);
150 for (seconds
= 0; seconds
< 10; ++seconds
)
152 PRIntervalTime ticks
= PR_SecondsToInterval(seconds
);
155 rv
= PR_WaitCondVar(cv
, ticks
);
158 LL_SUB(elapsed
, timeout
, timein
);
159 LL_I2L(thousand
, 1000);
160 LL_DIV(elapsed
, elapsed
, thousand
);
161 LL_L2UI(delta
, elapsed
);
162 if (debug_mode
) PR_fprintf(output
,
163 "TestIntervals: %swaiting %ld seconds took %ld msecs\n",
164 ((rv
== PR_SUCCESS
) ? "" : "FAILED "), seconds
, delta
);
166 PR_DestroyCondVar(cv
);
168 if (debug_mode
) PR_fprintf(output
, "\n");
169 } /* TestIntervals */
171 static PRIntn PR_CALLBACK
RealMain(int argc
, char** argv
)
173 PRUint32 vcpu
, cpus
= 0, loops
= 1000;
175 /* The command line argument: -d is used to determine if the test is being run
176 in debug mode. The regress tool requires only one line output:PASS or FAIL.
177 All of the printfs associated with this test has been handled with a if (debug_mode)
185 PLOptState
*opt
= PL_CreateOptState(argc
, argv
, "dl:c:");
186 while (PL_OPT_EOL
!= (os
= PL_GetNextOpt(opt
)))
188 if (PL_OPT_BAD
== os
) continue;
191 case 'd': /* debug mode */
194 case 'c': /* concurrency counter */
195 cpus
= atoi(opt
->value
);
197 case 'l': /* loop counter */
198 loops
= atoi(opt
->value
);
204 PL_DestroyOptState(opt
);
206 output
= PR_GetSpecialFD(PR_StandardOutput
);
207 PR_fprintf(output
, "inrval: Examine stdout to determine results.\n");
209 if (cpus
== 0) cpus
= 8;
210 if (loops
== 0) loops
= 1000;
214 PR_fprintf(output
, "Inrval: Using %d loops\n", loops
);
215 PR_fprintf(output
, "Inrval: Using 1 and %d cpu(s)\n", cpus
);
218 for (vcpu
= 1; vcpu
<= cpus
; vcpu
+= cpus
- 1)
221 PR_fprintf(output
, "\nInrval: Using %d CPU(s)\n\n", vcpu
);
222 PR_SetConcurrency(vcpu
);
225 TestIntervalOverhead();
234 PRIntn
main(PRIntn argc
, char *argv
[])
239 rv
= PR_Initialize(RealMain
, argc
, argv
, 0);