si_test.c 5.27 KB

/*************************************************************************
 *
 *  File: si_test.c
 *
 *  This file contains then main routine for BCP SI iosim tests.
 *
 */
#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"
#include "../bcptestsi.h"
#include "../trace.h"
#include "../bcp_util.h"
#include "../bcptest.h"


/***********************************************************************
 * Extern definitions
 */
//extern  TstCmd  TstCmdTbl[];
extern  void IoTestAll(int tests, int tests2, int levels, int seed);
extern   int IoCmd(int code, int data);

/***********************************************************************
 * Macro definitions
 */
#define TEST_CMD_FILE   "all.tst"
#define OPTARG      "d:l:o:t:u:s:qih"


/***********************************************************************
 * 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 *);


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

    int c, tests=0, tests2=0, levels=0, seed=0, req_quit=0, init_ddr=0;
    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%08lx\n", Dflags);
                break;
            }
            case 'o': { /* 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 't': { /* mask of tests to run */
                tests = strtoul(optarg,NULL,16);
                printf("tests=0x%08x\n", tests);
                break;
            }
            case 'u': { /* 2nd mask of tests to run */
                tests2 = strtoul(optarg,NULL,16);
                printf("tests2=0x%08x\n", tests2);
                break;
            }
            case 'l': { /* levels to run */
                levels = strtoul(optarg,NULL,10);
                printf("levels=%d\n", levels);
                break;
            }
            case 's': { /* seed that overrides any other method of getting seed */
                seed = strtoul(optarg,NULL,16);
                printf("seed=0x%08x\n", seed);
                break;
            }
            case 'q': { /* shut down simulator on exit */
                req_quit=1;
                printf("shut down simulator on exit\n");
                break;
            }
            case 'i': { /* do InitDDR before running tests */
                init_ddr=1;
                printf("do InitDDR before running tests\n");
                break;
            }
            case 'h': { /* Help */
                usage();
                exit(0);
            }
            default:
                break;
        }
    }  /* while */

    ExceptionHandlerInit();
    IpcInit(NULL);
    FindServer();
    do_keep_alive_socket(1);
    if( init_ddr )
        InitDDR(0x0, 0x0, 0x0, 0x0);
    IoTestAll(tests,tests2,levels,seed);

    if (fp)
        fclose(fp);

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

    do_keep_alive_socket(0);

    /* exit simulator */
    if(req_quit)
        IoCmd(REQ_QUIT, 0);

    exit(0);

}


void IoTestAll(int tests, int tests2, int levels, int seed)
{
    int i, ret, errCount;

    i = errCount = 0;
    i++;
    ret = SiRunTests(tests, tests2, levels, seed);
    if (ret == -1 || errorTotal) errCount++;
    fprintf(LogFp,
        "\n\n%3d. SiRunTests(%08x, %08x, %d, %08x) -> %s\n\n",
        i, tests, tests2, levels, seed, errCount ? "Failed":"Passed");

    fprintf(LogFp,
    "\n***** THE END (total test = %d, error count = %d) *****\n\n",
        i, errCount);

}


static void
usage(void)
{
    printf("Usage: si_test \n");
    printf("   -o <log_file>\n");
    printf("   -t <tests>\n");
    printf("         Hex mask identifying tests to run\n");
    printf("         Default if neither -t nor -u specified is all tests\n");
    printf("   -u <tests2>\n");
    printf("         Hex mask identifying more tests to run\n");
    printf("   -l <levels>\n");
    printf("         Decimal number identifying test levels to run\n");
    printf("         Default is all levels\n");
    printf("   -s <seed>\n");
    printf("         Hex seed that overrides default method of getting seed\n");
    printf("         Only used if <seed> is non-zero\n");
    printf("   -d <debug_flags in hex>\n");
    printf("   -i    do InitDDR before running tests\n");
    printf("   -q\n");
    printf("         Shut down the simulator on exit\n");
}