ai.c 3.49 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 "diag.h"
#include <dbg_comm.h>

#define AI_TEST_BASE	1

int ai_status_rd(TEST_REF *test_ref);
int ai_length_reg(TEST_REF *test_ref);
int ai_pintests(TEST_REF *test_ref);
int ai_sounds(TEST_REF *test_ref);

static int Failed;
/*
 * Create an array of tests, each of which corresponds to a separate menu
 * item callable from the master ide menu.
 */
static TEST_REF TestRefs[] = {
    {"AI Hard-Wired Status Read", 	AI_TEST_BASE+0, ai_status_rd},
    {"AI Length Reg Tests", 		AI_TEST_BASE+1, ai_length_reg},
    {"AI Pin Level Test",		AI_TEST_BASE+2, ai_pintests},
    {"AI Sound Buffer Play Test",	AI_TEST_BASE+3, ai_sounds},
    {"END OF TESTS",0,0}
};

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

static int aiInit();
static int aiDo(TEST_REF *test_ref);


int NameValid;
char Name[80];



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

    /*
     * Sample of how to parse command line args received from ide
     */
    while ((c = getopt(pGlobalComm->argc, pGlobalComm->argv, "ht:n:")) != 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;

	    case 'n':
	      NameValid = 1;
	      strcpy(Name, optarg); 
	      break;

	    default:
		printf("weird option character %c = 0x%x\n", c, c);
		break;
        }
    }

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

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

static int aiInit()
{
    char *env;

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

    /*
     * Setup the diagnostic communication link to the target system.
     *
     * (this uses the global ide variable "commtype", which by default
     * is set to DG_VERILOG.)
     */
    dgInitComm();

    return(0);
}

static int aiDo(TEST_REF *test_ref)
{
    int error_count;

    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 (error_count = test_ref->fnc(test_ref)) {
    Failed = 1;
    errlog(INFO, "... subtest %s FAILED, %d failures",
           test_ref->name, error_count);
  } else  {
    errlog(INFO, "... subtest %s PASSED", test_ref->name);
  }
  return 0;

}