📄 pklib.c
字号:
/* pkLib.c - BSP PortKit Validation Suite support routines *//* Copyright 2002 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------02c,20jun02,jtp evaluate config.h macros at runtime (SPR #78881).02b,24jan02,pmr using volatile declarations for for-loop-generated delays.02a,22jan02,pmr fixed non-ANSI compliant code in pkTimestampTestLong(); corrected use of NULL; fixed warnings.01z,12dec01,pch Don't use strncmp on binary data; make NvRam buffers global to assist debugging.01y,16oct99,sbs corrected documentation.01x,30sep99,sbs changed pkUdpEchoT function arguments (SPR #27842). added pkCatastrophicTest and pkCatastrophicClean to fix problems with error2 test and wtxtcl (SPR #27822).01w,23feb99,sbs added pkPrintTest1 and made some changes to make VTS compatible with Tornado 2.0 (SPR #22425).01v,22jul98,sbs added htons() for port assignment in pkUdpEchoT(). (SPR #20680)01u,27may98,dat removed ARM specific changes 01s and 01t.01t,27apr98,cdp make ARM pkTestNvRam buffers static to avoid stack overflow.01s,09apr98,cdp fix buffer alignment for ARM in pkTestNvRam.01r,21oct97,db fixed retrial of UDP packets in pkUdpEchoT().01q,04sep97,sbs added pkPrintSerialOutput, pkSerialTestInit, pkSerialTest and pkSerChanOutput.01p,28aug97,sbs addded pkBusErrorTest for error1 test and changed scsi routines to handle a larger buffer size.01o,21aug97,db renamed pkUdpEchoTest to pkUdpEchoT. added error handling.01n,31jul97,db included pingLib.h.01m,19jul97,db added pkTimestampTestShort and pkTimestampTestLong(timestamp test), pkUdpEchoTest and pkPing (network test) and pkIntGet and pkIntSet(busTas test). Removed conditional includes of header files and macros.01l,24jun97,sbs added pkPrintTest() and pkDivideZeroTest() for serial line testing and divide by zero testing respectively.01k,02jun97,sbs changed sp() in pkLoopbackTest to taskSpawn().01j,02aug96,mas added support for BSP-specific TAS clear routine in busTas.01i,15jun96,dat changed calc of # scsi blks to avoid overflow.01h,15feb96,dat limited pkRead to less than 512K cycles. Changed pkGetMacroValue to do a table walk.01h,02dec93,dzb added pkTimestampTest().01g,05may93,dzb combined pkGet<macro>()'s into pkGetMacroValue(). integrated serial loopback and network udp echo tests. added multiple serial loopback test. ANSIfied. added serial console echo test. removed pkTasInit(). removed cache coherency code from busTas test. +caf wrote sequential serial loopback test. +rfs wrote pkUdpEchod().01f,19feb93,dzb doc fixes. included additional header files. added support for non-writeable nvram. fixed ANSI warnings. added check for existing physical SCSI device. +caf changed VOID to void. changed READ to VX_READ. changed WRITE to VX_WRITE. changed copyright notice. fixed ANSI warnings. changed bitBucket from char to long in pkRead().01d,30apr92,caf added pkTestNvRam().01c,07apr92,caf don't #include header files when building documentation.01b,31mar92,caf added pkGet...() routines to read macros compiled into BSP. changed copyright notice. changed void to VOID. added routines for SCSI write/read/verify test. added routines for sysBusTas() test.01a,01mar92,caf written.*//*DESCRIPTIONThis library contains support routines for the BSP Developer's kitValidation Test Suite.This module should be copied in the BSP directory (with sysLib.c,config.h, etc.) and compiled by simply typing: % make pkLib.oAlternatively, this module may be linked in with the VxWorks image duringcompilation. This can be done by either adding "pkLib.o" to the MACH_EXTRAmacro in the makefiles, or by including "ADDED_MODULES=pkLib.o" on the commandline when building the VxWorks image. This approach is necessary when usingstandalone ROMS without network initialization, as pkLib.o cannot bedownloaded to the target during the tests.The object module will have a couple of unresolved references, whichwill be resolved by linking with VxWorks running on the target, orrebuilding the VxWorks image on the host to include this module.The routines contained in this library are called by the Expect scriptsduring the BSP tests. They contain operations that cannot be executeddirectly from the shell by the scripts.*//* includes */#ifndef DOC#include "vxWorks.h"#include "vxLib.h"#include "ioLib.h"#include "taskLib.h"#include "sysLib.h"#include "cacheLib.h"#include "string.h"#include "stdio.h"#include "config.h"#include "usrLib.h"#include "sockLib.h"#include "logLib.h"#include "in.h"#include "intLib.h"#include "tickLib.h"#include "semLib.h"#include "wdLib.h"#include "pingLib.h"#include "selectLib.h"#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <time.h>#include <signal.h>/* header files used by timestamp test */#include "drv/timer/timestampDev.h"#include "intLib.h"#include "tickLib.h"/* header file used by scsi test */#include "scsiLib.h"#ifdef INCLUDE_SM_NETIMPORT VOIDFUNCPTR smUtilTasClearRtn;#endif /* INCLUDE_SM_NET */#endif /* DOC *//* defines */#define PK_LOOP_PAT_LEN (255) /* length of loopback ASCII pattern */#define PK_LOOP_OUT_LEN (300) /* length of loopback output buffer */#define PK_LOOP_TASK_NUM (4) /* num of multiple loopback tasks */#define PK_READ_MAX_TESTS (128*1024) /* max number of pkRead tests */#define PK_TS_ERR 1.0 /* acceptable timestamp % error */#define MIN(X,Y) (((X) < (Y)) ? (X) : (Y))#define PK_MAX_SER_STR 20 /* max strings to receive(serial test)*/#define PK_MAX_STR 20 /* max string length */#define PATTERN_INC_LAW 0/* values used to prefill RW_TEST_UNIT */#define DEF_BUF_SIZE (64 * 1024) /* default buffer size (64K) */#define DEF_LAW PATTERN_INC_LAW /* incremental law */#define ST_PATTERN 0xa5a5a5a5 /* start pattern */#define DEF_NB_BUF 1 /* write one buffer *//* get field from SCSI_BLK_DEV to SCSI_PHYS_DEV */#define BLK_TO_PHYS(p,tag) (((SCSI_BLK_DEV*)p)->pScsiPhysDev->tag)/* check for bad buffer size */#define IF_BAD_BUFSIZE(pBlkDev,size) \ if ((size % ((SCSI_BLK_DEV*)pBlkDev)->pScsiPhysDev->blockSize) != 0)typedef union /* equivalence int char[] */ { int ival; UINT8 uint8val[4]; } EQUI_INT_UINT8;typedef struct /* structure used to start a RW test */ { /* value to initialize to start the test */ BLK_DEV *pBlk; /* pointer to the block device to test */ UINT8 *ptR; /* pointer to the read Buffer */ UINT8 *ptW; /* pointer to the write Buffer */ UINT32 size; /* buffer size to use */ int nbBuf; /* # of buffer to write/Read */ int law; /* law use to fill the patterns */ int stBlk; /* # of the first block to start */ int nbLoop; /* # of loop for the test */ int startPattern; /* value for the first pattern */ /* local value use by the routine useful for post checking */ TBOOL abort; /* flag to abort the test */ TBOOL abortOnError; /* stop at the first error */ int countErr; /* error counter */ int curStartPattern; /* first pattern to fill buffers */ int curPattern; /* current pattern used */ int curCycle; /* # of Current cycle executed */ int curBuf; /* # of Current buffer tested */ int curBlk; /* # of the current block device */ } RW_TEST_UNIT;/* defines used by pkUdpEchoT */#define MAX_PKT 4096 /* largest packet used */#define N_SIZES 16 /* number of different packet sizes */#define RESEND 1 /* times to resend before error */#ifndef IPPORT_ECHO#define IPPORT_ECHO 7 /* standard UDP echo port */#endif/* globals */int pkLoopbackAbort = 0; /* non-zero for loopback task exit */int pkMultiLoopCount [NUM_TTY][PK_LOOP_TASK_NUM]; /* multi loopback data */int pkSeqLoopCount [NUM_TTY][2]; /* seq loopback data */int pkLoopFd [NUM_TTY]; /* array of loopback serial dev desc */int pkLoopTask [NUM_TTY]; /* count of multi loopback tasks */int pkLoopInit = 0; /* init loopback data arrays ? */SEM_ID tsTmoSem; /* ID of timestamp timeout semaphore */WDOG_ID tsTmoWd; /* ID of timestamp timeout watchdog */int tsInit=FALSE; /* TRUE if tsTmoSem and tsTmoWd exist */char pkSerChanInput[PK_MAX_SER_STR][PK_MAX_STR]; /* serial I/O string array */int pkSerChanAbort=0; /* non-zero for serial I/O task exit */int pkConsoleEchoAbort = 0 ;RW_TEST_UNIT testUnit; /* accessible from VxWorks shell */RW_TEST_UNIT *pTestUnit = &testUnit; /* pointer to testUnit *//* Globals for udpEchod */int flagInitUdp = FALSE;int skt1 = -1; /* socket descriptor */struct sockaddr_in sin;struct sockaddr_in from;static char buf [MAX_PKT]; /* pkt buffer *//* Globals for udpEchoTest */int resendCnt = 0; /* times a single packet was resent */int resendTotal = 0; /* total number of packets resent */int packetTMO; /* packet timeout before resending */int packetNum; /* current packet number being sent */int curPktSiz; /* current packet size sent/received */int skt; /* socket descriptor */int sktAddrLen; /* length of socket addr */struct sockaddr_in serv_addr; /* target socket data */char dataOut [MAX_PKT]; /* outgoing pkt buf */char dataIn [MAX_PKT]; /* incoming pkt buf */int pktSizes [N_SIZES] = { 128, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840 }; /* various packet sizes *//* locals */LOCAL int loopState [NUM_TTY]; /* current state of seq loopback input *//* forward declarations */ STATUS pkRead(); void pkIncrement(); int pkGetMacroValue(); void pkTasTest(); STATUS pkTestRamByte(); STATUS pkConsoleEcho();LOCAL BOOL pkMultiLoopHook();LOCAL BOOL pkSeqLoopHook(); STATUS pkLoopbackTest(); STATUS pkSeqLoopShow(); STATUS pkMultiLoopShow(); STATUS pkUdpEchod(); void pkUdpInit(); STATUS pkTimestampTest(); STATUS pkTimestampTestShort(); void pkTimestampTestLong(); STATUS pkTimestampTestInit(); void pkPrintTest(); void pkDivideZeroTest(); int pkIntGet(); void pkIntSet(); STATUS pkTestNvRam(); STATUS pkBufFillPattern(); STATUS pkBlkWrite(); STATUS pkBlkRead(); STATUS pkTestUnit(); STATUS pkTestOneUnit(); void pkSerialTest(); void pkSerChanOutput();/********************************************************************************* pkRead - probe memory from start to end <length> bytes at a time** This routine probes memory from the start address to the end address* using vxMemProbe(), <length> bytes at a time. As soon as an error is* detected, the routine returns an ERROR.** RETURNS: OK, or ERROR if <startAdrs> through (<endAdrs> - 1) not readable.*/STATUS pkRead ( char *startAdrs, /* start of range to test */ char *endAdrs, /* end of range to test */ int length /* 1, 2, or 4 bytes */ ) { char * loopAdrs; long bitBucket; STATUS retValue = OK; int increment = 1; int size; size = ((UINT)endAdrs - (UINT)startAdrs) / length; /* limit the number of test cycles */ if (size >= (UINT)PK_READ_MAX_TESTS) increment = (size / (UINT)PK_READ_MAX_TESTS) * 2; for (loopAdrs = startAdrs; loopAdrs < endAdrs; loopAdrs += (length * increment)) { if (vxMemProbe (loopAdrs, VX_READ, length, (char *) &bitBucket) == ERROR) { /* probe caused a bus error or address misalignment */ retValue = ERROR; break; } } return retValue; }/********************************************************************************* pkIncrement - increment a counter** This routine adds one to the integer pointed to by <pCount>.** RETURNS: N/A*/void pkIncrement ( int *pCount /* address to increment */ ) { ++ *pCount; }/********************************************************************************* pkGetMacroValue - read a macro value** This routine returns the value of the macro associated with <macroName>,* else the value -1 (ERROR) is returned.** RETURNS: Value associated with macroName, or ERROR (-1).*/int pkGetMacroValue ( char *macroName /* name of desired macro */ ) { /* * Note: since the config macros may contain an expression that does * not have a constant integer value, it is important to evaluate * them inline here, rather than place them in a static array * initializer, which would be evaluated only at compile time. */#ifdef LOCAL_MEM_LOCAL_ADRS if (strcmp (macroName, "LOCAL_MEM_LOCAL_ADRS") == 0) return (int)LOCAL_MEM_LOCAL_ADRS;#endif#ifdef ROM_BASE_ADRS if (strcmp (macroName, "ROM_BASE_ADRS") == 0) return (int)ROM_BASE_ADRS;#endif#ifdef ROM_SIZE if (strcmp (macroName, "ROM_SIZE") == 0) return (int)ROM_SIZE;#endif#ifdef NV_RAM_SIZE if (strcmp (macroName, "NV_RAM_SIZE") == 0) return (int)NV_RAM_SIZE;#endif#ifdef CONSOLE_TTY if (strcmp (macroName, "CONSOLE_TTY") == 0) return (int)CONSOLE_TTY;#endif#ifdef SLIP_TTY if (strcmp (macroName, "SLIP_TTY") == 0) return (int)SLIP_TTY;#endif#ifdef SYS_CLK_RATE_MIN if (strcmp (macroName, "SYS_CLK_RATE_MIN") == 0) return (int)SYS_CLK_RATE_MIN;#endif#ifdef SYS_CLK_RATE_MAX if (strcmp (macroName, "SYS_CLK_RATE_MAX") == 0) return (int)SYS_CLK_RATE_MAX;#endif#ifdef AUX_CLK_RATE_MIN if (strcmp (macroName, "AUX_CLK_RATE_MIN") == 0) return (int)AUX_CLK_RATE_MIN;#endif#ifdef AUX_CLK_RATE_MAX if (strcmp (macroName, "AUX_CLK_RATE_MAX") == 0) return (int)AUX_CLK_RATE_MAX;#endif#ifdef EXC_MSG_ADRS if (strcmp (macroName, "EXC_MSG_ADRS") == 0) return (int)EXC_MSG_ADRS;#endif#ifdef PK_LOOP_TASK_NUM if (strcmp (macroName, "PK_LOOP_TASK_NUM") == 0) return (int)PK_LOOP_TASK_NUM;#endif return (int)ERROR; }/********************************************************************************* pkTasTest - test-and-set test** This routine, in conjunction with another pkTasTest() task, tests the* test-and-set mechanism. Both tasks (each on a separate target board)* spin on the semaphore pointed to by <semaphore> using sysBusTas() for* mutual exclusion. When this routine gets the semaphore, it increments* the <count> if it matches <odd>. It then enters a busy-wait loop* <delay> times, giving the other task a chance to take the semaphore.* It may be necessary to tune this task by increasing or decreasing <delay* if one task (board) is much faster than the other.** RETURNS: N/A (does not return)*/void pkTasTest ( char *semaphore, /* semaphore to spin on */ UINT32 *count, /* counter address */ BOOL odd, /* odd/even assignment */ UINT32 delay /* delay so other task gets time */ ) { volatile UINT32 busyWait; taskDelay (sysClkRateGet ()); /* wait 1 second */ FOREVER if (sysBusTas (semaphore)) { /* check <odd> and bump counter if matches */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -