|
1 // Copyright (c) 2002-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 "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 // |
|
15 |
|
16 #include "TestFrameworkMain.h" |
|
17 #include "../../recog/TestFrameworkRecog.h" |
|
18 #include "script.h" |
|
19 #include "parseline.h" |
|
20 #include "Filename.h" |
|
21 #include "config.h" |
|
22 |
|
23 // Hurricane emulator only - start all services which we require to run tests. |
|
24 // Future enhancement :- add these startups to TestUtils |
|
25 #if defined(__WINS__) |
|
26 IMPORT_C TInt FbsStartup(); |
|
27 #endif |
|
28 |
|
29 /** |
|
30 * |
|
31 * Literals : program information and usage |
|
32 * |
|
33 * @xxxx |
|
34 * |
|
35 */ |
|
36 _LIT(KTxtFrameworkStarting, "%S %S %S starting...."); |
|
37 //_LIT(KTxtUseExample,"Usage:\nTESTFRAMEWORK [-C] [-F] <file.script> [file.ini]"); // EABI warning removal |
|
38 |
|
39 /** |
|
40 * |
|
41 * Compiler switches |
|
42 * |
|
43 * @xxxx |
|
44 * |
|
45 */ |
|
46 #ifdef _WIN32 |
|
47 _LIT(KTxtTarget,"WINS"); |
|
48 #else |
|
49 #ifdef __MARM_THUMB__ |
|
50 _LIT(KTxtTarget,"THUMB"); |
|
51 #else |
|
52 _LIT(KTxtTarget,"ARM4"); |
|
53 #endif |
|
54 #endif |
|
55 |
|
56 #ifdef _DEBUG |
|
57 _LIT(KTxtBuild,"udeb"); |
|
58 #else |
|
59 _LIT(KTxtBuild,"urel"); |
|
60 #endif |
|
61 |
|
62 |
|
63 /** |
|
64 * |
|
65 * max length of command line |
|
66 * |
|
67 * @xxxx |
|
68 * |
|
69 */ |
|
70 const TInt KMaxLenCmdLine = 256; |
|
71 |
|
72 /** |
|
73 * |
|
74 * Test Framework startup function. |
|
75 * Creates an active scheduler for input if required, reads |
|
76 * the command line, starts the main test loop. |
|
77 * |
|
78 * @xxxx |
|
79 * |
|
80 */ |
|
81 void StartupL() |
|
82 { |
|
83 CActiveScheduler* pA=new(ELeave) CActiveScheduler; |
|
84 CleanupStack::PushL(pA); |
|
85 CActiveScheduler::Install(pA); |
|
86 |
|
87 // Hurricane emulator only - start all services which we require to run tests. |
|
88 // Future enhancement :- add these startups to TestUtils |
|
89 #if defined(__WINS__) |
|
90 #ifndef EXCLUDE_FOR_UNITTEST |
|
91 FbsStartup(); |
|
92 #endif // EXCLUDE_FOR_UNITTEST |
|
93 #endif |
|
94 |
|
95 // read the command line into cmd |
|
96 TPtr16 cmd(REINTERPRET_CAST(TUint16*,User::AllocLC(KMaxLenCmdLine*2)), 0, KMaxLenCmdLine); |
|
97 cmd.Fill('\0', KMaxLenCmdLine); |
|
98 |
|
99 User::CommandLine(cmd); |
|
100 cmd.UpperCase(); |
|
101 |
|
102 CTestFrameworkMain* tester = CTestFrameworkMain::NewLC(); |
|
103 tester->StartTestingL(cmd); |
|
104 |
|
105 // NOTE. Currently there is no need to start the active scheduler, as the input console is |
|
106 // now at the server. This will however change when AOs are implemented to replace |
|
107 // the main client loop. |
|
108 |
|
109 // CActiveScheduler::Start(); |
|
110 |
|
111 CleanupStack::PopAndDestroy(3); //tester, pA, cmd |
|
112 } |
|
113 |
|
114 |
|
115 GLDEF_C TInt E32Main() |
|
116 { |
|
117 |
|
118 __UHEAP_MARK; |
|
119 CTrapCleanup* cleanup = CTrapCleanup::New(); // get clean-up stack |
|
120 |
|
121 // start scheduler |
|
122 TRAPD(error, StartupL()); |
|
123 __ASSERT_ALWAYS(!error, User::Panic(_L("TestFramework"), error)); |
|
124 |
|
125 delete cleanup; // destroy clean-up stack |
|
126 __UHEAP_MARKEND; |
|
127 return KErrNone; |
|
128 } |
|
129 |
|
130 // Instructions for Console Display |
|
131 // Please add new entries to the right hand column, |
|
132 // Precede number and text with "\t " |
|
133 // Leave \n\ at end of each line except the last line |
|
134 //_LIT(KTxtMainInstructions, "Welcome to TestFramework. Press Q to quit "); // EABI warning removal |
|
135 |
|
136 |
|
137 /** |
|
138 * |
|
139 * CTestFrameworkMain static constructor. |
|
140 * |
|
141 * @xxxx |
|
142 * |
|
143 */ |
|
144 CTestFrameworkMain* CTestFrameworkMain::NewLC() |
|
145 { |
|
146 CTestFrameworkMain* s = new(ELeave) CTestFrameworkMain; |
|
147 CleanupStack::PushL(s); |
|
148 s->ConstructL(); |
|
149 return s; |
|
150 } |
|
151 |
|
152 /** |
|
153 * |
|
154 * CTestFrameworkMain first-phase constructor. |
|
155 * |
|
156 * @xxxx |
|
157 * |
|
158 */ |
|
159 CTestFrameworkMain::CTestFrameworkMain() |
|
160 { |
|
161 } |
|
162 |
|
163 /** |
|
164 * |
|
165 * CTestFrameworkMain second-phase constructor. |
|
166 * Loads log client and test utils. |
|
167 * |
|
168 * @xxxx |
|
169 * |
|
170 */ |
|
171 void CTestFrameworkMain::ConstructL() |
|
172 { |
|
173 iLogClient = CLog::NewL(); |
|
174 iLogMode = ELogToConsole | ELogToFile; |
|
175 iTestUtils = CTestUtils::NewL(iLogClient); |
|
176 iGuardTimer = KNoGuardTimer; // default value |
|
177 } |
|
178 |
|
179 /** |
|
180 * |
|
181 * CTestFrameworkMain destructor. |
|
182 * |
|
183 * @xxxx |
|
184 * |
|
185 */ |
|
186 CTestFrameworkMain::~CTestFrameworkMain() |
|
187 { |
|
188 delete iTestUtils; |
|
189 delete iLogClient; |
|
190 } |
|
191 |
|
192 /** |
|
193 * |
|
194 * CTestFrameworkMain - start testing. |
|
195 * Calls main test loop. |
|
196 * |
|
197 * @param "const TDesC& aCmdLine" |
|
198 * The command line |
|
199 * |
|
200 * @xxxx |
|
201 * |
|
202 */ |
|
203 void CTestFrameworkMain::StartTestingL(const TDesC& aCmdLine) |
|
204 { |
|
205 RunTestScriptL(aCmdLine); |
|
206 |
|
207 RSemaphore sem; |
|
208 TInt err = sem.OpenGlobal(KRecogSemaphoreName); |
|
209 if (err==KErrNone) |
|
210 { |
|
211 // Tell the recognizer thread that we're finished |
|
212 sem.Signal(); |
|
213 sem.Close(); |
|
214 } |
|
215 } |
|
216 |
|
217 /** |
|
218 * |
|
219 * Accessor : log client |
|
220 * |
|
221 * @return "CLog*" |
|
222 * The log client |
|
223 * |
|
224 * @xxxx |
|
225 * |
|
226 */ |
|
227 CLog* CTestFrameworkMain::LogClient() const |
|
228 { |
|
229 return iLogClient; |
|
230 } |
|
231 |
|
232 /** |
|
233 * |
|
234 * Main testing loop. |
|
235 * Read a script file, parse it and execute each test step in turn. |
|
236 * |
|
237 * @param "const TDesC& aCmdLine" |
|
238 * The command line |
|
239 * |
|
240 * @xxxx |
|
241 * |
|
242 */ |
|
243 void CTestFrameworkMain::RunTestScriptL(const TDesC& aCmdLine) |
|
244 { |
|
245 // use TLex to decode the cmd line |
|
246 TLex lex(aCmdLine); |
|
247 TPtrC token=lex.NextToken(); |
|
248 |
|
249 // if there is no input filename on the cmd line, panic |
|
250 if (token.Length() == 0) |
|
251 UsageL(); |
|
252 else |
|
253 { |
|
254 // Process any options |
|
255 while(token.Length() > 1 && token[0] == '-') |
|
256 { |
|
257 switch(token[1]) |
|
258 { |
|
259 case 'C': |
|
260 case 'c': |
|
261 // log to console ONLY |
|
262 iLogMode = ELogToConsole; |
|
263 break; |
|
264 case 'A': |
|
265 case 'a': |
|
266 iLogMode |= ELogConsoleFull; |
|
267 break; |
|
268 case 'F': |
|
269 case 'f': |
|
270 // log to file ONLY |
|
271 iLogMode = ELogToFile; |
|
272 break; |
|
273 case 'P': |
|
274 case 'p': |
|
275 // log to port AS WELL AS to console / file |
|
276 iLogMode |= ELogToPort; |
|
277 break; |
|
278 //This stops the emulator from thowing int 3 if a panic occurs in debug builds |
|
279 case 'T': |
|
280 case 't': |
|
281 User::SetJustInTime(EFalse); |
|
282 // -S flag removed - was for old Unit Test mode only |
|
283 // -A 'automated mode' removed - it's always automated |
|
284 break; |
|
285 case 'G': |
|
286 case 'g': |
|
287 { |
|
288 // ** guard timer override - get numeric value that follows |
|
289 TPtrC val = &token[2]; |
|
290 TLex lexTimeOut(val); |
|
291 if (lexTimeOut.Val(iGuardTimer) != KErrNone) |
|
292 UsageL(); |
|
293 } |
|
294 break; |
|
295 case 'm': |
|
296 case 'M': |
|
297 { |
|
298 if (token.Length()<=2) |
|
299 { |
|
300 // only -m found. must be -m<arg> with no space |
|
301 UsageL(); |
|
302 } |
|
303 TPtrC restOfLine = &token[2]; // this will be rest of command line |
|
304 TLex argument(restOfLine); |
|
305 TPtrC matchString = argument.NextToken(); // will be the argument itself |
|
306 ASSERT(matchString.Length()>1); |
|
307 iTestMatchString = matchString; |
|
308 } |
|
309 break; |
|
310 case 'Q': |
|
311 case 'q': |
|
312 { |
|
313 // This flag has been removed. This block is just to ensure that if used it wont panic |
|
314 } |
|
315 break; |
|
316 |
|
317 default: |
|
318 UsageL(); |
|
319 return; |
|
320 } |
|
321 |
|
322 token.Set(lex.NextToken()); |
|
323 } |
|
324 |
|
325 // save the input filename |
|
326 CFileName* scriptFileName = CFileName::NewLC(); |
|
327 *scriptFileName = token; |
|
328 |
|
329 // make the log file name from the script file name |
|
330 CFileName* logFileName = CFileName::NewLC(); |
|
331 *logFileName = token; |
|
332 RDebug::Print(_L("TestFrameWorkMain.cpp: RunTestScriptL 1")); |
|
333 // open the log file |
|
334 iLogClient->OpenLogFileL(logFileName->FileName(), iLogMode); |
|
335 RDebug::Print(_L("TestFrameWorkMain.cpp: RunTestScriptL 2")); |
|
336 iLogClient->LogExtra(__FILE8__, __LINE__, ESevrInfo, |
|
337 KTxtFrameworkStarting, &KTxtVersion(), &KTxtTarget(), &KTxtBuild()); |
|
338 RDebug::Print(_L("TestFrameWorkMain.cpp: RunTestScriptL 3")); |
|
339 // create a ParseScript object |
|
340 CScript* parseScript = CScript::NewLC(iTestUtils, |
|
341 iLogClient, |
|
342 iGuardTimer, |
|
343 iTestMatchString); |
|
344 RDebug::Print(_L("TestFrameWorkMain.cpp: RunTestScriptL 4")); |
|
345 // parse all scripts |
|
346 do |
|
347 { |
|
348 // get the next file |
|
349 *scriptFileName = token; |
|
350 |
|
351 // read in the script file |
|
352 if ( parseScript->OpenScriptFile(scriptFileName)) |
|
353 { |
|
354 // process it |
|
355 parseScript->ExecuteScriptL(); |
|
356 // display results summary |
|
357 parseScript->DisplayResults(); |
|
358 } |
|
359 // get the next |
|
360 token.Set(lex.NextToken()); |
|
361 } while ( token.Length()!=0 ); |
|
362 RDebug::Print(_L("TestFrameWorkMain.cpp: RunTestScriptL 5")); |
|
363 CleanupStack::PopAndDestroy(parseScript); |
|
364 |
|
365 // close the logging system |
|
366 iLogClient->CloseLogFile(); |
|
367 |
|
368 CleanupStack::PopAndDestroy(logFileName); |
|
369 CleanupStack::PopAndDestroy(scriptFileName); |
|
370 } |
|
371 } |
|
372 |
|
373 /** |
|
374 * |
|
375 * Display command line format. |
|
376 * |
|
377 * @xxxx |
|
378 * |
|
379 */ |
|
380 void CTestFrameworkMain::UsageL() |
|
381 { |
|
382 // If command line is erroneous, raise a panic. |
|
383 // At this point, there may be no log outputs at all. |
|
384 User::Panic(_L("TestFramework"), 2); |
|
385 } |