tstsim.c 2.13 KB

/*************************************************************************
 *
 *  File: tstsim.c
 *
 *  $Header: /root/leakn64/depot/rf/sw/bbplayer/iosim/src/tstsim.c,v 1.2 2002/05/30 05:52:50 whs Exp $
 *
 */
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>

#include "iomap.h"
#include "iotest.h"
#include "sim.h"
#include "simipc.h"


/***********************************************************************
 * Extern definitions
 */
extern	TstCmd	TstCmdTbl[];
extern	void	IoTestAll(void);


/***********************************************************************
 * Macro definitions
 */
#define	TEST_CMD_FILE	"all.tst"
#define	OPTARG		"d:l:h"


/***********************************************************************
 * Global definitions
 */
int		IpcFd = -1;
unsigned long	Dflags;
char		*CmdFile = TEST_CMD_FILE;
FILE		*LogFp, *CmdFp;
int		ConfigRdramV = 0;
int             NumberStallCycles = 0;


/***********************************************************************
 * Local static definitions
 */
static FILE		*dumpFp = NULL;

static void		usage(void);
static void		convertTst2C(char *);


main(int argc, char **argv)
{

	int c, testId;
	char	*file;
	FILE	*fp = NULL;

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

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

	while ((c = getopt(argc, argv, OPTARG)) != EOF) {
		switch (c) {
			case 'd': {	/* Debug flag */
				Dflags = strtoul(optarg, NULL, 16);
				printf("Debug flag=0x%08x\n", Dflags);
				break;
			}
			case 'l': {	/* Log file */
				file = optarg;
				printf("Log file = %s\n", file);
				if ((fp = fopen(file, "w+")) == NULL) {
					printf("Unable to open log: %s\n",
						file);
				}
				else
					LogFp = fp;
				break;
			}
			case 'h': {	/* Help */
				usage();
				exit(0);
			}
			default:
				break;
		}
	}  /* while */

	ExceptionHandlerInit();
	IoTestAll();

	if (fp)
		fclose(fp);

	if (IpcFd != -1)
		IpcClose(IpcFd);

	exit(0);

}

static void
usage(void)
{
	printf("Usage: tstsim \n");
	printf("       -l <log_file>\n");
	printf("       -d <debug_flags in hex>\n");
}