Mercurial > flash_v2
comparison host/tools/ecostest/common/TestResource.cpp @ 82:6736c52df507 ecos-sw-2000-04-14
Merge from eCos master repository on 2000-04-14-13:35:46-BST
| author | jlarmour |
|---|---|
| date | Tue, 18 Apr 2000 21:51:55 +0000 |
| parents | 435cced73e2f |
| children |
comparison
equal
deleted
inserted
replaced
| 81:89fef2181d7d | 82:6736c52df507 |
|---|---|
| 40 // | 40 // |
| 41 //####DESCRIPTIONEND#### | 41 //####DESCRIPTIONEND#### |
| 42 #include "eCosStd.h" | 42 #include "eCosStd.h" |
| 43 #include "eCosTestUtils.h" | 43 #include "eCosTestUtils.h" |
| 44 #include "eCosTrace.h" | 44 #include "eCosTrace.h" |
| 45 #ifdef _WIN32 | 45 #include "Subprocess.h" |
| 46 #include "Subprocess.h" | 46 |
| 47 #endif | |
| 48 #include "TestResource.h" | 47 #include "TestResource.h" |
| 49 | 48 |
| 50 CTestResource *CTestResource::pFirstInstance=0; | 49 CTestResource *CTestResource::pFirstInstance=0; |
| 51 unsigned int CTestResource::nCount=0; | 50 unsigned int CTestResource::nCount=0; |
| 52 | 51 |
| 53 String CTestResource::strResourceHost; | 52 String CTestResource::strResourceHostPort; |
| 54 int CTestResource::nResourcePort; | 53 |
| 55 | 54 CTestResource::CTestResource(LPCTSTR pszHostPort, LPCTSTR target, LPCTSTR pszDownloadPort, int nBaud, LPCTSTR pszResetString): |
| 56 CTestResource::CTestResource(LPCTSTR target, LPCTSTR pszDownloadPort, int nBaud, LPCTSTR pszResetString): | |
| 57 m_strReset(pszResetString), | 55 m_strReset(pszResetString), |
| 58 m_bInUse(false), | 56 m_bInUse(false), |
| 59 m_nBaud(nBaud), | 57 m_nBaud(nBaud), |
| 60 m_strPort(pszDownloadPort), | 58 m_strPort(pszDownloadPort), |
| 61 m_bLocked(false), | 59 m_bLocked(false), |
| 62 m_Target(target), | 60 m_Target(target) |
| 63 m_strHost(CeCosTestUtils::HostName()), | 61 { |
| 64 m_nPort(0) | 62 CeCosSocket::ParseHostPort(pszHostPort,m_strHost,m_nPort); |
| 65 { | 63 VTRACE(_T("@@@ Created resource %08x %s\n"),(unsigned int)this,(LPCTSTR)Image()); |
| 66 VTRACE(_T("@@@ Created resource %08x %s\n"),(unsigned int)this,(LPCTSTR)Output()); | |
| 67 Chain(); | 64 Chain(); |
| 68 } | 65 } |
| 69 | 66 |
| 70 CTestResource::~CTestResource() | 67 CTestResource::~CTestResource() |
| 71 { | 68 { |
| 72 ENTERCRITICAL; | 69 ENTERCRITICAL; |
| 73 VTRACE(_T("@@@ Destroy resource %08x %s\n"),this,(LPCTSTR)Output()); | 70 VTRACE(_T("@@@ Destroy resource %08x %s\n"),this,(LPCTSTR)Image()); |
| 74 if(m_pPrevInstance || m_pNextInstance){ | 71 if(m_pPrevInstance || m_pNextInstance){ |
| 75 nCount--; | 72 nCount--; |
| 76 } | 73 } |
| 77 if(pFirstInstance==this){ | 74 if(pFirstInstance==this){ |
| 78 pFirstInstance=m_pNextInstance; | 75 pFirstInstance=m_pNextInstance; |
| 86 LEAVECRITICAL; | 83 LEAVECRITICAL; |
| 87 } | 84 } |
| 88 | 85 |
| 89 // Find the resource matching the given host:port specification | 86 // Find the resource matching the given host:port specification |
| 90 // Returns 0 if no such host:port found | 87 // Returns 0 if no such host:port found |
| 91 CTestResource * CTestResource::Lookup(LPCTSTR pszHost, int nPort) | 88 CTestResource * CTestResource::Lookup(LPCTSTR pszHostPort) |
| 92 { | 89 { |
| 93 CTestResource *pResource; | 90 CTestResource *pResource=NULL; |
| 94 ENTERCRITICAL; | 91 ENTERCRITICAL; |
| 95 for(pResource=pFirstInstance;pResource;pResource=pResource->m_pNextInstance){ | 92 String strHost; |
| 96 if(nPort==pResource->TcpipPort() && 0==_tcsicmp(pszHost,pResource->Host())){ | 93 int nPort; |
| 97 break; | 94 if(CeCosSocket::ParseHostPort(pszHostPort,strHost,nPort)){ |
| 95 for(pResource=pFirstInstance;pResource;pResource=pResource->m_pNextInstance){ | |
| 96 if(nPort==pResource->TcpIPPort() && CeCosSocket::SameHost(strHost,pResource->Host())){ | |
| 97 break; | |
| 98 } | |
| 98 } | 99 } |
| 99 } | 100 } |
| 100 LEAVECRITICAL; | 101 LEAVECRITICAL; |
| 101 return pResource; | 102 return pResource; |
| 102 } | 103 } |
| 116 | 117 |
| 117 bool CTestResource::GetMatches (const CeCosTest::ExecutionParameters &e, StringArray &arstr, bool bIgnoreLocking) | 118 bool CTestResource::GetMatches (const CeCosTest::ExecutionParameters &e, StringArray &arstr, bool bIgnoreLocking) |
| 118 { | 119 { |
| 119 bool rc=false; | 120 bool rc=false; |
| 120 arstr.clear(); | 121 arstr.clear(); |
| 121 if(LoadSocket()){ | 122 if(Load()){ |
| 122 ENTERCRITICAL; | 123 ENTERCRITICAL; |
| 123 for(CTestResource *pResource=pFirstInstance;pResource;pResource=pResource->m_pNextInstance){ | 124 for(CTestResource *pResource=pFirstInstance;pResource;pResource=pResource->m_pNextInstance){ |
| 124 if(pResource->Matches(e,bIgnoreLocking)){ | 125 if(pResource->Matches(e,bIgnoreLocking)){ |
| 125 arstr.push_back(CeCosTestSocket::HostPort(pResource->Host(),pResource->TcpipPort())); | 126 arstr.push_back(pResource->HostPort()); |
| 126 } | 127 } |
| 127 } | 128 } |
| 128 LEAVECRITICAL; | 129 LEAVECRITICAL; |
| 129 rc=true; | 130 rc=true; |
| 130 } | 131 } |
| 131 return rc; | 132 return rc; |
| 138 delete pFirstInstance; | 139 delete pFirstInstance; |
| 139 } | 140 } |
| 140 LEAVECRITICAL; | 141 LEAVECRITICAL; |
| 141 } | 142 } |
| 142 | 143 |
| 143 bool CTestResource::LoadFile (LPCTSTR psz,void *key) | 144 bool CTestResource::LoadFromDirectory (LPCTSTR psz) |
| 144 { | 145 { |
| 145 bool rc=true; | 146 bool rc=true; |
| 146 ENTERCRITICAL; | 147 ENTERCRITICAL; |
| 147 DeleteAllInstances(); | 148 DeleteAllInstances(); |
| 148 #ifdef _WIN32 | 149 // Find all the files in directory "psz" and load from each of them |
| 149 if(key){ | 150 TCHAR szOrigDir[256]; |
| 150 // Find all the keys under "psz" and load from each of them | 151 _tgetcwd(szOrigDir,sizeof szOrigDir-1); |
| 151 HKEY hKey; | 152 if(0==_tchdir(psz)){ |
| 152 if(ERROR_SUCCESS==RegOpenKeyEx ((HKEY)key, psz, 0L, KEY_ENUMERATE_SUB_KEYS, &hKey)){ | 153 String strFile; |
| 153 TCHAR szName[256]; | 154 void *pHandle; |
| 154 DWORD dwSizeName=sizeof szName; | 155 for(bool b=CeCosTestUtils::StartSearch(pHandle,strFile);b;b=CeCosTestUtils::NextFile(pHandle,strFile)){ |
| 155 FILETIME ftLastWriteTime; | 156 if(CeCosTestUtils::IsFile(strFile)){ |
| 156 for(DWORD dwIndex=0;ERROR_SUCCESS==RegEnumKeyEx(hKey, dwIndex, szName, &dwSizeName, NULL, NULL, NULL, &ftLastWriteTime); dwIndex++){ | 157 CTestResource *pResource=new CTestResource(_T(""),_T("")); |
| 157 CTestResource *pResource=new CTestResource(_T("")); | 158 CTestResourceProperties prop(pResource); |
| 158 String strKey; | 159 prop.LoadFromFile(strFile); |
| 159 strKey.Format(_T("%s\\%s"),psz,szName); | 160 } |
| 160 CTestResourceProperties prop1(pResource,strKey,key); | 161 } |
| 161 prop1.SetDefaults(); | 162 CeCosTestUtils::EndSearch(pHandle); |
| 162 prop1.Load(); | 163 } else { |
| 163 dwSizeName=sizeof szName; | 164 TRACE(_T("Failed to change to %s from %s\n"),psz,szOrigDir); |
| 164 } | 165 } |
| 165 RegCloseKey(hKey); | 166 _tchdir(szOrigDir); |
| 166 } | 167 LEAVECRITICAL; |
| 167 } else | 168 |
| 168 #endif | 169 return rc; |
| 170 } | |
| 171 | |
| 172 bool CTestResource::SaveToDirectory (LPCTSTR pszDir) | |
| 173 { | |
| 174 bool rc=false; | |
| 175 ENTERCRITICAL; | |
| 169 { | 176 { |
| 170 // Find all the files in directory "psz" and load from each of them | 177 // Delete all the files under directory "pszDir" |
| 171 void *pHandle; | 178 void *pHandle; |
| 172 TCHAR szOrigDir[256]; | 179 TCHAR szOrigDir[256]; |
| 173 _tgetcwd(szOrigDir,sizeof szOrigDir-1); | 180 _tgetcwd(szOrigDir,sizeof szOrigDir-1); |
| 174 if(0==_tchdir(psz)){ | 181 if(0==_tchdir(pszDir)){ |
| 175 String strFile; | 182 String strFile; |
| 176 for(bool b=CeCosTestUtils::StartSearch(pHandle,strFile);b;b=CeCosTestUtils::NextFile(pHandle,strFile)){ | 183 for(bool b=CeCosTestUtils::StartSearch(pHandle,strFile);b;b=CeCosTestUtils::NextFile(pHandle,strFile)){ |
| 177 struct _stat buf; | 184 if(CeCosTestUtils::IsFile(strFile)){ |
| 178 if(0==_tstat(strFile,&buf) && 0==(S_IFDIR&buf.st_mode)){ | |
| 179 CTestResource *pResource=new CTestResource(_T("")); | |
| 180 CTestResourceProperties prop1(pResource,strFile); | |
| 181 prop1.SetDefaults(); | |
| 182 prop1.Load(); | |
| 183 } | |
| 184 } | |
| 185 CeCosTestUtils::EndSearch(pHandle); | |
| 186 } else { | |
| 187 TRACE(_T("Failed to change to %s from %s\n"),psz,szOrigDir); | |
| 188 } | |
| 189 _tchdir(szOrigDir); | |
| 190 } | |
| 191 LEAVECRITICAL; | |
| 192 | |
| 193 return rc; | |
| 194 } | |
| 195 | |
| 196 bool CTestResource::SaveFile (LPCTSTR psz,void *key) | |
| 197 { | |
| 198 bool rc=false; | |
| 199 ENTERCRITICAL; | |
| 200 #ifdef _WIN32 | |
| 201 if(key){ | |
| 202 // Delete all the keys under "psz" | |
| 203 HKEY hKey; | |
| 204 if(ERROR_SUCCESS==RegOpenKeyEx ((HKEY)key, psz, 0L, KEY_ENUMERATE_SUB_KEYS, &hKey)){ | |
| 205 TCHAR szName[256]; | |
| 206 DWORD dwSizeName=sizeof szName; | |
| 207 FILETIME ftLastWriteTime; | |
| 208 DWORD dwIndex; | |
| 209 if(ERROR_SUCCESS==RegQueryInfoKey(hKey,0,0,0,&dwIndex,0,0,0,0,0,0,0)){ | |
| 210 while((signed)--dwIndex>=0){ | |
| 211 if(ERROR_SUCCESS!=RegEnumKeyEx(hKey, dwIndex, szName, &dwSizeName, NULL, NULL, NULL, &ftLastWriteTime) || | |
| 212 ERROR_SUCCESS!=RegDeleteKey(hKey,szName)){ | |
| 213 rc=false; | |
| 214 } | |
| 215 dwSizeName=sizeof szName; | |
| 216 } | |
| 217 } | |
| 218 RegCloseKey(hKey); | |
| 219 } | |
| 220 } else | |
| 221 #endif | |
| 222 { | |
| 223 // Delete all the files under directory "psz" | |
| 224 void *pHandle; | |
| 225 TCHAR szOrigDir[256]; | |
| 226 _tgetcwd(szOrigDir,sizeof szOrigDir-1); | |
| 227 if(0==_tchdir(psz)){ | |
| 228 String strFile; | |
| 229 for(bool b=CeCosTestUtils::StartSearch(pHandle,strFile);b;b=CeCosTestUtils::NextFile(pHandle,strFile)){ | |
| 230 struct _stat buf; | |
| 231 if(0==_tstat(strFile,&buf) && 0==(S_IFDIR&buf.st_mode)){ | |
| 232 _tunlink(strFile); | 185 _tunlink(strFile); |
| 233 } | 186 } |
| 234 } | 187 } |
| 235 CeCosTestUtils::EndSearch(pHandle); | 188 CeCosTestUtils::EndSearch(pHandle); |
| 189 rc=true; | |
| 190 for(CTestResource *pResource=pFirstInstance;pResource;pResource=pResource->m_pNextInstance){ | |
| 191 CTestResourceProperties prop(pResource); | |
| 192 rc&=prop.SaveToFile(pResource->FileName()); | |
| 193 } | |
| 236 } else { | 194 } else { |
| 237 fprintf(stderr,"Failed to change to %s from %s\n",psz,szOrigDir); | 195 fprintf(stderr,"Failed to change to %s from %s\n",pszDir,szOrigDir); |
| 238 } | 196 } |
| 239 _tchdir(szOrigDir); | 197 _tchdir(szOrigDir); |
| 240 } | 198 } |
| 241 | 199 |
| 200 LEAVECRITICAL; | |
| 201 | |
| 202 return rc; | |
| 203 } | |
| 204 | |
| 205 #ifdef _WIN32 | |
| 206 bool CTestResource::LoadFromRegistry(HKEY key,LPCTSTR psz) | |
| 207 { | |
| 208 // Find all the keys under "psz" and load from each of them | |
| 209 bool rc=false; | |
| 210 ENTERCRITICAL; | |
| 211 HKEY hKey; | |
| 212 if(ERROR_SUCCESS==RegOpenKeyEx ((HKEY)key, psz, 0L, KEY_ENUMERATE_SUB_KEYS, &hKey)){ | |
| 213 TCHAR szName[256]; | |
| 214 DWORD dwSizeName=sizeof szName; | |
| 215 FILETIME ftLastWriteTime; | |
| 216 for(DWORD dwIndex=0;ERROR_SUCCESS==RegEnumKeyEx(hKey, dwIndex, szName, &dwSizeName, NULL, NULL, NULL, &ftLastWriteTime); dwIndex++){ | |
| 217 CTestResource *pResource=new CTestResource(_T(""),_T("")); | |
| 218 String strKey; | |
| 219 strKey.Format(_T("%s\\%s"),psz,szName); | |
| 220 CTestResourceProperties prop1(pResource); | |
| 221 prop1.LoadFromRegistry(key,strKey); | |
| 222 dwSizeName=sizeof szName; | |
| 223 } | |
| 224 RegCloseKey(hKey); | |
| 225 } | |
| 226 LEAVECRITICAL; | |
| 227 return rc; | |
| 228 } | |
| 229 | |
| 230 bool CTestResource::SaveToRegistry(HKEY key,LPCTSTR psz) | |
| 231 { | |
| 232 bool rc=false; | |
| 233 ENTERCRITICAL; | |
| 234 // Delete all the keys under "psz" | |
| 235 HKEY hKey; | |
| 236 if(ERROR_SUCCESS==RegOpenKeyEx ((HKEY)key, psz, 0L, KEY_ENUMERATE_SUB_KEYS, &hKey)){ | |
| 237 TCHAR szName[256]; | |
| 238 DWORD dwSizeName=sizeof szName; | |
| 239 FILETIME ftLastWriteTime; | |
| 240 DWORD dwIndex; | |
| 241 if(ERROR_SUCCESS==RegQueryInfoKey(hKey,0,0,0,&dwIndex,0,0,0,0,0,0,0)){ | |
| 242 while((signed)--dwIndex>=0){ | |
| 243 if(ERROR_SUCCESS!=RegEnumKeyEx(hKey, dwIndex, szName, &dwSizeName, NULL, NULL, NULL, &ftLastWriteTime) || | |
| 244 ERROR_SUCCESS!=RegDeleteKey(hKey,szName)){ | |
| 245 rc=false; | |
| 246 } | |
| 247 dwSizeName=sizeof szName; | |
| 248 } | |
| 249 } | |
| 250 RegCloseKey(hKey); | |
| 251 } | |
| 242 rc=true; | 252 rc=true; |
| 243 for(CTestResource *pResource=pFirstInstance;pResource;pResource=pResource->m_pNextInstance){ | 253 for(CTestResource *pResource=pFirstInstance;pResource;pResource=pResource->m_pNextInstance){ |
| 244 String strName; | 254 CTestResourceProperties prop1(pResource); |
| 245 if(key){ | 255 rc&=prop1.SaveToRegistry(key,pResource->FileName()); |
| 246 strName.Format(_T("%s\\%s-%d"),psz,(LPCTSTR)pResource->m_strHost,pResource->m_nPort); | 256 } |
| 247 CTestResourceProperties prop1(pResource,strName,key); | 257 |
| 248 rc&=prop1.Save(); | 258 LEAVECRITICAL; |
| 249 } else { | 259 return rc; |
| 250 strName.Format(_T("%s%c%s-%d"),psz,cPathsep,(LPCTSTR)pResource->m_strHost,pResource->m_nPort); | 260 } |
| 251 CTestResourceProperties prop1(pResource,strName,key); | 261 |
| 252 rc&=prop1.Save(); | 262 #endif |
| 253 } | 263 |
| 254 | 264 CTestResource::CTestResourceProperties::CTestResourceProperties(CTestResource *pResource) |
| 255 } | 265 { |
| 256 LEAVECRITICAL; | 266 Add(_T("Baud"), pResource->m_nBaud); |
| 257 | 267 Add(_T("BoardId"), pResource->m_strBoardID); |
| 258 return rc; | 268 Add(_T("Date"), pResource->m_strDate); |
| 259 } | 269 Add(_T("Email"), pResource->m_strEmail); |
| 260 | 270 Add(_T("Host"), pResource->m_strHost); |
| 261 CTestResource::CTestResourceProperties::CTestResourceProperties(CTestResource *pResource,LPCTSTR psz,void *key): | 271 Add(_T("Port"), pResource->m_nPort); |
| 262 CProperties(psz,key) | 272 Add(_T("Locked"), pResource->m_bLocked); |
| 263 { | 273 Add(_T("Originator"), pResource->m_strUser); |
| 264 CProperties::Add(_T("Baud"), pResource->m_nBaud,0); | 274 Add(_T("Reason"), pResource->m_strReason); |
| 265 Add(_T("BoardId"), pResource->m_strBoardID); | 275 Add(_T("Reset"), pResource->m_strReset); |
| 266 Add(_T("Date"), pResource->m_strDate); | 276 Add(_T("Serial"), pResource->m_strPort); |
| 267 Add(_T("Email"), pResource->m_strEmail); | 277 Add(_T("Target"), pResource->m_Target); |
| 268 Add(_T("Host"), pResource->m_strHost); | 278 Add(_T("User"), pResource->m_strUser); |
| 269 CProperties::Add(_T("Locked"), pResource->m_bLocked,0); | |
| 270 Add(_T("Originator"), pResource->m_strUser); | |
| 271 CProperties::Add(_T("Port"), pResource->m_nPort); | |
| 272 Add(_T("Reason"), pResource->m_strReason); | |
| 273 Add(_T("Reset"), pResource->m_strReset); | |
| 274 Add(_T("Serial"), pResource->m_strPort); | |
| 275 Add(_T("Target"), pResource->m_Target); | |
| 276 Add(_T("User"), pResource->m_strUser); | |
| 277 } | 279 } |
| 278 | 280 |
| 279 bool CTestResource::Lock() | 281 bool CTestResource::Lock() |
| 280 { | 282 { |
| 281 if(!m_bLocked){ | 283 if(!m_bLocked){ |
| 294 } else { | 296 } else { |
| 295 return false; | 297 return false; |
| 296 } | 298 } |
| 297 } | 299 } |
| 298 | 300 |
| 299 bool CTestResource::LoadSocket(LPCTSTR pszResourceHost,int nResourcePort,Duration dTimeout/*=10*1000*/) | 301 bool CTestResource::LoadSocket(LPCTSTR pszResourceHostPort,Duration dTimeout/*=10*1000*/) |
| 300 { | 302 { |
| 301 bool rc=false; | 303 bool rc=false; |
| 302 ENTERCRITICAL; | 304 ENTERCRITICAL; |
| 303 CTestResource *pResource; | 305 CTestResource *pResource; |
| 304 // If the resource is in use, we don't dare delete it! | 306 // If the resource is in use, we don't dare delete it! |
| 305 for(pResource=CTestResource::First();pResource;pResource=pResource->Next()){ | 307 for(pResource=CTestResource::First();pResource;pResource=pResource->Next()){ |
| 306 pResource->m_bFlag=false; | 308 pResource->m_bFlag=false; |
| 307 } | 309 } |
| 308 CeCosTestSocket sock; | 310 CeCosSocket sock; |
| 309 if(sock.Connect(pszResourceHost,nResourcePort,dTimeout)){ | 311 if(sock.Connect(pszResourceHostPort,dTimeout)){ |
| 310 // Write the message to the socket | 312 // Write the message to the socket |
| 311 int nRequest=0; // read | 313 int nRequest=0; // read |
| 312 if(!sock.sendInteger(nRequest)){ | 314 if(!sock.sendInteger(nRequest)){ |
| 313 ERROR(_T("Failed to write to socket\n")); | 315 ERROR(_T("Failed to write to socket\n")); |
| 314 } else { | 316 } else { |
| 319 String strImage; | 321 String strImage; |
| 320 if(sock.recvString(strImage,_T(""),dTimeout)){ | 322 if(sock.recvString(strImage,_T(""),dTimeout)){ |
| 321 VTRACE(_T("Recv \"%s\"\n"),(LPCTSTR)strImage); | 323 VTRACE(_T("Recv \"%s\"\n"),(LPCTSTR)strImage); |
| 322 CTestResource tmp; | 324 CTestResource tmp; |
| 323 tmp.FromStr(strImage); | 325 tmp.FromStr(strImage); |
| 324 CTestResource *pResource=Lookup(tmp.Host(),tmp.TcpipPort()); | 326 CTestResource *pResource=Lookup(tmp.HostPort()); |
| 325 if(0==pResource){ | 327 if(0==pResource){ |
| 326 pResource=new CTestResource(_T("")); | 328 pResource=new CTestResource(_T(""),_T("")); |
| 327 } | 329 } |
| 328 pResource->FromStr(strImage); | 330 pResource->FromStr(strImage); |
| 329 pResource->m_bFlag=true; | 331 pResource->m_bFlag=true; |
| 330 } else { | 332 } else { |
| 331 rc=false; | 333 rc=false; |
| 346 | 348 |
| 347 LEAVECRITICAL; | 349 LEAVECRITICAL; |
| 348 return rc; | 350 return rc; |
| 349 } | 351 } |
| 350 | 352 |
| 351 void CTestResource::Image(String &str) | 353 bool CTestResource::SaveSocket(LPCTSTR pszResourceHostPort,Duration dTimeout) |
| 352 { | |
| 353 CTestResourceProperties prop(this); | |
| 354 str=prop.MakeCommandString(); | |
| 355 VTRACE(_T("Make command string %s\n"),(LPCTSTR)str); | |
| 356 } | |
| 357 | |
| 358 bool CTestResource::FromStr(LPCTSTR pszImage) | |
| 359 { | |
| 360 CTestResourceProperties prop(this); | |
| 361 prop.LoadFromCommandString(pszImage); | |
| 362 VTRACE(_T("From command string %s\n"),pszImage); | |
| 363 return true; | |
| 364 } | |
| 365 | |
| 366 void CTestResource::Chain() | |
| 367 { | |
| 368 ENTERCRITICAL; | |
| 369 nCount++; | |
| 370 m_pNextInstance=pFirstInstance; | |
| 371 if(m_pNextInstance){ | |
| 372 m_pNextInstance->m_pPrevInstance=this; | |
| 373 } | |
| 374 m_pPrevInstance=0; | |
| 375 pFirstInstance=this; | |
| 376 LEAVECRITICAL; | |
| 377 } | |
| 378 | |
| 379 bool CTestResource::Matches (const CeCosTest::ExecutionParameters &e,bool bIgnoreLocking) const | |
| 380 { | |
| 381 return (bIgnoreLocking||(!m_bLocked)) && (0==_tcsicmp(e.Target(),m_Target)); | |
| 382 }; | |
| 383 | |
| 384 bool CTestResource::SaveSocket(LPCTSTR pszResourceServer,int nResourcePort,Duration dTimeout) | |
| 385 { | 354 { |
| 386 bool rc=true; | 355 bool rc=true; |
| 387 ENTERCRITICAL; | 356 ENTERCRITICAL; |
| 388 CeCosTestSocket sock(pszResourceServer,nResourcePort, dTimeout); | 357 CeCosSocket sock(pszResourceHostPort, dTimeout); |
| 389 if(sock.Ok()){ | 358 if(sock.Ok()){ |
| 390 // Write the message to the socket | 359 // Write the message to the socket |
| 391 int nRequest=1; //write | 360 int nRequest=1; //write |
| 392 if(!sock.sendInteger(nRequest, _T(""),dTimeout)){ | 361 if(!sock.sendInteger(nRequest, _T(""),dTimeout)){ |
| 393 ERROR(_T("Failed to write to socket\n")); | 362 ERROR(_T("Failed to write to socket\n")); |
| 399 nResources++; | 368 nResources++; |
| 400 } | 369 } |
| 401 if(sock.sendInteger(nResources,_T("resource count"),dTimeout)){ | 370 if(sock.sendInteger(nResources,_T("resource count"),dTimeout)){ |
| 402 for(pResource=CTestResource::First();pResource;pResource=pResource->Next()){ | 371 for(pResource=CTestResource::First();pResource;pResource=pResource->Next()){ |
| 403 String strImage; | 372 String strImage; |
| 404 pResource->Image(strImage); | 373 CTestResourceProperties prop(pResource); |
| 374 strImage=prop.MakeCommandString(); | |
| 405 TRACE(_T("Send \"%s\"\n"),(LPCTSTR)strImage); | 375 TRACE(_T("Send \"%s\"\n"),(LPCTSTR)strImage); |
| 406 if(!sock.sendString (strImage, _T("reply"),dTimeout)){ | 376 if(!sock.sendString (strImage, _T("reply"),dTimeout)){ |
| 407 rc=false; | 377 rc=false; |
| 408 break; | 378 break; |
| 409 } | 379 } |
| 417 } | 387 } |
| 418 LEAVECRITICAL; | 388 LEAVECRITICAL; |
| 419 return rc; | 389 return rc; |
| 420 } | 390 } |
| 421 | 391 |
| 392 /* | |
| 393 void CTestResource::Image(String &str) | |
| 394 { | |
| 395 CTestResourceProperties prop(this); | |
| 396 str=prop.MakeCommandString(); | |
| 397 VTRACE(_T("Make command string %s\n"),(LPCTSTR)str); | |
| 398 } | |
| 399 */ | |
| 400 | |
| 401 bool CTestResource::FromStr(LPCTSTR pszImage) | |
| 402 { | |
| 403 CTestResourceProperties prop(this); | |
| 404 prop.LoadFromCommandString(pszImage); | |
| 405 VTRACE(_T("From command string %s\n"),pszImage); | |
| 406 return true; | |
| 407 } | |
| 408 | |
| 409 void CTestResource::Chain() | |
| 410 { | |
| 411 ENTERCRITICAL; | |
| 412 nCount++; | |
| 413 m_pNextInstance=pFirstInstance; | |
| 414 if(m_pNextInstance){ | |
| 415 m_pNextInstance->m_pPrevInstance=this; | |
| 416 } | |
| 417 m_pPrevInstance=0; | |
| 418 pFirstInstance=this; | |
| 419 LEAVECRITICAL; | |
| 420 } | |
| 421 | |
| 422 bool CTestResource::Matches (const CeCosTest::ExecutionParameters &e,bool bIgnoreLocking) const | |
| 423 { | |
| 424 return (bIgnoreLocking||(!m_bLocked)) && (0==_tcsicmp(e.PlatformName(),m_Target)); | |
| 425 }; | |
| 426 | |
| 422 CeCosTest::ServerStatus CTestResource::Query() | 427 CeCosTest::ServerStatus CTestResource::Query() |
| 423 { | 428 { |
| 424 CeCosTest::ExecutionParameters e(CeCosTest::ExecutionParameters::QUERY,m_Target); | 429 CeCosTest::ExecutionParameters e(CeCosTest::ExecutionParameters::QUERY,m_Target); |
| 425 CeCosTestSocket *pSock=0; | 430 CeCosSocket *pSock=0; |
| 426 CeCosTest::ServerStatus s=CeCosTest::Connect(m_strHost,m_nPort,pSock,e,m_strInfo); | 431 CeCosTest::ServerStatus s=CeCosTest::Connect(HostPort(),pSock,e,m_strInfo); |
| 427 delete pSock; | 432 delete pSock; |
| 428 return s; | 433 return s; |
| 429 } | 434 } |
| 430 | 435 |
| 431 int CTestResource::Count(const CeCosTest::ExecutionParameters &e) | 436 int CTestResource::Count(const CeCosTest::ExecutionParameters &e) |
| 470 LEAVECRITICAL; | 475 LEAVECRITICAL; |
| 471 } | 476 } |
| 472 return p; | 477 return p; |
| 473 } | 478 } |
| 474 | 479 |
| 475 String CTestResource::Output() const | 480 const String CTestResource::Image() const |
| 476 { | 481 { |
| 477 String str; | 482 String str; |
| 478 str.Format( | 483 str.Format(_T("%10s %20s %8s"),(LPCTSTR)HostPort(),(LPCTSTR)Target(),(LPCTSTR)Serial()); |
| 479 _T("%10s:%d %20s %8s"), | |
| 480 Host(), | |
| 481 TcpipPort(), | |
| 482 Target(), | |
| 483 Serial()); | |
| 484 if(HasReset()){ | |
| 485 str+=_T(" Reset:"); | |
| 486 str+=m_strReset; | |
| 487 } | |
| 488 if(IsLocked()){ | 484 if(IsLocked()){ |
| 489 str+=_T(" [RL]"); | 485 str+=_T(" [RL]"); |
| 490 } | 486 } |
| 491 return str; | 487 return str; |
| 492 } | 488 } |
| 493 | 489 |
| 494 bool CTestResource::Matches(LPCTSTR pszHost, int nPort, const CeCosTest::ExecutionParameters &e) | 490 bool CTestResource::Matches(LPCTSTR pszHostPort, const CeCosTest::ExecutionParameters &e) |
| 495 { | 491 { |
| 496 bool rc=false; | 492 bool rc=false; |
| 497 ENTERCRITICAL; | 493 ENTERCRITICAL; |
| 498 if(LoadSocket()){ | 494 if(Load()){ |
| 499 CTestResource *pResource=Lookup(pszHost,nPort); | 495 CTestResource *pResource=Lookup(pszHostPort); |
| 500 if(pResource){ | 496 if(pResource){ |
| 501 rc=pResource->Matches(e); | 497 rc=pResource->Matches(e); |
| 502 } | 498 } |
| 503 } | 499 } |
| 504 LEAVECRITICAL; | 500 LEAVECRITICAL; |
| 523 } | 519 } |
| 524 | 520 |
| 525 | 521 |
| 526 CResetAttributes::ResetResult CTestResource::RemoteReset(LogFunc *pfnLog, void *pfnLogparam) | 522 CResetAttributes::ResetResult CTestResource::RemoteReset(LogFunc *pfnLog, void *pfnLogparam) |
| 527 { | 523 { |
| 524 String strHost; | |
| 525 int nPort; | |
| 526 CeCosSocket::ParseHostPort(HostPort(),strHost,nPort); | |
| 528 String strCmd; | 527 String strCmd; |
| 529 strCmd.Format(_T("rsh %s x10reset %s\n"),Host(),ResetString()); | 528 strCmd.Format(_T("rsh %s x10reset %s\n"),(LPCTSTR)strHost,ResetString()); |
| 530 pfnLog(pfnLogparam,strCmd); | 529 pfnLog(pfnLogparam,strCmd); |
| 531 | 530 |
| 532 #ifdef _WIN32 | |
| 533 // because this can be used from GUI tools | |
| 534 CSubprocess sp; | 531 CSubprocess sp; |
| 535 sp.Run(pfnLog,pfnLogparam,strCmd); | 532 sp.Run(pfnLog,pfnLogparam,strCmd); |
| 536 #else // UNIX | |
| 537 FILE *f=POPEN(strCmd,"rt"); | |
| 538 if(f){ | |
| 539 char buf[80]; | |
| 540 while(fgets(buf,sizeof buf,f)){ | |
| 541 pfnLog(pfnLogparam,buf); | |
| 542 } | |
| 543 PCLOSE(f); | |
| 544 } else { | |
| 545 String strMsg; | |
| 546 strMsg.Format(_T("Failed to execute '%s'\n"),(LPCTSTR)strCmd); | |
| 547 pfnLog(pfnLogparam,strMsg); | |
| 548 } | |
| 549 #endif | |
| 550 return CResetAttributes::RESET_OK; // FIXME | 533 return CResetAttributes::RESET_OK; // FIXME |
| 551 } | 534 } |
| 552 | 535 |
| 536 String CTestResource::FileName() const | |
| 537 { | |
| 538 String strHost; | |
| 539 int nPort; | |
| 540 CeCosSocket::ParseHostPort(HostPort(),strHost,nPort); | |
| 541 return String::SFormat(_T("%s-%d"),(LPCTSTR)strHost,nPort); | |
| 542 } | |
| 543 |
