|
1 /* |
|
2 * Copyright (c) 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: This file contains Hardcoded module implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // [INCLUDE FILES] - do not remove |
|
20 #include <StifTestInterface.h> |
|
21 #include "HardCodedTestModuleXXX.h" |
|
22 #include <SettingServerClient.h> |
|
23 |
|
24 // EXTERNAL DATA STRUCTURES |
|
25 //extern ?external_data; |
|
26 |
|
27 // EXTERNAL FUNCTION PROTOTYPES |
|
28 //extern ?external_function( ?arg_type,?arg_type ); |
|
29 |
|
30 // CONSTANTS |
|
31 //const ?type ?constant_var = ?constant; |
|
32 |
|
33 // MACROS |
|
34 //#define ?macro ?macro_def |
|
35 |
|
36 // LOCAL CONSTANTS AND MACROS |
|
37 //const ?type ?constant_var = ?constant; |
|
38 //#define ?macro_name ?macro_def |
|
39 |
|
40 // MODULE DATA STRUCTURES |
|
41 //enum ?declaration |
|
42 //typedef ?declaration |
|
43 |
|
44 // LOCAL FUNCTION PROTOTYPES |
|
45 //?type ?function_name( ?arg_type, ?arg_type ); |
|
46 |
|
47 // FORWARD DECLARATIONS |
|
48 //class ?FORWARD_CLASSNAME; |
|
49 |
|
50 // ============================= LOCAL FUNCTIONS =============================== |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // ?function_name ?description. |
|
54 // ?description |
|
55 // Returns: ?value_1: ?description |
|
56 // ?value_n: ?description_line1 |
|
57 // ?description_line2 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 /* |
|
61 ?type ?function_name( |
|
62 ?arg_type arg, // ?description |
|
63 ?arg_type arg) // ?description |
|
64 { |
|
65 |
|
66 ?code // ?comment |
|
67 |
|
68 // ?comment |
|
69 ?code |
|
70 } |
|
71 */ |
|
72 |
|
73 // ============================ MEMBER FUNCTIONS =============================== |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // CHardCodedTestModuleXXX::CHardCodedTestModuleXXX |
|
77 // C++ default constructor can NOT contain any code, that |
|
78 // might leave. |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 CHardCodedTestModuleXXX::CHardCodedTestModuleXXX() |
|
82 { |
|
83 |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CHardCodedTestModuleXXX::ConstructL |
|
88 // Symbian 2nd phase constructor can leave. |
|
89 // |
|
90 // Note: If OOM test case uses STIF Logger, then STIF Logger must be created |
|
91 // with static buffer size parameter (aStaticBufferSize). Otherwise Logger |
|
92 // allocates memory from heap and therefore causes error situations with OOM |
|
93 // testing. For more information about STIF Logger construction, see STIF Users |
|
94 // Guide. |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 void CHardCodedTestModuleXXX::ConstructL() |
|
98 { |
|
99 //Read logger settings to check whether test case name is to be |
|
100 //appended to log file name. |
|
101 RSettingServer settingServer; |
|
102 TInt ret = settingServer.Connect(); |
|
103 if(ret != KErrNone) |
|
104 { |
|
105 User::Leave(ret); |
|
106 } |
|
107 // Struct to StifLogger settigs. |
|
108 TLoggerSettings loggerSettings; |
|
109 // Parse StifLogger defaults from STIF initialization file. |
|
110 ret = settingServer.GetLoggerSettings(loggerSettings); |
|
111 if(ret != KErrNone) |
|
112 { |
|
113 User::Leave(ret); |
|
114 } |
|
115 // Close Setting server session |
|
116 settingServer.Close(); |
|
117 iAddTestCaseTitleToLogName = loggerSettings.iAddTestCaseTitle; |
|
118 |
|
119 iStdLog = CStifLogger::NewL( KHardCodedTestModuleXXXLogPath, |
|
120 KHardCodedTestModuleXXXLogFile); |
|
121 iLog = iStdLog; |
|
122 |
|
123 // Sample how to use logging |
|
124 _LIT( KLogStart, "HardCodedTestModuleXXX logging starts!" ); |
|
125 iLog->Log( KLogStart ); |
|
126 |
|
127 iVersionLogged = EFalse; |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CHardCodedTestModuleXXX::NewL |
|
132 // Two-phased constructor. |
|
133 // ----------------------------------------------------------------------------- |
|
134 // |
|
135 CHardCodedTestModuleXXX* CHardCodedTestModuleXXX::NewL() |
|
136 { |
|
137 CHardCodedTestModuleXXX* self = new (ELeave) CHardCodedTestModuleXXX; |
|
138 |
|
139 CleanupStack::PushL( self ); |
|
140 self->ConstructL(); |
|
141 CleanupStack::Pop(); |
|
142 |
|
143 return self; |
|
144 |
|
145 } |
|
146 |
|
147 // Destructor |
|
148 CHardCodedTestModuleXXX::~CHardCodedTestModuleXXX() |
|
149 { |
|
150 iLog = NULL; |
|
151 delete iStdLog; |
|
152 iStdLog = NULL; |
|
153 delete iTCLog; |
|
154 iTCLog = NULL; |
|
155 } |
|
156 |
|
157 // ----------------------------------------------------------------------------- |
|
158 // CHardCodedTestModuleXXX::InitL |
|
159 // InitL is used to initialize the Test Module. |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 TInt CHardCodedTestModuleXXX::InitL( |
|
163 TFileName& /*aIniFile*/, |
|
164 TBool /*aFirstTime*/ ) |
|
165 { |
|
166 return KErrNone; |
|
167 |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CHardCodedTestModuleXXX::GetTestCasesL |
|
172 // GetTestCases is used to inquire test cases from the Test Module. Test |
|
173 // cases are stored to array of test cases. The Test Framework will be |
|
174 // the owner of the data in the RPointerArray after GetTestCases return |
|
175 // and it does the memory deallocation. |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 TInt CHardCodedTestModuleXXX::GetTestCasesL( |
|
179 const TFileName& /*aConfig*/, |
|
180 RPointerArray<TTestCaseInfo>& aTestCases ) |
|
181 { |
|
182 |
|
183 // Loop through all test cases and create new |
|
184 // TTestCaseInfo items and append items to aTestCase array |
|
185 for( TInt i = 0; Case(i).iMethod != NULL; i++ ) |
|
186 { |
|
187 |
|
188 // Allocate new TTestCaseInfo from heap for a testcase definition. |
|
189 TTestCaseInfo* newCase = new( ELeave ) TTestCaseInfo(); |
|
190 |
|
191 // PushL TTestCaseInfo to CleanupStack. |
|
192 CleanupStack::PushL( newCase ); |
|
193 |
|
194 // Set number for the testcase. |
|
195 // When the testcase is run, this comes as a parameter to RunTestCaseL. |
|
196 newCase->iCaseNumber = i; |
|
197 |
|
198 // Set title for the test case. This is shown in UI to user. |
|
199 newCase->iTitle.Copy( Case(i).iCaseName ); |
|
200 |
|
201 // Append TTestCaseInfo to the testcase array. After appended |
|
202 // successfully the TTestCaseInfo object is owned (and freed) |
|
203 // by the TestServer. |
|
204 User::LeaveIfError(aTestCases.Append ( newCase ) ); |
|
205 |
|
206 // Pop TTestCaseInfo from the CleanupStack. |
|
207 CleanupStack::Pop( newCase ); |
|
208 |
|
209 } |
|
210 |
|
211 return KErrNone; |
|
212 |
|
213 } |
|
214 |
|
215 // ----------------------------------------------------------------------------- |
|
216 // CHardCodedTestModuleXXX::RunTestCaseL |
|
217 // RunTestCaseL is used to run an individual test case specified |
|
218 // by aTestCase. Test cases that can be run may be requested from |
|
219 // Test Module by GetTestCases method before calling RunTestCase. |
|
220 // ----------------------------------------------------------------------------- |
|
221 // |
|
222 TInt CHardCodedTestModuleXXX::RunTestCaseL( |
|
223 const TInt aCaseNumber, |
|
224 const TFileName& /*aConfig*/, |
|
225 TTestResult& aResult ) |
|
226 { |
|
227 if(!iVersionLogged) |
|
228 { |
|
229 SendTestModuleVersion(); |
|
230 iVersionLogged = ETrue; |
|
231 } |
|
232 |
|
233 // Return value |
|
234 TInt execStatus = KErrNone; |
|
235 |
|
236 // Get the pointer to test case function |
|
237 TCaseInfo tmp = Case ( aCaseNumber ); |
|
238 |
|
239 _LIT( KLogStartTC, "Starting testcase [%S]" ); |
|
240 iLog->Log( KLogStartTC, &tmp.iCaseName); |
|
241 |
|
242 // Check that case number was valid |
|
243 if ( tmp.iMethod != NULL ) |
|
244 { |
|
245 //Open new log file with test case title in file name |
|
246 if(iAddTestCaseTitleToLogName) |
|
247 { |
|
248 //Delete test case logger if exists |
|
249 if(iTCLog) |
|
250 { |
|
251 delete iTCLog; |
|
252 iTCLog = NULL; |
|
253 } |
|
254 |
|
255 TFileName logFileName; |
|
256 TName title; |
|
257 TestModuleIf().GetTestCaseTitleL(title); |
|
258 |
|
259 logFileName.Format(KHardCodedTestModuleXXXLogFileWithTitle, &title); |
|
260 |
|
261 iTCLog = CStifLogger::NewL(KHardCodedTestModuleXXXLogPath, |
|
262 logFileName); |
|
263 iLog = iTCLog; |
|
264 } |
|
265 |
|
266 // Valid case was found, call it via function pointer |
|
267 iMethod = tmp.iMethod; |
|
268 //execStatus = ( this->*iMethod )( aResult ); |
|
269 TRAPD(err, execStatus = ( this->*iMethod )( aResult )); |
|
270 if(iAddTestCaseTitleToLogName) |
|
271 { |
|
272 //Restore standard log and destroy test case logger |
|
273 iLog = iStdLog; |
|
274 delete iTCLog; //Close test case log |
|
275 iTCLog = NULL; |
|
276 } |
|
277 User::LeaveIfError(err); |
|
278 } |
|
279 else |
|
280 { |
|
281 // Valid case was not found, return error. |
|
282 execStatus = KErrNotFound; |
|
283 } |
|
284 |
|
285 // Return case execution status (not the result of the case execution) |
|
286 return execStatus; |
|
287 |
|
288 } |
|
289 |
|
290 // ----------------------------------------------------------------------------- |
|
291 // CHardCodedTestModuleXXX::OOMTestQueryL |
|
292 // Used to check if a particular test case should be run in OOM conditions and |
|
293 // which memory allocations should fail. |
|
294 // ----------------------------------------------------------------------------- |
|
295 // |
|
296 TBool CHardCodedTestModuleXXX::OOMTestQueryL( |
|
297 const TFileName& /* aTestCaseFile */, |
|
298 const TInt aCaseNumber, |
|
299 TOOMFailureType& /* aFailureType */, |
|
300 TInt& aFirstMemFailure, |
|
301 TInt& aLastMemFailure ) |
|
302 { |
|
303 _LIT( KLogOOMTestQueryL, "CHardCodedTestModuleXXX::OOMTestQueryL" ); |
|
304 iLog->Log( KLogOOMTestQueryL ); |
|
305 |
|
306 aFirstMemFailure = Case( aCaseNumber ).iFirstMemoryAllocation; |
|
307 aLastMemFailure = Case( aCaseNumber ).iLastMemoryAllocation; |
|
308 |
|
309 return Case( aCaseNumber ).iIsOOMTest; |
|
310 |
|
311 } |
|
312 |
|
313 // ----------------------------------------------------------------------------- |
|
314 // CHardCodedTestModuleXXX::OOMTestInitializeL |
|
315 // Used to perform the test environment setup for a particular OOM test case. |
|
316 // Test Modules may use the initialization file to read parameters for Test |
|
317 // Module initialization but they can also have their own configure file or |
|
318 // some other routine to initialize themselves. |
|
319 // |
|
320 // NOTE: User may add implementation for OOM test environment initialization. |
|
321 // Usually no implementation is required. |
|
322 // ----------------------------------------------------------------------------- |
|
323 // |
|
324 void CHardCodedTestModuleXXX::OOMTestInitializeL( |
|
325 const TFileName& /* aTestCaseFile */, |
|
326 const TInt /* aCaseNumber */ ) |
|
327 { |
|
328 } |
|
329 |
|
330 // ----------------------------------------------------------------------------- |
|
331 // CHardCodedTestModuleXXX::OOMHandleWarningL |
|
332 // In some cases the heap memory allocation should be skipped, either due to |
|
333 // problems in the OS code or components used by the code being tested, or even |
|
334 // inside the tested components which are implemented this way on purpose (by |
|
335 // design), so it is important to give the tester a way to bypass allocation |
|
336 // failures. |
|
337 // |
|
338 // NOTE: User may add implementation for OOM test warning handling. Usually no |
|
339 // implementation is required. |
|
340 // ----------------------------------------------------------------------------- |
|
341 // |
|
342 void CHardCodedTestModuleXXX::OOMHandleWarningL( |
|
343 const TFileName& /* aTestCaseFile */, |
|
344 const TInt /* aCaseNumber */, |
|
345 TInt& /* aFailNextValue */ ) |
|
346 { |
|
347 } |
|
348 |
|
349 // ----------------------------------------------------------------------------- |
|
350 // CHardCodedTestModuleXXX::OOMTestFinalizeL |
|
351 // Used to perform the test environment cleanup for a particular OOM test case. |
|
352 // |
|
353 // NOTE: User may add implementation for OOM test environment finalization. |
|
354 // Usually no implementation is required. |
|
355 // ----------------------------------------------------------------------------- |
|
356 // |
|
357 void CHardCodedTestModuleXXX::OOMTestFinalizeL( |
|
358 const TFileName& /* aTestCaseFile */, |
|
359 const TInt /* aCaseNumber */ ) |
|
360 { |
|
361 } |
|
362 |
|
363 //----------------------------------------------------------------------------- |
|
364 // CHardCodedTestModuleXXX::SendTestModuleVersion |
|
365 // Method used to send version of test module |
|
366 //----------------------------------------------------------------------------- |
|
367 // |
|
368 void CHardCodedTestModuleXXX::SendTestModuleVersion() |
|
369 { |
|
370 TVersion moduleVersion; |
|
371 moduleVersion.iMajor = TEST_MODULE_VERSION_MAJOR; |
|
372 moduleVersion.iMinor = TEST_MODULE_VERSION_MINOR; |
|
373 moduleVersion.iBuild = TEST_MODULE_VERSION_BUILD; |
|
374 |
|
375 TFileName moduleName; |
|
376 moduleName = _L("HardCodedTestModuleXXX.dll"); |
|
377 |
|
378 TBool newVersionOfMethod = ETrue; |
|
379 TestModuleIf().SendTestModuleVersion(moduleVersion, moduleName, newVersionOfMethod); |
|
380 } |
|
381 |
|
382 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
383 |
|
384 // ----------------------------------------------------------------------------- |
|
385 // LibEntryL is a polymorphic Dll entry point |
|
386 // Returns: CTestModuleBase*: Pointer to Test Module object |
|
387 // ----------------------------------------------------------------------------- |
|
388 // |
|
389 EXPORT_C CTestModuleBase* LibEntryL() |
|
390 { |
|
391 return CHardCodedTestModuleXXX::NewL(); |
|
392 |
|
393 } |
|
394 |
|
395 // ----------------------------------------------------------------------------- |
|
396 // SetRequirements handles test module parameters(implements evolution |
|
397 // version 1 for test module's heap and stack sizes configuring). |
|
398 // Returns: TInt: Symbian error code. |
|
399 // ----------------------------------------------------------------------------- |
|
400 // |
|
401 EXPORT_C TInt SetRequirements( CTestModuleParam*& /*aTestModuleParam*/, |
|
402 TUint32& /*aParameterValid*/ ) |
|
403 { |
|
404 |
|
405 /* --------------------------------- NOTE --------------------------------- |
|
406 USER PANICS occurs in test thread creation when: |
|
407 1) "The panic occurs when the value of the stack size is negative." |
|
408 2) "The panic occurs if the minimum heap size specified is less |
|
409 than KMinHeapSize". |
|
410 KMinHeapSize: "Functions that require a new heap to be allocated will |
|
411 either panic, or will reset the required heap size to this value if |
|
412 a smaller heap size is specified". |
|
413 3) "The panic occurs if the minimum heap size specified is greater than |
|
414 the maximum size to which the heap can grow". |
|
415 Other: |
|
416 1) Make sure that your hardware or Symbian OS is supporting given sizes. |
|
417 e.g. Hardware might support only sizes that are divisible by four. |
|
418 ------------------------------- NOTE end ------------------------------- */ |
|
419 |
|
420 // Normally STIF uses default heap and stack sizes for test thread, see: |
|
421 // KTestThreadMinHeap, KTestThreadMinHeap and KStackSize. |
|
422 // If needed heap and stack sizes can be configured here by user. Remove |
|
423 // comments and define sizes. |
|
424 |
|
425 /* |
|
426 aParameterValid = KStifTestModuleParameterChanged; |
|
427 |
|
428 CTestModuleParamVer01* param = CTestModuleParamVer01::NewL(); |
|
429 // Stack size |
|
430 param->iTestThreadStackSize= 16384; // 16K stack |
|
431 // Heap sizes |
|
432 param->iTestThreadMinHeap = 4096; // 4K heap min |
|
433 param->iTestThreadMaxHeap = 1048576;// 1M heap max |
|
434 |
|
435 aTestModuleParam = param; |
|
436 */ |
|
437 return KErrNone; |
|
438 |
|
439 } |
|
440 |
|
441 |
|
442 // End of File |