summaryrefslogtreecommitdiff
path: root/pr/tests/lock.c
diff options
context:
space:
mode:
Diffstat (limited to 'pr/tests/lock.c')
-rw-r--r--pr/tests/lock.c159
1 files changed, 94 insertions, 65 deletions
diff --git a/pr/tests/lock.c b/pr/tests/lock.c
index f10f80fd..83a4f418 100644
--- a/pr/tests/lock.c
+++ b/pr/tests/lock.c
@@ -9,12 +9,12 @@
**
** Modification History:
** 14-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.
**
** 11-Aug-97 LarryH. Win16 port of NSPR.
** - Added "PASS", "FAIL" messages on completion.
@@ -149,8 +149,8 @@ static PRIntervalTime ContentiousLock(PRUint32 loops)
contention->ml = PR_NewLock();
contention->interval = contention_interval;
thread = PR_CreateThread(
- PR_USER_THREAD, LockContender, contention,
- PR_PRIORITY_LOW, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, LockContender, contention,
+ PR_PRIORITY_LOW, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
PR_ASSERT(thread != NULL);
overhead = PR_IntervalNow() - timein;
@@ -211,12 +211,18 @@ static PRIntervalTime NonContentiousMonitor(PRUint32 loops)
static void PR_CALLBACK TryEntry(void *arg)
{
PRMonitor *ml = (PRMonitor*)arg;
- if (debug_mode) PR_fprintf(std_err, "Reentrant thread created\n");
+ if (debug_mode) {
+ PR_fprintf(std_err, "Reentrant thread created\n");
+ }
PR_EnterMonitor(ml);
PR_ASSERT_CURRENT_THREAD_IN_MONITOR(ml);
- if (debug_mode) PR_fprintf(std_err, "Reentrant thread acquired monitor\n");
+ if (debug_mode) {
+ PR_fprintf(std_err, "Reentrant thread acquired monitor\n");
+ }
PR_ExitMonitor(ml);
- if (debug_mode) PR_fprintf(std_err, "Reentrant thread released monitor\n");
+ if (debug_mode) {
+ PR_fprintf(std_err, "Reentrant thread released monitor\n");
+ }
} /* TryEntry */
static PRIntervalTime ReentrantMonitor(PRUint32 loops)
@@ -224,32 +230,40 @@ static PRIntervalTime ReentrantMonitor(PRUint32 loops)
PRStatus status;
PRThread *thread;
PRMonitor *ml = PR_NewMonitor();
- if (debug_mode) PR_fprintf(std_err, "\nMonitor created for reentrant test\n");
+ if (debug_mode) {
+ PR_fprintf(std_err, "\nMonitor created for reentrant test\n");
+ }
PR_EnterMonitor(ml);
PR_ASSERT_CURRENT_THREAD_IN_MONITOR(ml);
PR_EnterMonitor(ml);
PR_ASSERT_CURRENT_THREAD_IN_MONITOR(ml);
- if (debug_mode) PR_fprintf(std_err, "Monitor acquired twice\n");
+ if (debug_mode) {
+ PR_fprintf(std_err, "Monitor acquired twice\n");
+ }
thread = PR_CreateThread(
- PR_USER_THREAD, TryEntry, ml,
- PR_PRIORITY_LOW, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, TryEntry, ml,
+ PR_PRIORITY_LOW, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
PR_ASSERT(thread != NULL);
PR_Sleep(PR_SecondsToInterval(1));
PR_ASSERT_CURRENT_THREAD_IN_MONITOR(ml);
PR_ExitMonitor(ml);
PR_ASSERT_CURRENT_THREAD_IN_MONITOR(ml);
- if (debug_mode) PR_fprintf(std_err, "Monitor released first time\n");
+ if (debug_mode) {
+ PR_fprintf(std_err, "Monitor released first time\n");
+ }
PR_ExitMonitor(ml);
- if (debug_mode) PR_fprintf(std_err, "Monitor released second time\n");
+ if (debug_mode) {
+ PR_fprintf(std_err, "Monitor released second time\n");
+ }
status = PR_JoinThread(thread);
if (debug_mode) PR_fprintf(std_err,
- "Reentrant thread joined %s\n",
- (status == PR_SUCCESS) ? "successfully" : "in error");
+ "Reentrant thread joined %s\n",
+ (status == PR_SUCCESS) ? "successfully" : "in error");
PR_DestroyMonitor(ml);
return 0;
@@ -283,8 +297,8 @@ static PRUint32 ContentiousMonitor(PRUint32 loops)
contention->ml = PR_NewMonitor();
contention->interval = contention_interval;
thread = PR_CreateThread(
- PR_USER_THREAD, MonitorContender, contention,
- PR_PRIORITY_LOW, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, MonitorContender, contention,
+ PR_PRIORITY_LOW, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
PR_ASSERT(thread != NULL);
overhead = PR_IntervalNow() - timein;
@@ -352,8 +366,8 @@ static PRIntervalTime ContentiousCMonitor(PRUint32 loops)
contention->loops = loops;
contention->interval = contention_interval;
thread = PR_CreateThread(
- PR_USER_THREAD, Contender, contention,
- PR_PRIORITY_LOW, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, Contender, contention,
+ PR_PRIORITY_LOW, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
PR_ASSERT(thread != NULL);
overhead = PR_IntervalNow() - timein;
@@ -405,11 +419,15 @@ static PRIntervalTime Test(
accountable -= overhead;
elapsed = (PRFloat64)PR_IntervalToMicroseconds(accountable);
PR_fprintf(PR_STDOUT, "%s:", msg);
- while (spaces++ < 50) PR_fprintf(PR_STDOUT, " ");
- if ((PRInt32)accountable < 0)
+ while (spaces++ < 50) {
+ PR_fprintf(PR_STDOUT, " ");
+ }
+ if ((PRInt32)accountable < 0) {
PR_fprintf(PR_STDOUT, "*****.** usecs/iteration\n");
- else
+ }
+ else {
PR_fprintf(PR_STDOUT, "%8.2f usecs/iteration\n", elapsed/loops);
+ }
}
return duration;
} /* Test */
@@ -424,58 +442,68 @@ int main(int argc, char **argv)
PR_STDIO_INIT();
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 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.
+ /* 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.
Command line argument -l <num> sets the number of loops.
Command line argument -c <num> sets the number of cpus.
Usage: lock [-d] [-l <num>] [-c <num>]
- */
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "dvl:c:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ */
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "dvl: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 'd': /* debug mode */
- debug_mode = PR_TRUE;
- break;
- case 'v': /* debug mode */
- verbosity = PR_TRUE;
- break;
- case 'l': /* number of loops */
- loops = atoi(opt->value);
- break;
- case 'c': /* number of cpus */
- cpus = atoi(opt->value);
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = PR_TRUE;
+ break;
+ case 'v': /* debug mode */
+ verbosity = PR_TRUE;
+ break;
+ case 'l': /* number of loops */
+ loops = atoi(opt->value);
+ break;
+ case 'c': /* number of cpus */
+ cpus = atoi(opt->value);
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
}
- /* main test */
+ /* main test */
PR_SetConcurrency(8);
- if (loops == 0) loops = 100;
+ if (loops == 0) {
+ loops = 100;
+ }
if (debug_mode)
{
std_err = PR_STDERR;
PR_fprintf(std_err, "Lock: Using %d loops\n", loops);
}
- if (cpus == 0) cpus = 2;
- if (debug_mode) PR_fprintf(std_err, "Lock: Using %d cpu(s)\n", cpus);
+ if (cpus == 0) {
+ cpus = 2;
+ }
+ if (debug_mode) {
+ PR_fprintf(std_err, "Lock: Using %d cpu(s)\n", cpus);
+ }
(void)Sleeper(10); /* try filling in the caches */
for (cpu = 1; cpu <= cpus; ++cpu)
{
- if (debug_mode) PR_fprintf(std_err, "\nLock: Using %d CPU(s)\n", cpu);
+ if (debug_mode) {
+ PR_fprintf(std_err, "\nLock: Using %d CPU(s)\n", cpu);
+ }
PR_SetConcurrency(cpu);
duration = Test("Overhead of PR_Sleep", Sleeper, loops, 0);
@@ -498,20 +526,21 @@ int main(int argc, char **argv)
PR_fprintf(
std_err, "%s: test %s\n", "Lock(mutex) test",
((rv) ? "passed" : "failed"));
- else {
- if (!rv)
- failed_already=1;
- }
-
- if(failed_already)
- {
- PR_fprintf(PR_STDOUT, "FAIL\n");
- return 1;
+ else {
+ if (!rv) {
+ failed_already=1;
+ }
+ }
+
+ if(failed_already)
+ {
+ PR_fprintf(PR_STDOUT, "FAIL\n");
+ return 1;
}
- else
+ else
{
- PR_fprintf(PR_STDOUT, "PASS\n");
- return 0;
+ PR_fprintf(PR_STDOUT, "PASS\n");
+ return 0;
}
} /* main */