1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 ** description: Interval conversion test.
9 ** Modification History:
10 ** 15-May-97 AGarcia- Converted the test to accomodate the debug_mode flag.
11 ** The debug mode will print all of the printfs associated with this test.
12 ** The regress mode will be the default mode. Since the regress tool limits
13 ** the output to a one line status:PASS or FAIL,all of the printf statements
14 ** have been handled with an if (debug_mode) statement.
15 ** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to
16 ** recognize the return code from tha main program.
18 /***********************************************************************
20 ***********************************************************************/
21 /* Used to get the command line option */
25 #include "obsolete/pralarm.h"
40 static PRIntn debug_mode
;
41 static PRFileDesc
*output
;
44 static void TestConversions(void)
46 PRIntervalTime ticks
= PR_TicksPerSecond();
49 PR_fprintf(output
, "PR_TicksPerSecond: %ld\n\n", ticks
);
50 PR_fprintf(output
, "PR_SecondsToInterval(1): %ld\n", PR_SecondsToInterval(1));
51 PR_fprintf(output
, "PR_MillisecondsToInterval(1000): %ld\n", PR_MillisecondsToInterval(1000));
52 PR_fprintf(output
, "PR_MicrosecondsToInterval(1000000): %ld\n\n", PR_MicrosecondsToInterval(1000000));
54 PR_fprintf(output
, "PR_SecondsToInterval(3): %ld\n", PR_SecondsToInterval(3));
55 PR_fprintf(output
, "PR_MillisecondsToInterval(3000): %ld\n", PR_MillisecondsToInterval(3000));
56 PR_fprintf(output
, "PR_MicrosecondsToInterval(3000000): %ld\n\n", PR_MicrosecondsToInterval(3000000));
58 PR_fprintf(output
, "PR_IntervalToSeconds(%ld): %ld\n", ticks
, PR_IntervalToSeconds(ticks
));
59 PR_fprintf(output
, "PR_IntervalToMilliseconds(%ld): %ld\n", ticks
, PR_IntervalToMilliseconds(ticks
));
60 PR_fprintf(output
, "PR_IntervalToMicroseconds(%ld): %ld\n\n", ticks
, PR_IntervalToMicroseconds(ticks
));
63 PR_fprintf(output
, "PR_IntervalToSeconds(%ld): %ld\n", ticks
, PR_IntervalToSeconds(ticks
));
64 PR_fprintf(output
, "PR_IntervalToMilliseconds(%ld): %ld\n", ticks
, PR_IntervalToMilliseconds(ticks
));
65 PR_fprintf(output
, "PR_IntervalToMicroseconds(%ld): %ld\n\n", ticks
, PR_IntervalToMicroseconds(ticks
));
67 } /* TestConversions */
69 static void TestIntervalOverhead(void)
71 /* Hopefully the optimizer won't delete this function */
72 PRUint32 elapsed
, per_call
, loops
= 1000000;
74 PRIntervalTime timeout
, timein
= PR_IntervalNow();
76 timeout
= PR_IntervalNow();
78 elapsed
= 1000U * PR_IntervalToMicroseconds(timeout
- timein
);
79 per_call
= elapsed
/ 1000000U;
81 output
, "Overhead of 'PR_IntervalNow()' is %u nsecs\n\n", per_call
);
82 } /* TestIntervalOverhead */
84 static void TestNowOverhead(void)
86 PRTime timeout
, timein
;
87 PRInt32 overhead
, loops
= 1000000;
88 PRInt64 elapsed
, per_call
, ten23rd
, ten26th
;
90 LL_I2L(ten23rd
, 1000);
91 LL_I2L(ten26th
, 1000000);
97 LL_SUB(elapsed
, timeout
, timein
);
98 LL_MUL(elapsed
, elapsed
, ten23rd
);
99 LL_DIV(per_call
, elapsed
, ten26th
);
100 LL_L2I(overhead
, per_call
);
102 output
, "Overhead of 'PR_Now()' is %u nsecs\n\n", overhead
);
103 } /* TestNowOverhead */
105 static void TestIntervals(void)
110 PRUint64 elapsed
, thousand
;
111 PRTime timein
, timeout
;
112 PRLock
*ml
= PR_NewLock();
113 PRCondVar
*cv
= PR_NewCondVar(ml
);
114 for (seconds
= 0; seconds
< 10; ++seconds
)
116 PRIntervalTime ticks
= PR_SecondsToInterval(seconds
);
119 rv
= PR_WaitCondVar(cv
, ticks
);
122 LL_SUB(elapsed
, timeout
, timein
);
123 LL_I2L(thousand
, 1000);
124 LL_DIV(elapsed
, elapsed
, thousand
);
125 LL_L2UI(delta
, elapsed
);
126 if (debug_mode
) PR_fprintf(output
,
127 "TestIntervals: %swaiting %ld seconds took %ld msecs\n",
128 ((rv
== PR_SUCCESS
) ? "" : "FAILED "), seconds
, delta
);
130 PR_DestroyCondVar(cv
);
132 if (debug_mode
) PR_fprintf(output
, "\n");
133 } /* TestIntervals */
135 static PRIntn PR_CALLBACK
RealMain(int argc
, char** argv
)
137 PRUint32 vcpu
, cpus
= 0, loops
= 1000;
139 /* The command line argument: -d is used to determine if the test is being run
140 in debug mode. The regress tool requires only one line output:PASS or FAIL.
141 All of the printfs associated with this test has been handled with a if (debug_mode)
149 PLOptState
*opt
= PL_CreateOptState(argc
, argv
, "dl:c:");
150 while (PL_OPT_EOL
!= (os
= PL_GetNextOpt(opt
)))
152 if (PL_OPT_BAD
== os
) continue;
155 case 'd': /* debug mode */
158 case 'c': /* concurrency counter */
159 cpus
= atoi(opt
->value
);
161 case 'l': /* loop counter */
162 loops
= atoi(opt
->value
);
168 PL_DestroyOptState(opt
);
170 output
= PR_GetSpecialFD(PR_StandardOutput
);
171 PR_fprintf(output
, "inrval: Examine stdout to determine results.\n");
173 if (cpus
== 0) cpus
= 8;
174 if (loops
== 0) loops
= 1000;
178 PR_fprintf(output
, "Inrval: Using %d loops\n", loops
);
179 PR_fprintf(output
, "Inrval: Using 1 and %d cpu(s)\n", cpus
);
182 for (vcpu
= 1; vcpu
<= cpus
; vcpu
+= cpus
- 1)
185 PR_fprintf(output
, "\nInrval: Using %d CPU(s)\n\n", vcpu
);
186 PR_SetConcurrency(vcpu
);
189 TestIntervalOverhead();
198 int main(int argc
, char **argv
)
203 rv
= PR_Initialize(RealMain
, argc
, argv
, 0);