rsp_bp.c 4.45 KB
#include <sys/types.h>
#include <sys/sbd.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/sema.h>

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

#include <sys/u64driver.h>
#include <rsp.h>

/*
 * From $ROOT/usr/include/ide, which is installed from $ROOT/PR/diags/include
 */
#include "diag.h"

#define RSP_TEST_BASE	10

static int rsptest(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[] = {
    {"RSP test", 	RSP_TEST_BASE+0, rsptest},
    {"",0,0}
};

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

static int rsp_bpInit();
static int rsp_bpDo(TEST_REF *test_ref);

int debug;

/*
 * 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 rspcmd.awk script.  These command
 * names correspond to the names you see from the ide menu.  For this
 * module, there will be an ide command "rsp_bp" (until this
 * silly module is retired, that is).
 */
int rsp_bp(struct diagcomm *pcomm)
{
    int c;

    debug = 0;

    /*
     * Sample of how to parse command line args received from ide
     */
    while ((c = getopt(pcomm->argc, pcomm->argv, "d")) != EOF) {
	switch(c) {
	    case 'd':
		debug = 1;
		break;
	    default:
		printf("weird option character %c = 0x%x\n", c, c);
		break;
        }
    }

    TestName = pcomm->argv[0];

    /*
     * IDE will call our one-time initialization function rsp_bpInit(),
     * then invoke rsp_bpDo() for as many tests as we've put into the
     * global test array "TestRefs", declared at the top of this module.
     */
    diaginit(TestRefs, rsp_bpInit, rsp_bpDo);

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

static int rsp_bpInit()
{
    char *env;

    if (env = getenv("IDE_DEBUG_LEVEL")) DebugLevel = atoi(env);
    if (env = getenv("IDE_SHORT_MSG")) ShortMsg = atoi(env);
    errlog(INFO_START, 0, 0, "Starting test %s ... ", TestName);
    NumFailures = 0;

    /*
     * Setup the diagnostic communication link to the target system.
     *
     * For now, this can only be done with the TARGET indy environment.
     */
    if (debug)
	dgInitComm();

    return(0);
}

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

    if (!ShortMsg)
        errlog(INFO_START, test_ref->num, 0,
            "%s: starting subtest %s (%d) ...",
            TestName, 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 (!ShortMsg) {
        if (rc == 0) errlog(INFO_END, test_ref->num, 0, "... PASSED");
        else errlog(INFO_END, test_ref->num, 0, "... FAILED");
    }
    return(NumFailures);
}

/*
 * Return value: number of errors encountered.  "Zero" indicates success.
 */
int
rsptest(TEST_REF *test_ref)
{
    int ret_len;
    int len = 4; /* hardwired to four bytes for simple test */
    int id = 0;	/* use a thread id of zero, seems to work with dbgif */
    unsigned char buf[256];
    int *pBuf;

    /*
     * If the debug flag is set, try writing, then reading back some values
     * to a safe memory location on the TARGET indy.
     */
    if (debug) {
	pBuf = (int *)buf;
	*pBuf = 0xdeadbeef;
	ret_len = dgWriteMem (id, RSP_DMEM_BASE, len, pBuf);

	if (ret_len < 0) {
	    errlog(ERR_SEVERE, test_ref->num, 0,
		"%s: error: dgWriteMem() call failed.\n", TestName);
	    return(1);
	}

	ret_len = dgReadMem (id, RSP_DMEM_BASE, len, pBuf);

	if (ret_len < 0) {
	    errlog(ERR_SEVERE, test_ref->num, 0,
		"%s: error: dgReadMem() call failed.\n", TestName);
	    return(1);
	}

	if (ret_len < len) {
	    errlog(ERR_SIMPLE, test_ref->num, 0,
		"%s: warning: %d bytes requested, could only read %d bytes.\n",
		TestName, len, ret_len);
	}

	if (*pBuf != 0xdeadbeef) {
	    errlog(ERR_SIMPLE, test_ref->num, 0, 
	      "0x%08x: read 0x%x, exp 0x%x, rd^exp = 0x%x\n", 
	      RSP_DMEM_BASE, *pBuf, 0xdeadbeef, (*pBuf ^ 0xdeadbeef));
	} else {
	    errlog(INFO, test_ref->num, 0, "0x%08x: 0x%x\n", RSP_DMEM_BASE, *pBuf);
	}
    }
    return(0);
}