1 //####COPYRIGHTBEGIN####
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
6 // This program is part of the eCos host tools.
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)
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
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.
22 // ----------------------------------------------------------------------------
24 //####COPYRIGHTEND####
25 //=================================================================
29 // Test resource class
31 //=================================================================
32 //=================================================================
33 //#####DESCRIPTIONBEGIN####
38 // Description: This class abstracts test resources for use in the testing infrastructure
41 //####DESCRIPTIONEND####
43 #ifndef _TESTRESOURCE_H
44 #define _TESTRESOURCE_H
46 #include "Collections.h"
49 #include "eCosSerial.h"
50 #include "Properties.h"
51 #include "ResetAttributes.h"
53 // This class is used to manipulate test resources. A test resource is the means to execute
54 // a test (usually an eCosTestServer running on a tcp/ip port)
60 LPCTSTR pszHostPort, // Where the resource "lives" - i.e. the host and TCP/IP port for the server
62 // Physical port characteristics. If pszPort is null, simulator run is meant (in which case nBaud is ignored)
63 LPCTSTR pszPort=0, int nBaud=0,
64 // Associated reset characteristics: pszPort may be a remote server (host:port) or a local port
65 LPCTSTR pszResetString=_T("")
67 // Not chained or fully initialized
68 CTestResource():m_nBaud(0),m_bLocked(false),m_pNextInstance(0),m_pPrevInstance(0){}
69 virtual ~CTestResource();
71 bool Use(); // Mark this resource as "in use"
73 // This causes the reset to be performed (via rsh, on the machine
74 CResetAttributes::ResetResult RemoteReset(LogFunc *pfnLog, void *pfnLogparam=0);
75 const String Image() const;
77 // Receive details from the socket
78 static bool Load(Duration dTimeout=10*1000) { return LoadSocket(strResourceHostPort,dTimeout); }
79 static bool Save(Duration dTimeout=10*1000) { return SaveSocket(strResourceHostPort,dTimeout); }
81 CeCosTest::ServerStatus Query();
83 // [Resource] locking:
86 bool IsLocked() const { return m_bLocked; }
88 static CTestResource *First() { return pFirstInstance; }
89 CTestResource *Next() const { return m_pNextInstance; }
90 static CTestResource * Lookup(LPCTSTR pszHostPort);
91 static unsigned int ResourceCount() { return nCount; }
92 static void DeleteAllInstances();
93 static bool LoadFromDirectory (LPCTSTR psz); // Load information from a set of files in given directory
94 static bool SaveToDirectory (LPCTSTR psz); // Save information, likewise
97 static bool SaveToRegistry(HKEY key,LPCTSTR pszKey); // Save information to the registry
98 static bool LoadFromRegistry(HKEY key,LPCTSTR pszKey);// Load information from the registry
101 void SetInfo (LPCTSTR pszInfo) { m_strInfo=pszInfo; }
102 LPCTSTR Info() const { return m_strInfo; }
104 // Host and TCP/IP port:
105 String HostPort() const { return CeCosSocket::HostPort(m_strHost,m_nPort); }
106 // Same information, but separately:
107 String Host() const { return m_strHost; }
108 int TcpIPPort() const { return m_nPort; }
110 // Serial (comms) port:
111 LPCTSTR Serial() const { return m_strPort; }
113 LPCTSTR Target() const { return m_Target; }
115 // Is there an associated reset string?
116 bool HasReset() const { return !m_strReset.empty(); }
119 int Baud() const { return m_nBaud; }
121 void SetHostPort(LPCTSTR pszHostPort) { CeCosSocket::ParseHostPort(pszHostPort,m_strHost,m_nPort); }
123 void SetTarget (LPCTSTR target) { m_Target=target; }
124 void SetDownload(LPCTSTR pszDownloadPort,int nBaud) { m_strPort=pszDownloadPort; m_nBaud=nBaud; }
125 void SetReset (LPCTSTR pszReset) { m_strReset=pszReset; }
126 void SetUser (LPCTSTR pszUser,LPCTSTR pszEmail) {m_strUser=pszUser; m_strEmail=pszEmail; }
127 void SetReason (LPCTSTR pszReason) {m_strReason=pszReason; }
128 void SetBoardID(LPCTSTR pszBoardID){m_strBoardID=pszBoardID; }
129 void SetDate (LPCTSTR pszDate) {m_strDate =pszDate; }
131 LPCTSTR Email () { return m_strEmail; }
132 LPCTSTR User () { return m_strUser; }
133 LPCTSTR Reason () { return m_strReason; }
134 LPCTSTR BoardID() { return m_strBoardID; }
135 LPCTSTR Date () { return m_strDate; }
137 // Scheduling functions
138 // Get the array of resources capable of executing "e"
139 // nCount gives the number of entries in ar on input
140 // result is the number of entries required in ar (may exceed nCount, but this case does no damage)
141 static unsigned int GetMatchCount (const CeCosTest::ExecutionParameters &e,bool bIgnoreLocking=false);
142 static bool GetMatches (const CeCosTest::ExecutionParameters &e,StringArray &arstr,bool bIgnoreLocking=false); // as before, but callee allocates. Deallocate using delete [].
144 static bool SetResourceServer (LPCTSTR pszHostPort) { bool b=CeCosSocket::IsLegalHostPort(pszHostPort);if(b)strResourceHostPort=pszHostPort; return b;}
145 static String GetResourceServer (){ return strResourceHostPort; }
146 static bool ResourceServerSet() { return CeCosSocket::IsLegalHostPort(GetResourceServer()); }
148 static CTestResource *GetResource(const CeCosTest::ExecutionParameters &e);
150 //VTRACE(_T("Release %s\n"),Serial1());
154 bool InUse() const { return m_bInUse; }
155 static int Count (const CeCosTest::ExecutionParameters &e);
157 // Reset the hardware attached to this port. Output goes to pfnLog
158 CResetAttributes::ResetResult Reset(LogFunc *pfnLog=0, void *pfnLogparam=0);
159 CResetAttributes::ResetResult Reset(String &str); // as above, output to string
161 static bool Matches(LPCTSTR pszHostPort, const CeCosTest::ExecutionParameters &e);
162 bool FromStr(LPCTSTR pszImage);
163 LPCTSTR ResetString() const { return m_strReset; }
165 class CTestResourceProperties : public CProperties {
167 CTestResourceProperties(CTestResource *pResource);
168 virtual ~CTestResourceProperties(){}
174 friend class CTestResourceProperties;
176 String FileName() const;
177 String m_strReason,m_strUser,m_strEmail,m_strBoardID, m_strDate;
181 static void CALLBACK StringLogFunc (void *pParam,LPCTSTR psz);
183 static bool LoadSocket (LPCTSTR pszHostPort,Duration dTimeout=10*1000);
184 static bool SaveSocket (LPCTSTR pszHostPort,Duration dTimeout=10*1000);
185 static LPCTSTR szFormat;
189 unsigned static int nCount;
190 static String strResourceHostPort;
191 static CTestResource *pFirstInstance;
193 bool Matches (const CeCosTest::ExecutionParameters &e,bool bIgnoreLocking=false) const;
207 CTestResource *m_pNextInstance;
208 CTestResource *m_pPrevInstance;