|
1 // Copyright (c) 2001-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 /** |
|
17 @file consoleMain.cpp |
|
18 @internalComponent |
|
19 */ |
|
20 |
|
21 // system includes |
|
22 #include <e32base.h> |
|
23 #include <e32cons.h> |
|
24 #include "f32file.h" |
|
25 |
|
26 // test system includes |
|
27 #include "../inc/Log.h" |
|
28 #include "../inc/TestSuite.h" |
|
29 #include "../inc/TestStep.h" |
|
30 #include "../inc/TestUtils.h" |
|
31 #include "script.h" |
|
32 #include "parseline.h" |
|
33 |
|
34 /** |
|
35 Holds EPOC32EX string constant |
|
36 */ |
|
37 _LIT(KTxtEPOC32EX,"EPOC32EX"); |
|
38 |
|
39 /** |
|
40 Holds Example Code string constant |
|
41 */ |
|
42 _LIT(KTxtExampleCode,"Integration Test Harness v 1.012"); |
|
43 |
|
44 /** |
|
45 Failed format string constant |
|
46 */ |
|
47 _LIT(KFormatFailed,"failed: leave code=%d"); |
|
48 |
|
49 /** |
|
50 Holds OK string constant |
|
51 */ |
|
52 _LIT(KTxtOK,"script completed \n"); |
|
53 |
|
54 /** |
|
55 Holds Example Usage constant |
|
56 */ |
|
57 _LIT(KTxtUseExample,"Usage:\nSCHEDULETEST [-a] [-Sn] <file.script>\nSCHEDULETEST [-a] [-Sn] -u <test_suite.DLL> [file.ini]"); |
|
58 |
|
59 /** |
|
60 Holds DLL fullpath |
|
61 */ |
|
62 _LIT(KTxtDLLpath,"c:\\;c:\\system\\libs"); |
|
63 |
|
64 /** |
|
65 Constant that holds press any key string |
|
66 */ |
|
67 _LIT(KTxtPressAnyKey,"[press any key to continue]\n"); |
|
68 |
|
69 #ifdef _WIN32 |
|
70 #ifdef __CW32__ |
|
71 /** WINSCW target constant */ |
|
72 _LIT(KTxtTarget,"WINSCW"); |
|
73 #else |
|
74 /** WINS target constant */ |
|
75 _LIT(KTxtTarget,"WINS"); |
|
76 #endif |
|
77 #else |
|
78 #ifdef __MARM_THUMB__ |
|
79 /** THUMB target constant */ |
|
80 #ifdef __EABI__ |
|
81 _LIT(KTxtTarget,"ARMV5"); |
|
82 #else |
|
83 _LIT(KTxtTarget,"THUMB"); |
|
84 #endif |
|
85 #else |
|
86 /** ARM4 target constant */ |
|
87 _LIT(KTxtTarget,"ARM4"); |
|
88 #endif |
|
89 #endif |
|
90 |
|
91 #ifdef _DEBUG |
|
92 /** |
|
93 debug build string constant |
|
94 */ |
|
95 _LIT(KTxtBuild,"udeb"); |
|
96 #else |
|
97 /** |
|
98 release build string constant |
|
99 */ |
|
100 _LIT(KTxtBuild,"urel"); |
|
101 #endif |
|
102 |
|
103 /** |
|
104 Platform String Constant for EKA2 |
|
105 */ |
|
106 _LIT(KTxtPlatform,"EKA2"); |
|
107 |
|
108 /** |
|
109 maximum length of command line |
|
110 */ |
|
111 #define MAX_LEN_CMD_LINE 0x100 |
|
112 |
|
113 /** |
|
114 Global data: Asynchronous timer service |
|
115 */ |
|
116 GLDEF_D static RTimer TheTimer; |
|
117 |
|
118 // private |
|
119 |
|
120 /** |
|
121 initialize with cleanup stack |
|
122 */ |
|
123 LOCAL_C void callConsoleMainL(void); |
|
124 |
|
125 /** the main function */ |
|
126 LOCAL_C void doConsoleMainL(void); |
|
127 |
|
128 LOCAL_C void doUnitTestL(TInt aSeverity,const TFileName& aSuitDLL,const TFileName& aIniFile); |
|
129 LOCAL_C void Usage(void); |
|
130 |
|
131 /** |
|
132 The main function called by E32. |
|
133 @returns 0 |
|
134 */ |
|
135 GLDEF_C TInt E32Main() |
|
136 { |
|
137 //__UHEAP_MARK; |
|
138 // get clean-up stack |
|
139 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
140 |
|
141 |
|
142 // more initialization, then do console main |
|
143 TRAPD(error,callConsoleMainL()); |
|
144 __ASSERT_ALWAYS(!error,User::Panic(KTxtEPOC32EX,error)); |
|
145 |
|
146 // destroy clean-up stack |
|
147 delete cleanup; |
|
148 //__UHEAP_MARKEND; |
|
149 |
|
150 return 0; |
|
151 } |
|
152 |
|
153 /** |
|
154 The main entry point for console applications. |
|
155 Initialize and call doConsoleMainL code under cleanup stack. |
|
156 */ |
|
157 LOCAL_C void callConsoleMainL() |
|
158 { |
|
159 console=Console::NewL(KTxtExampleCode,TSize(KConsFullScreen,KConsFullScreen)); |
|
160 CleanupStack::PushL(console); |
|
161 TRAPD(error,doConsoleMainL()); // perform tests |
|
162 if (error) |
|
163 console->Printf(KFormatFailed, error); |
|
164 else |
|
165 console->Printf(KTxtOK); |
|
166 |
|
167 CleanupStack::PopAndDestroy(); // close console |
|
168 } |
|
169 |
|
170 |
|
171 /** |
|
172 The start of code. |
|
173 */ |
|
174 LOCAL_C void doConsoleMainL() |
|
175 { |
|
176 // console is initialised |
|
177 // now start the Log system |
|
178 TInt severity = ESevrAll; |
|
179 pLogSystem = CLog::NewL( console ); |
|
180 CleanupStack::PushL(pLogSystem); |
|
181 |
|
182 // initialise the CTestUtils |
|
183 pTestUtils = CTestUtils::NewL( pLogSystem ); |
|
184 CleanupStack::PushL(pTestUtils); |
|
185 |
|
186 // read the command line into cmd |
|
187 TBuf<MAX_LEN_CMD_LINE> cmd; |
|
188 User::CommandLine(cmd); |
|
189 cmd.UpperCase(); |
|
190 |
|
191 // use Tlex to decode the cmd line |
|
192 TLex lex(cmd); |
|
193 TPtrC token=lex.NextToken(); |
|
194 |
|
195 // if there is no input filename on the cmd line Panic! |
|
196 if (token.Length()==0) |
|
197 Usage(); |
|
198 else |
|
199 { |
|
200 // Process any options |
|
201 TBool unitTest = EFalse; |
|
202 while(token.Length() > 1 && token[0] == '-') |
|
203 { |
|
204 switch(token[1]) |
|
205 { |
|
206 case 'U': |
|
207 case 'u': |
|
208 unitTest = ETrue; |
|
209 break; |
|
210 case 'S': |
|
211 case 's': |
|
212 { |
|
213 if( token.Length() == 3 ) |
|
214 { |
|
215 TLex Severity(token); |
|
216 Severity.Inc(2); |
|
217 if((Severity.Peek()).IsDigit()) |
|
218 { |
|
219 Severity.Val(severity); |
|
220 // wrong severity level |
|
221 if( (severity < 0) || (severity > 7 )) |
|
222 severity = 7; |
|
223 } |
|
224 } |
|
225 break; |
|
226 } |
|
227 case 'A': |
|
228 case 'a': |
|
229 automatedMode = ETrue; |
|
230 break; |
|
231 default: |
|
232 Usage(); |
|
233 return; |
|
234 } |
|
235 |
|
236 token.Set(lex.NextToken()); |
|
237 } |
|
238 |
|
239 if(unitTest) |
|
240 { |
|
241 // get suite name |
|
242 TFileName suitFileName; |
|
243 |
|
244 if (token.Length()!=0) |
|
245 suitFileName = token; |
|
246 else |
|
247 { |
|
248 Usage(); |
|
249 User::Leave(KErrArgument); |
|
250 } |
|
251 |
|
252 pLogSystem->OpenLogFileL(suitFileName); |
|
253 |
|
254 pLogSystem->LogExtra(((TText8*)(__FILE__)), (__LINE__), ESevrErr, |
|
255 _L("%S %S %S %S starting...."), &KTxtExampleCode(), &KTxtTarget(), &KTxtPlatform(), &KTxtBuild() ); |
|
256 |
|
257 // get ini file |
|
258 token.Set(lex.NextToken()); |
|
259 |
|
260 TFileName configFileName; |
|
261 if (token.Length()!=0) |
|
262 { |
|
263 if(token.Find(_L("-S")) == KErrNotFound ) |
|
264 configFileName = token; |
|
265 } |
|
266 |
|
267 // do unit test |
|
268 doUnitTestL(severity, suitFileName, configFileName); |
|
269 |
|
270 if(!automatedMode) |
|
271 { |
|
272 console->Printf(KTxtPressAnyKey); |
|
273 console->Getch(); // get and ignore character |
|
274 } |
|
275 } |
|
276 else |
|
277 { |
|
278 // there is a script file so lets do it! |
|
279 // save the input filename |
|
280 TFileName scriptFileName=token; |
|
281 |
|
282 // make the log file name from the script file name |
|
283 TFileName LogFileName = token; |
|
284 |
|
285 // open the log file |
|
286 pLogSystem->OpenLogFileL( LogFileName); |
|
287 |
|
288 pLogSystem->LogExtra(((TText8*)(__FILE__)), (__LINE__), ESevrErr, |
|
289 _L("%S %S %S %S starting...."), |
|
290 &KTxtExampleCode(), &KTxtTarget(), &KTxtPlatform(), &KTxtBuild() ); |
|
291 |
|
292 // create a ParseScript object |
|
293 CScript* parseScript=CScript::NewL(); |
|
294 CleanupStack::PushL(parseScript); |
|
295 |
|
296 // parse all scripts |
|
297 do |
|
298 { |
|
299 // get the next file |
|
300 scriptFileName=token; |
|
301 |
|
302 // read in the script file |
|
303 if ( parseScript->OpenScriptFile( scriptFileName )) |
|
304 { |
|
305 // process it |
|
306 parseScript->ExecuteScriptL( ); |
|
307 |
|
308 // display results summary |
|
309 parseScript->DisplayResults( ); |
|
310 |
|
311 } |
|
312 // get the next |
|
313 token.Set(lex.NextToken()); |
|
314 } while ( token.Length()!=0 ); |
|
315 |
|
316 CleanupStack::PopAndDestroy(parseScript); |
|
317 |
|
318 // close the logging system |
|
319 pLogSystem->CloseLogFile(); |
|
320 } |
|
321 } |
|
322 |
|
323 // delete the test utils object |
|
324 CleanupStack::PopAndDestroy(pTestUtils); |
|
325 // delete pTestUtils; |
|
326 |
|
327 // close the log file |
|
328 CleanupStack::PopAndDestroy(pLogSystem); |
|
329 // delete pLogSystem; |
|
330 |
|
331 } |
|
332 |
|
333 /** |
|
334 Performs unit test. |
|
335 |
|
336 @param aSeverity The current logging severity level. |
|
337 @param aSuitDLL The test suite DLL which contains the unit test. |
|
338 @param aIniFile The ini file name. |
|
339 */ |
|
340 LOCAL_C void doUnitTestL(TInt aSeverity, const TFileName& aSuitDLL,const TFileName& aIniFile) |
|
341 { |
|
342 // check the dll can be found before trying to load |
|
343 RLibrary lib; |
|
344 TInt err = lib.Load(aSuitDLL, KTxtDLLpath); |
|
345 if (err == KErrNone) |
|
346 { |
|
347 lib.Close(); |
|
348 } |
|
349 |
|
350 if ( err==KErrNotFound ) |
|
351 { |
|
352 // this is not going to load ! |
|
353 //pLogSystem->Log(_L("Test suite %S could not be found"), &aSuitDLL ); |
|
354 //return; |
|
355 } |
|
356 |
|
357 // create a new suitedll object to store info on loaded DLL |
|
358 CSuiteDll * newRef = CSuiteDll::NewL( aSuitDLL ); |
|
359 |
|
360 // set severity level and logging system |
|
361 newRef->iTestSuite->SetSeverity(aSeverity); |
|
362 newRef->iTestSuite->SetLogSystem(pLogSystem); |
|
363 |
|
364 // do unit test |
|
365 newRef->iTestSuite->DoTestUnit(const_cast<TFileName&>(aIniFile)); |
|
366 |
|
367 delete newRef; |
|
368 } |
|
369 |
|
370 /** |
|
371 Display command line format. |
|
372 */ |
|
373 LOCAL_C void Usage() |
|
374 { |
|
375 console->Printf(_L("%S command line error...\n"), &KTxtExampleCode()); |
|
376 console->Printf(_L("%S"), &KTxtUseExample() ); |
|
377 console->Getch(); |
|
378 } |