OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [tools/] [src/] [tools/] [ecostest/] [common/] [TestResource.h] - Blame information for rev 438

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 26 unneback
//####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
 
46
#include "Collections.h"
47
#include "eCosStd.h"
48
#include "eCosTest.h"
49
#include "eCosSerial.h"
50
#include "Properties.h"
51
#include "ResetAttributes.h"
52
 
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)
55
class CTestResource {
56
public:
57
 
58
  // ctors/dtors
59
  CTestResource(
60
    LPCTSTR pszHostPort,  // Where the resource "lives" - i.e. the host and TCP/IP port for the server
61
    LPCTSTR target,
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("")
66
    );
67
  // Not chained or fully initialized
68
  CTestResource():m_nBaud(0),m_bLocked(false),m_pNextInstance(0),m_pPrevInstance(0){}
69
  virtual ~CTestResource();
70
 
71
  bool Use(); // Mark this resource as "in use"
72
 
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;
76
 
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); }
80
 
81
  CeCosTest::ServerStatus Query();
82
 
83
  // [Resource] locking:
84
  bool Unlock();
85
  bool Lock ();
86
  bool IsLocked() const { return m_bLocked; }
87
 
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
95
 
96
#ifdef _WIN32
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
99
#endif
100
 
101
  void SetInfo (LPCTSTR pszInfo) { m_strInfo=pszInfo; }
102
  LPCTSTR  Info() const { return m_strInfo; }
103
 
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; }
109
 
110
  // Serial (comms) port:
111
  LPCTSTR Serial() const { return m_strPort; }
112
 
113
  LPCTSTR Target() const { return m_Target; }
114
 
115
  // Is there an associated reset string?
116
  bool HasReset() const { return !m_strReset.empty(); }
117
 
118
  // Baud rate:
119
  int Baud() const { return m_nBaud; }
120
 
121
  void SetHostPort(LPCTSTR pszHostPort) { CeCosSocket::ParseHostPort(pszHostPort,m_strHost,m_nPort); }
122
 
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; }
130
 
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; }
136
 
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 [].
143
 
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()); }
147
 
148
  static CTestResource *GetResource(const CeCosTest::ExecutionParameters &e);
149
  void Release() {
150
    //VTRACE(_T("Release %s\n"),Serial1());
151
    m_bInUse=false;
152
  }
153
 
154
  bool InUse() const { return m_bInUse; }
155
  static int Count (const CeCosTest::ExecutionParameters &e);
156
 
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
160
 
161
  static bool Matches(LPCTSTR pszHostPort, const CeCosTest::ExecutionParameters &e);
162
  bool FromStr(LPCTSTR pszImage);
163
  LPCTSTR ResetString() const { return m_strReset; }
164
 
165
  class CTestResourceProperties : public CProperties {
166
  public:
167
    CTestResourceProperties(CTestResource *pResource);
168
    virtual ~CTestResourceProperties(){}
169
  protected:
170
  };
171
 
172
protected:
173
 
174
  friend class CTestResourceProperties;
175
 
176
  String FileName() const;
177
  String m_strReason,m_strUser,m_strEmail,m_strBoardID, m_strDate;
178
 
179
  String m_strReset;
180
 
181
  static void CALLBACK StringLogFunc (void *pParam,LPCTSTR psz);
182
 
183
  static bool LoadSocket (LPCTSTR pszHostPort,Duration dTimeout=10*1000);
184
  static bool SaveSocket (LPCTSTR pszHostPort,Duration dTimeout=10*1000);
185
  static LPCTSTR szFormat;
186
 
187
  void Chain();
188
 
189
  unsigned static int nCount;
190
  static String strResourceHostPort;
191
  static CTestResource *pFirstInstance;
192
 
193
  bool Matches  (const CeCosTest::ExecutionParameters &e,bool bIgnoreLocking=false) const;
194
 
195
 
196
  String m_strInfo;
197
  bool m_bFlag;
198
  bool m_bInUse;
199
  int  m_nBaud;
200
  String m_strPort;
201
 
202
  bool m_bLocked;
203
 
204
  String m_Target;
205
  String m_strHost;
206
  int m_nPort;
207
  CTestResource *m_pNextInstance;
208
  CTestResource *m_pPrevInstance;
209
};
210
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.