summaryrefslogtreecommitdiffstats
path: root/nsprpub/pr/tests/alarm.c
diff options
context:
space:
mode:
Diffstat (limited to 'nsprpub/pr/tests/alarm.c')
-rw-r--r--nsprpub/pr/tests/alarm.c259
1 files changed, 146 insertions, 113 deletions
diff --git a/nsprpub/pr/tests/alarm.c b/nsprpub/pr/tests/alarm.c
index e3dedb67f..10a148e44 100644
--- a/nsprpub/pr/tests/alarm.c
+++ b/nsprpub/pr/tests/alarm.c
@@ -12,12 +12,12 @@
**
** Modification History:
** 13-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 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.
+** 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.
+** recognize the return code from tha main program.
***********************************************************************/
/***********************************************************************
@@ -60,8 +60,9 @@ static void Notifier(void *arg)
PR_Lock(notifyData->ml);
while (notifyData->counter > 0)
{
- while (!notifyData->pending)
+ while (!notifyData->pending) {
PR_WaitCondVar(notifyData->child, PR_INTERVAL_NO_TIMEOUT);
+ }
notifyData->counter -= 1;
notifyData->pending = PR_FALSE;
PR_NotifyCondVar(notifyData->parent);
@@ -71,17 +72,17 @@ static void Notifier(void *arg)
/***********************************************************************
** PRIVATE FUNCTION: ConditionNotify
** DESCRIPTION:
-**
+**
** INPUTS: loops
** OUTPUTS: None
** RETURN: overhead
** SIDE EFFECTS:
-**
+**
** RESTRICTIONS:
** None
** MEMORY: NA
** ALGORITHM:
-**
+**
***********************************************************************/
@@ -90,7 +91,7 @@ static PRIntervalTime ConditionNotify(PRUint32 loops)
PRThread *thread;
NotifyData notifyData;
PRIntervalTime timein, overhead;
-
+
timein = PR_IntervalNow();
notifyData.counter = loops;
@@ -98,9 +99,9 @@ static PRIntervalTime ConditionNotify(PRUint32 loops)
notifyData.child = PR_NewCondVar(notifyData.ml);
notifyData.parent = PR_NewCondVar(notifyData.ml);
thread = PR_CreateThread(
- PR_USER_THREAD, Notifier, &notifyData,
- PR_GetThreadPriority(PR_GetCurrentThread()),
- thread_scope, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, Notifier, &notifyData,
+ PR_GetThreadPriority(PR_GetCurrentThread()),
+ thread_scope, PR_JOINABLE_THREAD, 0);
overhead = PR_IntervalNow() - timein; /* elapsed so far */
@@ -109,8 +110,9 @@ static PRIntervalTime ConditionNotify(PRUint32 loops)
{
notifyData.pending = PR_TRUE;
PR_NotifyCondVar(notifyData.child);
- while (notifyData.pending)
+ while (notifyData.pending) {
PR_WaitCondVar(notifyData.parent, PR_INTERVAL_NO_TIMEOUT);
+ }
}
PR_Unlock(notifyData.ml);
@@ -120,7 +122,7 @@ static PRIntervalTime ConditionNotify(PRUint32 loops)
PR_DestroyCondVar(notifyData.child);
PR_DestroyCondVar(notifyData.parent);
PR_DestroyLock(notifyData.ml);
-
+
overhead += (PR_IntervalNow() - timein); /* more overhead */
return overhead;
@@ -171,38 +173,44 @@ static PRBool AlarmFn1(PRAlarmID *id, void *clientData, PRUint32 late)
ad->late += late;
ad->times += 1;
keepGoing = ((PRIntervalTime)(now - ad->timein) < ad->duration) ?
- PR_TRUE : PR_FALSE;
- if (!keepGoing)
+ PR_TRUE : PR_FALSE;
+ if (!keepGoing) {
rv = PR_NotifyCondVar(ad->cv);
+ }
resetAlarm = ((ad->times % 31) == 0) ? PR_TRUE : PR_FALSE;
-
+
interval = (ad->period + ad->rate - 1) / ad->rate;
if (!late && (interval > 10))
{
interval &= (now & 0x03) + 1;
PR_WaitCondVar(ad->cv, interval);
}
-
+
PR_Unlock(ad->ml);
if (rv != PR_SUCCESS)
{
- if (!debug_mode) failed_already=1;
- else
- printf("AlarmFn: notify status: FAIL\n");
-
- }
+ if (!debug_mode) {
+ failed_already=1;
+ }
+ else {
+ printf("AlarmFn: notify status: FAIL\n");
+ }
+
+ }
if (resetAlarm)
- {
+ {
ad->rate += 3;
ad->late = ad->times = 0;
if (PR_ResetAlarm(id, ad->period, ad->rate) != PR_SUCCESS)
{
- if (!debug_mode)
- failed_already=1;
- else
- printf("AlarmFn: Resetting alarm status: FAIL\n");
+ if (!debug_mode) {
+ failed_already=1;
+ }
+ else {
+ printf("AlarmFn: Resetting alarm status: FAIL\n");
+ }
keepGoing = PR_FALSE;
}
@@ -235,12 +243,13 @@ static PRIntervalTime Alarms1(PRUint32 loops)
(void)PR_SetAlarm(
alarm, ad.period, ad.rate, AlarmFn1, &ad);
-
+
overhead = PR_IntervalNow() - timein;
PR_Lock(ml);
- while ((PRIntervalTime)(PR_IntervalNow() - ad.timein) < duration)
+ while ((PRIntervalTime)(PR_IntervalNow() - ad.timein) < duration) {
PR_WaitCondVar(cv, PR_INTERVAL_NO_TIMEOUT);
+ }
PR_Unlock(ml);
timein = PR_IntervalNow();
@@ -248,7 +257,7 @@ static PRIntervalTime Alarms1(PRUint32 loops)
PR_DestroyCondVar(cv);
PR_DestroyLock(ml);
overhead += (PR_IntervalNow() - timein);
-
+
return duration + overhead;
} /* Alarms1 */
@@ -262,7 +271,7 @@ static PRBool AlarmFn2(PRAlarmID *id, void *clientData, PRUint32 late)
PR_Lock(ad->ml);
ad->times += 1;
keepGoing = ((PRIntervalTime)(now - ad->timein) < ad->duration) ?
- PR_TRUE : PR_FALSE;
+ PR_TRUE : PR_FALSE;
interval = (ad->period + ad->rate - 1) / ad->rate;
if (!late && (interval > 10))
@@ -271,13 +280,16 @@ static PRBool AlarmFn2(PRAlarmID *id, void *clientData, PRUint32 late)
PR_WaitCondVar(ad->cv, interval);
}
- if (!keepGoing) rv = PR_NotifyCondVar(ad->cv);
+ if (!keepGoing) {
+ rv = PR_NotifyCondVar(ad->cv);
+ }
PR_Unlock(ad->ml);
- if (rv != PR_SUCCESS)
- failed_already=1;;
+ if (rv != PR_SUCCESS) {
+ failed_already=1;
+ };
return keepGoing;
} /* AlarmFn2 */
@@ -306,31 +318,34 @@ static PRIntervalTime Alarms2(PRUint32 loops)
(void)PR_SetAlarm(
alarm, ad.period, ad.rate, AlarmFn2, &ad);
-
+
overhead = PR_IntervalNow() - timein;
PR_Lock(ml);
- while ((PRIntervalTime)(PR_IntervalNow() - ad.timein) < duration)
+ while ((PRIntervalTime)(PR_IntervalNow() - ad.timein) < duration) {
PR_WaitCondVar(cv, PR_INTERVAL_NO_TIMEOUT);
+ }
PR_Unlock(ml);
-
+
timein = PR_IntervalNow();
rv = PR_DestroyAlarm(alarm);
if (rv != PR_SUCCESS)
{
- if (!debug_mode)
- failed_already=1;
- else
- printf("***Destroying alarm status: FAIL\n");
+ if (!debug_mode) {
+ failed_already=1;
+ }
+ else {
+ printf("***Destroying alarm status: FAIL\n");
+ }
}
-
+
PR_DestroyCondVar(cv);
PR_DestroyLock(ml);
-
+
overhead += (PR_IntervalNow() - timein);
-
+
return duration + overhead;
} /* Alarms2 */
@@ -370,35 +385,38 @@ static PRIntervalTime Alarms3(PRUint32 loops)
alarm, ad[i].period, ad[i].rate,
AlarmFn2, &ad[i]);
}
-
+
overhead = PR_IntervalNow() - timein;
PR_Lock(ml);
for (i = 0; i < 3; ++i)
{
- while ((PRIntervalTime)(PR_IntervalNow() - ad[i].timein) < duration)
+ while ((PRIntervalTime)(PR_IntervalNow() - ad[i].timein) < duration) {
PR_WaitCondVar(cv, PR_INTERVAL_NO_TIMEOUT);
+ }
}
PR_Unlock(ml);
timein = PR_IntervalNow();
- if (debug_mode)
- printf
+ if (debug_mode)
+ printf
("Alarms3 finished at %u, %u, %u\n",
- ad[0].timein, ad[1].timein, ad[2].timein);
-
+ ad[0].timein, ad[1].timein, ad[2].timein);
+
rv = PR_DestroyAlarm(alarm);
if (rv != PR_SUCCESS)
{
- if (!debug_mode)
- failed_already=1;
- else
- printf("***Destroying alarm status: FAIL\n");
- }
+ if (!debug_mode) {
+ failed_already=1;
+ }
+ else {
+ printf("***Destroying alarm status: FAIL\n");
+ }
+ }
PR_DestroyCondVar(cv);
PR_DestroyLock(ml);
-
+
overhead += (duration / 3);
overhead += (PR_IntervalNow() - timein);
@@ -411,15 +429,17 @@ static PRUint32 TimeThis(
PRUint32 overhead, usecs;
PRIntervalTime predicted, timein, timeout, ticks;
- if (debug_mode)
- printf("Testing %s ...", msg);
+ if (debug_mode) {
+ printf("Testing %s ...", msg);
+ }
timein = PR_IntervalNow();
predicted = func(loops);
timeout = PR_IntervalNow();
- if (debug_mode)
- printf(" done\n");
+ if (debug_mode) {
+ printf(" done\n");
+ }
ticks = timeout - timein;
usecs = PR_IntervalToMicroseconds(ticks);
@@ -427,18 +447,18 @@ static PRUint32 TimeThis(
if(ticks < predicted)
{
- if (debug_mode) {
- printf("\tFinished in negative time\n");
- printf("\tpredicted overhead was %d usecs\n", overhead);
- printf("\ttest completed in %d usecs\n\n", usecs);
- }
+ if (debug_mode) {
+ printf("\tFinished in negative time\n");
+ printf("\tpredicted overhead was %d usecs\n", overhead);
+ printf("\ttest completed in %d usecs\n\n", usecs);
+ }
}
else
{
- if (debug_mode)
- printf(
- "\ttotal: %d usecs\n\toverhead: %d usecs\n\tcost: %6.3f usecs\n\n",
- usecs, overhead, ((double)(usecs - overhead) / (double)loops));
+ if (debug_mode)
+ printf(
+ "\ttotal: %d usecs\n\toverhead: %d usecs\n\tcost: %6.3f usecs\n\n",
+ usecs, overhead, ((double)(usecs - overhead) / (double)loops));
}
return overhead;
@@ -448,70 +468,83 @@ int prmain(int argc, char** argv)
{
PRUint32 cpu, cpus = 0, loops = 0;
- /* 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]
- */
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "Gdl:c:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ /* 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]
+ */
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "Gdl:c:");
+ while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
{
- if (PL_OPT_BAD == os) continue;
+ if (PL_OPT_BAD == os) {
+ continue;
+ }
switch (opt->option)
{
- case 'G': /* GLOBAL threads */
- thread_scope = PR_GLOBAL_THREAD;
- break;
- case 'd': /* debug mode */
- debug_mode = 1;
- break;
- case 'l': /* loop count */
- loops = atoi(opt->value);
- break;
- case 'c': /* concurrency limit */
- cpus = atoi(opt->value);
- break;
- default:
- break;
+ case 'G': /* GLOBAL threads */
+ thread_scope = PR_GLOBAL_THREAD;
+ break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ case 'l': /* loop count */
+ loops = atoi(opt->value);
+ break;
+ case 'c': /* concurrency limit */
+ cpus = atoi(opt->value);
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- if (cpus == 0) cpus = 1;
- if (loops == 0) loops = 4;
+ if (cpus == 0) {
+ cpus = 1;
+ }
+ if (loops == 0) {
+ loops = 4;
+ }
- if (debug_mode)
- printf("Alarm: Using %d loops\n", loops);
+ if (debug_mode) {
+ printf("Alarm: Using %d loops\n", loops);
+ }
- if (debug_mode)
+ if (debug_mode) {
printf("Alarm: Using %d cpu(s)\n", cpus);
+ }
for (cpu = 1; cpu <= cpus; ++cpu)
{
- if (debug_mode)
- printf("\nAlarm: Using %d CPU(s)\n", cpu);
+ if (debug_mode) {
+ printf("\nAlarm: Using %d CPU(s)\n", cpu);
+ }
- PR_SetConcurrency(cpu);
+ PR_SetConcurrency(cpu);
- /* some basic time test */
- (void)TimeThis("ConditionNotify", ConditionNotify, loops);
- (void)TimeThis("ConditionTimeout", ConditionTimeout, loops);
- (void)TimeThis("Alarms1", Alarms1, loops);
- (void)TimeThis("Alarms2", Alarms2, loops);
- (void)TimeThis("Alarms3", Alarms3, loops);
+ /* some basic time test */
+ (void)TimeThis("ConditionNotify", ConditionNotify, loops);
+ (void)TimeThis("ConditionTimeout", ConditionTimeout, loops);
+ (void)TimeThis("Alarms1", Alarms1, loops);
+ (void)TimeThis("Alarms2", Alarms2, loops);
+ (void)TimeThis("Alarms3", Alarms3, loops);
}
return 0;
}
int main(int argc, char** argv)
{
- PR_Initialize(prmain, argc, argv, 0);
- PR_STDIO_INIT();
- if (failed_already) return 1;
- else return 0;
+ PR_Initialize(prmain, argc, argv, 0);
+ PR_STDIO_INIT();
+ if (failed_already) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
} /* main */