📄 scsitest.c
字号:
/* scsiTest.c - Program to test SCSI library *//* Copyright 1994 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01c,25sep96,dds added documentation and corrected for wrs coding standards.01b,17jun94,jds added check in testDirectCmdsAll for 10 byte commands not supported by SCSI device.01a,29apr94,jds written*//* DESCRIPTIONThese set of routines are written to test the functionality of the SCSIlibrary. This object module must be loaded after "scsiTestLib.o" hasbeen loaded.*/#define INCLUDE_SCSI2#include "vxWorks.h"#include "tickLib.h"#include "taskLib.h"#include "ioLib.h"#include "memLib.h"#include "usrLib.h"#include "fppLib.h"#include "scsiLib.h"#include "scsi2Lib.h"#include "stdio.h"/* defines */#define FACTOR (0x800 * 512)#define TOTAL 0x1000000#define BLOCK (0x400 * 512)#define LINES (TOTAL / FACTOR)#define THIS_TASK 0/* Note: change size according to the tape drive under test */#define FIXED_BLK_SIZE 0x400 /* default fixed block size for Exabyte drive */IMPORT errno;IMPORT STATUS errnoGet ();IMPORT STATUS scsiTargetOptionsGet ();IMPORT STATUS scsiTargetOptionsSet ();IMPORT STATUS scsiTestTestUnitRdy ();IMPORT VOID logMsg ();IMPORT STATUS scsiTestReqSense ();IMPORT STATUS scsiTestTapeModeSense ();IMPORT STATUS scsiTestTapeModeSelect ();IMPORT STATUS scsiTestReadBlockLimits ();IMPORT STATUS scsiTestLoad ();IMPORT STATUS scsiTestUnload ();IMPORT STATUS scsiTestReserveUnit ();IMPORT STATUS scsiTestRewind ();IMPORT STATUS scsiTestErase ();IMPORT STATUS scsiTestReleaseUnit ();IMPORT STATUS scsiTestWrtFileMarks ();IMPORT STATUS scsiTestSpace ();IMPORT STATUS scsiTestWrtTapeVar ();IMPORT STATUS scsiTestWrtTapeFixed ();IMPORT STATUS scsiTestRdTapeVar ();IMPORT STATUS scsiTestRdTapeFixed ();IMPORT STATUS scsiTestInquiry ();IMPORT STATUS scsiTestModeSense ();IMPORT STATUS scsiTestModeSelect ();IMPORT STATUS scsiTestReserve ();IMPORT STATUS scsiTestRelease ();IMPORT STATUS scsiTestReadCapacity ();IMPORT STATUS scsiTestStartStopUnit ();IMPORT STATUS scsiTestFormatUnit ();IMPORT STATUS scsiTestWrtSecs ();IMPORT STATUS scsiTestRdSecs ();IMPORT STATUS scsiIoctl ();/* stdlib functions */IMPORT int strcpy ();IMPORT int strlen ();IMPORT int strcmp ();IMPORT int bzero ();IMPORT int strncmp ();/* global variables */char scsiTestBuffer[500];int scsiMaxBlockLimit;UINT16 scsiMinBlockLimit;union mixed{ char * string; int testNo;}; /******************************************************************************** optionSet - set maxOffset and minPeriod for the scsi target** This function call scsiTargetOptionsSet to set option for scsi target* Variables need to be changed:* busID* which* option.maxOffset/option.minPeriod* * RETURNS: OK if passes, or ERROR if an error is encountered.*/int optionSet() { SCSI_OPTIONS option; int which; int busID = 0; option.maxOffset = 0; option.minPeriod = 25; which = SCSI_SET_OPT_XFER_PARAMS; if (scsiTargetOptionsSet(pSysScsiCtrl, busID, &option, which) == ERROR) { SCSI_DEBUG_MSG("userScsiConfig: could not set options\n",0,0,0,0,0,0); return(ERROR); } return (OK); }/******************************************************************************** testCommonCmds - test scsi commands common to sequential & direct devices** test all mandatory and commonn scsi commands for sequential devices and* direct access devices. These commands are* 1. TEST UNIT READY* 2. REQUEST SENSE* 3. INQUIRY* * RETURNS: OK if passes, or ERROR if an error is encountered.*/STATUS testCommonCmds ( SCSI_PHYS_DEV *pScsiPhysDev ) { /* retry if unit attention */ if (scsiTestTestUnitRdy (pScsiPhysDev) == ERROR) { if (errnoGet() == S_scsiLib_UNIT_ATTENTION) { if (scsiTestTestUnitRdy (pScsiPhysDev) == ERROR) return (ERROR); else printf ("Pass TEST UNIT READY\n"); } else return (ERROR); } /* if TUR OK then do a Request Sense */ if (scsiTestReqSense (pScsiPhysDev, scsiTestBuffer, REQ_SENSE_ADD_LENGTH_BYTE + 1) == ERROR) return (ERROR); /* if REQUEST SENSE OK then do an INQUIRY */ if (scsiTestInquiry (pScsiPhysDev, scsiTestBuffer, 36) == ERROR) return (ERROR); return (OK); }/******************************************************************************** testDirectCmdsAll - test all direct access device (disk) commands** test all the direct access commands. FORMAT command is optionally tested* by specifying the boolean parameter doFormat as TRUE* test the following commands:* 1. MODE SENSE 6* 3. MODE SELECT 6* 5. RESERVE* 6. RELEASE* 7. READ CAPACITY* 8. READ 6* 10. WRITE 6* 12. START STOP UNIT* 13. FORMAT (optional)** RETURNS: OK if passes, or ERROR if an error is encountered.*/STATUS testDirectCmdsAll ( SCSI_PHYS_DEV *pScsiPhysDev, SCSI_BLK_DEV *pBlkDev, BOOL doFormat ) { int lastLBA; int blkLength; char *buffer; int i; int blockNumber; int ctrlBusId; buffer = (char *) malloc (512 * 257); /* 6 Byte Mode Sense */ if (scsiTestModeSense (pScsiPhysDev, 0x00, 0x00, buffer, 0x0c) == ERROR) return (ERROR); buffer[0] = 0x00; buffer[1] = 0x00; buffer[2] = buffer[2] & 0x7f; /* 6 Byte Mode Select */ if (scsiTestModeSelect (pScsiPhysDev, 1, 0, buffer, 0x0c) == ERROR) return (ERROR); if (scsiTestReserve (pScsiPhysDev) == ERROR) return (ERROR); if (scsiTestRelease (pScsiPhysDev) == ERROR) return (ERROR); if (scsiTestReadCapacity (pScsiPhysDev, &lastLBA, &blkLength) == ERROR) return (ERROR); if (scsiTestStartStopUnit (pScsiPhysDev, FALSE) == ERROR) return (ERROR); if (scsiTestStartStopUnit (pScsiPhysDev, TRUE) == ERROR) return (ERROR); if (doFormat) { if (scsiTestFormatUnit (pScsiPhysDev, 0, 0, 0, 0, (char *) NULL, 0) == ERROR) return (ERROR); } ctrlBusId = pScsiPhysDev->pScsiCtrl->scsiCtrlBusId; blockNumber = 1000 * ctrlBusId; /* initialize buffer with pattern */ for (i=0; i < 512; i++) buffer[i] = 'a'; /* 6 BYTE WRITE AND READ */ /* write the pattern to 1 sector */ if (scsiTestWrtSecs (pBlkDev, blockNumber, 1, buffer) == ERROR) return (ERROR); /* read pattern from sector written to */ if (scsiTestRdSecs (pBlkDev, blockNumber, 1, buffer) == ERROR) return (ERROR); free (buffer); return (OK); }/******************************************************************************** testDirectRW - test direct access device (disk) read and write commands** test the following scenarios:* 1. write, read and check data pattern for 6Byte commands* 2. write, read and check data pattern for 10Byte commands* In doing so, cache coherency will automatically get tested** RETURNS: OK if passes, or ERROR if an error is encountered.*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -