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