[ Previous | Next | Contents | Home | Search ]
AIX Version 4.3 Understanding the Diagnostic Subsystem for AIX

Example TU exectu function

/*
 * COMPONENT_NAME: (TU_DEVICE) Device Adapter Test Units
 *
 * FUNCTIONS: exectu
 */
  
  
/*   FILE NAME: device_exectu.c                                           */
/*   FUNCTION:  Device Adapter Application Test Units.                    */
/*                                                                        */
/*    This source file contains source code for the Device adapter's      */
/*    Application Test Units to aid in various testing environments       */
/*    of the device   adapter. These test units provide a basic inter-    */
/*    face between the diagnostic application program and functions       */
/*    written in the diagnostic extension (pdiagex) which provide direct  */
/*    access to the device without the need for a device driver.          */
/*                                                                        */
/*                                                                        */
/*   EXTERNAL PROCEDURES CALLED:                                          */
/*                                                                        */
  
/* INCLUDED FILES */
#include <sys/types.h>
#include <stdio.h>
#include <errno.h>
  
#include "device_input_params.h"
#include "device_err_detail.h"
#include "tu.h"
#include <diag/tucb.h>
  
/*- global variables -*/
TU_GLOBAL_DATA *tu_data;
  
/*- extern functions -*/
extern void Do_INIT_TUS(TU_TYPE *, TU_GLOBAL_DATA *, TU_RETURN_TYPE *tu_rc);
extern void Do_TERM_TUS(TU_TYPE *, TU_GLOBAL_DATA *, TU_RETURN_TYPE *tu_rc);
  
/*
 * NAME: exectu
 *
 * FUNCTION:  Execute a specific Resource Test Unit.
 *
 * EXECUTION ENVIRONMENT:
 *      This routine is called as a subroutine of a diagnostic application.
 *
 * NOTES:  This routine is used as the interface between an application
 *         and the test units for a Resource.
 *
 */
   
ulong
exectu(TU_TYPE *dev_tucb, TU_INFO_HANDLE *tu_handle, TU_RETURN_TYPE *tu_rc)
{
        int loopcount;
        int mfg_flag=0;
  
        /* Set the tu_handle pointing to the global tu structure data */
        /* if the first time in. Also initialize elements.            */
        if ( *tu_handle == (TU_INFO_HANDLE *)NULL ) {
                tu_data = (TU_GLOBAL_DATA *)calloc(1,sizeof(TU_GLOBAL_DATA));
                *tu_handle = (TU_INFO_HANDLE *)tu_data;
        }
  
        /* number of times to repeat a command */
        loopcount = dev_tucb->parms.loop;
  
        /*---------------------------------------*/
        /* assure adapter is proper state        */
        /* before attempting test unit           */
        /*---------------------------------------*/
        if ((dev_tucb->parms.tu != 1) &&      /* for tus other than init tu */
            (tu.adapter_diagnose_state != 1)){ /* test for NOT Diag state */
                tu_rc->major_rc = TU_INCORRECT_STATE;
                if ( dev_tucb->parms.msg_file != (FILE *)NULL)
                        fprintf( dev_tucb->parms.msg_file, "TU is not 1, and                           not in correct state. status = %d\n", tu_rc->major_rc);
                return(tu_rc->major_rc);       /* must be in diagnose state */
        }
        else if ((dev_tucb->parms.tu == 1) &&  /*- for tu 1 only           -*/
                                               /*- test for Diagnose state -*/
                    (tu.adapter_diagnose_state == 1)) {
                tu_rc->major_rc = TU_SUCCESS;
                if ( dev_tucb->parms.msg_file != (FILE *)NULL)
                        fprintf( dev_tucb->parms.msg_file, "TU is 1, and is in                              correct state. status = %d\n", tu_rc->major_rc);
                return(tu_rc->major_rc);      /*- already in diagnose state -*/
        }
  
        switch (dev_tucb->parms.tu) {
  
                /*--------------------------------------*/
                /*- INITIALIZE Test Unit  #1           -*/
                /*--------------------------------------*/
        case TU_OPEN:
                {
                        (void) Do_INIT_TUS(dev_tucb, tu_data, tu_rc);
                        if (tu_rc->major_rc == TU_SUCCESS)
                                /*- flag Diagnose state -*/
                                tu.adapter_diagnose_state = 1;
                        if ( dev_tucb->parms.msg_file != (FILE *)NULL)
                                fprintf( dev_tucb->parms.msg_file,
                                   "TU is 1 status = %d\n", tu_rc->major_rc);
                        break;
  
                }
  
                /*--------------------------------------*/
                /*- Other Test Units                   -*/
                /*--------------------------------------*/
    
                /*--------------------------------------*/
                /*- TERMINATE Test Unit  #EFFF         -*/
                /*--------------------------------------*/
        case TU_CLOSE:
                {
                        (void) Do_TERM_TUS(dev_tucb, tu_data, tu_rc);
                        if (tu_rc->major_rc == TU_SUCCESS)
                                /*- reset Diagnose state -*/
                                tu.adapter_diagnose_state = 0;
                        if ( dev_tucb->parms.msg_file != (FILE *)NULL)
                                fprintf( dev_tucb->parms.msg_file,
                                   "TU is 2 status = %d\n", tu_rc->major_rc);
                        break;
                }
  
                /*---------------------------------------*/
                /* Unknown tu number                     */
                /*---------------------------------------*/
        default:
                tu.rc.major_rc = TU_INVALID_PARAM;
  
        }  /* end of switch on tu number */
  
        /* If the OUTPUT_DATA is wanted by the calling application, */
        /* then the tucb->data_log should not be NULL. If so, then  */
        /* this structure may be used.                              */
  
        if ( dev_tucb->parms.data_log )
                dev_tucb->parms.data_log->error_code = TU_FAILED;
  
        /* If the INPUT_DATA is specified by the calling application, */
        /* then the tucb->tu_data should not be NULL. If so, then     */
        /* get specific input data from this structure                */
  
        if ( dev_tucb->parms.tu_data )
                mfg_flag = dev_tucb->parms.tu_data->mfg_mode;
  
        return (tu_rc->major_rc);
  
}   /* end of exectu()-------------------------------------------------------*/
 

[ Previous | Next | Contents | Home | Search ]