|
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of the License "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // f32\runtests\runtests.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32std.h> |
|
19 #include <e32std_private.h> |
|
20 #include <e32def_private.h> |
|
21 #include <e32svr.h> |
|
22 #include <e32ldr.h> |
|
23 #include <hal.h> |
|
24 #include "f32file.h" |
|
25 #include "f32dbg.h" |
|
26 #include "runtests.h" |
|
27 #include <u32hal.h> |
|
28 |
|
29 #define __PANIC(r) Panic(__LINE__,r) |
|
30 |
|
31 //#define _RUN_FOREVER_ |
|
32 //#define _PANIC_ON_FAILURE_ |
|
33 |
|
34 const TInt KDefaultTimeout=1200; // 20 minutes |
|
35 const TInt KBackgroundTimeout=3000000; // 3 seconds |
|
36 const TInt KDestroyTimeout=1000000; // 1 second |
|
37 |
|
38 _LIT(KLitBackslash,"\\"); |
|
39 _LIT(KDebugMessage, "Testing finished, and the system will be panicked"); |
|
40 #ifdef __EPOC32__ |
|
41 _LIT(KLitDefaultTestPath,"Z:\\TEST"); |
|
42 #else |
|
43 _LIT(KLitDefaultTestPath,""); |
|
44 #endif |
|
45 |
|
46 #ifdef _DEBUG |
|
47 _LIT(KBuildType, "UDEB"); |
|
48 #else |
|
49 _LIT(KBuildType, "UREL"); |
|
50 #endif |
|
51 |
|
52 typedef RArray<TUint> RProcIdList; |
|
53 |
|
54 GLDEF_D TPath TheTestPath = KLitDefaultTestPath(); |
|
55 GLDEF_D RFs TheFs; |
|
56 GLDEF_D RLoader TheLoaderSession; |
|
57 GLDEF_D TDesC8* TheTestList; |
|
58 GLDEF_D RTimer TheTimer; |
|
59 GLDEF_D TBuf<256> TheProcessCommand=KNullDesC(); |
|
60 GLDEF_D TInt TheTimeOut = KDefaultTimeout; |
|
61 GLDEF_D TInt TheCurrentProcessList; |
|
62 GLDEF_D RProcIdList ProcLists[2]; |
|
63 GLDEF_D RTimer IdleWaitTimer; |
|
64 GLDEF_D RTimer DestructionTimer; |
|
65 GLDEF_D RProperty CurrTest; |
|
66 TBool ShowTimings = 0; |
|
67 TInt TickPeriod = 15625; |
|
68 TBool CleanUpProcesses = EFalse; |
|
69 |
|
70 #ifdef _ENABLE_BTRACE_ANALYSIS_ |
|
71 |
|
72 // BTrace analysis forward declarations |
|
73 const TInt KDefaultBTraceLevel = 0; |
|
74 TBool BtraceAnalysis = EFalse; |
|
75 TInt BTraceAnalysisLevel; |
|
76 TInt BTraceAnalyseSetup(); |
|
77 void BTraceAnalyseEnd(); |
|
78 void BTraceAnalyse(TInt aAnalysisLevel); |
|
79 |
|
80 #endif //_ENABLE_BTRACE_ANALYSIS_ |
|
81 |
|
82 _LIT(KLitPanicCategory,"RUNTESTS-"); |
|
83 _LIT(KLitLogPreamble,"RUNTESTS: "); |
|
84 |
|
85 void LogMsg(TRefByValue<const TDesC> aFmt,...); |
|
86 |
|
87 void DisableSimulatedFailure() |
|
88 { |
|
89 // Turn off simulated failure mechanisms for all base servers |
|
90 TheFs.SetAllocFailure(KAllocFailureOff); // F32 heap failure |
|
91 TheFs.SetErrorCondition(KErrNone, 0); // F32 other failure |
|
92 TheLoaderSession.DebugFunction(ELoaderDebug_SetHeapFail, 0, 0, 0); // Loader heap failure |
|
93 TheLoaderSession.DebugFunction(ELoaderDebug_SetRFsFail, KErrNone, 0, 0); // Loader RFs failure |
|
94 |
|
95 // make sure kernel heap debug is off |
|
96 __KHEAP_TOTAL_RESET; |
|
97 } |
|
98 |
|
99 GLDEF_C void Panic(TInt aLine, TInt aReason) |
|
100 { |
|
101 TBuf<16> cat=KLitPanicCategory(); |
|
102 cat.AppendNum(aLine); |
|
103 User::Panic(cat,aReason); |
|
104 } |
|
105 |
|
106 TInt CloseAndWait(RHandleBase aH, TRequestStatus *aN = NULL) |
|
107 { |
|
108 TRequestStatus tempS; |
|
109 if(!aN) |
|
110 { |
|
111 // Create a destruction notifier if none was supplied. |
|
112 aH.NotifyDestruction(tempS); |
|
113 aN = &tempS; |
|
114 } |
|
115 if (*aN!=KRequestPending) |
|
116 { |
|
117 User::WaitForRequest(*aN); |
|
118 aH.Close(); |
|
119 return KErrNoMemory; |
|
120 } |
|
121 TRequestStatus t; |
|
122 DestructionTimer.After(t, KDestroyTimeout); |
|
123 aH.Close(); |
|
124 User::WaitForRequest(*aN, t); |
|
125 if (*aN != KRequestPending) |
|
126 { |
|
127 DestructionTimer.Cancel(); |
|
128 User::WaitForRequest(t); |
|
129 return KErrNone; |
|
130 } |
|
131 User::CancelMiscNotifier(*aN); |
|
132 User::WaitForRequest(*aN); |
|
133 return KErrTimedOut; |
|
134 } |
|
135 |
|
136 void CloseWaitAndWarn(RHandleBase aH, TRequestStatus *aN = NULL) |
|
137 { |
|
138 TFullName fn(aH.FullName()); |
|
139 TInt r = CloseAndWait(aH, aN); |
|
140 if (r == KErrNoMemory) |
|
141 LogMsg(_L("WARNING OOM checking destruction of %S"), &fn); |
|
142 else if (r == KErrTimedOut) |
|
143 LogMsg(_L("ERROR Destruction of %S timed out"), &fn); |
|
144 } |
|
145 |
|
146 TInt InitIdleWait() |
|
147 { |
|
148 TInt r = IdleWaitTimer.CreateLocal(); |
|
149 if (r!=KErrNone) |
|
150 return r; |
|
151 return KErrNone; |
|
152 } |
|
153 |
|
154 void WaitForIdle() |
|
155 { |
|
156 TRequestStatus idle_req; |
|
157 TRequestStatus timer_req; |
|
158 IdleWaitTimer.After(timer_req, KBackgroundTimeout); |
|
159 User::NotifyOnIdle(idle_req); |
|
160 User::WaitForRequest(idle_req, timer_req); |
|
161 if (idle_req != KRequestPending) |
|
162 { |
|
163 IdleWaitTimer.Cancel(); |
|
164 User::WaitForRequest(timer_req); |
|
165 } |
|
166 else |
|
167 { |
|
168 User::CancelMiscNotifier(idle_req); |
|
169 User::WaitForRequest(idle_req); |
|
170 LogMsg(_L("WARNING Excessive Background Activity Detected")); |
|
171 } |
|
172 } |
|
173 |
|
174 TBool IntentionallyPersistent(RProcess aProcess) |
|
175 { |
|
176 TInt v; |
|
177 TInt r = RProperty::Get(aProcess.SecureId(), KRuntestsIntentionalPersistenceKey, v); |
|
178 if (r==KErrNone && TUint(v)==KRuntestsIntentionalPersistenceValue) |
|
179 return ETrue; |
|
180 return EFalse; |
|
181 } |
|
182 |
|
183 TInt GetProcessListThread(TAny* a) |
|
184 { |
|
185 RProcIdList& pl = *(RProcIdList*)a; |
|
186 TFindProcess fp(_L("*")); |
|
187 TFullName fn; |
|
188 TInt r = KErrNone; |
|
189 while (r==KErrNone && fp.Next(fn)==KErrNone) |
|
190 { |
|
191 RProcess p; |
|
192 r = p.Open(fp, EOwnerThread); |
|
193 if (r==KErrNone) |
|
194 { |
|
195 TUint id = (TUint)p.Id(); |
|
196 r = pl.Append(id); |
|
197 p.Close(); |
|
198 } |
|
199 } |
|
200 return r; |
|
201 } |
|
202 |
|
203 TInt GetProcessList(RProcIdList& aList) |
|
204 { |
|
205 aList.Reset(); |
|
206 RThread t; |
|
207 TRequestStatus s; |
|
208 TInt r = t.Create(KNullDesC, &GetProcessListThread, 0x1000, NULL, &aList); |
|
209 if (r==KErrNone) |
|
210 { |
|
211 t.Logon(s); |
|
212 t.SetPriority(EPriorityAbsoluteHigh); |
|
213 if (s==KRequestPending) |
|
214 t.Resume(); |
|
215 User::WaitForRequest(s); |
|
216 r=s.Int(); |
|
217 if (t.ExitType()==EExitPending) |
|
218 { |
|
219 t.Kill(0); |
|
220 WaitForIdle(); |
|
221 } |
|
222 else if (t.ExitType()!=EExitKill) |
|
223 { |
|
224 r = -99; |
|
225 } |
|
226 CloseWaitAndWarn(t); |
|
227 } |
|
228 aList.Sort(); |
|
229 return r; |
|
230 } |
|
231 |
|
232 TBool ParseNumber(TLex& aLex, TUint& aNumber, TBool isTime) |
|
233 { |
|
234 TPtrC numberDes = aLex.NextToken(); |
|
235 TInt len = numberDes.Length(); |
|
236 if (len == 0) |
|
237 { |
|
238 return EFalse; |
|
239 } |
|
240 |
|
241 aNumber = 0; |
|
242 TInt magnitude = 1; |
|
243 TChar c = numberDes[len-1]; |
|
244 if (isTime) |
|
245 { |
|
246 switch (c) |
|
247 { |
|
248 case 'h': |
|
249 case 'H': |
|
250 len -= 1; |
|
251 magnitude = 3600; |
|
252 break; |
|
253 |
|
254 case 'm': |
|
255 case 'M': |
|
256 len -= 1; |
|
257 /*FALLTHRU*/ |
|
258 default: |
|
259 magnitude = 60; |
|
260 break; |
|
261 |
|
262 case 's': |
|
263 case 'S': |
|
264 len -= 1; |
|
265 magnitude = 1; |
|
266 break; |
|
267 } |
|
268 } |
|
269 |
|
270 for (TInt i = len-1; i >= 0; --i) |
|
271 { |
|
272 c = numberDes[i]; |
|
273 if (c < '0' || c > '9') |
|
274 __PANIC(KErrArgument); |
|
275 aNumber += ((TInt)c-'0')*magnitude; |
|
276 magnitude *= 10; |
|
277 } |
|
278 |
|
279 return ETrue; |
|
280 } |
|
281 |
|
282 void GetTimeOut(TLex& aLex) |
|
283 // |
|
284 // |
|
285 // |
|
286 { |
|
287 TheTimeOut = KDefaultTimeout; |
|
288 TUint timeOut = 0; |
|
289 if (ParseNumber(aLex, timeOut, ETrue)) |
|
290 { |
|
291 TheTimeOut = timeOut; |
|
292 } |
|
293 } |
|
294 |
|
295 #ifdef _ENABLE_BTRACE_ANALYSIS_ |
|
296 |
|
297 void GetAnalysisLevel(TLex& aLex) |
|
298 { |
|
299 BTraceAnalysisLevel = KDefaultBTraceLevel; |
|
300 TUint level; |
|
301 if (ParseNumber(aLex, level, EFalse)) |
|
302 { |
|
303 BTraceAnalysisLevel = level; |
|
304 } |
|
305 } |
|
306 #endif //_ENABLE_BTRACE_ANALYSIS_ |
|
307 |
|
308 void LogMsg(TRefByValue<const TDesC> aFmt,...) |
|
309 { |
|
310 VA_LIST list; |
|
311 VA_START(list,aFmt); |
|
312 TBuf<0x100> buf=KLitLogPreamble(); |
|
313 buf.AppendFormatList(aFmt,list); |
|
314 RDebug::Print(_L("%S"),&buf); |
|
315 } |
|
316 |
|
317 _LIT(KLitError, "Error "); |
|
318 TBool LogProcess(TUint aId, TBool aInit) |
|
319 { |
|
320 TFullName pn; |
|
321 TFileName fn; |
|
322 RProcess p; |
|
323 TBool killed = EFalse; |
|
324 TInt r = p.Open(TProcessId(aId)); |
|
325 if (r==KErrNone) |
|
326 { |
|
327 if (IntentionallyPersistent(p)) |
|
328 { |
|
329 p.Close(); |
|
330 return killed; |
|
331 } |
|
332 pn = p.FullName(); |
|
333 fn = p.FileName(); |
|
334 if (!aInit && CleanUpProcesses && p.ExitType()==EExitPending) |
|
335 {// p is a left over process so terminate it. |
|
336 killed = ETrue; |
|
337 TRequestStatus status; |
|
338 p.Logon(status); |
|
339 p.Kill(KErrNone); // Kill with KErrNone to suppress extra debug output from kernel. |
|
340 User::WaitForRequest(status); |
|
341 CloseAndWait(p); |
|
342 } |
|
343 else |
|
344 { |
|
345 p.Close(); |
|
346 } |
|
347 } |
|
348 else |
|
349 { |
|
350 pn = KLitError; |
|
351 pn.AppendNum(r); |
|
352 } |
|
353 if (aInit) |
|
354 LogMsg(_L("Running process id=%d: %S (%S)"),aId,&pn,&fn); |
|
355 else |
|
356 { |
|
357 if(killed) |
|
358 LogMsg(_L("ERROR Leftover process was killed id=%d: %S (%S)"),aId,&pn,&fn); |
|
359 else |
|
360 LogMsg(_L("ERROR Leftover process id=%d: %S (%S)"),aId,&pn,&fn); |
|
361 } |
|
362 return killed; |
|
363 } |
|
364 |
|
365 void ListProcesses() |
|
366 { |
|
367 RProcIdList& cur_list = ProcLists[TheCurrentProcessList]; |
|
368 TInt cc = cur_list.Count(); |
|
369 TInt ci; |
|
370 for (ci=0; ci<cc; ++ci) |
|
371 { |
|
372 LogProcess(cur_list[ci], ETrue); |
|
373 } |
|
374 } |
|
375 |
|
376 void CheckProcesses() |
|
377 { |
|
378 RProcIdList& cur_list = ProcLists[TheCurrentProcessList]; |
|
379 RProcIdList& new_list = ProcLists[1-TheCurrentProcessList]; |
|
380 TInt r = GetProcessList(new_list); |
|
381 if (r!=KErrNone) |
|
382 { |
|
383 LogMsg(_L("WARNING Problem getting process list, error %d"),r); |
|
384 return; |
|
385 } |
|
386 |
|
387 TInt cc = cur_list.Count(); |
|
388 TInt nc = new_list.Count(); |
|
389 TInt ci = 0; |
|
390 TInt ni = 0; |
|
391 while (ci<cc || ni<nc) |
|
392 { |
|
393 TUint id1=0; |
|
394 TUint id2=0; |
|
395 if (ci<cc) |
|
396 id1 = cur_list[ci]; |
|
397 if (ni<nc) |
|
398 id2 = new_list[ni]; |
|
399 if (ci==cc) |
|
400 { |
|
401 // extra process has appeared so kill it and output an error message. |
|
402 if (LogProcess(id2, EFalse)) |
|
403 {// Remove from list as we don't want it to be considered as vanished when the next test completes. |
|
404 new_list.Remove(ni); |
|
405 nc--; |
|
406 } |
|
407 else |
|
408 {// Extra process was left running so just move onto the next one. |
|
409 ni++; |
|
410 } |
|
411 } |
|
412 else if (ni<nc && id1==id2) |
|
413 { |
|
414 // process remains |
|
415 ++ci, ++ni; |
|
416 } |
|
417 else |
|
418 { |
|
419 // process has disappeared |
|
420 LogMsg(_L("WARNING Vanished process, id=%d"),id1); |
|
421 ++ci; |
|
422 } |
|
423 } |
|
424 |
|
425 // current list = new list |
|
426 TheCurrentProcessList = 1 - TheCurrentProcessList; |
|
427 |
|
428 // throw away the old list |
|
429 cur_list.Reset(); |
|
430 } |
|
431 |
|
432 _LIT8 (KLitRemark,"REM"); |
|
433 _LIT8 (KLitAtRemark,"@REM"); |
|
434 |
|
435 void ProcessLine(const TDesC8& aLine) |
|
436 { |
|
437 TLex8 lex(aLine); |
|
438 TPtrC8 testname=lex.NextToken(); |
|
439 if (testname.Length()>=2 && testname[0]=='/' && testname[1]=='/') |
|
440 return; |
|
441 // ignore this line if it begins with rem or @rem |
|
442 if (testname.CompareF(KLitRemark) == 0 || testname.CompareF(KLitAtRemark) == 0) |
|
443 return; |
|
444 TFileName testnameU; |
|
445 testnameU.Copy(testname); |
|
446 TFileName fullpathname; |
|
447 if (testnameU.Locate(TChar('\\'))==KErrNotFound) |
|
448 fullpathname=TheTestPath; |
|
449 fullpathname+=testnameU; |
|
450 if (testname.Locate(TChar('.'))==KErrNotFound) |
|
451 fullpathname+=_L(".EXE"); |
|
452 TInt r; |
|
453 |
|
454 RFile file; |
|
455 r=file.Open(TheFs,fullpathname,EFileRead); |
|
456 if (r!=KErrNone) |
|
457 { |
|
458 // Remove path to let loader locate exe |
|
459 fullpathname = fullpathname.Mid(fullpathname.LocateReverse('\\')+1); |
|
460 } |
|
461 else |
|
462 file.Close(); |
|
463 |
|
464 RProcess p; |
|
465 if(TheProcessCommand==KNullDesC) |
|
466 { |
|
467 TheProcessCommand.Copy(lex.Remainder()); |
|
468 r=p.Create(fullpathname, TheProcessCommand); |
|
469 TheProcessCommand=KNullDesC(); |
|
470 } |
|
471 else |
|
472 r=p.Create(fullpathname, TheProcessCommand); |
|
473 if (r!=KErrNone) |
|
474 { |
|
475 LogMsg(_L("Test %S ERROR Could not load file, error %d"),&fullpathname,r); |
|
476 return; |
|
477 } |
|
478 TRequestStatus ds; |
|
479 p.NotifyDestruction(ds); // allocate the destruction notifier early so that it doesn't get flagged as a leak by kernel heap checking in e.g., efile (DEF133800) |
|
480 CurrTest.Set(p.FileName()); |
|
481 User::After(100000); // allow latency measurements to be output |
|
482 p.SetJustInTime(EFalse); // we don't want the automatic test run to be halted by the debugger |
|
483 TRequestStatus ps; |
|
484 p.Rendezvous(ps); |
|
485 TInt time_remain = TheTimeOut; |
|
486 TRequestStatus ts; |
|
487 TUint start = User::TickCount(); |
|
488 p.Resume(); |
|
489 TBool persist = EFalse; |
|
490 TBool timer_running = EFalse; |
|
491 FOREVER |
|
492 { |
|
493 TInt nsec = Min(time_remain, 1800); |
|
494 if (!timer_running) |
|
495 TheTimer.After(ts, nsec*1000000); |
|
496 timer_running = ETrue; |
|
497 User::WaitForRequest(ps,ts); |
|
498 if (ps!=KRequestPending) |
|
499 { |
|
500 if (p.ExitType()==EExitPending) |
|
501 { |
|
502 // rendezvous completed but process not terminated |
|
503 if (!IntentionallyPersistent(p)) |
|
504 { |
|
505 // not persistent - wait for process to terminate |
|
506 p.Logon(ps); |
|
507 continue; |
|
508 } |
|
509 persist = ETrue; |
|
510 } |
|
511 break; |
|
512 } |
|
513 timer_running = EFalse; |
|
514 time_remain -= nsec; |
|
515 if (time_remain==0) |
|
516 { |
|
517 LogMsg(_L("Going to kill test %S: it's taken %u seconds, which is too long"),&fullpathname,TheTimeOut); |
|
518 p.Kill(0); |
|
519 User::WaitForRequest(ps); |
|
520 p.Logon(ps); |
|
521 User::WaitForRequest(ps); |
|
522 |
|
523 CloseWaitAndWarn(p, &ds); |
|
524 RDebug::Print(_L("\n")); |
|
525 LogMsg(_L("Test %S TIMEOUT"),&fullpathname); |
|
526 return; |
|
527 } |
|
528 else |
|
529 { |
|
530 LogMsg(_L("Taken %u seconds so far"),TheTimeOut-time_remain); |
|
531 } |
|
532 } |
|
533 TUint end = User::TickCount(); |
|
534 if(timer_running) |
|
535 { |
|
536 TheTimer.Cancel(); |
|
537 User::WaitForRequest(ts); |
|
538 } |
|
539 |
|
540 #ifdef _ENABLE_BTRACE_ANALYSIS_ |
|
541 // |
|
542 // |
|
543 // |
|
544 if (BtraceAnalysis) |
|
545 {// Analyse BTrace buffer |
|
546 BTraceAnalyse(BTraceAnalysisLevel); |
|
547 } |
|
548 #endif //_ENABLE_BTRACE_ANALYSIS_ |
|
549 |
|
550 TBuf<32> exitCat=p.ExitCategory(); |
|
551 TExitType exitType=p.ExitType(); |
|
552 TInt exitReason=p.ExitReason(); |
|
553 if (persist || (exitType==EExitKill && exitReason==KErrNone)) |
|
554 { |
|
555 TUint time = TUint((TUint64)(end-start)*(TUint64)TickPeriod/(TUint64)1000000); |
|
556 if(ShowTimings) |
|
557 { |
|
558 LogMsg(_L("Test %S OK - Seconds Taken: %u"),&fullpathname, time); |
|
559 } |
|
560 else |
|
561 { |
|
562 LogMsg(_L("Test %S OK"),&fullpathname); |
|
563 } |
|
564 if (persist) |
|
565 { |
|
566 // We do not need this destruction notifier so cancel it. |
|
567 User::CancelMiscNotifier(ds); |
|
568 User::WaitForRequest(ds); |
|
569 |
|
570 p.Close(); |
|
571 } |
|
572 else |
|
573 { |
|
574 CloseWaitAndWarn(p, &ds); |
|
575 } |
|
576 return; |
|
577 } |
|
578 LogMsg(_L("Test %S FAIL - Exit code %d,%d,%S"),&fullpathname,exitType,exitReason,&exitCat); |
|
579 CloseWaitAndWarn(p, &ds); |
|
580 #if defined(_PANIC_ON_FAILURE_) |
|
581 __PANIC(KErrGeneral); |
|
582 #endif |
|
583 } |
|
584 |
|
585 void ProcessTestList() |
|
586 { |
|
587 TUint start = User::TickCount(); |
|
588 |
|
589 TLex8 llex(*TheTestList); |
|
590 while(!llex.Eos()) |
|
591 { |
|
592 llex.SkipSpace(); |
|
593 llex.Mark(); |
|
594 while(!llex.Eos() && llex.Peek()!='\n' && llex.Peek()!='\r') |
|
595 llex.Inc(); |
|
596 TPtrC8 line=llex.MarkedToken(); |
|
597 if (line.Length()!=0) |
|
598 ProcessLine(line); |
|
599 |
|
600 // allow cleanup to complete before starting the next test |
|
601 WaitForIdle(); |
|
602 |
|
603 // make sure simulated failure is off |
|
604 DisableSimulatedFailure(); |
|
605 |
|
606 // check for leftover processes |
|
607 CheckProcesses(); |
|
608 |
|
609 // Reset the demand paging cache to its default size. |
|
610 UserSvr::HalFunction(EHalGroupVM,EVMHalSetCacheSize, 0, 0); |
|
611 } |
|
612 |
|
613 TUint end = User::TickCount(); |
|
614 TUint time = TUint((TUint64)(end-start)*(TUint64)TickPeriod/(TUint64)1000000); |
|
615 LogMsg(_L("Elapsed Seconds: %u"), time); |
|
616 } |
|
617 |
|
618 void Help() |
|
619 { |
|
620 RDebug::Print(_L("Runtests test list [-x where tests are] [-d drive letter to test] [-t timeout] [-p] [-st] [-c]")); |
|
621 RDebug::Print(_L("where -p sets runtests to be system permanent, -st enables timing information,")); |
|
622 RDebug::Print(_L("-c enables left over processes to be cleaned up")); |
|
623 } |
|
624 |
|
625 GLDEF_C TInt E32Main() |
|
626 { |
|
627 HAL::Get(HAL::ESystemTickPeriod, TickPeriod); |
|
628 RThread().SetPriority(EPriorityAbsoluteHigh); |
|
629 TBuf<0x100> cmd; |
|
630 User::CommandLine(cmd); |
|
631 TFileName thisfile=RProcess().FileName(); |
|
632 TLex lex(cmd); |
|
633 TPtrC token=lex.NextToken(); |
|
634 if (token.MatchF(thisfile)==0) |
|
635 { |
|
636 token.Set(lex.NextToken()); |
|
637 } |
|
638 if (token.Length()==0) |
|
639 {// __PANIC(0); |
|
640 Help(); |
|
641 return 0; |
|
642 } |
|
643 TFileName listfilename=token; |
|
644 while (!lex.Eos()) |
|
645 { |
|
646 token.Set(lex.NextToken()); |
|
647 if (token.Length()==0) |
|
648 break; // ignore trailing whitespace |
|
649 else if (token==_L("-x")) |
|
650 { |
|
651 token.Set(lex.NextToken()); |
|
652 TheTestPath = token; |
|
653 } |
|
654 else if (token==_L("-d")) |
|
655 { |
|
656 token.Set(lex.NextToken()); |
|
657 TheProcessCommand = token; |
|
658 } |
|
659 else if (token==_L("-t")) |
|
660 { |
|
661 GetTimeOut(lex); |
|
662 } |
|
663 else if (token==_L("-p")) |
|
664 { |
|
665 User::SetCritical(User::ESystemPermanent); |
|
666 } |
|
667 else if (token==_L("-st")) |
|
668 ShowTimings = 1; |
|
669 |
|
670 #ifdef _ENABLE_BTRACE_ANALYSIS_ |
|
671 else if (token == _L("-a")) |
|
672 { |
|
673 BtraceAnalysis = ETrue; |
|
674 GetAnalysisLevel(lex); |
|
675 TInt r = BTraceAnalyseSetup(); |
|
676 if (r != KErrNone) |
|
677 { |
|
678 RDebug::Print(_L("ERROR - Couldn't open BTrace driver (Code %d)"), r); |
|
679 return 0; |
|
680 } |
|
681 } |
|
682 #endif //_ENABLE_BTRACE_ANALYSIS_ |
|
683 |
|
684 else if (token == _L("-c")) |
|
685 CleanUpProcesses = ETrue; |
|
686 else |
|
687 { |
|
688 RDebug::Print(_L("Unknown option %S"), &token); |
|
689 Help(); |
|
690 return 0; |
|
691 } |
|
692 } |
|
693 |
|
694 RDebug::Print(_L("TPTT= %S \n"), &TheProcessCommand); |
|
695 RDebug::Print(_L("TTL= %S \n"), &listfilename); |
|
696 RDebug::Print(_L("TTP= %S \n"), &TheTestPath); |
|
697 RDebug::Print(_L("TO= %d seconds\n"), TheTimeOut); |
|
698 |
|
699 TInt l=TheTestPath.Length(); |
|
700 if (l > 0 && TheTestPath[l-1]!='\\') |
|
701 TheTestPath+=KLitBackslash; |
|
702 if (listfilename.Locate(TChar('\\'))==KErrNotFound) |
|
703 listfilename.Insert(0,TheTestPath); |
|
704 TInt r=TheFs.Connect(); |
|
705 if (r!=KErrNone) |
|
706 __PANIC(r); |
|
707 r = TheLoaderSession.Connect(); |
|
708 if (r!=KErrNone) |
|
709 __PANIC(r); |
|
710 DisableSimulatedFailure(); |
|
711 r=TheFs.SetSessionPath(_L("Z:\\test\\")); |
|
712 if (r!=KErrNone) |
|
713 __PANIC(r); |
|
714 r=TheTimer.CreateLocal(); |
|
715 if (r!=KErrNone) |
|
716 __PANIC(r); |
|
717 RFile listfile; |
|
718 r=listfile.Open(TheFs,listfilename,EFileRead|EFileShareAny); |
|
719 if (r!=KErrNone) |
|
720 __PANIC(r); |
|
721 TInt listfilesize; |
|
722 r=listfile.Size(listfilesize); |
|
723 if (r!=KErrNone) |
|
724 __PANIC(r); |
|
725 HBufC8* pL=HBufC8::New(listfilesize); |
|
726 if (!pL) |
|
727 __PANIC(KErrNoMemory); |
|
728 TPtr8 ptr=pL->Des(); |
|
729 TheTestList=pL; |
|
730 r=listfile.Read(ptr); |
|
731 if (r!=KErrNone) |
|
732 __PANIC(r); |
|
733 listfile.Close(); |
|
734 LogMsg(_L("Running test script %S"),&listfilename); |
|
735 LogMsg(_L("Build %S"),&KBuildType); |
|
736 LogMsg(_L("Path to test %S"),&TheProcessCommand); |
|
737 |
|
738 r = RProperty::Define( KRuntestsCurrentTestKey, |
|
739 RProperty::EText, |
|
740 TSecurityPolicy(TSecurityPolicy::EAlwaysPass), |
|
741 TSecurityPolicy(RProcess().SecureId()), |
|
742 512 |
|
743 ); |
|
744 if (r!=KErrNone && r!=KErrAlreadyExists) |
|
745 __PANIC(r); |
|
746 r = CurrTest.Attach(RProcess().SecureId(), KRuntestsCurrentTestKey); |
|
747 if (r!=KErrNone) |
|
748 __PANIC(r); |
|
749 r = CurrTest.Set(KNullDesC); |
|
750 if (r!=KErrNone) |
|
751 __PANIC(r); |
|
752 |
|
753 r = DestructionTimer.CreateLocal(); |
|
754 if (r!=KErrNone) |
|
755 __PANIC(r); |
|
756 TheCurrentProcessList = 0; |
|
757 r = GetProcessList(ProcLists[0]); |
|
758 if (r!=KErrNone) |
|
759 __PANIC(r); |
|
760 ListProcesses(); |
|
761 r = InitIdleWait(); |
|
762 if (r!=KErrNone) |
|
763 __PANIC(r); |
|
764 #if defined(_RUN_FOREVER_) |
|
765 FOREVER |
|
766 #endif |
|
767 ProcessTestList(); |
|
768 r = CurrTest.Set(KNullDesC); |
|
769 if (r!=KErrNone) |
|
770 __PANIC(r); |
|
771 CurrTest.Close(); |
|
772 User::After(1000000); // allow latency measurements to be output before exiting |
|
773 LogMsg(_L("Completed test script %S"),&listfilename); |
|
774 TheLoaderSession.Close(); |
|
775 TheFs.Close(); |
|
776 TheTimer.Close(); |
|
777 IdleWaitTimer.Close(); |
|
778 DestructionTimer.Close(); |
|
779 |
|
780 #ifdef _ENABLE_BTRACE_ANALYSIS_ |
|
781 BTraceAnalyseEnd(); |
|
782 #endif //_ENABLE_BTRACE_ANALYSIS_ |
|
783 if(User::Critical()==User::ESystemPermanent) |
|
784 RDebug::Print(KDebugMessage); |
|
785 return KErrNone; |
|
786 } |