|
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 * Main log server engine. |
|
16 * Process log requests from multiple clients simultaneously. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 #include <e32math.h> |
|
23 #include <e32cons.h> |
|
24 |
|
25 #include "utils.h" |
|
26 #include "wrapperapplication.h" |
|
27 //#include "applauncher.h" |
|
28 |
|
29 _LIT( KScriptFileExt, ".script" ); |
|
30 |
|
31 const TInt KExtLength( 7 ); |
|
32 extern CConsoleBase* console; |
|
33 |
|
34 CTefWrapperApplication::CTefWrapperApplication() |
|
35 : iIsDebug( EFalse), iIsSlf( EFalse ), |
|
36 iIsTcx( EFalse ), iIsTci( EFalse ), iHasScript( EFalse ) |
|
37 { |
|
38 } |
|
39 |
|
40 CTefWrapperApplication* CTefWrapperApplication::NewLC() |
|
41 { |
|
42 CTefWrapperApplication* self = new (ELeave) CTefWrapperApplication; |
|
43 CleanupStack::PushL( self ); |
|
44 self->ConstructL(); |
|
45 |
|
46 return self; |
|
47 } |
|
48 |
|
49 CTefWrapperApplication* CTefWrapperApplication::NewL() |
|
50 { |
|
51 CTefWrapperApplication* self = CTefWrapperApplication::NewLC(); |
|
52 CleanupStack::Pop( self ); |
|
53 |
|
54 return self; |
|
55 } |
|
56 |
|
57 void CTefWrapperApplication::ConstructL() |
|
58 { |
|
59 User::LeaveIfError( iFs.Connect() ); |
|
60 //iConsole = Console::NewL( KConsoleTitle, TSize( KConsFullScreen, KConsFullScreen ) ); |
|
61 //iAppLauncher = CAppLauncher::NewL(); |
|
62 } |
|
63 |
|
64 CTefWrapperApplication::~CTefWrapperApplication() |
|
65 { |
|
66 iFs.Close(); |
|
67 //delete iConsole; |
|
68 //delete iAppLauncher; |
|
69 } |
|
70 |
|
71 TBool CTefWrapperApplication::IsScriptFile( const TDesC& aFileName ) |
|
72 { |
|
73 TBool ret = EFalse; |
|
74 TBuf<KFileNameLength> scriptFile = aFileName; |
|
75 scriptFile.LowerCase(); |
|
76 |
|
77 if ( scriptFile.Right(KExtLength) == KScriptFileExt ) |
|
78 { |
|
79 ret = ETrue; |
|
80 } |
|
81 |
|
82 return ret; |
|
83 } |
|
84 |
|
85 void CTefWrapperApplication::PrintHelpMessage() |
|
86 { |
|
87 console->Printf( _L("testexecute2 Version : 0.1\r\n\r\n") ); |
|
88 console->Printf( _L("testexecute2 <scriptfilepath>\\<scriptfilename> [-d] [-slf]\r\n\r\n") ); |
|
89 console->Printf( _L(" : Executes the scriptfile with optional modes for JustInTime debugging or sepqrate log files\r\n\r\n\r\n") ); |
|
90 console->Printf( _L("testexecute2 [-h/--help/-v]\r\n\r\n") ); |
|
91 console->Printf( _L(" : Run testexecute2 with optional modes to display list of help options and the version numer\r\n\r\n") ); |
|
92 console->Printf( _L("-h/--help : For displaying the help options available for using testexecute2 framework\r\n\r\n") ); |
|
93 console->Printf( _L("-v : For displaying the version of the testexecute2 framework\r\n\r\n") ); |
|
94 console->Printf( _L("-slf : For printing the messages for each of the tests in separate log files\r\n\r\n") ); |
|
95 console->Printf( _L("-d : For enableing just in time debug mode while execution\r\n\r\n") ); |
|
96 } |
|
97 void CTefWrapperApplication::ParseCommandLineL() |
|
98 { |
|
99 // todo : handle tcs and tcsdata. |
|
100 |
|
101 _LIT( KDebugMode, "-d" ); |
|
102 _LIT( KSlfTag, "-slf" ); |
|
103 _LIT( KTciFlag, "-tci" ); |
|
104 _LIT( KTcxFlag, "-tcx" ); |
|
105 _LIT( KHelp, "-h" ); |
|
106 _LIT( KHelpMsg, "--help" ); |
|
107 _LIT( KVer, "-v" ); |
|
108 |
|
109 const TInt length = User().CommandLineLength(); |
|
110 if ( length == 0 ) |
|
111 { |
|
112 PrintHelpMessage(); |
|
113 User::Leave( Utils::EErrHelp ); |
|
114 } |
|
115 |
|
116 HBufC* cmdLine = HBufC::NewLC( length ); |
|
117 TPtr ptr = cmdLine->Des(); |
|
118 User().CommandLine( ptr ); |
|
119 |
|
120 TLex lex( ptr ); |
|
121 |
|
122 // Parse the command line |
|
123 while ( !lex.Eos() ) |
|
124 { |
|
125 TPtrC tmpPtr = lex.NextToken(); |
|
126 |
|
127 if ( IsScriptFile( tmpPtr )) |
|
128 { |
|
129 // Script=xxxx.script |
|
130 iScriptFileName = tmpPtr; |
|
131 if ( Utils::FileExists( iFs, iScriptFileName ) ) |
|
132 { |
|
133 iHasScript = ETrue; |
|
134 } |
|
135 else |
|
136 { |
|
137 User::Leave( Utils::EErrFileNotFound ); |
|
138 } |
|
139 } |
|
140 else if ( tmpPtr == KDebugMode )// Check -d |
|
141 { |
|
142 // Debug = ON / Debug = OFF |
|
143 iIsDebug = ETrue; |
|
144 } |
|
145 else if ( tmpPtr == KSlfTag ) // Check -slf |
|
146 { |
|
147 // SeparateLog = OFF / SeparateLog = ON |
|
148 iIsSlf = ETrue; |
|
149 } |
|
150 else if ( tmpPtr == KTciFlag ) // Check -tci |
|
151 { |
|
152 TPtrC tmpTciParam = lex.NextToken(); |
|
153 iTciParam = tmpTciParam; |
|
154 iIsTci = ETrue; |
|
155 } |
|
156 else if ( tmpPtr == KTcxFlag ) // Check tcx |
|
157 { |
|
158 TPtrC tmpTcxParam = lex.NextToken(); |
|
159 iTcxParam = tmpTcxParam; |
|
160 iIsTcx = ETrue; |
|
161 } |
|
162 else if ( (tmpPtr == KHelp)||(tmpPtr == KHelpMsg) ) |
|
163 { |
|
164 PrintHelpMessage(); |
|
165 User::Leave( Utils::EErrHelp ); |
|
166 } |
|
167 else if ( tmpPtr == KVer ) |
|
168 { |
|
169 console->Printf( _L("testexecute2 Version : 0.1\r\n\r\n") ); |
|
170 User::Leave( Utils::EErrVersion ); |
|
171 } |
|
172 else |
|
173 { |
|
174 User::Leave( Utils::EErrBadParam ); |
|
175 } |
|
176 } // while |
|
177 |
|
178 if ( !iHasScript ) |
|
179 { |
|
180 User::Leave( KErrNotFound ); |
|
181 } |
|
182 |
|
183 if ( iIsTci || iIsTcx ) |
|
184 { |
|
185 TBool r = EFalse; |
|
186 if ( iTciParam.Length() != 0 ) |
|
187 { |
|
188 r = ETrue; |
|
189 } |
|
190 |
|
191 if ( iTcxParam.Length() != 0 ) |
|
192 { |
|
193 r = ETrue; |
|
194 } |
|
195 |
|
196 if( !r ) |
|
197 { |
|
198 User::Leave( KErrNotFound ); |
|
199 } |
|
200 } |
|
201 |
|
202 // Destroy command line buffer |
|
203 CleanupStack::PopAndDestroy( cmdLine ); |
|
204 } |
|
205 |
|
206 void CTefWrapperApplication::WriteLineL( const TDesC& aFileName, const TDesC& aString ) |
|
207 { |
|
208 _LIT( KCR, "\r\n" ); |
|
209 |
|
210 RFile file; |
|
211 if ( Utils::FileExists( iFs, aFileName ) ) |
|
212 { |
|
213 User::LeaveIfError( file.Open( iFs, aFileName, EFileWrite ) ); |
|
214 } |
|
215 else |
|
216 { |
|
217 User::LeaveIfError( file.Create( iFs, aFileName, EFileWrite ) ); |
|
218 } |
|
219 |
|
220 CleanupClosePushL( file ); |
|
221 |
|
222 TBuf8<KFileNameLength> strLine; |
|
223 strLine.Copy( aString ); |
|
224 strLine.Append( KCR ); |
|
225 |
|
226 TInt pos = 0; |
|
227 file.Size( pos ); |
|
228 /*RFileWriteStream writeStream( file, pos ); |
|
229 writeStream.PushL(); |
|
230 writeStream.WriteL( strLine ); |
|
231 writeStream.CommitL(); |
|
232 writeStream.Pop(); |
|
233 writeStream.Release();*/ |
|
234 |
|
235 file.Write( pos, strLine ); |
|
236 file.Close(); |
|
237 |
|
238 CleanupStack::PopAndDestroy( &file ); |
|
239 } |
|
240 |
|
241 void CTefWrapperApplication::WriteLineL( const TDesC& aFileName, const TDesC& aKey, const TDesC& aValue ) |
|
242 { |
|
243 _LIT( KAssignOpr, "=" ); |
|
244 TBuf<KFileNameLength> strLine; |
|
245 strLine.Append( aKey ); |
|
246 strLine.Append( KAssignOpr ); |
|
247 strLine.Append( aValue ); |
|
248 |
|
249 WriteLineL( aFileName, strLine ); |
|
250 } |
|
251 |
|
252 void CTefWrapperApplication::GetConfigFileName( TDes& aConfigFileName ) |
|
253 { |
|
254 _LIT( KFormatString, "c:\\testframework\\stf_%x.cfg" ); |
|
255 _LIT( KTestFrameWork, "c:\\testframework\\" ); |
|
256 |
|
257 TTime theTime; |
|
258 theTime.UniversalTime(); |
|
259 TInt64 randSeed( theTime.Int64() ); |
|
260 TInt number( Math::Rand( randSeed ) ); |
|
261 aConfigFileName.Format( KFormatString, number ); |
|
262 |
|
263 // check if the specific dir exists. |
|
264 if ( !Utils::FileExists( iFs, iCfgFileName ) ) |
|
265 { |
|
266 Utils::MkDir( iFs, KTestFrameWork ); |
|
267 } |
|
268 } |
|
269 |
|
270 void CTefWrapperApplication::WriteConfigFileL() |
|
271 { |
|
272 _LIT( KSectionBegin, "[New_TEFTest]" ); |
|
273 _LIT( KSectionEnd, "[End_TEFTest]" ); |
|
274 _LIT( KTcs, "Tcs" ); |
|
275 _LIT( KInclude, "Include" ); |
|
276 _LIT( KExclude, "Exclude" ); |
|
277 _LIT( KDebug, "Debug" ); |
|
278 _LIT( KOn, "ON" ); |
|
279 _LIT( KOff, "OFF" ); |
|
280 _LIT( KSeparateLog, "SeparateLog" ); |
|
281 _LIT( KPipe, "Pipe" ); |
|
282 _LIT( KScript, "Script" ); |
|
283 _LIT( KTcsData, "TcsData" ); |
|
284 |
|
285 GetConfigFileName( iCfgFileName ); |
|
286 WriteLineL( iCfgFileName, KSectionBegin ); |
|
287 |
|
288 // write tcs flag. |
|
289 if ( iIsTci || iIsTcx ) |
|
290 { |
|
291 WriteLineL( iCfgFileName, KTcs, iIsTci?KInclude:KExclude ); |
|
292 } |
|
293 |
|
294 // write debug flag. |
|
295 if( iIsDebug ) |
|
296 { |
|
297 WriteLineL( iCfgFileName, KDebug, KOn ); |
|
298 } |
|
299 else |
|
300 { |
|
301 WriteLineL( iCfgFileName, KDebug, KOff ); |
|
302 } |
|
303 |
|
304 // write slf flag. |
|
305 if( iIsSlf ) |
|
306 { |
|
307 WriteLineL( iCfgFileName, KSeparateLog, KOn ); |
|
308 } |
|
309 else |
|
310 { |
|
311 WriteLineL( iCfgFileName, KSeparateLog, KOff ); |
|
312 } |
|
313 |
|
314 // write Pipe=OFF. // handle pipe section. |
|
315 WriteLineL( iCfgFileName, KPipe, KOff ); |
|
316 |
|
317 // write script file. |
|
318 WriteLineL( iCfgFileName, KScript, iScriptFileName ); |
|
319 |
|
320 // write tcs |
|
321 if ( iIsTci || iIsTcx ) |
|
322 { |
|
323 WriteLineL( iCfgFileName, KTcsData, iIsTci?iTciParam:iTcxParam ); |
|
324 } |
|
325 |
|
326 // write Section End. |
|
327 WriteLineL( iCfgFileName, KSectionEnd ); |
|
328 } |
|
329 |
|
330 void CTefWrapperApplication::ExecuteL() |
|
331 { |
|
332 _LIT( KAtsInterface, "atsinterface.exe" ); |
|
333 _LIT( KAtsInterfaceArgs, "-testmodule TEFTestModule -config " ); |
|
334 |
|
335 TBuf<KFileNameLength> strArgs; |
|
336 strArgs.Copy( KAtsInterfaceArgs ); |
|
337 strArgs.Append( iCfgFileName ); |
|
338 |
|
339 RProcess proc; |
|
340 proc.Create( KAtsInterface, strArgs ); |
|
341 TRequestStatus status; |
|
342 proc.Logon( status ); |
|
343 proc.Resume(); |
|
344 |
|
345 //iAppLauncher->ExecuteL( KAtsInterface, strArgs ); |
|
346 //User::WaitForRequest( iAppLauncher->iStatus ); |
|
347 |
|
348 User::WaitForRequest( status ); |
|
349 proc.Close(); |
|
350 if ( KErrNone != status.Int() ) |
|
351 { |
|
352 console->Printf( _L("Launch TEF Test Module failed.\n") ); |
|
353 User::LeaveIfError( status.Int() ); |
|
354 } |
|
355 } |
|
356 |
|
357 void CTefWrapperApplication::DeleteConfigFile() |
|
358 { |
|
359 if ( Utils::FileExists( iFs, iCfgFileName ) ) |
|
360 { |
|
361 Utils::DeleteFile( iFs, iCfgFileName ); |
|
362 } |
|
363 } |