summaryrefslogtreecommitdiffstats
path: root/nsprpub/lib/tests/arena.c
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@wolfbeast.com>2020-01-02 21:01:38 +0100
committerwolfbeast <mcwerewolf@wolfbeast.com>2020-01-02 21:01:38 +0100
commitf7d30133221896638f7bf4f66c504255c4b14f48 (patch)
tree5f3e07a049f388a3a309a615b8884318f6668a98 /nsprpub/lib/tests/arena.c
parent26b297510a11758727438df4669357a2a2bc42ce (diff)
downloadUXP-f7d30133221896638f7bf4f66c504255c4b14f48.tar
UXP-f7d30133221896638f7bf4f66c504255c4b14f48.tar.gz
UXP-f7d30133221896638f7bf4f66c504255c4b14f48.tar.lz
UXP-f7d30133221896638f7bf4f66c504255c4b14f48.tar.xz
UXP-f7d30133221896638f7bf4f66c504255c4b14f48.zip
Issue #1338 - Part 1: Update NSPR to 4.24
Diffstat (limited to 'nsprpub/lib/tests/arena.c')
-rw-r--r--nsprpub/lib/tests/arena.c220
1 files changed, 111 insertions, 109 deletions
diff --git a/nsprpub/lib/tests/arena.c b/nsprpub/lib/tests/arena.c
index e82e4f8b5..2be2d5b4c 100644
--- a/nsprpub/lib/tests/arena.c
+++ b/nsprpub/lib/tests/arena.c
@@ -33,7 +33,7 @@ PRIntn stressThreads = 4;
void DumpAll( void )
{
- return;
+ return;
}
/*
@@ -43,34 +43,34 @@ static void ArenaAllocate( void )
{
PLArenaPool ap;
void *ptr;
- PRInt32 i;
+ PRInt32 i;
PL_InitArenaPool( &ap, "AllocArena", 2048, sizeof(double));
- PR_LOG( tLM, PR_LOG_DEBUG, ("AA, InitPool -- Pool: %p. first: %p, current: %p, size: %d",
- &ap, ap.first, ap.current, ap.arenasize ));
-
- for( i = 0; i < 150; i++ )
- {
- PL_ARENA_ALLOCATE( ptr, &ap, 512 );
- PR_LOG( tLM, PR_LOG_DEBUG,("AA, after alloc -- Pool: %p. first: %p, current: %p, size: %d",
- &ap, ap.first, ap.current, ap.arenasize ));
- PR_LOG( tLM, PR_LOG_DEBUG,(
- "AA -- Pool: %p. alloc: %p ", &ap, ptr ));
- }
+ PR_LOG( tLM, PR_LOG_DEBUG, ("AA, InitPool -- Pool: %p. first: %p, current: %p, size: %d",
+ &ap, ap.first, ap.current, ap.arenasize ));
+
+ for( i = 0; i < 150; i++ )
+ {
+ PL_ARENA_ALLOCATE( ptr, &ap, 512 );
+ PR_LOG( tLM, PR_LOG_DEBUG,("AA, after alloc -- Pool: %p. first: %p, current: %p, size: %d",
+ &ap, ap.first, ap.current, ap.arenasize ));
+ PR_LOG( tLM, PR_LOG_DEBUG,(
+ "AA -- Pool: %p. alloc: %p ", &ap, ptr ));
+ }
PL_FreeArenaPool( &ap );
- for( i = 0; i < 221; i++ )
- {
- PL_ARENA_ALLOCATE( ptr, &ap, 512 );
- PR_LOG( tLM, PR_LOG_DEBUG,("AA, after alloc -- Pool: %p. first: %p, current: %p, size: %d",
- &ap, ap.first, ap.current, ap.arenasize ));
- PR_LOG( tLM, PR_LOG_DEBUG,(
- "AA -- Pool: %p. alloc: %p ", &ap, ptr ));
- }
+ for( i = 0; i < 221; i++ )
+ {
+ PL_ARENA_ALLOCATE( ptr, &ap, 512 );
+ PR_LOG( tLM, PR_LOG_DEBUG,("AA, after alloc -- Pool: %p. first: %p, current: %p, size: %d",
+ &ap, ap.first, ap.current, ap.arenasize ));
+ PR_LOG( tLM, PR_LOG_DEBUG,(
+ "AA -- Pool: %p. alloc: %p ", &ap, ptr ));
+ }
PL_FreeArenaPool( &ap );
-
+
return;
} /* end ArenaGrow() */
/*
@@ -80,18 +80,18 @@ static void ArenaGrow( void )
{
PLArenaPool ap;
void *ptr;
- PRInt32 i;
+ PRInt32 i;
PL_InitArenaPool( &ap, "TheArena", 4096, sizeof(double));
PL_ARENA_ALLOCATE( ptr, &ap, 512 );
- PR_LOG( tLM, PR_LOG_DEBUG, ("Before growth -- Pool: %p. alloc: %p ", &ap, ptr ));
+ PR_LOG( tLM, PR_LOG_DEBUG, ("Before growth -- Pool: %p. alloc: %p ", &ap, ptr ));
- for( i = 0; i < 10; i++ )
- {
- PL_ARENA_GROW( ptr, &ap, 512, 7000 );
- PR_LOG( tLM, PR_LOG_DEBUG, ("After growth -- Pool: %p. alloc: %p ", &ap, ptr ));
- }
+ for( i = 0; i < 10; i++ )
+ {
+ PL_ARENA_GROW( ptr, &ap, 512, 7000 );
+ PR_LOG( tLM, PR_LOG_DEBUG, ("After growth -- Pool: %p. alloc: %p ", &ap, ptr ));
+ }
return;
@@ -111,69 +111,69 @@ static void MarkAndRelease( void )
PL_InitArenaPool( &ap, "TheArena", 4096, sizeof(double));
mark0 = PL_ARENA_MARK( &ap );
PR_LOG( tLM, PR_LOG_DEBUG,
- ("mark0. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p, m0: %p",
- &ap, ap.first.next, ap.current, ap.arenasize, ptr, mark0 ));
+ ("mark0. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p, m0: %p",
+ &ap, ap.first.next, ap.current, ap.arenasize, ptr, mark0 ));
- for( i = 0; i < 201; i++ )
- {
- PL_ARENA_ALLOCATE( ptr, &ap, 512 );
+ for( i = 0; i < 201; i++ )
+ {
+ PL_ARENA_ALLOCATE( ptr, &ap, 512 );
PR_LOG( tLM, PR_LOG_DEBUG,
- ("mr. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
- &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
- }
+ ("mr. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
+ &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
+ }
mark1 = PL_ARENA_MARK( &ap );
PR_LOG( tLM, PR_LOG_DEBUG,
- ("mark1. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p, m1: %p",
- &ap, ap.first.next, ap.current, ap.arenasize, ptr, mark1 ));
+ ("mark1. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p, m1: %p",
+ &ap, ap.first.next, ap.current, ap.arenasize, ptr, mark1 ));
- for( i = 0; i < 225; i++ )
- {
- PL_ARENA_ALLOCATE( ptr, &ap, 512 );
+ for( i = 0; i < 225; i++ )
+ {
+ PL_ARENA_ALLOCATE( ptr, &ap, 512 );
PR_LOG( tLM, PR_LOG_DEBUG,
- ("mr. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
- &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
- }
+ ("mr. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
+ &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
+ }
PL_ARENA_RELEASE( &ap, mark1 );
PR_LOG( tLM, PR_LOG_DEBUG,
- ("Release-1: %p -- Pool: %p. first: %p, current: %p, size: %d",
- mark1, &ap, ap.first, ap.current, ap.arenasize ));
+ ("Release-1: %p -- Pool: %p. first: %p, current: %p, size: %d",
+ mark1, &ap, ap.first, ap.current, ap.arenasize ));
- for( i = 0; i < 20; i++ )
- {
- PL_ARENA_ALLOCATE( ptr, &ap, 512 );
+ for( i = 0; i < 20; i++ )
+ {
+ PL_ARENA_ALLOCATE( ptr, &ap, 512 );
PR_LOG( tLM, PR_LOG_DEBUG,
- ("mr. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
- &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
- }
+ ("mr. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
+ &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
+ }
PL_ARENA_RELEASE( &ap, mark1 );
PR_LOG( tLM, PR_LOG_DEBUG,
- ("Release-1. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
- &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
+ ("Release-1. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
+ &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
PL_ARENA_RELEASE( &ap, mark0 );
PR_LOG( tLM, PR_LOG_DEBUG,
- ("Release-0. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
- &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
+ ("Release-0. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
+ &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
PL_FreeArenaPool( &ap );
PR_LOG( tLM, PR_LOG_DEBUG,
- ("Free. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
- &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
-
+ ("Free. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
+ &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
+
PL_FinishArenaPool( &ap );
PR_LOG( tLM, PR_LOG_DEBUG,
- ("Finish. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
- &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
+ ("Finish. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
+ &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
return;
} /* end MarkAndRelease() */
/*
-** RandSize() returns a random number in the range
+** RandSize() returns a random number in the range
** min..max, rounded to the next doubleword
**
*/
@@ -230,15 +230,15 @@ static void PR_CALLBACK StressThread( void *arg )
PR_EnterMonitor(tMon);
threadCount--;
PR_Notify(tMon);
- PR_ExitMonitor(tMon);
+ PR_ExitMonitor(tMon);
return;
-}
+}
/*
** Stress()
** Flog the hell out of arenas multi-threaded.
** Do NOT pass an individual arena to another thread.
-**
+**
*/
static void Stress( void )
{
@@ -251,24 +251,24 @@ static void Stress( void )
{
PR_EnterMonitor(tMon);
tt = PR_CreateThread(PR_USER_THREAD,
- StressThread,
- NULL,
- PR_PRIORITY_NORMAL,
- PR_GLOBAL_THREAD,
- PR_UNJOINABLE_THREAD,
- 0);
+ StressThread,
+ NULL,
+ PR_PRIORITY_NORMAL,
+ PR_GLOBAL_THREAD,
+ PR_UNJOINABLE_THREAD,
+ 0);
threadCount++;
PR_ExitMonitor(tMon);
}
/* Wait for all threads to exit */
PR_EnterMonitor(tMon);
- while ( threadCount != 0 )
+ while ( threadCount != 0 )
{
PR_Wait(tMon, PR_INTERVAL_NO_TIMEOUT);
}
PR_ExitMonitor(tMon);
- PR_DestroyMonitor(tMon);
+ PR_DestroyMonitor(tMon);
return;
} /* end Stress() */
@@ -286,7 +286,7 @@ static PRIntn EvaluateResults(void)
{
PR_LOG( tLM, PR_LOG_DEBUG, ("FAIL\n"));
rc =1;
- }
+ }
else
{
PR_LOG( tLM, PR_LOG_DEBUG, ("PASS\n"));
@@ -308,55 +308,57 @@ void Help( void )
printf("-d enable debug mode\n");
printf("\n");
exit(1);
-}
+}
PRIntn main(PRIntn argc, char *argv[])
{
PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "dhp:P:a:A:i:s:t:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ PLOptState *opt = PL_CreateOptState(argc, argv, "dhp:P:a:A:i:s:t:");
+ while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
{
- if (PL_OPT_BAD == os) continue;
+ if (PL_OPT_BAD == os) {
+ continue;
+ }
switch (opt->option)
{
- case 'a': /* arena Min size */
- arenaMin = atol( opt->value );
- break;
- case 'A': /* arena Max size */
- arenaMax = atol( opt->value );
- break;
- case 'p': /* pool Min size */
- poolMin = atol( opt->value );
- break;
- case 'P': /* pool Max size */
- poolMax = atol( opt->value );
- break;
- case 'i': /* Iterations in stress tests */
- stressIterations = atol( opt->value );
- break;
- case 's': /* storage to get per iteration */
- maxAlloc = atol( opt->value );
- break;
- case 't': /* Number of stress threads to create */
- stressThreads = atol( opt->value );
- break;
- case 'd': /* debug mode */
- debug_mode = 1;
- break;
- case 'h': /* help */
- default:
- Help();
+ case 'a': /* arena Min size */
+ arenaMin = atol( opt->value );
+ break;
+ case 'A': /* arena Max size */
+ arenaMax = atol( opt->value );
+ break;
+ case 'p': /* pool Min size */
+ poolMin = atol( opt->value );
+ break;
+ case 'P': /* pool Max size */
+ poolMax = atol( opt->value );
+ break;
+ case 'i': /* Iterations in stress tests */
+ stressIterations = atol( opt->value );
+ break;
+ case 's': /* storage to get per iteration */
+ maxAlloc = atol( opt->value );
+ break;
+ case 't': /* Number of stress threads to create */
+ stressThreads = atol( opt->value );
+ break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ case 'h': /* help */
+ default:
+ Help();
} /* end switch() */
} /* end while() */
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
srand( (unsigned)time( NULL ) ); /* seed random number generator */
tLM = PR_NewLogModule("testcase");
#if 0
- ArenaAllocate();
- ArenaGrow();
+ ArenaAllocate();
+ ArenaGrow();
#endif
MarkAndRelease();