summaryrefslogtreecommitdiffstats
path: root/nsprpub/pr/src/cplus/tests/ranfile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'nsprpub/pr/src/cplus/tests/ranfile.cpp')
-rw-r--r--nsprpub/pr/src/cplus/tests/ranfile.cpp205
1 files changed, 127 insertions, 78 deletions
diff --git a/nsprpub/pr/src/cplus/tests/ranfile.cpp b/nsprpub/pr/src/cplus/tests/ranfile.cpp
index c3ac0d3a4..0fb4c5d23 100644
--- a/nsprpub/pr/src/cplus/tests/ranfile.cpp
+++ b/nsprpub/pr/src/cplus/tests/ranfile.cpp
@@ -12,12 +12,12 @@
** Description: Test to hammer on various components of NSPR
** Modification History:
** 20-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.
***********************************************************************/
@@ -46,19 +46,21 @@ class HammerData
{
public:
typedef enum {
- sg_go, sg_stop, sg_done} Action;
+ sg_go, sg_stop, sg_done
+ } Action;
typedef enum {
- sg_okay, sg_open, sg_close, sg_delete, sg_write, sg_seek} Problem;
+ sg_okay, sg_open, sg_close, sg_delete, sg_write, sg_seek
+ } Problem;
- virtual ~HammerData();
- HammerData(RCLock* lock, RCCondition *cond, PRUint32 clip);
+ virtual ~HammerData();
+ HammerData(RCLock* lock, RCCondition *cond, PRUint32 clip);
virtual PRUint32 Random();
Action action;
Problem problem;
PRUint32 writes;
RCInterval timein;
-friend class Hammer;
+ friend class Hammer;
private:
RCLock *ml;
RCCondition *cv;
@@ -117,7 +119,7 @@ Hammer::~Hammer() { }
Hammer::Hammer(
RCThread::Scope scope, RCLock* lock, RCCondition *cond, PRUint32 clip):
- HammerData(lock, cond, clip), RCThread(scope, RCThread::joinable, 0) { }
+ HammerData(lock, cond, clip), RCThread(scope, RCThread::joinable, 0) { }
HammerData::~HammerData() { }
@@ -171,7 +173,9 @@ void Hammer::RootFunction()
(void)sprintf(filename, "%ssg%04p.dat", baseName, this);
- if (debug_mode) PR_fprintf(output, "Starting work on %s\n", filename);
+ if (debug_mode) {
+ PR_fprintf(output, "Starting work on %s\n", filename);
+ }
while (PR_TRUE)
{
@@ -182,52 +186,78 @@ void Hammer::RootFunction()
while (minor-- > 0)
{
problem = sg_okay;
- if (action != sg_go) goto finished;
+ if (action != sg_go) {
+ goto finished;
+ }
problem = sg_open;
rv = file.Open(filename, PR_RDWR|PR_CREATE_FILE, 0666);
- if (PR_FAILURE == rv) goto finished;
+ if (PR_FAILURE == rv) {
+ goto finished;
+ }
for (index = 0; index < pages; index++)
{
problem = sg_okay;
- if (action != sg_go) goto close;
+ if (action != sg_go) {
+ goto close;
+ }
problem = sg_seek;
bytes = file.Seek(pageSize * index, RCFileIO::set);
- if (bytes != pageSize * index) goto close;
+ if (bytes != pageSize * index) {
+ goto close;
+ }
problem = sg_write;
bytes = file.Write(&zero, sizeof(zero));
- if (bytes <= 0) goto close;
+ if (bytes <= 0) {
+ goto close;
+ }
writes += 1;
}
problem = sg_close;
rv = file.Close();
- if (rv != PR_SUCCESS) goto purge;
+ if (rv != PR_SUCCESS) {
+ goto purge;
+ }
problem = sg_okay;
- if (action != sg_go) goto purge;
+ if (action != sg_go) {
+ goto purge;
+ }
problem = sg_open;
rv = file.Open(filename, PR_RDWR, 0666);
- if (PR_FAILURE == rv) goto finished;
+ if (PR_FAILURE == rv) {
+ goto finished;
+ }
for (index = 0; index < pages; index++)
{
problem = sg_okay;
- if (action != sg_go) goto close;
+ if (action != sg_go) {
+ goto close;
+ }
problem = sg_seek;
bytes = file.Seek(pageSize * index, RCFileIO::set);
- if (bytes != pageSize * index) goto close;
+ if (bytes != pageSize * index) {
+ goto close;
+ }
problem = sg_write;
bytes = file.Write(&zero, sizeof(zero));
- if (bytes <= 0) goto close;
+ if (bytes <= 0) {
+ goto close;
+ }
writes += 1;
random = (random + 511) % pages;
}
problem = sg_close;
rv = file.Close();
- if (rv != PR_SUCCESS) goto purge;
+ if (rv != PR_SUCCESS) {
+ goto purge;
+ }
problem = sg_delete;
rv = file.Delete(filename);
- if (rv != PR_SUCCESS) goto finished;
- }
+ if (rv != PR_SUCCESS) {
+ goto finished;
+ }
+ }
}
close:
@@ -239,7 +269,9 @@ finished:
action = HammerData::sg_done;
cv->Notify();
- if (debug_mode) PR_fprintf(output, "Ending work on %s\n", filename);
+ if (debug_mode) {
+ PR_fprintf(output, "Ending work on %s\n", filename);
+ }
return;
} /* Hammer::RootFunction */
@@ -278,7 +310,7 @@ static Hammer* hammer[100];
PRIntn main (PRIntn argc, char *argv[])
{
RCLock ml;
- PLOptStatus os;
+ PLOptStatus os;
RCCondition cv(&ml);
PRUint32 writesMax = 0, durationTot = 0;
RCThread::Scope thread_scope = RCThread::local;
@@ -288,57 +320,65 @@ PRIntn main (PRIntn argc, char *argv[])
const char *where[] = {"okay", "open", "close", "delete", "write", "seek"};
- PLOptState *opt = PL_CreateOptState(argc, argv, "Gdl:t:i:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ PLOptState *opt = PL_CreateOptState(argc, argv, "Gdl:t:i:");
+ while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
{
- if (PL_OPT_BAD == os) continue;
+ if (PL_OPT_BAD == os) {
+ continue;
+ }
switch (opt->option)
{
- case 0:
- baseName = opt->value;
- break;
- case 'G': /* global threads */
- thread_scope = RCThread::global;
- break;
- case 'd': /* debug mode */
- debug_mode = 1;
- break;
- case 'l': /* limiting number */
- limit = atoi(opt->value);
- break;
- case 't': /* number of threads */
- threads = atoi(opt->value);
- break;
- case 'i': /* iteration counter */
- max_virtual_procs = atoi(opt->value);
- break;
- default:
- break;
+ case 0:
+ baseName = opt->value;
+ break;
+ case 'G': /* global threads */
+ thread_scope = RCThread::global;
+ break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ case 'l': /* limiting number */
+ limit = atoi(opt->value);
+ break;
+ case 't': /* number of threads */
+ threads = atoi(opt->value);
+ break;
+ case 'i': /* iteration counter */
+ max_virtual_procs = atoi(opt->value);
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
output = PR_GetSpecialFD(PR_StandardOutput);
- /* main test */
-
+ /* main test */
+
cv.SetTimeout(interleave);
-
- if (max_virtual_procs == 0) max_virtual_procs = 2;
- if (limit == 0) limit = 57;
- if (threads == 0) threads = 10;
+
+ if (max_virtual_procs == 0) {
+ max_virtual_procs = 2;
+ }
+ if (limit == 0) {
+ limit = 57;
+ }
+ if (threads == 0) {
+ threads = 10;
+ }
if (debug_mode) PR_fprintf(output,
- "%s: Using %d virtual processors, %d threads, limit = %d and %s threads\n",
- programName, max_virtual_procs, threads, limit,
- (thread_scope == RCThread::local) ? "LOCAL" : "GLOBAL");
+ "%s: Using %d virtual processors, %d threads, limit = %d and %s threads\n",
+ programName, max_virtual_procs, threads, limit,
+ (thread_scope == RCThread::local) ? "LOCAL" : "GLOBAL");
for (virtual_procs = 0; virtual_procs < max_virtual_procs; ++virtual_procs)
{
if (debug_mode)
- PR_fprintf(output,
- "%s: Setting number of virtual processors to %d\n",
- programName, virtual_procs + 1);
- RCPrimordialThread::SetVirtualProcessors(virtual_procs + 1);
+ PR_fprintf(output,
+ "%s: Setting number of virtual processors to %d\n",
+ programName, virtual_procs + 1);
+ RCPrimordialThread::SetVirtualProcessors(virtual_procs + 1);
for (active = 0; active < threads; active++)
{
hammer[active] = new Hammer(thread_scope, &ml, &cv, limit);
@@ -354,8 +394,9 @@ PRIntn main (PRIntn argc, char *argv[])
RCEnter scope(&ml);
for (poll = 0; poll < threads; poll++)
{
- if (hammer[poll]->action == HammerData::sg_go) /* don't overwrite done */
- hammer[poll]->action = HammerData::sg_stop; /* ask him to stop */
+ if (hammer[poll]->action == HammerData::sg_go) { /* don't overwrite done */
+ hammer[poll]->action = HammerData::sg_stop; /* ask him to stop */
+ }
}
}
@@ -364,24 +405,32 @@ PRIntn main (PRIntn argc, char *argv[])
for (poll = 0; poll < threads; poll++)
{
ml.Acquire();
- while (hammer[poll]->action < HammerData::sg_done) cv.Wait();
+ while (hammer[poll]->action < HammerData::sg_done) {
+ cv.Wait();
+ }
ml.Release();
if (hammer[poll]->problem == HammerData::sg_okay)
{
duration = RCInterval(RCInterval::now) - hammer[poll]->timein;
writes = hammer[poll]->writes * 1000 / duration;
- if (writes < writesMin) writesMin = writes;
- if (writes > writesMax) writesMax = writes;
+ if (writes < writesMin) {
+ writesMin = writes;
+ }
+ if (writes > writesMax) {
+ writesMax = writes;
+ }
writesTot += hammer[poll]->writes;
durationTot += duration;
}
else
{
if (debug_mode) PR_fprintf(output,
- "%s: test failed %s after %ld seconds\n",
- programName, where[hammer[poll]->problem], duration);
- else failed_already=1;
+ "%s: test failed %s after %ld seconds\n",
+ programName, where[hammer[poll]->problem], duration);
+ else {
+ failed_already=1;
+ }
}
active -= 1; /* this is another one down */
(void)hammer[poll]->Join();
@@ -389,12 +438,12 @@ PRIntn main (PRIntn argc, char *argv[])
}
}
if (debug_mode) PR_fprintf(output,
- "%s: [%ld [%ld] %ld] writes/sec average\n",
- programName, writesMin,
- writesTot * 1000 / durationTot, writesMax);
+ "%s: [%ld [%ld] %ld] writes/sec average\n",
+ programName, writesMin,
+ writesTot * 1000 / durationTot, writesMax);
}
- failed_already |= (PR_FAILURE == RCPrimordialThread::Cleanup());
- PR_fprintf(output, "%s\n", (failed_already) ? "FAIL\n" : "PASS\n");
- return failed_already;
+ failed_already |= (PR_FAILURE == RCPrimordialThread::Cleanup());
+ PR_fprintf(output, "%s\n", (failed_already) ? "FAIL\n" : "PASS\n");
+ return failed_already;
} /* main */