📄 ecostest.cpp
字号:
//=================================================================//// eCosTest.cpp//// Test class////=================================================================//####COPYRIGHTBEGIN####//// -------------------------------------------// The contents of this file are subject to the Cygnus eCos Public License// Version 1.0 (the "License"); you may not use this file except in// compliance with the License. You may obtain a copy of the License at// http://sourceware.cygnus.com/ecos// // Software distributed under the License is distributed on an "AS IS"// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the// License for the specific language governing rights and limitations under// the License.// // The Original Code is eCos - Embedded Cygnus Operating System, released// September 30, 1998.// // The Initial Developer of the Original Code is Cygnus. Portions created// by Cygnus are Copyright (C) 1998, 1999 Cygnus Solutions.// All Rights Reserved.// -------------------------------------------////####COPYRIGHTEND####//=================================================================//#####DESCRIPTIONBEGIN####//// Author(s): sdf// Contributors: sdf// Date: 1999-04-01// Description: This class abstracts a test for use in the testing infrastructure// Usage:////####DESCRIPTIONEND####///////////////////////////////////////////////////////////////////////////////#include "stdafx.h"#include "eCosTest.h"#include "Port.h"#include "TestResource.h"#include "eCosTestUtils.h"#include "eCosTestSocket.h"#define WF(n) (n+50)/1000,((n+50)%1000)/100 // Present n as whole and fractional part. Round to nearest least significant digit#define WFS "%d.%d" // The format string to output the abovestatic int nAuxPort; //hackstatic int nAuxListenSock; // hack// Static data:// Do not use spaces in image strings for consideration of sscanfconst CeCosTest::TargetInfo CeCosTest::arTargetInfo[1+CeCosTest::TargetTypeMax]={ // Image prefix sim? gdbcommand {"TX39-jmr3904", "mips-tx39-elf", false,0}, // TX39_jmr3904, {"TX39-jmr3904-minsim", "mips-tx39-elf", true, "target sim --board=jmr3904pal" " --memory-region 0xffff8000,0x900" " --memory-region 0xffffe000,0x4" " --memory-region 0xb2100000,0x4"}, {"TX39-jmr3904-sim", "mips-tx39-elf", true, "target sim --board=jmr3904" " --memory-region 0xffff8000,0x900" " --memory-region 0xffffe000,0x4" " --memory-region 0xb2100000,0x4"}, {"PowerPC-cogent", "powerpc-eabi", false,0}, // PowerPC_cogent, {"PowerPC-sim", "powerpc-eabi", true, "target sim" " -o '/#address-cells 1'" " -o '/openprom/init/register/pc 0x100'" " -o '/iobus@0xf0000000/reg 0xf0000000 0x01000000'" " -o '/iobus/pal@0xf0001000/reg 0xf0001000 32'"}, {"SPARClite-sim", "sparclite-elf", true, "target sim -nfp -sparclite -dumbio"}, {"SPARClite-sleb", "sparclite-elf", false,0}, // SPARClite_sleb, {"ARM-PID", "arm-elf", false,"set remotebinarydownload 0"}, {"ARM-AEB", "arm-elf", false,"set remotebinarydownload 0"}, {"MN10300-stdeval1", "mn10300-elf", false,0}, // MN10300_stdeval1, {"MN10300-minsim", "mn10300-elf", true, "target sim --board=stdeval1" /*" --memory-region 0x28400000,0x800"*/ /*" --memory-region 0x28401000,0x800"*/ " --memory-region 0x34004000,0x8"}, {"MN10300-stdeval1-sim","mn10300-elf", true, "target sim --board=stdeval1" /*" --memory-region 0x28400000,0x800"*/ /*" --memory-region 0x28401000,0x800"*/ " --memory-region 0x34004000,0x8"}, {"I386-Linux", "i686-pc-linux-gnu",true,0}, // I386_Linux {"Unknown", "", false, 0}};const char * const CeCosTest::arResultImage[1+CeCosTest::StatusTypeMax]= {"NotStarted", "NoResult", "Inapplicable", "Pass", "DTimeout", "Timeout", "Cancelled", "Fail", "Unknown"};const char CeCosTest::szGdbPrompt[]="(gdb) ";const unsigned int CeCosTest::nGdbPromptLen=sizeof szGdbPrompt-1;const CeCosTest::Callback CeCosTest::NoCallback;CeCosTest *CeCosTest::pFirstInstance=0;int CeCosTest::InstanceCount=0;CeCosTestUtils::String CeCosTest::strLogFile;const char * const CeCosTest::arServerStatusImage[1+CeCosTest::ServerStatusMax]={ "Busy", "Ready", "Can't run", "Connection failed", "Locked", "Bad server status"};const char * CeCosTest::ExecutionParameters::arRequestImage [1+ExecutionParameters::RequestTypeMax]={ "Run", "Query", "Lock", "Unlock", "Stop", "Bad request" };CeCosTest::AliveInfo CeCosTest::AliveInfoZero;static bool CALLBACK IsCancelled(void *pThis){ return CeCosTest::Cancelled==((CeCosTest *)pThis)->Status();}// Ctors and dtors:CeCosTest::CeCosTest(const ExecutionParameters &e, const char *pszExecutable,const char *pszTitle): m_strTitle(pszTitle), m_pPort(0), m_Status(NotStarted), m_bSocketErrorOccurred(false), m_ep(e), m_pSock(0), m_bDownloading(false), m_nMaxInactiveTime(0), m_nDownloadTime(0), m_nTotalTime(0), m_nStrippedSize(0){ SetExecutable (pszExecutable); Trace("%%%% Create instance exe count:=%d\n",InstanceCount+1); GetPath(m_strPath); ENTERCRITICAL; InstanceCount++; m_pNextInstance=pFirstInstance; if(m_pNextInstance){ m_pNextInstance->m_pPrevInstance=this; } m_pPrevInstance=0; pFirstInstance=this; LEAVECRITICAL; memset(&AliveInfoZero,0,sizeof AliveInfoZero);}CeCosTest::~CeCosTest(){ Trace("CeCosTest::~CeCosTest(): Calling Cancel()\n"); Cancel(); CloseSocket(); if(m_pPort){ m_pPort->Release(); m_pPort=0; } VTRACE("~CeCosTest(): EnterCritical and decrease instance count\n"); ENTERCRITICAL; InstanceCount--; Trace("%%%% Destroy instance. Instance count:=%d\n",InstanceCount); if(pFirstInstance==this){ pFirstInstance=m_pNextInstance; } if(m_pPrevInstance){ m_pPrevInstance->m_pNextInstance=m_pNextInstance; } if(m_pNextInstance){ m_pNextInstance->m_pPrevInstance=m_pPrevInstance; } LEAVECRITICAL; Trace("~CeCosTest() - exiting\n");}// Run the test remotely (on host:port as given by the first argument)bool CeCosTest::RunRemote (const char *pszRemoteHostPort,const CeCosTest::Callback &cb){ m_Status=NotStarted; Trace("RunRemote\n"); char *pszHostPort; if(0!=pszRemoteHostPort){ // take a copy to avoid arg going out of scope in the caller pszHostPort=new char [1+strlen(pszRemoteHostPort)]; strcpy(pszHostPort,pszRemoteHostPort); } else { pszHostPort=0; } return 0!=RUNTHREAD (RemoteThreadFunc,pszHostPort,cb); }// Run the test locallybool CeCosTest::RunLocal (const Callback &cb){ m_Status=NotStarted; m_tPrevSample=0; GetPath(m_strPath); bool rc=false; VTRACE("RunLocal()\n"); if(0==CPort::Count(m_ep)){ Log("Cannot run a %s " "test\n",Image(m_ep.Target()) ); // Need to perform these functions otherwise taken care of by SThreadFunc InvokeCallback (cb); } else { Trace("Run %s" " timeouts(active=%d elapsed=%d)\n",(const char *)m_strExecutable , ActiveTimeout(), ElapsedTimeout()); VTRACE("RunLocal(): Starting thread for LocalThreadFunc()\n"); rc=(0!=RUNTHREAD (LocalThreadFunc,0,cb)); } return rc;}void CeCosTest::Cancel (){ SetStatus(Cancelled);}CeCosTest::ServerStatus CeCosTest::Connect (CeCosTestUtils::String strHost,int port, CeCosTestSocket *&pSock, const ExecutionParameters &e,CeCosTestUtils::Duration dTimeout){ // Find out whether this host is receptive ServerStatus s=CONNECTION_FAILED; pSock=new CeCosTestSocket(strHost,port,dTimeout); if(pSock->Ok() && pSock->send(e.Marshall(), sizeof(ExecutionParameters::Data),"execution parameters") && pSock->recv(&s, sizeof s,"ready status")){ s=min(s,ServerStatusMax); } if(SERVER_READY!=s || ExecutionParameters::RUN!=e.Request()){ delete pSock; pSock=0; } return s;}// Initiate a connection to hostName:nPort and acquire the ready status// The socket (m_pSock) is left open by Connect.in the case of successbool CeCosTest::ConnectForExecution (CeCosTestUtils::String strHost,int port){ bool bSchedule=(0==strHost.GetLength()); int nChoices,nOrigChoices; CeCosTestUtils::Duration nDelay=500; const CeCosTestUtils::Time ft0=CeCosTestUtils::Time::Now(); m_pSock=0; ServerStatus s=ServerStatusMax; int nChoice; CeCosTestUtils::String *arstrHostPort;Retry: if(bSchedule){ LOCKRESOURCES; const CTestResource **ar=0; nChoices=CTestResource::GetMatches(m_ep,ar,/*bIgnoreLocking=*/true); nOrigChoices=nChoices; arstrHostPort=new CeCosTestUtils::String[nChoices]; if(nChoices>0){ Trace("ConnectForExecution: choices are:\n"); for(int i=0;i<nChoices;i++){ Trace("\t%s:%d\n",(const char *)ar[i]->Host(),ar[i]->Port()); arstrHostPort[i].Format("%s:%d",(const char *)ar[i]->Host(),ar[i]->Port()); } } delete [] ar; UNLOCKRESOURCES; if(0==nChoices){ Log("No servers available to execute %s" " test\n", Image(m_ep.Target()) ); for(CTestResource *pResource=CTestResource::First();pResource;pResource=pResource->Next()){ const char *pszStatus=CeCosTest::Image(pResource->Query()); if(pResource->Sim()){ Log(" %10s %10s %20s Sim\n", pResource->Host(), pszStatus, CeCosTest::Image(pResource->Target())); } else { Log(" %10s %10s %20s %8s %d %c%c %s:%d\n", pResource->Host(), pszStatus, CeCosTest::Image(pResource->Target()), (const char *)pResource->DownloadPort(), pResource->Baud(), pResource->Control1(), pResource->Control2(), (const char *)pResource->ResetHost(), pResource->ResetPort()); } } goto Done; } nChoice=rand() % nChoices; } else { nChoices=1; arstrHostPort=new CeCosTestUtils::String[nChoices]; arstrHostPort[0].Format("%s:%d",(const char *)strHost,port); nChoice=0; // Hobson's } for(;;) { m_strExecutionHostPort=arstrHostPort[nChoice]; // Find somewhere to execute the test Trace("ConnectForExecution: chosen %s\n",(const char *)m_strExecutionHostPort); CeCosTestUtils::ParseHostPort(m_strExecutionHostPort, strHost, port); s=Connect(strHost,port,m_pSock,m_ep); Trace("Connect: %s:%d says %s\n",(const char *)strHost,port,Image(s)); switch(s){ case SERVER_READY: Trace("Connected to %s\n",(const char *)m_strExecutionHostPort); goto Done; break; case SERVER_LOCKED: case SERVER_BUSY: { Trace("ConnectForExecution: waiting %d msec for %s... \n",nDelay,(const char *)m_strExecutionHostPort); CeCosTestUtils::Sleep(nDelay); if(Cancelled==m_Status){ Trace("ConnectForExecution : cancelled\n"); s=CONNECTION_FAILED; goto Done; } if(bSchedule&&nChoices>1){ // Reselect, but avoid the one we've just chosen int n; do { n=rand() % nChoices; } while (n==nChoice); nChoice=n; } else { // Choice remains the same if(nDelay<20*1000){ nDelay+=rand() % 500; } } } continue; default: Trace("Connect to %s failed - status=%s\n",(const char *)m_strExecutionHostPort,Image(s)); if(bSchedule){ if(nChoices>1){ // Remove this permanently from the possibilities to be considered for(int i=nChoice;i<nChoices-1;i++){ arstrHostPort[i]=arstrHostPort[i+1]; } nChoices--; nChoice=rand() % nChoices; } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -