arena.c revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Netscape Portable Runtime (NSPR).
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998-2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
** File: arena.c
** Description: Testing arenas
**
*/
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include "nspr.h"
#include "plarena.h"
#include "plgetopt.h"
PRIntn threadCount = 0;
/* Arguments from the command line with default values */
PRIntn debug_mode = 0;
void DumpAll( void )
{
return;
}
/*
** Test Arena allocation.
*/
static void ArenaAllocate( void )
{
void *ptr;
PRInt32 i;
for( i = 0; i < 150; i++ )
{
}
PL_FreeArenaPool( &ap );
for( i = 0; i < 221; i++ )
{
}
PL_FreeArenaPool( &ap );
return;
} /* end ArenaGrow() */
/*
** Test Arena grow.
*/
static void ArenaGrow( void )
{
void *ptr;
PRInt32 i;
for( i = 0; i < 10; i++ )
{
}
return;
} /* end ArenaGrow() */
/*
** Test arena Mark and Release.
*/
static void MarkAndRelease( void )
{
PRIntn i;
for( i = 0; i < 201; i++ )
{
}
for( i = 0; i < 225; i++ )
{
}
("Release-1: %p -- Pool: %p. first: %p, current: %p, size: %d",
for( i = 0; i < 20; i++ )
{
}
PL_FreeArenaPool( &ap );
PL_FinishArenaPool( &ap );
return;
} /* end MarkAndRelease() */
/*
** RandSize() returns a random number in the range
** min..max, rounded to the next doubleword
**
*/
{
sz &= ~sizeof(double)-1;
return(sz);
}
/*
** StressThread()
** A bunch of these beat on individual arenas
** This tests the free_list protection.
**
*/
{
PRIntn i;
void *ptr;
for ( i = 0; i < stressIterations; i++ )
{
{
{
break;
}
}
PL_FreeArenaPool( &ap );
}
PL_FinishArenaPool( &ap );
/* That's all folks! let's quit */
threadCount--;
return;
}
/*
** Stress()
** Flog the hell out of arenas multi-threaded.
** Do NOT pass an individual arena to another thread.
**
*/
static void Stress( void )
{
PRIntn i;
tMon = PR_NewMonitor();
for ( i = 0 ; i < stressThreads ; i++ )
{
NULL,
0);
threadCount++;
}
/* Wait for all threads to exit */
while ( threadCount != 0 )
{
}
return;
} /* end Stress() */
/*
** EvaluateResults()
** uses failed_already to display results and set program
** exit code.
*/
static PRIntn EvaluateResults(void)
{
if ( failed_already == PR_TRUE )
{
rc =1;
}
else
{
}
return(rc);
} /* EvaluateResults() */
void Help( void )
{
printf("arena [options]\n");
printf("where options are:\n");
printf("-d enable debug mode\n");
printf("\n");
exit(1);
}
{
{
if (PL_OPT_BAD == os) continue;
{
case 'a': /* arena Min size */
break;
case 'A': /* arena Max size */
break;
case 'p': /* pool Min size */
break;
case 'P': /* pool Max size */
break;
case 'i': /* Iterations in stress tests */
break;
case 's': /* storage to get per iteration */
break;
case 't': /* Number of stress threads to create */
break;
case 'd': /* debug mode */
debug_mode = 1;
break;
case 'h': /* help */
default:
Help();
} /* end switch() */
} /* end while() */
#if 0
ArenaGrow();
#endif
Stress();
return(EvaluateResults());
} /* end main() */
/* arena.c */