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