Mercurial > flash_v2
comparison host/tools/ecostest/common/TestResource.h @ 76:435cced73e2f ecos-v1_3_1-release
eCos v1.3.1 merged from eCos master repository on 2000-03-27-23:22:51-BST
| author | jlarmour |
|---|---|
| date | Tue, 28 Mar 2000 14:10:45 +0000 |
| parents | |
| children | 6736c52df507 |
comparison
equal
deleted
inserted
replaced
| 75:41bf073c0c32 | 76:435cced73e2f |
|---|---|
| 1 //####COPYRIGHTBEGIN#### | |
| 2 // | |
| 3 // ---------------------------------------------------------------------------- | |
| 4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. | |
| 5 // | |
| 6 // This program is part of the eCos host tools. | |
| 7 // | |
| 8 // This program is free software; you can redistribute it and/or modify it | |
| 9 // under the terms of the GNU General Public License as published by the Free | |
| 10 // Software Foundation; either version 2 of the License, or (at your option) | |
| 11 // any later version. | |
| 12 // | |
| 13 // This program is distributed in the hope that it will be useful, but WITHOUT | |
| 14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 15 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
| 16 // more details. | |
| 17 // | |
| 18 // You should have received a copy of the GNU General Public License along with | |
| 19 // this program; if not, write to the Free Software Foundation, Inc., | |
| 20 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
| 21 // | |
| 22 // ---------------------------------------------------------------------------- | |
| 23 // | |
| 24 //####COPYRIGHTEND#### | |
| 25 //================================================================= | |
| 26 // | |
| 27 // TestResource.h | |
| 28 // | |
| 29 // Test resource class | |
| 30 // | |
| 31 //================================================================= | |
| 32 //================================================================= | |
| 33 //#####DESCRIPTIONBEGIN#### | |
| 34 // | |
| 35 // Author(s): sdf | |
| 36 // Contributors: sdf | |
| 37 // Date: 1999-04-01 | |
| 38 // Description: This class abstracts test resources for use in the testing infrastructure | |
| 39 // Usage: | |
| 40 // | |
| 41 //####DESCRIPTIONEND#### | |
| 42 | |
| 43 #ifndef _TESTRESOURCE_H | |
| 44 #define _TESTRESOURCE_H | |
| 45 #include "eCosStd.h" | |
| 46 #include "eCosTest.h" | |
| 47 #include "eCosTestSerial.h" | |
| 48 #include "Properties.h" | |
| 49 #include "ResetAttributes.h" | |
| 50 | |
| 51 // This class is used to manipulate test resources. A test resource is the means to execute | |
| 52 // a test (a test agent running on a tcp/ip port) | |
| 53 class CTestResource { | |
| 54 public: | |
| 55 | |
| 56 class CTestResourceProperties : public CProperties { | |
| 57 public: | |
| 58 CTestResourceProperties(CTestResource *pResource,LPCTSTR psz=0,void *key=0); | |
| 59 virtual ~CTestResourceProperties(){} | |
| 60 void Add(LPCTSTR pszName,String &str,LPCTSTR pszDefault=_T("")) {CProperties::Add(pszName,(void *)&str,GetFn,PutFn,pszDefault);} | |
| 61 protected: | |
| 62 static LPCTSTR CALLBACK GetFn (void *pObj) { return (LPCTSTR)*(String *)pObj; } | |
| 63 static void CALLBACK PutFn (void *pObj,LPCTSTR psz) { *(String *)pObj=psz; } | |
| 64 }; | |
| 65 friend class CTestResourceProperties; | |
| 66 | |
| 67 // ctors/dtors | |
| 68 CTestResource( | |
| 69 LPCTSTR target, | |
| 70 // Physical port characteristics. If pszPort is null, simulator run is meant (in which case nBaud is ignored) | |
| 71 LPCTSTR pszPort=0, int nBaud=0, | |
| 72 // Associated reset characteristics: pszPort may be a remote server (host:port) or a local port | |
| 73 LPCTSTR pszResetString=_T("") | |
| 74 ); | |
| 75 virtual ~CTestResource(); | |
| 76 | |
| 77 bool Use(); | |
| 78 | |
| 79 CResetAttributes::ResetResult RemoteReset(LogFunc *pfnLog, void *pfnLogparam=0); | |
| 80 String Output() const; | |
| 81 | |
| 82 static void UnlockResources(LPCTSTR pszFile,int nLine); | |
| 83 static void LockResources (LPCTSTR pszFile,int nLine); | |
| 84 void Image (String &str); | |
| 85 static bool SaveSocket (Duration dTimeout=10*1000) { return SaveSocket(strResourceHost,nResourcePort,dTimeout); } | |
| 86 static bool LoadSocket (Duration dTimeout=10*1000) { return LoadSocket(strResourceHost,nResourcePort,dTimeout); } | |
| 87 | |
| 88 CeCosTest::ServerStatus Query(); | |
| 89 bool Unlock(); | |
| 90 bool Lock (); | |
| 91 static CTestResource *First() { return pFirstInstance; } | |
| 92 CTestResource *Next() const { return m_pNextInstance; } | |
| 93 static CTestResource * Lookup(LPCTSTR pszHost, int nPort); | |
| 94 static unsigned int ResourceCount() { return nCount; } | |
| 95 static void DeleteAllInstances(); | |
| 96 bool IsLocked() const { return m_bLocked; } | |
| 97 static bool LoadFile (LPCTSTR psz,void *key=0); // Load information from the registry or a file | |
| 98 static bool SaveFile (LPCTSTR psz,void *key=0); // Save information to the registry or a file | |
| 99 | |
| 100 void SetInfo (LPCTSTR pszInfo) { m_strInfo=pszInfo; } | |
| 101 LPCTSTR Info() const { return m_strInfo; } | |
| 102 | |
| 103 // Attributes | |
| 104 LPCTSTR Host() const { return m_strHost; } | |
| 105 int TcpipPort() const { return m_nPort; } | |
| 106 LPCTSTR Serial() const { return m_strPort; } | |
| 107 | |
| 108 LPCTSTR Target() const { return m_Target; } | |
| 109 | |
| 110 bool HasReset() const { return m_strReset.GetLength()>0; } | |
| 111 | |
| 112 int Baud() const { return m_nBaud; } // Baud rate | |
| 113 | |
| 114 void SetHostPort(LPCTSTR pszHost,int nPort) { m_strHost=pszHost;m_nPort=nPort; } | |
| 115 | |
| 116 void SetTarget (LPCTSTR target) { m_Target=target; } | |
| 117 void SetDownload(LPCTSTR pszDownloadPort,int nBaud) { m_strPort=pszDownloadPort; m_nBaud=nBaud; } | |
| 118 void SetReset (LPCTSTR pszReset) { m_strReset=pszReset; } | |
| 119 void SetUser (LPCTSTR pszUser,LPCTSTR pszEmail) {m_strUser=pszUser; m_strEmail=pszEmail; } | |
| 120 void SetReason (LPCTSTR pszReason) {m_strReason=pszReason; } | |
| 121 void SetBoardID(LPCTSTR pszBoardID){m_strBoardID=pszBoardID; } | |
| 122 void SetDate (LPCTSTR pszDate) {m_strDate =pszDate; } | |
| 123 | |
| 124 LPCTSTR Email () { return m_strEmail; } | |
| 125 LPCTSTR User () { return m_strUser; } | |
| 126 LPCTSTR Reason () { return m_strReason; } | |
| 127 LPCTSTR BoardID() { return m_strBoardID; } | |
| 128 LPCTSTR Date () { return m_strDate; } | |
| 129 | |
| 130 // Scheduling functions | |
| 131 // Get the array of resources capable of executing "e" | |
| 132 // nCount gives the number of entries in ar on input | |
| 133 // result is the number of entries required in ar (may exceed nCount, but this case does no damage) | |
| 134 static unsigned int GetMatchCount (const CeCosTest::ExecutionParameters &e,bool bIgnoreLocking=false); | |
| 135 static bool GetMatches (const CeCosTest::ExecutionParameters &e,StringArray &arstr,bool bIgnoreLocking=false); // as before, but callee allocates. Deallocate using delete []. | |
| 136 | |
| 137 static void SetResourceServer (LPCTSTR pszHost,int nPort){ strResourceHost=pszHost;nResourcePort=nPort; } | |
| 138 | |
| 139 static CTestResource *GetResource(const CeCosTest::ExecutionParameters &e); | |
| 140 void Release() { | |
| 141 //TRACE(_T("Release %s\n"),Serial1()); | |
| 142 m_bInUse=false; | |
| 143 } | |
| 144 | |
| 145 | |
| 146 static int Count (const CeCosTest::ExecutionParameters &e); | |
| 147 | |
| 148 // Reset the hardware attached to this port. Output goes to pfnLog | |
| 149 CResetAttributes::ResetResult Reset(LogFunc *pfnLog=0, void *pfnLogparam=0); | |
| 150 CResetAttributes::ResetResult Reset(String &str); // as above, output to string | |
| 151 | |
| 152 static bool Matches(LPCTSTR pszHost, int nPort, const CeCosTest::ExecutionParameters &e); | |
| 153 bool FromStr(LPCTSTR pszImage); | |
| 154 LPCTSTR ResetString() const { return m_strReset; } | |
| 155 protected: | |
| 156 CTestResource():m_pNextInstance(0),m_pPrevInstance(0){} // not chained or initialized - for internal use only | |
| 157 String m_strReason,m_strUser,m_strEmail,m_strBoardID, m_strDate; | |
| 158 | |
| 159 String m_strReset; | |
| 160 | |
| 161 static void CALLBACK StringLogFunc (void *pParam,LPCTSTR psz); | |
| 162 | |
| 163 static bool LoadSocket (LPCTSTR pszHost,int nPort,Duration dTimeout=10*1000); | |
| 164 static bool SaveSocket (LPCTSTR pszHost,int nPort,Duration dTimeout=10*1000); | |
| 165 static LPCTSTR szFormat; | |
| 166 | |
| 167 void Chain(); | |
| 168 | |
| 169 unsigned static int nCount; | |
| 170 static String strResourceHost; | |
| 171 static int nResourcePort; | |
| 172 static CTestResource *pFirstInstance; | |
| 173 | |
| 174 bool Matches (const CeCosTest::ExecutionParameters &e,bool bIgnoreLocking=false) const; | |
| 175 | |
| 176 | |
| 177 String m_strInfo; | |
| 178 bool m_bFlag; | |
| 179 bool m_bInUse; | |
| 180 int m_nBaud; | |
| 181 String m_strPort; | |
| 182 | |
| 183 bool m_bLocked; | |
| 184 | |
| 185 String m_Target; | |
| 186 String m_strHost; | |
| 187 int m_nPort; | |
| 188 CTestResource *m_pNextInstance; | |
| 189 CTestResource *m_pPrevInstance; | |
| 190 }; | |
| 191 #endif |
