rdpDump.c 3.46 KB
#include <sys/types.h>
#ifdef __sgi__
#include <sys/sbd.h>
#endif
#include <sys/stat.h>
#include <sys/mman.h>
#ifdef __sgi__
#include <sys/sema.h>
#endif
#include <netinet/in.h>

#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <getopt.h>

#include <sys/u64driver.h>

#include <diag.h>
#include <dbg_comm.h>

#define RDP_DUMP_TEST_BASE	10

static int rdpDump(TEST_REF *test_ref);

/*
 * Create an array of tests, each of which corresponds to a separate menu
 * item callable from the master ide menu.
 */
static TEST_REF TestRefs[] = {
    {"Dump of important RDP registers", RDP_DUMP_TEST_BASE+0, rdpDump},
    {"",0,0}
};

static char *addr, *mask, *count;
static int NumFailures = 0;

static int rdpDump_Init();
static int rdpDump_Do(TEST_REF *test_ref);

/*
 * diagnostic entry point:
 *
 * Each separately invokable ide diagnostic command corresponds to an
 * independent ".c" module; the entry point herein must match
 * the test name as specified in the commoncmd.awk script.  These command
 * names correspond to the names you see from the ide menu.  
 */
int
dgRdpDumpEntry()
{
    int c, testNum;
    int i;

for (i = 0; i < pGlobalComm->argc; i++) {
    printf("argv[%d] = %s\n", i, pGlobalComm->argv[i]);
}

    /*
     * Sample of how to parse command line args received from ide
     */
    while ((c = getopt(pGlobalComm->argc, pGlobalComm->argv, "ht:")) != EOF) {
	switch(c) {
	    case 'h':
		/*
		 * Print out the available subtests, then return without
		 * invoking any subtests (which is done by calling diaginit()).
		 */
		dgListSubTests(TestRefs);
		return(0);
		break;
	    case 't':
		testNum = atoi(optarg);
		pGlobalComm->entryNum = -(testNum);
		break;
	    default:
		printf("weird option character %c = 0x%x\n", c, c);
		while (1);
		break;
        }
    }
return;
    /*
     * IDE will call our one-time initialization function rdpDump_Init(),
     * then invoke rdpDump_Do() for as many tests as we've put into the
     * global test array "TestRefs", declared at the top of this module.
     */
    diaginit(TestRefs, rdpDump_Init, rdpDump_Do);

    if (NumFailures) {
        errlog(INFO_END, "... test %s FAILED, %d failures.",
            ideTestName, NumFailures);
    } else {
	errlog(INFO_END, "... test %s PASSED", ideTestName);
    }
}

static int rdpDump_Init()
{
    char *env;

    errlog(INFO_START, "Starting test %s ... ", ideTestName);
    NumFailures = 0;

    /*
     * Setup the diagnostic communication link to the target system.
     */
    if ( dgInitComm() ) {
	errlog(ERR_SEVERE,
	  "Unable to initialize communication with target system.\n");
	pGlobalComm->entryNum = -1;
    }

    return(0);
}

static int rdpDump_Do(TEST_REF *test_ref)
{
    int rc;

    errlog(INFO_START, "%s: starting subtest %s (%d) ...",
      ideTestName, test_ref->name, test_ref->num);

    /*
     * Invoke the actual test from the "TEST_REF" array statically declared
     * as a global within this test module.
     */
    if (rc = test_ref->fnc(test_ref)) NumFailures++;

    if (rc == 0) {
	errlog(INFO_END, "... PASSED");
    } else {
	errlog(INFO_END, "... FAILED");
    }
    return(NumFailures);
}

/*
 * Return value: number of errors encountered.  "Zero" indicates success.
 */
int
rdpDump(TEST_REF *test_ref)
{
    int i;
    unsigned int revision1, revision;

    dgReadWord(0x04300004, &revision1);
    for (i = 0; i < 10000000; i++) {
	dgReadWord(0x04300004, &revision);
	if (revision != revision1)
	    errlog(INFO, "ulp!\n");
    }

    return(0);
}