0
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
/**
|
|
21 |
@file ScriptEngine.h
|
|
22 |
*/
|
|
23 |
|
|
24 |
#if !(defined __SCRIPT_ENGINE_H__)
|
|
25 |
#define __SCRIPT_ENGINE_H__
|
|
26 |
|
|
27 |
#include <e32base.h>
|
|
28 |
#include <f32file.h>
|
|
29 |
#include "TestExecuteStepBase.h"
|
|
30 |
#include <e32cons.h>
|
|
31 |
#if !(defined TEF_LITE)
|
|
32 |
#include <apgcli.h>
|
|
33 |
#include <w32std.h>
|
|
34 |
#endif
|
|
35 |
#include <iniparser.h>
|
|
36 |
#include <tefshareddata.h>
|
|
37 |
#include <testshareddata.h>
|
|
38 |
#include "TEFConst.h"
|
|
39 |
#include "BlockItems.h"
|
|
40 |
|
|
41 |
#define SUB_PROC_TYPE RProcess
|
|
42 |
|
|
43 |
/**
|
|
44 |
* Define flogger based class that can also be used to log to console
|
|
45 |
*/
|
|
46 |
class RConsoleLogger
|
|
47 |
{
|
|
48 |
public:
|
|
49 |
RConsoleLogger(CConsoleBase& aConsole) : iConsole(aConsole) {};
|
|
50 |
inline CConsoleBase& Console() const;
|
|
51 |
private:
|
|
52 |
CConsoleBase& iConsole;
|
|
53 |
};
|
|
54 |
|
|
55 |
class CActiveBase;
|
|
56 |
class MChildCompletion
|
|
57 |
{
|
|
58 |
public:
|
|
59 |
virtual void ChildCompletion(TInt aError) = 0;
|
|
60 |
};
|
|
61 |
|
|
62 |
class RScriptTestServ : public RTestServ
|
|
63 |
{
|
|
64 |
friend class RScriptTestSession;
|
|
65 |
public:
|
|
66 |
inline RScriptTestServ();
|
|
67 |
TInt Connect(const TDesC& aServerName,TBool aSharedData = EFalse);
|
|
68 |
inline TBool SharedData() const;
|
|
69 |
inline TInt SessionCount() const;
|
|
70 |
private:
|
|
71 |
inline void AddSession();
|
|
72 |
inline void RemoveSession();
|
|
73 |
private:
|
|
74 |
TBool iSharedData;
|
|
75 |
TBool iSessionCount;
|
|
76 |
};
|
|
77 |
|
|
78 |
class RScriptTestSession : public RTestSession
|
|
79 |
{
|
|
80 |
public:
|
|
81 |
TInt Open(RScriptTestServ& aServ, const TBool aIsTestStep, const TDesC& aStepName = KNull );
|
|
82 |
inline void Close();
|
|
83 |
protected:
|
|
84 |
RScriptTestServ* iServ;
|
|
85 |
private:
|
|
86 |
};
|
|
87 |
|
|
88 |
class CActiveBase : public CActive
|
|
89 |
{
|
|
90 |
public:
|
|
91 |
inline void Kick();
|
|
92 |
inline virtual ~CActiveBase();
|
|
93 |
protected:
|
|
94 |
inline void Prime();
|
|
95 |
inline void Complete(TInt aErr);
|
|
96 |
inline CActiveBase();
|
|
97 |
};
|
|
98 |
|
|
99 |
class CScriptActive : public CActiveBase, public MChildCompletion
|
|
100 |
{
|
|
101 |
public:
|
|
102 |
inline virtual ~CScriptActive();
|
|
103 |
inline virtual void ChildCompletion(TInt aErr);
|
|
104 |
protected:
|
|
105 |
inline CScriptActive();
|
|
106 |
};
|
|
107 |
|
|
108 |
|
|
109 |
class MTaskCompletion
|
|
110 |
{
|
|
111 |
public:
|
|
112 |
virtual void TaskCompletion(TInt aErr, const TDesC& aPanicString, TInt aScriptLineNumber,const TDesC& aCommand,TBool aTaskCanComplete,TTEFItemArray* aItemArray=NULL) = 0;
|
|
113 |
};
|
|
114 |
|
|
115 |
class TRange
|
|
116 |
{
|
|
117 |
public :
|
|
118 |
enum EState
|
|
119 |
{
|
|
120 |
EStateNotUsed,
|
|
121 |
EStateInUse,
|
|
122 |
EStateUsed,
|
|
123 |
};
|
|
124 |
|
|
125 |
TRange(TPtrC aStartTestCase,TPtrC aEndTestCase ):
|
|
126 |
iStartTestCase (aStartTestCase),
|
|
127 |
iEndTestCase (aEndTestCase ),
|
|
128 |
iState (EStateNotUsed)
|
|
129 |
{};
|
|
130 |
|
|
131 |
//some utility methods
|
|
132 |
static TBool CompareTRangeEnd(const TRange& aRng1, const TRange& aRng2) ;
|
|
133 |
static TBool CompareTRangeStartCase(const TRange& aRng1, const TRange& aRng2) ;
|
|
134 |
static TInt CompareTRangeStartOrder(const TRange& aRng1, const TRange& aRng2) ;
|
|
135 |
|
|
136 |
public :
|
|
137 |
TPtrC iStartTestCase ;
|
|
138 |
TPtrC iEndTestCase ;
|
|
139 |
EState iState ;
|
|
140 |
|
|
141 |
};
|
|
142 |
|
|
143 |
enum ESelectiveTesting
|
|
144 |
{
|
|
145 |
iInclusive =0 ,
|
|
146 |
iExclusive
|
|
147 |
};
|
|
148 |
|
|
149 |
class TSelectiveTestingOptions
|
|
150 |
{
|
|
151 |
public :
|
|
152 |
TSelectiveTestingOptions(RArray<TRange>& aSelectiveCaseRange,ESelectiveTesting& aSelectiveTestingType )
|
|
153 |
:iSelectiveCaseRange(aSelectiveCaseRange),
|
|
154 |
iSelectiveTestingType(aSelectiveTestingType)
|
|
155 |
{};
|
|
156 |
|
|
157 |
//some utility methods...
|
|
158 |
static TBool CompareTPtrC(const TPtrC& aPtrC1, const TPtrC& aPtrC2);
|
|
159 |
static TInt CompareTPtrCOrder(const TPtrC& aPtrC1, const TPtrC& aPtrC2) ;
|
|
160 |
|
|
161 |
TSelectiveTestingOptions::~TSelectiveTestingOptions()
|
|
162 |
{iSelectiveCaseRange.Close();};
|
|
163 |
|
|
164 |
|
|
165 |
public :
|
|
166 |
RArray<TRange> iSelectiveCaseRange;
|
|
167 |
ESelectiveTesting iSelectiveTestingType;
|
|
168 |
};
|
|
169 |
|
|
170 |
class CScriptMaster : public CScriptActive
|
|
171 |
{
|
|
172 |
public:
|
|
173 |
CScriptMaster(const TDesC& aScriptFilePath, CTestExecuteLogger& aLogger, RConsoleLogger& aConsoleLogger, const TDriveName& aSysDrive, const TDriveName& aTestSysDrive, TSelectiveTestingOptions* aSelTestingOptions = NULL );
|
|
174 |
virtual ~CScriptMaster();
|
|
175 |
void RunL();
|
|
176 |
inline void DoCancel();
|
|
177 |
private:
|
|
178 |
inline CTestExecuteLogger& Logger() const;
|
|
179 |
inline RConsoleLogger& ConsoleLogger() const;
|
|
180 |
private:
|
|
181 |
enum TState{EInit,ERunning};
|
|
182 |
TState iState;
|
|
183 |
TPtrC iScriptFilePath;
|
|
184 |
CTestExecuteLogger& iLogger;
|
|
185 |
RConsoleLogger& iConsoleLogger;
|
|
186 |
TBool iLoop;
|
|
187 |
TBool iStartLooping;
|
|
188 |
TDriveName iDefaultSysDrive;
|
|
189 |
TDriveName iTestSysDrive;
|
|
190 |
TSelectiveTestingOptions* iSelTestingOptions;
|
|
191 |
};
|
|
192 |
|
|
193 |
class CSyncControl;
|
|
194 |
class CScriptControl : public CScriptActive, public MTaskCompletion
|
|
195 |
{
|
|
196 |
public:
|
|
197 |
CScriptControl(MChildCompletion& aCompletion,const TDesC& aScriptFilePath,CTestExecuteLogger& aLogger,RConsoleLogger& aConsoleLogger,TBool aStartLooping,TBool aLoop, const TDriveName& aSysDrive, const TDriveName& aTestSysDrive, TSelectiveTestingOptions* aSelTestingOptions = NULL);
|
|
198 |
virtual ~CScriptControl();
|
|
199 |
virtual void TaskCompletion(TInt aErr, const TDesC& aPanicString, TInt aScriptLineNumber, const TDesC& aCommand, TBool aTaskCanComplete, TTEFItemArray* aItemArray = NULL);
|
|
200 |
void RunL();
|
|
201 |
inline void DoCancel();
|
|
202 |
private:
|
|
203 |
void PrintFromScriptLine() const;
|
|
204 |
void LogTestCaseMarkerL();
|
|
205 |
TVerdict HasTestCasePassedL(TPtrC TestCaseMarker);
|
|
206 |
void PrintCurrentScriptLine() const;
|
|
207 |
void SetPrefix();
|
|
208 |
TBool GetNextScriptLine(TPtrC& aScriptLine);
|
|
209 |
TBool GetLoopScriptLine(TPtrC& aScriptLine);
|
|
210 |
void CreateScriptDataFromScriptFileL();
|
|
211 |
void CreateServerFromScriptLineL();
|
|
212 |
TBool GetServerIndexFromScriptLine(TInt& aIndex);
|
|
213 |
void RunUtilsFromScriptLineL() const;
|
|
214 |
void GetScriptFileFromScriptLine();
|
|
215 |
void RunCedFromScriptLineL();
|
|
216 |
void StartTimerFromScriptLine();
|
|
217 |
void LogResult(TVerdict aResult, const TDesC& aPanicString, TInt aScriptLineNumber, const TDesC& aCommand);
|
|
218 |
inline CTestExecuteLogger& Logger() const;
|
|
219 |
inline RConsoleLogger& ConsoleLogger() const;
|
|
220 |
void PrintScriptEngineError(TInt aErr) const;
|
|
221 |
TBool CheckValidScriptLine() const;
|
|
222 |
TBool CheckCommentedCommands() const;
|
|
223 |
void FindValueL(CIniData* aConfigData, TPtrC aConfigSection, TPtrC aSharedData, TInt& aSharedDataNum);
|
|
224 |
void FindValueL(CIniData* aConfigData, TPtrC aConfigSection, TPtrC aSharedData, TPtrC& aSharedDataName);
|
|
225 |
void CreateSharedObjectsFromScriptLineL();
|
|
226 |
void ParseTestBlockL( TTEFItemArray& aItemArray );
|
|
227 |
void MakeAbsoluteFilePathsL(TPtrC16& aScriptLineString);
|
|
228 |
void ConvertRelativeToAbsoluteL(TDes& aCommandString);
|
|
229 |
TInt RunError(TInt aError);
|
|
230 |
void ExpandVariables(TDes& aCommandString);
|
|
231 |
TBool ProceedTestCase() ;
|
|
232 |
void ProcessEndCase();
|
|
233 |
// Fix defect 118337
|
|
234 |
TBool ParseTestBlockHeader();
|
|
235 |
// End defect 118337
|
|
236 |
private:
|
|
237 |
enum TState{
|
|
238 |
EInit,
|
|
239 |
ERunning,
|
|
240 |
EClosing,
|
|
241 |
ERunCedPending,
|
|
242 |
ERunCed,
|
|
243 |
ERunScriptPending,
|
|
244 |
ERunScript,
|
|
245 |
EDelayPending,
|
|
246 |
EPausePending,
|
|
247 |
EPause,
|
|
248 |
EEndTestCasePending,
|
|
249 |
ERunEndTestCase,
|
|
250 |
ERunStartSyncTestCase,
|
|
251 |
EPrefixPending,
|
|
252 |
ERunPrefix,
|
|
253 |
EDelay,
|
|
254 |
EIdling,
|
|
255 |
EWaitCompletions,
|
|
256 |
ETestCaseIgnore
|
|
257 |
};
|
|
258 |
TPtrC iScriptFile;
|
|
259 |
RTimer iTimer;
|
|
260 |
TState iState;
|
|
261 |
HBufC* iScriptData;
|
|
262 |
TLex iScriptLex;
|
|
263 |
MChildCompletion& iParent;
|
|
264 |
TPtrC iCurrentScriptLine;
|
|
265 |
TBuf<KMaxTestExecuteCommandLength> iScriptLinePrefix;
|
|
266 |
TBuf<KMaxTestExecuteCommandLength> iPrefixedCurrentScriptLine;
|
|
267 |
TBool iConcurrent;
|
|
268 |
TBool iCanComplete;
|
|
269 |
TBool iBreakOnError;
|
|
270 |
TInt iAsyncTasksOutstanding;
|
|
271 |
RPointerArray<RScriptTestServ> iServers;
|
|
272 |
TInt iCurrentScriptLineNumber;
|
|
273 |
CTestExecuteLogger& iLogger;
|
|
274 |
RConsoleLogger& iConsoleLogger;
|
|
275 |
TPtrC iChildScriptFile;
|
|
276 |
RFs iFS;
|
|
277 |
RFile iResultFile;
|
|
278 |
TBool iScriptLinePrefixSet;
|
|
279 |
TLex iTempStoreLoop;
|
|
280 |
TLex iStoreLoop;
|
|
281 |
TBool iStartLooping;
|
|
282 |
TInt iLoopCounter;
|
|
283 |
TBool iCheckVar;
|
|
284 |
TInt iRepeatParam;
|
|
285 |
TBool iLoop;
|
|
286 |
CTEFSharedData<CTestSharedData>* iSharedDataArray[KTEFMaxSharedArraySize];
|
|
287 |
TInt iSharedDataNum;
|
|
288 |
TBool iIsSharedData;
|
|
289 |
CSyncControl* iSyncControl;
|
|
290 |
// Fix defect 119337. Change static TBool value to TInt value
|
|
291 |
// This value shows the nested count when call RUN_SCRIPT in loop
|
|
292 |
static TInt iNestedNumRunScriptInLoop;
|
|
293 |
// End defect 119337
|
|
294 |
TBuf<KMaxTestExecuteCommandLength> iTestCaseID;
|
|
295 |
TBuf<KTEFMaxScriptLineLength> iAlteredScriptLine;
|
|
296 |
TDriveName iDefaultSysDrive;
|
|
297 |
TDriveName iTestSysDrive;
|
|
298 |
TSelectiveTestingOptions* iSelTestingOptions;
|
|
299 |
TBool iSelectOne;
|
|
300 |
TInt iRangeRefCounter;
|
|
301 |
TInt iTestCaseCounter;
|
|
302 |
TPtrC iTestCaseIDToIgnore ;
|
|
303 |
public:
|
|
304 |
static TInt commentedCommandsCount;
|
|
305 |
static TInt iRunScriptFailCount;
|
|
306 |
};
|
|
307 |
|
|
308 |
class MTaskTimerCompletion
|
|
309 |
{
|
|
310 |
public:
|
|
311 |
virtual void TaskTimerCompletion() =0;
|
|
312 |
};
|
|
313 |
|
|
314 |
class CTaskTimer : public CTimer
|
|
315 |
{
|
|
316 |
public:
|
|
317 |
static CTaskTimer* NewL(MTaskTimerCompletion& aCompletion);
|
|
318 |
~CTaskTimer();
|
|
319 |
void RunL();
|
|
320 |
void Timeout(TInt aSeconds);
|
|
321 |
private:
|
|
322 |
CTaskTimer(MTaskTimerCompletion& aCompletion);
|
|
323 |
void RunTimeout();
|
|
324 |
inline void ConstructL();
|
|
325 |
private:
|
|
326 |
MTaskTimerCompletion& iParent;
|
|
327 |
TInt iTimesAfter;
|
|
328 |
TInt iSecondsRemaining;
|
|
329 |
};
|
|
330 |
|
|
331 |
const TInt KDefaultTimeoutSeconds = 120;
|
|
332 |
const TInt KDefaultDelayMilliseconds = 5000;
|
|
333 |
const TInt KTEFStatusDelay = 2000;
|
|
334 |
|
|
335 |
|
|
336 |
class CTaskControlBase : public CActiveBase , public MTaskTimerCompletion
|
|
337 |
{
|
|
338 |
public:
|
|
339 |
inline void SetTaskComplete(TBool aTaskCanComplete);
|
|
340 |
protected:
|
|
341 |
CTaskControlBase(const TDesC& aCommand, MTaskCompletion& aCompletion,TInt aScriptLineNumber, CTestExecuteLogger& aLogger);
|
|
342 |
virtual ~CTaskControlBase();
|
|
343 |
inline const CTestExecuteLogger& Logger() const;
|
|
344 |
private:
|
|
345 |
protected:
|
|
346 |
TBuf<KTEFMaxScriptLineLength> iCommandLine;
|
|
347 |
MTaskCompletion& iParent;
|
|
348 |
TInt iScriptLineNumber;
|
|
349 |
CTestExecuteLogger& iLogger;
|
|
350 |
CTaskTimer* iTaskTimer;
|
|
351 |
TInt iTaskTimeout;
|
|
352 |
TBuf<KTEFMaxTaskExitCategory> iTaskExitCategory;
|
|
353 |
TBool iTaskCanComplete;
|
|
354 |
private:
|
|
355 |
};
|
|
356 |
|
|
357 |
class CClientControl : public CTaskControlBase
|
|
358 |
{
|
|
359 |
public:
|
|
360 |
CClientControl( RScriptTestServ& aTestServ,
|
|
361 |
const TDesC& aStepCommand,
|
|
362 |
MTaskCompletion& aCompletion,
|
|
363 |
TInt aScriptLineNumber,
|
|
364 |
CTestExecuteLogger& aLogger,
|
|
365 |
TInt aLoopIndex,
|
|
366 |
const TDesC& aTestCaseID,
|
|
367 |
TPtrC& aScriptFilePath,
|
|
368 |
const TDriveName& aSysDrive,
|
|
369 |
const TDriveName& aTestSysDrive);
|
|
370 |
|
|
371 |
static CClientControl* NewL( RScriptTestServ& aTestServ,
|
|
372 |
const TDesC& aCommand,
|
|
373 |
MTaskCompletion& aCompletion,
|
|
374 |
TInt aScriptLineNumber,
|
|
375 |
CTestExecuteLogger& aLogger,
|
|
376 |
TInt aLoopIndex,
|
|
377 |
const TDesC& aTestCaseID,
|
|
378 |
const TDesC& aEndBlockCommand,
|
|
379 |
TPtrC& aScriptFilePath,
|
|
380 |
const TTEFItemArray& aBlockArray,
|
|
381 |
const TDriveName& aSysDrive,
|
|
382 |
const TDriveName& aTestSysDrive);
|
|
383 |
|
|
384 |
virtual void TaskTimerCompletion();
|
|
385 |
virtual ~CClientControl();
|
|
386 |
void RunL();
|
|
387 |
inline void DoCancel();
|
|
388 |
private:
|
|
389 |
void GetStepParamsFromStepCommand();
|
|
390 |
void ConstructL( const TDesC& aEndBlockCommand, const TTEFItemArray& aBlockArray );
|
|
391 |
TTEFItemArray* CreateBlockArrayLC();
|
|
392 |
TInt RunError(TInt aError);
|
|
393 |
void TestStepComplete();
|
|
394 |
|
|
395 |
private:
|
|
396 |
enum TState
|
|
397 |
{
|
|
398 |
EInit = 0,
|
|
399 |
ERunning,
|
|
400 |
EServerRetry
|
|
401 |
};
|
|
402 |
|
|
403 |
TPtrC iEndBlockCommand;
|
|
404 |
TState iState;
|
|
405 |
RScriptTestServ& iServ;
|
|
406 |
TBuf<KMaxTestExecuteCommandLength> iStepArgs;
|
|
407 |
TPtrC iStepName;
|
|
408 |
RScriptTestSession iSession;
|
|
409 |
RTimer iTimer;
|
|
410 |
TInt iRetryCount;
|
|
411 |
TPtrC iTaskHeapSize;
|
|
412 |
TBool iOOMRequestSet;
|
|
413 |
TBuf<KMaxTestExecuteCommandLength> iSetUpParamValue;
|
|
414 |
TInt iLoopIndex;
|
|
415 |
TBuf<KMaxTestExecuteCommandLength> iTestCaseID;
|
|
416 |
HBufC8* iBlockArrayPkg;
|
|
417 |
TPtr8 iBlockArrayPtr;
|
|
418 |
TPtrC iScriptFilePath;
|
|
419 |
TDriveName iDefaultSysDrive;
|
|
420 |
TDriveName iTestSysDrive;
|
|
421 |
};
|
|
422 |
|
|
423 |
class CProgramControl : public CTaskControlBase
|
|
424 |
{
|
|
425 |
public:
|
|
426 |
virtual void TaskTimerCompletion();
|
|
427 |
CProgramControl(const TDesC& aCommand,MTaskCompletion& aCompletion,TInt aScriptLineNumber, CTestExecuteLogger& aLogger, TBool aWSProgRun=EFalse);
|
|
428 |
~CProgramControl();
|
|
429 |
void RunL();
|
|
430 |
inline void DoCancel();
|
|
431 |
private:
|
|
432 |
void GetProgramArgsFromCommand();
|
|
433 |
void RunProgramL();
|
|
434 |
#if !defined TEF_LITE
|
|
435 |
bool IsWindowServerAvailable(void) const;
|
|
436 |
#endif
|
|
437 |
private:
|
|
438 |
SUB_PROC_TYPE iProgram;
|
|
439 |
TPtrC iProgramArgs;
|
|
440 |
TBool iProgRenamed;
|
|
441 |
enum TState{EInit,ERunning};
|
|
442 |
TState iState;
|
|
443 |
TBool iWSProgRun;
|
|
444 |
#if !defined TEF_LITE
|
|
445 |
RThread iProgramWS; // Specific for EKA2 with a Window Server available
|
|
446 |
RApaLsSession iApaLsSess;
|
|
447 |
RWsSession iWs;
|
|
448 |
#endif
|
|
449 |
};
|
|
450 |
|
|
451 |
#if !defined TEF_LITE
|
|
452 |
inline bool CProgramControl::IsWindowServerAvailable(void) const
|
|
453 |
{
|
|
454 |
return (0 != iWs.WsHandle());
|
|
455 |
}
|
|
456 |
#endif
|
|
457 |
class CSyncControl : public CBase
|
|
458 |
{
|
|
459 |
public:
|
|
460 |
CSyncControl();
|
|
461 |
~CSyncControl();
|
|
462 |
|
|
463 |
static CSyncControl* NewL();
|
|
464 |
static CSyncControl* NewLC();
|
|
465 |
|
|
466 |
void SetResultL( TVerdict aError );
|
|
467 |
TBool TestCaseContinueL();
|
|
468 |
|
|
469 |
private:
|
|
470 |
void ConstructL();
|
|
471 |
|
|
472 |
CTEFSharedData<CTestSharedData>* iSharedTEFStatus;
|
|
473 |
CTEFSharedData<CTestSharedData>* iSharedTEFResult;
|
|
474 |
};
|
|
475 |
|
|
476 |
#include "ScriptEngine.inl"
|
|
477 |
#endif
|