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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [tools/] [ecostest/] [common/] [eCosTest.h] - Blame information for rev 825

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

Line No. Rev Author Line
1 786 skrzyp
// ####ECOSHOSTGPLCOPYRIGHTBEGIN####                                        
2
// -------------------------------------------                              
3
// This file is part of the eCos host tools.                                
4
// Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.            
5
//
6
// This program is free software; you can redistribute it and/or modify     
7
// it under the terms of the GNU General Public License as published by     
8
// the Free Software Foundation; either version 2 or (at your option) any   
9
// later version.                                                           
10
//
11
// This program is distributed in the hope that it will be useful, but      
12
// WITHOUT ANY WARRANTY; without even the implied warranty of               
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        
14
// General Public License for more details.                                 
15
//
16
// You should have received a copy of the GNU General Public License        
17
// along with this program; if not, write to the                            
18
// Free Software Foundation, Inc., 51 Franklin Street,                      
19
// Fifth Floor, Boston, MA  02110-1301, USA.                                
20
// -------------------------------------------                              
21
// ####ECOSHOSTGPLCOPYRIGHTEND####                                          
22
//=================================================================
23
//
24
//        eCosTest.h
25
//
26
//        run test header
27
//
28
//=================================================================
29
//=================================================================
30
//#####DESCRIPTIONBEGIN####
31
//
32
// Author(s):     sdf
33
// Contributors:  sdf
34
// Date:          1999-04-01
35
// Description:   Run one or more tests
36
// Usage:
37
//
38
//####DESCRIPTIONEND####
39
 
40
#ifndef _ECOSTEST_H
41
#define _ECOSTEST_H
42
 
43
//=================================================================
44
// This class represents a single eCos test [executable].
45
// It includes member functions to run the test and to manage related system resources.
46
//=================================================================
47
 
48
#include "Collections.h"
49
#include "eCosStd.h"
50
#include "eCosTestPlatform.h"
51
#include "eCosTestUtils.h"
52
#include "ResetAttributes.h"
53
 
54
class CSubprocess;
55
class CTestResource;
56
class CeCosSocket;
57
 
58
class CeCosTest{
59
public:
60
 
61
  static LPCTSTR pszFormat;
62
 
63
  ///////////////////////////////////////////////////////////////////////////
64
  // Representation of an elapsed time (units of milliseconds)
65
  enum {NOTIMEOUT=0x7fffffff}; // No timeout specified
66
 
67
  ///////////////////////////////////////////////////////////////////////////
68
  // ctors, dtors and their friends
69
  class ExecutionParameters;
70
  CeCosTest(const ExecutionParameters &e, LPCTSTR  const pszExecutable, LPCTSTR  const pszTitle=0);
71
  virtual ~CeCosTest();
72
  // Count of number of instances of this class:
73
  static int InstanceCount;
74
  // Delete all heap instances of this class (*must* be allocated on heap)
75
  static void DeleteAllInstances ();
76
  // Simply wait for instances to die a natural death
77
  static bool WaitForAllInstances (int nPoll=1000,Duration nTimeout=NOTIMEOUT);
78
  // Tap them on the shoulder (does not wait)
79
  static void CancelAllInstances ();
80
  ///////////////////////////////////////////////////////////////////////////
81
 
82
  ///////////////////////////////////////////////////////////////////////////
83
  // Class used to represent execution parameters (to be passed with request to execute a test)
84
  ///////////////////////////////////////////////////////////////////////////
85
  class ExecutionParameters {
86
  public:
87
 
88
    enum RequestType { RUN, QUERY, LOCK, UNLOCK, STOP, RequestTypeMax};
89
    static RequestType RequestTypeValue(LPCTSTR );
90
    static const String Image(RequestType r) { return (r>=0 && r<=RequestTypeMax)?String(arRequestImage[r]):String::SFormat(_T("Unknown(%d)"),r); }
91
 
92
    Duration    ActiveTimeout()   const { return m_nActiveTimeout; }
93
    Duration    DownloadTimeout() const { return m_nDownloadTimeout; }
94
 
95
    const CeCosTestPlatform *Platform() const { return CeCosTestPlatform::Get(m_Target); }
96
    LPCTSTR PlatformName() const { return Platform()?Platform()->Name():_T("UNKNOWN"); }
97
 
98
    RequestType Request() const { return m_Request;}
99
    void SetActiveTimeout   (Duration t){m_nActiveTimeout=t;}
100
    void SetDownloadTimeout (Duration t){m_nDownloadTimeout=t;}
101
 
102
    ExecutionParameters (
103
      RequestType r=CeCosTest::ExecutionParameters::RUN,
104
      LPCTSTR  Target=_T(""),
105
      Duration    nActiveTimeout=NOTIMEOUT,
106
      Duration    nDownloadTimeout=NOTIMEOUT);
107
    bool FromStr(LPCTSTR psz);
108
 
109
    String Image() const;
110
    virtual ~ExecutionParameters(){}
111
    bool m_bUseFilter;
112
  protected:
113
    static LPCTSTR  arRequestImage [1+RequestTypeMax];
114
    String m_Target;
115
    Duration m_nActiveTimeout,m_nDownloadTimeout;
116
    RequestType m_Request;
117
    int  m_nUnused1;
118
    int  m_nUnused2;
119
    int  m_nUnused3;
120
    bool m_bUnused2;
121
    bool m_bUnused3;
122
  };
123
  ///////////////////////////////////////////////////////////////////////////
124
 
125
  ///////////////////////////////////////////////////////////////////////////
126
  // Result status stuff.
127
  // Order is important - SetStatus can only change status in left-to-right direction
128
  void AnalyzeOutput();
129
  enum StatusType {NotStarted, NoResult, Inapplicable, Pass, DownloadTimeOut, TimeOut, Cancelled, Fail,
130
    AssertFail, StatusTypeMax};
131
  static StatusType StatusTypeValue (LPCTSTR  const pszStr);
132
  static const String Image(StatusType s) { return (s>=0 && s<StatusTypeMax)?String(arResultImage[s]):String::SFormat(_T("Unknown(%d)"),s); }
133
  ///////////////////////////////////////////////////////////////////////////
134
 
135
  ///////////////////////////////////////////////////////////////////////////
136
  // Attributes
137
  LPCTSTR  const      Executable()             const { return m_strExecutable;}            // Executable name
138
 
139
  StatusType          Status()                 const { return m_Status; }                  // Test status
140
 
141
  Duration            Download()               const { return m_nDownloadTime; }           // Download time
142
  Duration            Total()                  const { return m_nTotalTime; }              // Total
143
  Duration            MaxInactive()            const { return m_nMaxInactiveTime; }        // Max. inactive
144
 
145
  LPCTSTR  const  Output()                     const { return m_strOutput; }               // Output generated by a test run [for report purposes]
146
  //const CTestResource * const Port()           const { return m_pResource; }               // Resource used for a test run [for report purposes]
147
 
148
  const String ResultString (bool bIncludeOutput=true)             const;
149
  ///////////////////////////////////////////////////////////////////////////
150
 
151
  ///////////////////////////////////////////////////////////////////////////
152
  // Running a test:
153
 
154
  // Run a test locally:
155
  bool RunLocal ();
156
 
157
  // Run a test remotely: 
158
  // If pszRemoteHostPort is given, it sends the test for execution on the given host:post.
159
  // Otherwise, a suitable host:port is determined from the test resource information.
160
  bool RunRemote (LPCTSTR  const pszRemoteHostPort);
161
  ///////////////////////////////////////////////////////////////////////////
162
 
163
  ///////////////////////////////////////////////////////////////////////////
164
  // Resource functions
165
 
166
  // Run as a server on given TCP/IP port
167
  static bool RunAgent(int nTcpPort);
168
 
169
  bool InteractiveInferior(LPCTSTR pszHostPort,TCHAR **argv);
170
  void SetTimeouts (Duration dActive=NOTIMEOUT,Duration dDownload=NOTIMEOUT/*,Duration dElapsed=15*60*1000*/);
171
  void SetExecutable (LPCTSTR pszExecutable);
172
  static bool Value (
173
    LPCTSTR pszStr,
174
    struct tm &t,
175
    StatusType &status,
176
    String &target,
177
    String &strExecutionHostPort,
178
    String &strExecutableTail,
179
    String &strTitle,
180
    int &nFileSize,
181
    Duration &nTotalTime,
182
    Duration &nMaxInactiveTime,
183
    Duration &nDownloadTime,
184
    Duration &nDownloadTimeout,
185
    Duration &nActiveTimeout,
186
    int &nDownloadedSize);
187
 
188
  enum ServerStatus {SERVER_BUSY, SERVER_READY, SERVER_CANT_RUN, CONNECTION_FAILED, SERVER_LOCKED, ServerStatusMax};
189
  static LPCTSTR  const Image(ServerStatus s) { return arServerStatusImage[MIN(s,ServerStatusMax)]; }
190
  static ServerStatus ServerStatusValue(LPCTSTR psz);
191
 
192
  // Force the result to change.  Generally you can only set the result left-to-right in the order of the enumeration literals
193
  void ForceResult(StatusType s) { m_Status=s; }
194
 
195
  // Get size information (generally by running *gdb-size)
196
  bool GetSizes();
197
 
198
  // Connect to a test server
199
  static ServerStatus Connect (LPCTSTR pszHostPort, CeCosSocket *&pSock, const ExecutionParameters &e,String &strInfo,Duration dTimeout=10*1000);
200
 
201
  // Log some output.  The accumulated output can be retrieved using Output()
202
  void Log (LPCTSTR  const pszFormat,...);
203
  void LogString (LPCTSTR psz);
204
 
205
protected:
206
        int m_nOutputLen;
207
 
208
  void Cancel (); // Stop the run
209
 
210
  // Connect to m_strExecutionHostPort
211
  void ConnectForExecution ();
212
 
213
  // Callback used when EXEC output is used to create host-side processes
214
  static void CALLBACK AppendFunc(void *pParam,LPCTSTR psz) { ((CeCosTest*)pParam)->Log(_T("%%%% %s"),psz);}
215
 
216
        void GetInferiorCommands (StringArray &arstrInferiorCmds);
217
  CSubprocess *m_pspPipe;
218
  PtrArray m_arpExecsp;
219
 
220
  // Extract a directive (such as "EXEC:") from the test output.  The index passed keeps track of the last such
221
  // directive extracted such that successive calls march through the output, returning a different one each time.
222
        bool GetDirective (LPCTSTR pszDirective, String &str,int &nIndex);
223
 
224
  // Keep track of directives in the gdb output
225
  int m_nLastGdbInst;     // GDB
226
  int m_nLastExecInst;    // EXEC
227
  int m_nLastTimeoutInst; // TIMEOUT
228
  int m_nLastPipeInst;    // PIPE   
229
 
230
  // Commands to be sent to gdb, or other inferior process
231
  StringArray m_arstrInferiorCmds;
232
  // Last command sent
233
        unsigned int m_nCmdIndex;
234
 
235
  // Inferior process output comes through here
236
  static void CALLBACK SInferiorOutputFunc(void *pParam,LPCTSTR psz) { ((CeCosTest *)pParam)->InferiorOutputFunc(psz); }
237
  void InferiorOutputFunc(LPCTSTR psz);
238
 
239
  // Has a timeout occurred?  Returns false if so.
240
  static bool CALLBACK SCheckForTimeout(void *pParam) { return ((CeCosTest *)pParam)->CheckForTimeout(); }
241
 
242
  // Read target ready indicator from server
243
  bool GetTargetReady(String &strHostPort);
244
 
245
  // This may be set to force the socket-to-serial connection to terminate
246
  bool m_bStopConnectSocketToSerial;
247
 
248
  // Convert a path to one understandable by Cygwin
249
  static String CygPath (LPCTSTR pszPath);
250
 
251
  // Are we at a prompt?
252
  bool AtPrompt();
253
 
254
  // To limit calls to ps, under UNIX.  This prevents the acquisition of cpu time consuming the whole machine :-).
255
  mutable Time m_tInferiorCpuTime;
256
  mutable Time m_tPrevSample;
257
  Time InferiorTime() const;
258
 
259
  unsigned int m_nStrippedSize;
260
 
261
  // Path to use to execute subprocesses
262
  String m_strPath;
263
 
264
  // Size of executable
265
  unsigned int m_nFileSize;
266
 
267
  // host:port we are connecting to
268
  String m_strExecutionHostPort;
269
 
270
  ///////////////////////////////////////////////////////////////////////////
271
  // Stuff to manage running gdb (or some other inferior process)
272
  bool CheckForTimeout();                     // Check for a timeout - set status and return false if it happens
273
  bool m_bDownloading;                        // Are we currently downloading executable?
274
  bool InferiorProcessAlive ();                    // Is gdb still alive and kicking?
275
  Time m_tBase;                               // Base used for measurement of timeouts
276
  Time m_tBase0;                              // Base used for measurement of timeouts
277
  Time m_tWallClock0;                         // When the test was actually started
278
 
279
  ///////////////////////////////////////////////////////////////////////////
280
  // Close the socket used by the current class instance
281
  void CloseSocket ();
282
 
283
  bool send(const void * const pData,unsigned int nLength,LPCTSTR  const pszMsg=_T(""),Duration dTimeout=10*1000);
284
  bool recv(const void *pData,unsigned int nLength,LPCTSTR  const pszMsg=_T(""),Duration dTimeout=10*1000);
285
 
286
  bool sendResult(Duration dTimeout=10*1000);
287
  bool recvResult(Duration dTimeout=10*1000);
288
 
289
  ///////////////////////////////////////////////////////////////////////////
290
 
291
  ///////////////////////////////////////////////////////////////////////////
292
  CeCosSocket *m_pSock;
293
 
294
  ExecutionParameters m_ep;
295
 
296
  // Chaining to allow *AllInstances functions to work:
297
  static CeCosTest * pFirstInstance;
298
  CeCosTest * m_pPrevInstance;
299
  CeCosTest * m_pNextInstance;
300
 
301
  void RunInferior (LPCTSTR pszCmdline);
302
 
303
  bool OutputContains(LPCTSTR psz) const { return 0!=_tcsstr(m_strOutput,psz); }
304
 
305
  static void CALLBACK SAcceptThreadFunc (void *pParam) {((CeCosTest *)pParam)->AcceptThreadFunc(); }
306
  void AcceptThreadFunc();
307
 
308
  static void CALLBACK SConnectSocketToSerialThreadFunc(void *pParam) { ((CeCosTest *)pParam)->ConnectSocketToSerialThreadFunc(); }
309
  void ConnectSocketToSerialThreadFunc();
310
 
311
  String m_strExecutable;
312
  String m_strTitle;
313
 
314
  void SetStatus (StatusType status);
315
  StatusType m_Status;
316
 
317
  Duration  m_nDownloadTime;
318
  Duration  m_nTotalTime;
319
  Duration  m_nMaxInactiveTime;
320
 
321
  CTestResource *m_pResource;
322
  CSubprocess *m_psp;
323
 
324
  String m_strOutput; // the output of the test run goes here
325
 
326
  static LPCTSTR  const arResultImage[1+StatusTypeMax];
327
  static LPCTSTR  const arServerStatusImage[1+ServerStatusMax];
328
  bool m_bConnectSocketToSerialThreadDone;
329
  static void CALLBACK ResetLogFunc(void *pParam, LPCTSTR psz);
330
 
331
  // These are used by RunAgent and its friends for setting up the RDI connection
332
  int m_nAuxPort;
333
  int m_nAuxListenSock;
334
 
335
 
336
}; // class CeCosTest
337
 
338
 
339
 
340
#endif

powered by: WebSVN 2.1.0

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