rsp_regr_common.c 6.63 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 <rcp.h>
#include <rsp.h>

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

#define DMEM_R1 0x04000f84
#define RSP_TEST_BASE	001
#define RDRAM_SCRATCH_BASE 0x00100000

void mem_init(FILE *file_p, unsigned int start_addr);
int rsp_regrInit();
int rsp_regrDo(TEST_REF *test_ref);

extern int NumFailures = 0;
extern int failed_tests[512];

int rsp_regr(TestRefs)
    TEST_REF TestRefs[];
{
    int c;
    int i;

    while ((c = getopt(pGlobalComm->argc, pGlobalComm->argv, "hdet:")) != EOF) {
	switch(c) {
	    case 'h':
	        dgListSubTests(TestRefs);
		return;
	    case 'd':
		printmask = 0xff;
		errlog(INFO, "Test will be run in debug mode.");
		break;
	    case 'e':
		exitmask = 0x0;
		errlog(INFO, "Test will not terminate on errors.");
		break;
	    case 't':
		pGlobalComm->entryNum = -atoi(optarg);
		errlog(INFO, "Running test %d only.", pGlobalComm->entryNum);
		break;
	    default:
		printf("weird option character %c = 0x%x\n", c, c);
		break;
        }
    }

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

    if (NumFailures) {
	for (i=1; i<512; i++) {
	  if (failed_tests[i]) {
	    errlog(INFO_END, "Test %d: %s failed.", i, TestRefs[i-1].name);
	  }
        }
        errlog(ERR_SEVERE, "... test %s FAILED, %d failures.",
            ideTestName, NumFailures);
    } else {
	errlog(INFO_END, "... test %s PASSED", ideTestName);
    }
}

int rsp_regrInit()
{
    int i;

    errlog(INFO, "Starting test %s ... ", ideTestName);
    for (i=0; i<512; i++) {failed_tests[i] = 0;}
    NumFailures = 0;
    dgInitComm();
    return(0);
}

int rsp_regrDo(TEST_REF *test_ref)
{
    int rc;

    errlog(INFO, " %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, "--- subtest %s PASSED", test_ref->name);
    else {
      errlog(ERR_SEVERE, "--- subtest %s FAILED", test_ref->name);
      failed_tests[test_ref->num] = 1;
    }
    
    return(NumFailures);
}


void
mem_init(FILE *file_p, unsigned int start_addr)
{
  unsigned int data;
  int cont = 1;
  int c;

  while (cont==1) {
    cont = fscanf(file_p, "%x", &data);
    if (cont==1) {
      if ((start_addr & 0xff) == 0)
        errlog(DEBUG, "Loading Mem[%x] with %x", start_addr, data);
      dgWriteWord(start_addr, data);
    }
    start_addr +=4;

    /* scan to end of line */
    while (c != '\n' && c != EOF) {
    c = fgetc(file_p);
    }
  }
}

void
unhalt_and_go()
{
  dgWriteWord(0x04080000, 0x00000000);       /* Initialize PC */
  dgWriteWord(0x04040010, 0x00000005);       /* Clear break and halt */
}

int
generic_rsp_regression (const char *file_name)
{
  int done = 0;
  unsigned int status;
  unsigned int r1_contents;
  unsigned int pc;
  char dmem_file[100];
  char imem_file[100];
  FILE *file_i;
  FILE *file_d;

  char ifile[100];
  char dfile[100];
  
  sprintf(imem_file, "%s.ihex", file_name);
  sprintf(dmem_file, "%s.dhex", file_name);
  
  if (! dgFindFile(ifile, "/PR/diags/rsp", imem_file)) {
    if (! dgFindFile(ifile, "/usr/diags/data/rsp",imem_file)){
      errlog(ERR_SEVERE,"Could not find file %s",imem_file);}}
  if (! dgFindFile(dfile, "/PR/diags/rsp", dmem_file)) {
    if (! dgFindFile(dfile, "/usr/diags/data/rsp",dmem_file)){
      errlog(ERR_SEVERE,"Could not find file %s",dmem_file);}}

  if ((file_i = fopen(ifile, "r")) == NULL) {
    errlog(ERR_SEVERE, "could not open file %s", imem_file);
      return 1;
  }

  if ((file_d = fopen(dfile, "r")) == NULL) {
    errlog(ERR_SEVERE, "could not open file %s", dmem_file);
      return 1;
  }

  dgWriteWord(DMEM_R1, 0x000c1ea7);       /* Clear DMem R1 contents */
  mem_init(file_i, RSP_IMEM_BASE);
  mem_init(file_d, RSP_DMEM_BASE);

  fclose(file_i);
  fclose(file_d);
  
  unhalt_and_go();
  while (!done) {
    dgReadWord(0x04040010, &status);           /* Check break status */
    done = status & 0x2;
  }
  dgReadWord(DMEM_R1, &r1_contents);
  errlog(DEBUG, "R1 contents:%x", r1_contents);
  dgReadWord(0x04080000, &pc);
  errlog(DEBUG, "PC::%x", pc);
  return((r1_contents != 0x0000feed) && (r1_contents != 0xfeed0000));
}
     
int
generic_rsp_dma_regression (const char *file_name)
{
  int done = 0;
  unsigned int status;
  unsigned int r1_contents;
  unsigned int pc;
  char dmem_file[100];
  char imem_file[100];
  FILE *file_i;
  FILE *file_d;
  FILE *file_r;

  char ifile[100];
  char dfile[100];
  char rfile[100];
  
  errlog(DEBUG, "dgRdramFree: %x", dgRdramFree);
  sprintf(imem_file, "%s.ihex", file_name);
  sprintf(dmem_file, "%s.dhex", file_name);
  
  if (! dgFindFile(ifile, "/PR/diags/rsp", imem_file)) {
    if (! dgFindFile(ifile, "/usr/diags/data/rsp",imem_file)){
      errlog(ERR_SEVERE,"Could not find file %s",imem_file);}}
  if (! dgFindFile(dfile, "/PR/diags/rsp", dmem_file)) {
    if (! dgFindFile(dfile, "/usr/diags/data/rsp",dmem_file)){
      errlog(ERR_SEVERE,"Could not find file %s",dmem_file);}}
  if (! dgFindFile(rfile, "/PR/diags/rsp", "dmatests/rdram.rhex")) {
    if (! dgFindFile(rfile, "/usr/diags/data/rsp","dmatests/rdram.rhex")){
      errlog(ERR_SEVERE,"Could not find file dmatests/rdram.rhex");}}

  if ((file_i = fopen(ifile, "r")) == NULL) {
    errlog(ERR_SEVERE, "could not open file %s", imem_file);
      return 1;
  }

  if ((file_d = fopen(dfile, "r")) == NULL) {
    errlog(ERR_SEVERE, "could not open file %s", dmem_file);
      return 1;
  }

  if ((file_r = fopen(rfile, "r")) == NULL) {
    errlog(ERR_SEVERE, "could not open file dmatests/rdram.rhex");
      return 1;
  }

  mem_init(file_i, RSP_IMEM_BASE);
  mem_init(file_d, RSP_DMEM_BASE);
  mem_init(file_r, RDRAM_SCRATCH_BASE);
  
  fclose(file_i);
  fclose(file_d);
  fclose(file_r);
  
  unhalt_and_go();
  while (!done) {
    dgReadWord(0x04040010, &status);           /* Check break status */
    done = status & 0x2;
  }
  dgReadWord(DMEM_R1, &r1_contents);
  errlog(DEBUG, "R1 contents:%x", r1_contents);
  dgReadWord(0x04080000, &pc);
  errlog(DEBUG, "PC::%x", pc);
  return((r1_contents != 0x0000feed) && (r1_contents != 0xfeed0000));
}