randmain.c 4.97 KB

/*************************************************************************
 *
 *  File: main.c
 *
 *  This file contains the main routine for the I/O random test.
 *
 *  $Header: /root/leakn64/depot/rf/sw/n64os20l/iosim/src/randmain.c,v 1.2 2002/05/30 05:52:50 whs Exp $
 *
 */

#ifdef __sgi__
	#include <sys/cachectl.h>
#endif
#include <sys/mman.h>
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#ifdef __sgi__
	#include <libelf.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include <time.h>

#include "sim.h"
#include "simipc.h"

#define	OPTARG		"CRad:i:f:l:m:n:o:c:r:s:t:h:?"

/*
 * Forward declarations
 */
static void	usage(void);

/*
 * External references
 */
extern void	SyncInit(void);
extern void	IoInit(void);
extern int	IoRandInit(char *);
extern int	IoRandTest(char *);
extern void	ShutdownServer(void);
extern unsigned int	LoopCount;
extern unsigned int	MinRunCount;
extern unsigned int	TestSeed;
extern unsigned int	CompareEnabled;
extern unsigned int	RoundRobinEnabled;
extern unsigned int     RandomRobinEnabled;
extern unsigned int     Ai441Enabled;
extern unsigned int     RdramSize;
extern char	IpcName[];

/*
 * Global variables
 */
int		IpcFd = -1;
unsigned long	Dflags;
char		*CmdFile;
char		*LogFile;
FILE		*LogFp, *CmdFp;
int		ConfigRdramV = 0;
char		*Server = NULL;
int             NumberStallCycles = 0;

/*
 * Local variables
 */
static char	*ipcName = NULL;
static char	*testRange = "0-14";	/* Default test range: 0-14 */


/*
 * Main
 */
main(int argc, char **argv)
{

	int		  c, ret;
	FILE		  *fp = NULL;
	struct descriptor d;
        time_t            t;
        char              *s;

	extern char *optarg;
	extern int optind, opterr, optopt;

	optind = 1;
	Dflags = 0;
	LogFp  = stderr;

	while ((c = getopt(argc, argv, OPTARG)) != EOF) {
		switch (c) {
			case 'C': {	/* Turn off DMA compare */
				printf("DMA compare is disabled!\n");
				CompareEnabled = 0;
				break;
			}
			case 'R': {	/* Turn on round robin scheduling */
				printf("Round-robin scheduling is enabled!\n");
				RoundRobinEnabled = 1;
				break;
			}
			case 'a': {	/* Turn on audio to run at 44.1 KHz */
				printf("Audio at 44.1 KHz is enabled!\n");
				Ai441Enabled = 1;
				break;
			}
			case 'd': {	/* Debug */
				Dflags = strtoul(optarg, NULL, 16);
				printf("Debug flag=0x%08x\n", Dflags);
				break;
			}
			case 'i': {	/* Iteration */
				LoopCount = atoi(optarg);
				printf("Minimum iteration=%d\n", LoopCount);
				break;
			}
			case 'l': {	/* Log file */
				LogFile = optarg;
				printf("Log file = %s\n", LogFile);
				if ((fp = fopen(LogFile, "w+")) == NULL) {
					printf("Unable to open log: %s\n",
						LogFile);
				}
				else
					LogFp = fp;
				break;
			}
			case 'm': {     /* Memory size = 4,6 */
				ret = atoi(optarg);
				switch (ret) {
					case 4:
					case 6:
						RdramSize = ret;
						break;
					default:   
						RdramSize = 4;
						break;
				}
				break;
			}
			case 'n': {     /* IPC name */
				ipcName = optarg;
				break;
			}
			case 'o': {	/* Random test 'ovule' */
				TestSeed = atoi(optarg);
				break;
			}
				
			case 'c': {	/* Config RDRAM */
				printf("Config RDRAM using verilog\n");
				ConfigRdramV = 1;
				break;
			}
			case 'r': {	/* Run count */
				MinRunCount = atoi(optarg);
				printf("Minimum thread run count=%d\n", 
					MinRunCount);
				break;
			}
			case 's': {	/* Automatically exec simv.ipc */
				Server = optarg;
				break;
			}
			case 't': {	/* Test range */
				testRange = optarg;
				printf("Test range=%s\n", testRange);
				break;
			}
			case 'h': 	/* Help */
			case '?': {
				usage();
				exit(0);
			}
			default:
				break;
		}
	}  /* while */

	SyncInit();
	IpcInit(ipcName);
	printf("Using IPC name '%s' ...\n", IpcName);

	if (Server == NULL) {
		Server = getenv("SIMV");
		if ((Server != NULL) && (*Server == '\0'))
			Server = NULL;
	}

	if (Server != NULL)
		ExecServer(Server);

	FindServer();
	ExceptionHandlerInit();
	IoInit();

        t = time(NULL);
        s = asctime(localtime(&t));
        fprintf(LogFp, "\n=======> IO random test begins at\t%s\n", s);

	IoRandInit(testRange);
	if (IoRandTest(testRange) < 0)
		printf("ERROR: Unable to perform random IO testing!\n");

        t = time(NULL);
        s = asctime(localtime(&t));
        fprintf(LogFp, "\n=======> IO random test ends at\t%s\n", s);

	ShutdownServer();

	if (fp)
		fclose(fp);

	if (Server != NULL)
		WaitServer();

	exit(0);

}

static void
usage(void)
{
	printf("Usage: iorand \n");
	printf("       -C (Turn off data comparison for most DMA tests)\n");
	printf("       -R (Turn on round-robin scheduling)\n");
	printf("       -a (Turn audio to run at 44.1 KHz)\n");
	printf("       -n <ipc name>\n");
	printf("       -d <debug_flags in hex>\n");
	printf("       -i <iteration>\n");
	printf("       -m <memory size>\n");
	printf("       -r <thread run count>\n");
	printf("       -t <test range>\n");
	printf("       -l <log_file>\n");
	printf("       -s <simv ... >\n");
	printf("       -h <help - this message>\n");
}