ranfile.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 ***** */
/***********************************************************************
**
** Contact: AOF<freier@netscape.com>
**
** Name: ranfile.c
**
** 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 output to a one line status:PASS or FAIL,all of the printf statements
** 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.
***********************************************************************/
/***********************************************************************
** Includes
***********************************************************************/
/* Used to get the command line option */
#include "plgetopt.h"
#include "prinit.h"
#include "prthread.h"
#include "prlock.h"
#include "prcvar.h"
#include "prmem.h"
#include "prinrval.h"
#include "prio.h"
#include <string.h>
#include <stdio.h>
static PRIntn debug_mode = 0;
static PRIntn failed_already=0;
typedef struct Hammer_s {
} Hammer_t;
#define DEFAULT_LIMIT 10
#define DEFAULT_THREADS 2
#define DEFAULT_LOOPS 1
static const char* baseName = "./";
static const char *programName = "Random File";
#ifdef XP_MAC
#include "prlog.h"
#define printf PR_LogPrint
extern void SetupMacPrintfLog(char *logFile);
#endif
/***********************************************************************
** PRIVATE FUNCTION: Random
** DESCRIPTION:
** Generate a pseudo-random number
** INPUTS: None
** OUTPUTS: None
** RETURN: A pseudo-random unsigned number, 32-bits wide
** SIDE EFFECTS:
** Updates random seed (a static)
** RESTRICTIONS:
** None
** MEMORY: NA
** ALGORITHM:
** Uses the current interval timer value, promoted to a 64 bit
** float as a multiplier for a static residue (which begins
** as an uninitialized variable). The result is bits [16..48)
** of the product. Seed is then updated with the return value
** promoted to a float-64.
***********************************************************************/
{
return rv;
} /* Random */
/***********************************************************************
** PRIVATE FUNCTION: Thread
** DESCRIPTION:
** Hammer on the file I/O system
** INPUTS: A pointer to the thread's private data
** OUTPUTS: None
** RETURN: None
** SIDE EFFECTS:
** Creates, accesses and deletes a file
** RESTRICTIONS:
** MEMORY: NA
** ALGORITHM:
** This function is a root of a thread
** 2) Writes a zero to a random number of sequential pages
** 3) Closes the file
** 4) Reopens the file
** 5) Seeks to a random page within the file
** 6) Writes a one byte on that page
** 7) Repeat steps [5..6] for each page in the file
** 8) Close and delete the file
** 9) Repeat steps [1..8] until told to stop
** 10) Notify complete and return
***********************************************************************/
{
char filename[30];
const char zero = 0;
while (PR_TRUE)
{
while (minor-- > 0)
{
{
}
{
}
}
}
return;
} /* Thread */
/***********************************************************************
** PRIVATE FUNCTION: main
** DESCRIPTION:
** Hammer on the file I/O system
** INPUTS: The usual argc and argv
** argv[0] - program name (not used)
** argv[1] - the number of times to execute the major loop
** argv[2] - the number of threads to toss into the batch
** argv[3] - the clipping number applied to randoms
** default values: loops = 2, threads = 10, limit = 57
** OUTPUTS: None
** RETURN: None
** SIDE EFFECTS:
** Creates, accesses and deletes lots of files
** RESTRICTIONS:
** MEMORY: NA
** ALGORITHM:
** 1) Fork a "Thread()"
** 2) Wait for 'interleave' seconds
** 3) For [0..'threads') repeat [1..2]
** 4) Mark all objects to stop
** 5) Collect the threads, accumulating the results
** 6) For [0..'loops') repeat [1..5]
** 7) Print accumulated results and exit
**
** Characteristic output (from IRIX)
** Random File: Using loops = 2, threads = 10, limit = 57
***********************************************************************/
{
PRIntervalTime duration = 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
*/
{
if (PL_OPT_BAD == os) continue;
{
case 'G': /* global threads */
break;
case 'd': /* debug mode */
debug_mode = 1;
break;
case 'l': /* limiting number */
break;
case 't': /* number of threads */
break;
case 'i': /* iteration counter */
break;
default:
break;
}
}
/* main test */
#ifdef XP_MAC
SetupMacPrintfLog("ranfile.log");
debug_mode = 1;
#endif
ml = PR_NewLock();
if (debug_mode) printf(
"%s: Using loops = %d, threads = %d, limit = %d and %s threads\n",
{
{
}
/*
* The last thread started has had the opportunity to run for
* 'interleave' seconds. Now gather them all back in.
*/
{
}
while (active > 0)
{
{
{
durationTot += duration;
}
else
if (debug_mode) printf(
"%s: test failed %s after %ld seconds\n",
else failed_already=1;
}
}
}
if (debug_mode) printf(
if (failed_already)
{
printf("FAIL\n");
return 1;
}
else
{
printf("PASS\n");
return 0;
}
} /* main */