ide_init.c 3.54 KB
/*
 * FILE: ide_init.c:
 *
 * diagInit(): Common initialization for all diagnostic modules.
 */

#include "setjmp.h"
#include "diag.h"
#include "stdio.h"

extern jmp_buf intr_jump;

static int badTestNumber(int testNum);

int ideSubTestNum = 0;

diagInit(test_refs, initFcn, dispatchFcn)
    TEST_REF test_refs[];	/* array of test numbers for this module    */
    int (*initFcn)();		/* pointer to this module's init function   */
    int (*dispatchFcn)();	/* ptr to this module's dispatch function   */
{
    return (diaginit(test_refs, initFcn, dispatchFcn));
}

diaginit(test_refs, initFcn, dispatchFcn)
    TEST_REF test_refs[];	/* array of test numbers for this module    */
    int (*initFcn)();		/* pointer to this module's init function   */
    int (*dispatchFcn)();	/* ptr to this module's dispatch function   */
{
    int testIndex, skipIndex;

    if (pGlobalComm->init) {
	/*
	 * Execute the caller's diagnostic module specific initialization 
	 * function.  It is probably just a function from the graphics
	 * utilities library libgm.a (ucode init, gate array initializations, 
	 * etc...).
	 */
	(*initFcn)();
    }

    if (pGlobalComm->entryNum < 0) {
	/* 
	 * Run a single test and return.  Make sure the requested number
	 * exists within the diagnostic module's test_refs[] array, though.
	 */
	testIndex = 0;
	ideSubTestNum = -(pGlobalComm->entryNum);
	while ((test_refs[testIndex].num != TEST_NULL) && 
	       (test_refs[testIndex].num != ideSubTestNum)) {
	    testIndex++;
	}
	if (test_refs[testIndex].num != ideSubTestNum) {
	    badTestNumber(ideSubTestNum);
	    return;
	}
	(*dispatchFcn)(&test_refs[testIndex]);
	return;
    } else if (pGlobalComm->entryNum == 0) {
	ideSubTestNum = test_refs[0].num;	/* run all the tests */
	testIndex = 0;
    } else {
	/*
	 * Start at a specific test.  Make sure the requested number exists
	 * within this diagnostic module's test_refs[] array, though.
	 */
	testIndex = 0;
	ideSubTestNum = pGlobalComm->entryNum;
	while ((test_refs[testIndex].num != TEST_NULL) && 
	       (test_refs[testIndex].num != ideSubTestNum)) {
	    testIndex++;
	}
	if (test_refs[testIndex].num != ideSubTestNum) {
	    badTestNumber(ideSubTestNum);
	    return;
	}
    }

    /*
     * Before entering the loop which runs the diagnostic sequence, advance a
     * pointer into the "Skip numbers" array to point to the first test 
     * greater than or equal to the first test to be run.  Thereafter, we can
     * just advance the skipIndex each time through the loop (if necessary).
     */
    skipIndex = 0;
    while ((pGlobalComm->skipNums[skipIndex] != TEST_NULL) && 
	   (pGlobalComm->skipNums[skipIndex] < ideSubTestNum)) {
	skipIndex++;
    }
    /*
     * Now execute the diagnostic sequence.
     */
    while (test_refs[testIndex].num != TEST_NULL) {
	if (pGlobalComm->skipNums[skipIndex] == test_refs[testIndex].num) {
	    /*
	     * Skip this test & setup to run the next.
	     */
	    skipIndex++;
	    testIndex++;
	} else {
	    /*
	     * Call the diagnostic module's dispatch routine and pass it the
	     * test number to be executed.
	     */
	    (*dispatchFcn)(&test_refs[testIndex]);
	    testIndex++;
	}
    }
}

diagExit()
{
    return (diagexit());
}

diagexit()
{
    fflush(stdout);
    fflush(stderr);
    longjmp(intr_jump, 1);
}

/*
 * Print out an info message indicating that the server screwed up and called
 * for a test number that doesn't correspond to the diagnostic module's test
 * numbering scheme.
 */
static int badTestNumber(int testNum)
{
    errlog(INFO,
	"diagInit(): Unknown test number %d requested by server.\n", 
	testNum);
}