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