//####COPYRIGHTBEGIN####
|
//####COPYRIGHTBEGIN####
|
//
|
//
|
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
// Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
|
// Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
|
//
|
//
|
// This program is part of the eCos host tools.
|
// This program is part of the eCos host tools.
|
//
|
//
|
// This program is free software; you can redistribute it and/or modify it
|
// This program is free software; you can redistribute it and/or modify it
|
// under the terms of the GNU General Public License as published by the Free
|
// under the terms of the GNU General Public License as published by the Free
|
// Software Foundation; either version 2 of the License, or (at your option)
|
// Software Foundation; either version 2 of the License, or (at your option)
|
// any later version.
|
// any later version.
|
//
|
//
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
// more details.
|
// more details.
|
//
|
//
|
// You should have received a copy of the GNU General Public License along with
|
// You should have received a copy of the GNU General Public License along with
|
// this program; if not, write to the Free Software Foundation, Inc.,
|
// this program; if not, write to the Free Software Foundation, Inc.,
|
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
//
|
//
|
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
//
|
//
|
//####COPYRIGHTEND####
|
//####COPYRIGHTEND####
|
//=================================================================
|
//=================================================================
|
//
|
//
|
// TestResource.cpp
|
// TestResource.cpp
|
//
|
//
|
// Resource test class
|
// Resource test class
|
//
|
//
|
//=================================================================
|
//=================================================================
|
//=================================================================
|
//=================================================================
|
//#####DESCRIPTIONBEGIN####
|
//#####DESCRIPTIONBEGIN####
|
//
|
//
|
// Author(s): sdf
|
// Author(s): sdf
|
// Contributors: sdf
|
// Contributors: sdf
|
// Date: 1999-04-01
|
// Date: 1999-04-01
|
// Description: This class abstracts a test resource for use in the testing infrastructure
|
// Description: This class abstracts a test resource for use in the testing infrastructure
|
// Usage:
|
// Usage:
|
//
|
//
|
//####DESCRIPTIONEND####
|
//####DESCRIPTIONEND####
|
#include "eCosStd.h"
|
#include "eCosStd.h"
|
#include "eCosTestUtils.h"
|
#include "eCosTestUtils.h"
|
#include "eCosTrace.h"
|
#include "eCosTrace.h"
|
#include "Subprocess.h"
|
#include "Subprocess.h"
|
|
|
#include "TestResource.h"
|
#include "TestResource.h"
|
|
|
CTestResource *CTestResource::pFirstInstance=0;
|
CTestResource *CTestResource::pFirstInstance=0;
|
unsigned int CTestResource::nCount=0;
|
unsigned int CTestResource::nCount=0;
|
|
|
String CTestResource::strResourceHostPort;
|
String CTestResource::strResourceHostPort;
|
|
|
CTestResource::CTestResource(LPCTSTR pszHostPort, LPCTSTR target, LPCTSTR pszDownloadPort, int nBaud, LPCTSTR pszResetString):
|
CTestResource::CTestResource(LPCTSTR pszHostPort, LPCTSTR target, LPCTSTR pszDownloadPort, int nBaud, LPCTSTR pszResetString):
|
m_strReset(pszResetString),
|
m_strReset(pszResetString),
|
m_bInUse(false),
|
m_bInUse(false),
|
m_nBaud(nBaud),
|
m_nBaud(nBaud),
|
m_strPort(pszDownloadPort),
|
m_strPort(pszDownloadPort),
|
m_bLocked(false),
|
m_bLocked(false),
|
m_Target(target)
|
m_Target(target)
|
{
|
{
|
CeCosSocket::ParseHostPort(pszHostPort,m_strHost,m_nPort);
|
CeCosSocket::ParseHostPort(pszHostPort,m_strHost,m_nPort);
|
VTRACE(_T("@@@ Created resource %08x %s\n"),(unsigned int)this,(LPCTSTR)Image());
|
VTRACE(_T("@@@ Created resource %08x %s\n"),(unsigned int)this,(LPCTSTR)Image());
|
Chain();
|
Chain();
|
}
|
}
|
|
|
CTestResource::~CTestResource()
|
CTestResource::~CTestResource()
|
{
|
{
|
ENTERCRITICAL;
|
ENTERCRITICAL;
|
VTRACE(_T("@@@ Destroy resource %08x %s\n"),this,(LPCTSTR)Image());
|
VTRACE(_T("@@@ Destroy resource %08x %s\n"),this,(LPCTSTR)Image());
|
if(m_pPrevInstance || m_pNextInstance){
|
if(m_pPrevInstance || m_pNextInstance){
|
nCount--;
|
nCount--;
|
}
|
}
|
if(pFirstInstance==this){
|
if(pFirstInstance==this){
|
pFirstInstance=m_pNextInstance;
|
pFirstInstance=m_pNextInstance;
|
}
|
}
|
if(m_pPrevInstance){
|
if(m_pPrevInstance){
|
m_pPrevInstance->m_pNextInstance=m_pNextInstance;
|
m_pPrevInstance->m_pNextInstance=m_pNextInstance;
|
}
|
}
|
if(m_pNextInstance){
|
if(m_pNextInstance){
|
m_pNextInstance->m_pPrevInstance=m_pPrevInstance;
|
m_pNextInstance->m_pPrevInstance=m_pPrevInstance;
|
}
|
}
|
LEAVECRITICAL;
|
LEAVECRITICAL;
|
}
|
}
|
|
|
// Find the resource matching the given host:port specification
|
// Find the resource matching the given host:port specification
|
// Returns 0 if no such host:port found
|
// Returns 0 if no such host:port found
|
CTestResource * CTestResource::Lookup(LPCTSTR pszHostPort)
|
CTestResource * CTestResource::Lookup(LPCTSTR pszHostPort)
|
{
|
{
|
CTestResource *pResource=NULL;
|
CTestResource *pResource=NULL;
|
ENTERCRITICAL;
|
ENTERCRITICAL;
|
String strHost;
|
String strHost;
|
int nPort;
|
int nPort;
|
if(CeCosSocket::ParseHostPort(pszHostPort,strHost,nPort)){
|
if(CeCosSocket::ParseHostPort(pszHostPort,strHost,nPort)){
|
for(pResource=pFirstInstance;pResource;pResource=pResource->m_pNextInstance){
|
for(pResource=pFirstInstance;pResource;pResource=pResource->m_pNextInstance){
|
if(nPort==pResource->TcpIPPort() && CeCosSocket::SameHost(strHost,pResource->Host())){
|
if(nPort==pResource->TcpIPPort() && CeCosSocket::SameHost(strHost,pResource->Host())){
|
break;
|
break;
|
}
|
}
|
}
|
}
|
}
|
}
|
LEAVECRITICAL;
|
LEAVECRITICAL;
|
return pResource;
|
return pResource;
|
}
|
}
|
|
|
unsigned int CTestResource::GetMatchCount (const CeCosTest::ExecutionParameters &e,bool bIgnoreLocking)
|
unsigned int CTestResource::GetMatchCount (const CeCosTest::ExecutionParameters &e,bool bIgnoreLocking)
|
{
|
{
|
unsigned int i=0;
|
unsigned int i=0;
|
ENTERCRITICAL;
|
ENTERCRITICAL;
|
for(const CTestResource *pResource=pFirstInstance;pResource;pResource=pResource->m_pNextInstance){
|
for(const CTestResource *pResource=pFirstInstance;pResource;pResource=pResource->m_pNextInstance){
|
if(pResource->Matches(e,bIgnoreLocking)){
|
if(pResource->Matches(e,bIgnoreLocking)){
|
i++;
|
i++;
|
}
|
}
|
}
|
}
|
LEAVECRITICAL;
|
LEAVECRITICAL;
|
return i;
|
return i;
|
}
|
}
|
|
|
bool CTestResource::GetMatches (const CeCosTest::ExecutionParameters &e, StringArray &arstr, bool bIgnoreLocking)
|
bool CTestResource::GetMatches (const CeCosTest::ExecutionParameters &e, StringArray &arstr, bool bIgnoreLocking)
|
{
|
{
|
bool rc=false;
|
bool rc=false;
|
arstr.clear();
|
arstr.clear();
|
if(Load()){
|
if(Load()){
|
ENTERCRITICAL;
|
ENTERCRITICAL;
|
for(CTestResource *pResource=pFirstInstance;pResource;pResource=pResource->m_pNextInstance){
|
for(CTestResource *pResource=pFirstInstance;pResource;pResource=pResource->m_pNextInstance){
|
if(pResource->Matches(e,bIgnoreLocking)){
|
if(pResource->Matches(e,bIgnoreLocking)){
|
arstr.push_back(pResource->HostPort());
|
arstr.push_back(pResource->HostPort());
|
}
|
}
|
}
|
}
|
LEAVECRITICAL;
|
LEAVECRITICAL;
|
rc=true;
|
rc=true;
|
}
|
}
|
return rc;
|
return rc;
|
}
|
}
|
|
|
void CTestResource::DeleteAllInstances()
|
void CTestResource::DeleteAllInstances()
|
{
|
{
|
ENTERCRITICAL;
|
ENTERCRITICAL;
|
while(pFirstInstance){
|
while(pFirstInstance){
|
delete pFirstInstance;
|
delete pFirstInstance;
|
}
|
}
|
LEAVECRITICAL;
|
LEAVECRITICAL;
|
}
|
}
|
|
|
bool CTestResource::LoadFromDirectory (LPCTSTR psz)
|
bool CTestResource::LoadFromDirectory (LPCTSTR psz)
|
{
|
{
|
bool rc=true;
|
bool rc=true;
|
ENTERCRITICAL;
|
ENTERCRITICAL;
|
DeleteAllInstances();
|
DeleteAllInstances();
|
// Find all the files in directory "psz" and load from each of them
|
// Find all the files in directory "psz" and load from each of them
|
TCHAR szOrigDir[256];
|
TCHAR szOrigDir[256];
|
_tgetcwd(szOrigDir,sizeof szOrigDir-1);
|
_tgetcwd(szOrigDir,sizeof szOrigDir-1);
|
if(0==_tchdir(psz)){
|
if(0==_tchdir(psz)){
|
String strFile;
|
String strFile;
|
void *pHandle;
|
void *pHandle;
|
for(bool b=CeCosTestUtils::StartSearch(pHandle,strFile);b;b=CeCosTestUtils::NextFile(pHandle,strFile)){
|
for(bool b=CeCosTestUtils::StartSearch(pHandle,strFile);b;b=CeCosTestUtils::NextFile(pHandle,strFile)){
|
if(CeCosTestUtils::IsFile(strFile)){
|
if(CeCosTestUtils::IsFile(strFile)){
|
CTestResource *pResource=new CTestResource(_T(""),_T(""));
|
CTestResource *pResource=new CTestResource(_T(""),_T(""));
|
CTestResourceProperties prop(pResource);
|
CTestResourceProperties prop(pResource);
|
prop.LoadFromFile(strFile);
|
prop.LoadFromFile(strFile);
|
}
|
}
|
}
|
}
|
CeCosTestUtils::EndSearch(pHandle);
|
CeCosTestUtils::EndSearch(pHandle);
|
} else {
|
} else {
|
TRACE(_T("Failed to change to %s from %s\n"),psz,szOrigDir);
|
TRACE(_T("Failed to change to %s from %s\n"),psz,szOrigDir);
|
}
|
}
|
_tchdir(szOrigDir);
|
_tchdir(szOrigDir);
|
LEAVECRITICAL;
|
LEAVECRITICAL;
|
|
|
return rc;
|
return rc;
|
}
|
}
|
|
|
bool CTestResource::SaveToDirectory (LPCTSTR pszDir)
|
bool CTestResource::SaveToDirectory (LPCTSTR pszDir)
|
{
|
{
|
bool rc=false;
|
bool rc=false;
|
ENTERCRITICAL;
|
ENTERCRITICAL;
|
{
|
{
|
// Delete all the files under directory "pszDir"
|
// Delete all the files under directory "pszDir"
|
void *pHandle;
|
void *pHandle;
|
TCHAR szOrigDir[256];
|
TCHAR szOrigDir[256];
|
_tgetcwd(szOrigDir,sizeof szOrigDir-1);
|
_tgetcwd(szOrigDir,sizeof szOrigDir-1);
|
if(0==_tchdir(pszDir)){
|
if(0==_tchdir(pszDir)){
|
String strFile;
|
String strFile;
|
for(bool b=CeCosTestUtils::StartSearch(pHandle,strFile);b;b=CeCosTestUtils::NextFile(pHandle,strFile)){
|
for(bool b=CeCosTestUtils::StartSearch(pHandle,strFile);b;b=CeCosTestUtils::NextFile(pHandle,strFile)){
|
if(CeCosTestUtils::IsFile(strFile)){
|
if(CeCosTestUtils::IsFile(strFile)){
|
_tunlink(strFile);
|
_tunlink(strFile);
|
}
|
}
|
}
|
}
|
CeCosTestUtils::EndSearch(pHandle);
|
CeCosTestUtils::EndSearch(pHandle);
|
rc=true;
|
rc=true;
|
for(CTestResource *pResource=pFirstInstance;pResource;pResource=pResource->m_pNextInstance){
|
for(CTestResource *pResource=pFirstInstance;pResource;pResource=pResource->m_pNextInstance){
|
CTestResourceProperties prop(pResource);
|
CTestResourceProperties prop(pResource);
|
rc&=prop.SaveToFile(pResource->FileName());
|
rc&=prop.SaveToFile(pResource->FileName());
|
}
|
}
|
} else {
|
} else {
|
fprintf(stderr,"Failed to change to %s from %s\n",pszDir,szOrigDir);
|
fprintf(stderr,"Failed to change to %s from %s\n",pszDir,szOrigDir);
|
}
|
}
|
_tchdir(szOrigDir);
|
_tchdir(szOrigDir);
|
}
|
}
|
|
|
LEAVECRITICAL;
|
LEAVECRITICAL;
|
|
|
return rc;
|
return rc;
|
}
|
}
|
|
|
#ifdef _WIN32
|
#ifdef _WIN32
|
bool CTestResource::LoadFromRegistry(HKEY key,LPCTSTR psz)
|
bool CTestResource::LoadFromRegistry(HKEY key,LPCTSTR psz)
|
{
|
{
|
// Find all the keys under "psz" and load from each of them
|
// Find all the keys under "psz" and load from each of them
|
bool rc=false;
|
bool rc=false;
|
ENTERCRITICAL;
|
ENTERCRITICAL;
|
HKEY hKey;
|
HKEY hKey;
|
if(ERROR_SUCCESS==RegOpenKeyEx ((HKEY)key, psz, 0L, KEY_ENUMERATE_SUB_KEYS, &hKey)){
|
if(ERROR_SUCCESS==RegOpenKeyEx ((HKEY)key, psz, 0L, KEY_ENUMERATE_SUB_KEYS, &hKey)){
|
TCHAR szName[256];
|
TCHAR szName[256];
|
DWORD dwSizeName=sizeof szName;
|
DWORD dwSizeName=sizeof szName;
|
FILETIME ftLastWriteTime;
|
FILETIME ftLastWriteTime;
|
for(DWORD dwIndex=0;ERROR_SUCCESS==RegEnumKeyEx(hKey, dwIndex, szName, &dwSizeName, NULL, NULL, NULL, &ftLastWriteTime); dwIndex++){
|
for(DWORD dwIndex=0;ERROR_SUCCESS==RegEnumKeyEx(hKey, dwIndex, szName, &dwSizeName, NULL, NULL, NULL, &ftLastWriteTime); dwIndex++){
|
CTestResource *pResource=new CTestResource(_T(""),_T(""));
|
CTestResource *pResource=new CTestResource(_T(""),_T(""));
|
String strKey;
|
String strKey;
|
strKey.Format(_T("%s\\%s"),psz,szName);
|
strKey.Format(_T("%s\\%s"),psz,szName);
|
CTestResourceProperties prop1(pResource);
|
CTestResourceProperties prop1(pResource);
|
prop1.LoadFromRegistry(key,strKey);
|
prop1.LoadFromRegistry(key,strKey);
|
dwSizeName=sizeof szName;
|
dwSizeName=sizeof szName;
|
}
|
}
|
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
}
|
}
|
LEAVECRITICAL;
|
LEAVECRITICAL;
|
return rc;
|
return rc;
|
}
|
}
|
|
|
bool CTestResource::SaveToRegistry(HKEY key,LPCTSTR psz)
|
bool CTestResource::SaveToRegistry(HKEY key,LPCTSTR psz)
|
{
|
{
|
bool rc=false;
|
bool rc=false;
|
ENTERCRITICAL;
|
ENTERCRITICAL;
|
// Delete all the keys under "psz"
|
// Delete all the keys under "psz"
|
HKEY hKey;
|
HKEY hKey;
|
if(ERROR_SUCCESS==RegOpenKeyEx ((HKEY)key, psz, 0L, KEY_ENUMERATE_SUB_KEYS, &hKey)){
|
if(ERROR_SUCCESS==RegOpenKeyEx ((HKEY)key, psz, 0L, KEY_ENUMERATE_SUB_KEYS, &hKey)){
|
TCHAR szName[256];
|
TCHAR szName[256];
|
DWORD dwSizeName=sizeof szName;
|
DWORD dwSizeName=sizeof szName;
|
FILETIME ftLastWriteTime;
|
FILETIME ftLastWriteTime;
|
DWORD dwIndex;
|
DWORD dwIndex;
|
if(ERROR_SUCCESS==RegQueryInfoKey(hKey,0,0,0,&dwIndex,0,0,0,0,0,0,0)){
|
if(ERROR_SUCCESS==RegQueryInfoKey(hKey,0,0,0,&dwIndex,0,0,0,0,0,0,0)){
|
while((signed)--dwIndex>=0){
|
while((signed)--dwIndex>=0){
|
if(ERROR_SUCCESS!=RegEnumKeyEx(hKey, dwIndex, szName, &dwSizeName, NULL, NULL, NULL, &ftLastWriteTime) ||
|
if(ERROR_SUCCESS!=RegEnumKeyEx(hKey, dwIndex, szName, &dwSizeName, NULL, NULL, NULL, &ftLastWriteTime) ||
|
ERROR_SUCCESS!=RegDeleteKey(hKey,szName)){
|
ERROR_SUCCESS!=RegDeleteKey(hKey,szName)){
|
rc=false;
|
rc=false;
|
}
|
}
|
dwSizeName=sizeof szName;
|
dwSizeName=sizeof szName;
|
}
|
}
|
}
|
}
|
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
}
|
}
|
rc=true;
|
rc=true;
|
for(CTestResource *pResource=pFirstInstance;pResource;pResource=pResource->m_pNextInstance){
|
for(CTestResource *pResource=pFirstInstance;pResource;pResource=pResource->m_pNextInstance){
|
CTestResourceProperties prop1(pResource);
|
CTestResourceProperties prop1(pResource);
|
rc&=prop1.SaveToRegistry(key,pResource->FileName());
|
rc&=prop1.SaveToRegistry(key,pResource->FileName());
|
}
|
}
|
|
|
LEAVECRITICAL;
|
LEAVECRITICAL;
|
return rc;
|
return rc;
|
}
|
}
|
|
|
#endif
|
#endif
|
|
|
CTestResource::CTestResourceProperties::CTestResourceProperties(CTestResource *pResource)
|
CTestResource::CTestResourceProperties::CTestResourceProperties(CTestResource *pResource)
|
{
|
{
|
Add(_T("Baud"), pResource->m_nBaud);
|
Add(_T("Baud"), pResource->m_nBaud);
|
Add(_T("BoardId"), pResource->m_strBoardID);
|
Add(_T("BoardId"), pResource->m_strBoardID);
|
Add(_T("Date"), pResource->m_strDate);
|
Add(_T("Date"), pResource->m_strDate);
|
Add(_T("Email"), pResource->m_strEmail);
|
Add(_T("Email"), pResource->m_strEmail);
|
Add(_T("Host"), pResource->m_strHost);
|
Add(_T("Host"), pResource->m_strHost);
|
Add(_T("Port"), pResource->m_nPort);
|
Add(_T("Port"), pResource->m_nPort);
|
Add(_T("Locked"), pResource->m_bLocked);
|
Add(_T("Locked"), pResource->m_bLocked);
|
Add(_T("Originator"), pResource->m_strUser);
|
Add(_T("Originator"), pResource->m_strUser);
|
Add(_T("Reason"), pResource->m_strReason);
|
Add(_T("Reason"), pResource->m_strReason);
|
Add(_T("Reset"), pResource->m_strReset);
|
Add(_T("Reset"), pResource->m_strReset);
|
Add(_T("Serial"), pResource->m_strPort);
|
Add(_T("Serial"), pResource->m_strPort);
|
Add(_T("Target"), pResource->m_Target);
|
Add(_T("Target"), pResource->m_Target);
|
Add(_T("User"), pResource->m_strUser);
|
Add(_T("User"), pResource->m_strUser);
|
}
|
}
|
|
|
bool CTestResource::Lock()
|
bool CTestResource::Lock()
|
{
|
{
|
if(!m_bLocked){
|
if(!m_bLocked){
|
m_bLocked=true;
|
m_bLocked=true;
|
return true;
|
return true;
|
} else {
|
} else {
|
return false;
|
return false;
|
}
|
}
|
}
|
}
|
|
|
bool CTestResource::Unlock()
|
bool CTestResource::Unlock()
|
{
|
{
|
if(m_bLocked){
|
if(m_bLocked){
|
m_bLocked=false;
|
m_bLocked=false;
|
return true;
|
return true;
|
} else {
|
} else {
|
return false;
|
return false;
|
}
|
}
|
}
|
}
|
|
|
bool CTestResource::LoadSocket(LPCTSTR pszResourceHostPort,Duration dTimeout/*=10*1000*/)
|
bool CTestResource::LoadSocket(LPCTSTR pszResourceHostPort,Duration dTimeout/*=10*1000*/)
|
{
|
{
|
bool rc=false;
|
bool rc=false;
|
ENTERCRITICAL;
|
ENTERCRITICAL;
|
CTestResource *pResource;
|
CTestResource *pResource;
|
// If the resource is in use, we don't dare delete it!
|
// If the resource is in use, we don't dare delete it!
|
for(pResource=CTestResource::First();pResource;pResource=pResource->Next()){
|
for(pResource=CTestResource::First();pResource;pResource=pResource->Next()){
|
pResource->m_bFlag=false;
|
pResource->m_bFlag=false;
|
}
|
}
|
CeCosSocket sock;
|
CeCosSocket sock;
|
if(sock.Connect(pszResourceHostPort,dTimeout)){
|
if(sock.Connect(pszResourceHostPort,dTimeout)){
|
// Write the message to the socket
|
// Write the message to the socket
|
int nRequest=0; // read
|
int nRequest=0; // read
|
if(!sock.sendInteger(nRequest)){
|
if(!sock.sendInteger(nRequest)){
|
ERROR(_T("Failed to write to socket\n"));
|
ERROR(_T("Failed to write to socket\n"));
|
} else {
|
} else {
|
int nResources;
|
int nResources;
|
if(sock.recvInteger(nResources,_T(""),dTimeout)){
|
if(sock.recvInteger(nResources,_T(""),dTimeout)){
|
rc=true;
|
rc=true;
|
while(nResources--){
|
while(nResources--){
|
String strImage;
|
String strImage;
|
if(sock.recvString(strImage,_T(""),dTimeout)){
|
if(sock.recvString(strImage,_T(""),dTimeout)){
|
VTRACE(_T("Recv \"%s\"\n"),(LPCTSTR)strImage);
|
VTRACE(_T("Recv \"%s\"\n"),(LPCTSTR)strImage);
|
CTestResource tmp;
|
CTestResource tmp;
|
tmp.FromStr(strImage);
|
tmp.FromStr(strImage);
|
CTestResource *pResource=Lookup(tmp.HostPort());
|
CTestResource *pResource=Lookup(tmp.HostPort());
|
if(0==pResource){
|
if(0==pResource){
|
pResource=new CTestResource(_T(""),_T(""));
|
pResource=new CTestResource(_T(""),_T(""));
|
}
|
}
|
pResource->FromStr(strImage);
|
pResource->FromStr(strImage);
|
pResource->m_bFlag=true;
|
pResource->m_bFlag=true;
|
} else {
|
} else {
|
rc=false;
|
rc=false;
|
break;
|
break;
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
// If the resource is in use, we don't dare delete it!
|
// If the resource is in use, we don't dare delete it!
|
CTestResource *pNext;
|
CTestResource *pNext;
|
for(pResource=CTestResource::First();pResource;pResource=pNext){
|
for(pResource=CTestResource::First();pResource;pResource=pNext){
|
pNext=pResource->Next();
|
pNext=pResource->Next();
|
if(!pResource->m_bFlag && !pResource->m_bInUse){
|
if(!pResource->m_bFlag && !pResource->m_bInUse){
|
delete pResource;
|
delete pResource;
|
}
|
}
|
}
|
}
|
|
|
LEAVECRITICAL;
|
LEAVECRITICAL;
|
return rc;
|
return rc;
|
}
|
}
|
|
|
bool CTestResource::SaveSocket(LPCTSTR pszResourceHostPort,Duration dTimeout)
|
bool CTestResource::SaveSocket(LPCTSTR pszResourceHostPort,Duration dTimeout)
|
{
|
{
|
bool rc=true;
|
bool rc=true;
|
ENTERCRITICAL;
|
ENTERCRITICAL;
|
CeCosSocket sock(pszResourceHostPort, dTimeout);
|
CeCosSocket sock(pszResourceHostPort, dTimeout);
|
if(sock.Ok()){
|
if(sock.Ok()){
|
// Write the message to the socket
|
// Write the message to the socket
|
int nRequest=1; //write
|
int nRequest=1; //write
|
if(!sock.sendInteger(nRequest, _T(""),dTimeout)){
|
if(!sock.sendInteger(nRequest, _T(""),dTimeout)){
|
ERROR(_T("Failed to write to socket\n"));
|
ERROR(_T("Failed to write to socket\n"));
|
rc=false;
|
rc=false;
|
} else {
|
} else {
|
int nResources=0;
|
int nResources=0;
|
CTestResource *pResource;
|
CTestResource *pResource;
|
for(pResource=CTestResource::First();pResource;pResource=pResource->Next()){
|
for(pResource=CTestResource::First();pResource;pResource=pResource->Next()){
|
nResources++;
|
nResources++;
|
}
|
}
|
if(sock.sendInteger(nResources,_T("resource count"),dTimeout)){
|
if(sock.sendInteger(nResources,_T("resource count"),dTimeout)){
|
for(pResource=CTestResource::First();pResource;pResource=pResource->Next()){
|
for(pResource=CTestResource::First();pResource;pResource=pResource->Next()){
|
String strImage;
|
String strImage;
|
CTestResourceProperties prop(pResource);
|
CTestResourceProperties prop(pResource);
|
strImage=prop.MakeCommandString();
|
strImage=prop.MakeCommandString();
|
TRACE(_T("Send \"%s\"\n"),(LPCTSTR)strImage);
|
TRACE(_T("Send \"%s\"\n"),(LPCTSTR)strImage);
|
if(!sock.sendString (strImage, _T("reply"),dTimeout)){
|
if(!sock.sendString (strImage, _T("reply"),dTimeout)){
|
rc=false;
|
rc=false;
|
break;
|
break;
|
}
|
}
|
}
|
}
|
} else {
|
} else {
|
rc=false;
|
rc=false;
|
}
|
}
|
}
|
}
|
} else {
|
} else {
|
rc=false;
|
rc=false;
|
}
|
}
|
LEAVECRITICAL;
|
LEAVECRITICAL;
|
return rc;
|
return rc;
|
}
|
}
|
|
|
/*
|
/*
|
void CTestResource::Image(String &str)
|
void CTestResource::Image(String &str)
|
{
|
{
|
CTestResourceProperties prop(this);
|
CTestResourceProperties prop(this);
|
str=prop.MakeCommandString();
|
str=prop.MakeCommandString();
|
VTRACE(_T("Make command string %s\n"),(LPCTSTR)str);
|
VTRACE(_T("Make command string %s\n"),(LPCTSTR)str);
|
}
|
}
|
*/
|
*/
|
|
|
bool CTestResource::FromStr(LPCTSTR pszImage)
|
bool CTestResource::FromStr(LPCTSTR pszImage)
|
{
|
{
|
CTestResourceProperties prop(this);
|
CTestResourceProperties prop(this);
|
prop.LoadFromCommandString(pszImage);
|
prop.LoadFromCommandString(pszImage);
|
VTRACE(_T("From command string %s\n"),pszImage);
|
VTRACE(_T("From command string %s\n"),pszImage);
|
return true;
|
return true;
|
}
|
}
|
|
|
void CTestResource::Chain()
|
void CTestResource::Chain()
|
{
|
{
|
ENTERCRITICAL;
|
ENTERCRITICAL;
|
nCount++;
|
nCount++;
|
m_pNextInstance=pFirstInstance;
|
m_pNextInstance=pFirstInstance;
|
if(m_pNextInstance){
|
if(m_pNextInstance){
|
m_pNextInstance->m_pPrevInstance=this;
|
m_pNextInstance->m_pPrevInstance=this;
|
}
|
}
|
m_pPrevInstance=0;
|
m_pPrevInstance=0;
|
pFirstInstance=this;
|
pFirstInstance=this;
|
LEAVECRITICAL;
|
LEAVECRITICAL;
|
}
|
}
|
|
|
bool CTestResource::Matches (const CeCosTest::ExecutionParameters &e,bool bIgnoreLocking) const
|
bool CTestResource::Matches (const CeCosTest::ExecutionParameters &e,bool bIgnoreLocking) const
|
{
|
{
|
return (bIgnoreLocking||(!m_bLocked)) && (0==_tcsicmp(e.PlatformName(),m_Target));
|
return (bIgnoreLocking||(!m_bLocked)) && (0==_tcsicmp(e.PlatformName(),m_Target));
|
};
|
};
|
|
|
CeCosTest::ServerStatus CTestResource::Query()
|
CeCosTest::ServerStatus CTestResource::Query()
|
{
|
{
|
CeCosTest::ExecutionParameters e(CeCosTest::ExecutionParameters::QUERY,m_Target);
|
CeCosTest::ExecutionParameters e(CeCosTest::ExecutionParameters::QUERY,m_Target);
|
CeCosSocket *pSock=0;
|
CeCosSocket *pSock=0;
|
CeCosTest::ServerStatus s=CeCosTest::Connect(HostPort(),pSock,e,m_strInfo);
|
CeCosTest::ServerStatus s=CeCosTest::Connect(HostPort(),pSock,e,m_strInfo);
|
delete pSock;
|
delete pSock;
|
return s;
|
return s;
|
}
|
}
|
|
|
int CTestResource::Count(const CeCosTest::ExecutionParameters &e)
|
int CTestResource::Count(const CeCosTest::ExecutionParameters &e)
|
{
|
{
|
int nCount=0;
|
int nCount=0;
|
for(const CTestResource *p=pFirstInstance;p;p=p->m_pNextInstance){
|
for(const CTestResource *p=pFirstInstance;p;p=p->m_pNextInstance){
|
if(p->Matches(e)){
|
if(p->Matches(e)){
|
nCount++;
|
nCount++;
|
}
|
}
|
}
|
}
|
return nCount;
|
return nCount;
|
}
|
}
|
|
|
bool CTestResource::Use()
|
bool CTestResource::Use()
|
{
|
{
|
bool rc;
|
bool rc;
|
ENTERCRITICAL;
|
ENTERCRITICAL;
|
if(m_bInUse){
|
if(m_bInUse){
|
rc=false;
|
rc=false;
|
} else {
|
} else {
|
m_bInUse=true;
|
m_bInUse=true;
|
rc=true;
|
rc=true;
|
}
|
}
|
LEAVECRITICAL;
|
LEAVECRITICAL;
|
return rc;
|
return rc;
|
}
|
}
|
|
|
CTestResource *CTestResource::GetResource (const CeCosTest::ExecutionParameters &e)
|
CTestResource *CTestResource::GetResource (const CeCosTest::ExecutionParameters &e)
|
{
|
{
|
CTestResource *p=0;
|
CTestResource *p=0;
|
if(0==Count(e)){
|
if(0==Count(e)){
|
ERROR(_T("GetResource: no candidates available\n"));
|
ERROR(_T("GetResource: no candidates available\n"));
|
} else {
|
} else {
|
ENTERCRITICAL;
|
ENTERCRITICAL;
|
for(p=pFirstInstance;p;p=p->m_pNextInstance){
|
for(p=pFirstInstance;p;p=p->m_pNextInstance){
|
if(p->Matches(e) && !p->m_bInUse){
|
if(p->Matches(e) && !p->m_bInUse){
|
TRACE(_T("Acquired %s\n"),p->Serial());
|
TRACE(_T("Acquired %s\n"),p->Serial());
|
p->Use();
|
p->Use();
|
break;
|
break;
|
}
|
}
|
}
|
}
|
LEAVECRITICAL;
|
LEAVECRITICAL;
|
}
|
}
|
return p;
|
return p;
|
}
|
}
|
|
|
const String CTestResource::Image() const
|
const String CTestResource::Image() const
|
{
|
{
|
String str;
|
String str;
|
str.Format(_T("%10s %20s %8s"),(LPCTSTR)HostPort(),(LPCTSTR)Target(),(LPCTSTR)Serial());
|
str.Format(_T("%10s %20s %8s"),(LPCTSTR)HostPort(),(LPCTSTR)Target(),(LPCTSTR)Serial());
|
if(IsLocked()){
|
if(IsLocked()){
|
str+=_T(" [RL]");
|
str+=_T(" [RL]");
|
}
|
}
|
return str;
|
return str;
|
}
|
}
|
|
|
bool CTestResource::Matches(LPCTSTR pszHostPort, const CeCosTest::ExecutionParameters &e)
|
bool CTestResource::Matches(LPCTSTR pszHostPort, const CeCosTest::ExecutionParameters &e)
|
{
|
{
|
bool rc=false;
|
bool rc=false;
|
ENTERCRITICAL;
|
ENTERCRITICAL;
|
if(Load()){
|
if(Load()){
|
CTestResource *pResource=Lookup(pszHostPort);
|
CTestResource *pResource=Lookup(pszHostPort);
|
if(pResource){
|
if(pResource){
|
rc=pResource->Matches(e);
|
rc=pResource->Matches(e);
|
}
|
}
|
}
|
}
|
LEAVECRITICAL;
|
LEAVECRITICAL;
|
return rc;
|
return rc;
|
}
|
}
|
|
|
CResetAttributes::ResetResult CTestResource::Reset(LogFunc *pfnLog, void *pfnLogparam)
|
CResetAttributes::ResetResult CTestResource::Reset(LogFunc *pfnLog, void *pfnLogparam)
|
{
|
{
|
String strReset;
|
String strReset;
|
strReset.Format(_T("port(%s,%d) %s"),Serial(),Baud(),ResetString());
|
strReset.Format(_T("port(%s,%d) %s"),Serial(),Baud(),ResetString());
|
return CResetAttributes(strReset).Reset(pfnLog,pfnLogparam);
|
return CResetAttributes(strReset).Reset(pfnLog,pfnLogparam);
|
}
|
}
|
|
|
CResetAttributes::ResetResult CTestResource::Reset(String &str)
|
CResetAttributes::ResetResult CTestResource::Reset(String &str)
|
{
|
{
|
return Reset(StringLogFunc,&str);
|
return Reset(StringLogFunc,&str);
|
}
|
}
|
|
|
void CALLBACK CTestResource::StringLogFunc (void *pParam,LPCTSTR psz)
|
void CALLBACK CTestResource::StringLogFunc (void *pParam,LPCTSTR psz)
|
{
|
{
|
*((String *)pParam)+=psz;
|
*((String *)pParam)+=psz;
|
}
|
}
|
|
|
|
|
CResetAttributes::ResetResult CTestResource::RemoteReset(LogFunc *pfnLog, void *pfnLogparam)
|
CResetAttributes::ResetResult CTestResource::RemoteReset(LogFunc *pfnLog, void *pfnLogparam)
|
{
|
{
|
String strHost;
|
String strHost;
|
int nPort;
|
int nPort;
|
CeCosSocket::ParseHostPort(HostPort(),strHost,nPort);
|
CeCosSocket::ParseHostPort(HostPort(),strHost,nPort);
|
String strCmd;
|
String strCmd;
|
strCmd.Format(_T("rsh %s x10reset %s\n"),(LPCTSTR)strHost,ResetString());
|
strCmd.Format(_T("rsh %s x10reset %s\n"),(LPCTSTR)strHost,ResetString());
|
pfnLog(pfnLogparam,strCmd);
|
pfnLog(pfnLogparam,strCmd);
|
|
|
CSubprocess sp;
|
CSubprocess sp;
|
sp.Run(pfnLog,pfnLogparam,strCmd);
|
sp.Run(pfnLog,pfnLogparam,strCmd);
|
return CResetAttributes::RESET_OK; // FIXME
|
return CResetAttributes::RESET_OK; // FIXME
|
}
|
}
|
|
|
String CTestResource::FileName() const
|
String CTestResource::FileName() const
|
{
|
{
|
String strHost;
|
String strHost;
|
int nPort;
|
int nPort;
|
CeCosSocket::ParseHostPort(HostPort(),strHost,nPort);
|
CeCosSocket::ParseHostPort(HostPort(),strHost,nPort);
|
return String::SFormat(_T("%s-%d"),(LPCTSTR)strHost,nPort);
|
return String::SFormat(_T("%s-%d"),(LPCTSTR)strHost,nPort);
|
}
|
}
|
|
|
|
|