|
1 // Copyright (c) 1996-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 the License "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 // e32test\heap\t_fail.cpp |
|
15 // Overview: |
|
16 // Test deterministic, random and fail-next heap failure modes. |
|
17 // API Information: |
|
18 // RHeap. |
|
19 // Details: |
|
20 // - Simulate the EFailNext, EDeterministic, ERandom, ETrueRandom, |
|
21 // ENone modes of heap allocation failures and the burst variants. |
|
22 // - Reallocate the size of an existing cell without moving it |
|
23 // and check the result is as expected. |
|
24 // - Check whether heap has been corrupted by all the tests. |
|
25 // Platforms/Drives/Compatibility: |
|
26 // All |
|
27 // Assumptions/Requirement/Pre-requisites: |
|
28 // Failures and causes: |
|
29 // Base Port information: |
|
30 // |
|
31 // |
|
32 |
|
33 #define __E32TEST_EXTENSION__ |
|
34 #include <e32test.h> |
|
35 #include <hal.h> |
|
36 #include <f32file.h> |
|
37 #include <e32panic.h> |
|
38 #include <e32def.h> |
|
39 #include <e32def_private.h> |
|
40 #include "d_kheap.h" |
|
41 |
|
42 LOCAL_D RTest test(_L("T_FAIL")); |
|
43 RKHeapDevice KHeapDevice; |
|
44 |
|
45 |
|
46 #if defined _DEBUG |
|
47 |
|
48 /** |
|
49 Test we fail burst times for EBurstFailNext |
|
50 Defined as a macro so that it is easier to determine which test is failing. |
|
51 |
|
52 @param aCount The number of allocations before it should fail. |
|
53 @param aBurst The number of allocations that should fail. |
|
54 */ |
|
55 |
|
56 #define __UHEAP_TEST_BURST_FAILNEXT(aCount, aBurst) \ |
|
57 __UHEAP_BURSTFAILNEXT(aCount, aBurst); \ |
|
58 TEST_BURST_FAILNEXT(__UHEAP_CHECKFAILURE, aCount, aBurst) |
|
59 |
|
60 |
|
61 #define __RHEAP_TEST_BURST_FAILNEXT(aHeap, aCount, aBurst) \ |
|
62 __RHEAP_BURSTFAILNEXT(aHeap, aCount, aBurst); \ |
|
63 TEST_BURST_FAILNEXT(__RHEAP_CHECKFAILURE(aHeap), aCount, aBurst) |
|
64 |
|
65 |
|
66 #define __KHEAP_TEST_BURST_FAILNEXT(aCount, aBurst) \ |
|
67 __KHEAP_BURSTFAILNEXT(aCount, aBurst); \ |
|
68 test_Equal(0, __KHEAP_CHECKFAILURE); \ |
|
69 test_KErrNone(KHeapDevice.TestBurstFailNext(aCount, aBurst)); \ |
|
70 test_Equal(aBurst, __KHEAP_CHECKFAILURE) |
|
71 |
|
72 |
|
73 #define TEST_BURST_FAILNEXT(aCheckFailure, aCount, aBurst) \ |
|
74 { \ |
|
75 test_Equal(0, aCheckFailure); \ |
|
76 for (i = 0; i < aCount; i++) \ |
|
77 { \ |
|
78 if (i < aCount - 1) \ |
|
79 { \ |
|
80 p = new TInt; \ |
|
81 test_NotNull(p); \ |
|
82 delete p; \ |
|
83 } \ |
|
84 else \ |
|
85 { \ |
|
86 for (TUint j = 0; j < aBurst; j++) \ |
|
87 { \ |
|
88 p = new TInt; \ |
|
89 test_Equal(NULL, p); \ |
|
90 test_Equal(j + 1, aCheckFailure); \ |
|
91 } \ |
|
92 } \ |
|
93 } \ |
|
94 p = new TInt; \ |
|
95 test_NotNull(p); \ |
|
96 delete p; \ |
|
97 } |
|
98 |
|
99 |
|
100 /** |
|
101 Test we fail burst times for EBurstDeterministic |
|
102 Defined as a macro so that it is easier to determine which test is failing. |
|
103 |
|
104 @param aRate The rate of each set of failures. |
|
105 @param aBurst The number of allocations that should fail. |
|
106 */ |
|
107 #define __UHEAP_TEST_BURST_DETERMINISTIC(aRate, aBurst) \ |
|
108 __UHEAP_SETBURSTFAIL(RHeap::EBurstDeterministic, aRate, aBurst); \ |
|
109 TEST_BURST_DETERMINISTIC(__UHEAP_CHECKFAILURE, aRate, aBurst) |
|
110 |
|
111 #define __RHEAP_TEST_BURST_DETERMINISTIC(aHeap, aRate, aBurst) \ |
|
112 __RHEAP_SETBURSTFAIL(aHeap, RHeap::EBurstDeterministic, aRate, aBurst); \ |
|
113 TEST_BURST_DETERMINISTIC(__RHEAP_CHEAKFAILURE(aHeap), aRate, aBurst) |
|
114 |
|
115 #define __KHEAP_TEST_BURST_DETERMINISTIC(aRate, aBurst) \ |
|
116 __KHEAP_SETBURSTFAIL(RHeap::EBurstDeterministic, aRate, aBurst); \ |
|
117 test_Equal(0, __KHEAP_CHECKFAILURE); \ |
|
118 test_KErrNone(KHeapDevice.TestBurstDeterministic(aRate, aBurst)); \ |
|
119 test_Equal(aBurst * KHeapFailCycles, __KHEAP_CHECKFAILURE) |
|
120 |
|
121 #define TEST_BURST_DETERMINISTIC(aCheckFailure, aRate, aBurst) \ |
|
122 { \ |
|
123 test_Equal(0, aCheckFailure); \ |
|
124 TUint failures = 0; \ |
|
125 for (i = 1; i <= aRate * KHeapFailCycles; i++) \ |
|
126 { \ |
|
127 if (i % aRate == 0) \ |
|
128 { \ |
|
129 for (TInt j = 0; j < aBurst; j++) \ |
|
130 { \ |
|
131 p = new TInt; \ |
|
132 test_Equal(NULL, p); \ |
|
133 test_Equal(++failures, aCheckFailure); \ |
|
134 } \ |
|
135 } \ |
|
136 else \ |
|
137 { \ |
|
138 p = new TInt; \ |
|
139 test(p!=NULL); \ |
|
140 delete p; \ |
|
141 } \ |
|
142 } \ |
|
143 } |
|
144 |
|
145 /** |
|
146 Test we fail burst times for EBurstRandom and EBurstTrueRandom. |
|
147 Even though it is random it should always fail within aRate allocations. |
|
148 Defined as a macro so that it is easier to determine which test is failing. |
|
149 |
|
150 @param aRate The limiting rate of each set of failures. |
|
151 @param aBurst The number of allocations that should fail. |
|
152 |
|
153 */ |
|
154 #define __UHEAP_TEST_BURST_RANDOM(aRate, aBurst) \ |
|
155 __UHEAP_SETBURSTFAIL(RHeap::EBurstRandom, aRate, aBurst); \ |
|
156 TEST_BURST_RANDOM(aRate, aBurst) |
|
157 |
|
158 #define __RHEAP_TEST_BURST_RANDOM(aHeap, aRate, aBurst) \ |
|
159 __RHEAP_SETBURSTFAIL(aHeap, RHeap::EBurstRandom, aRate, aBurst); \ |
|
160 TEST_BURST_RANDOM(aRate, aBurst) |
|
161 |
|
162 #define __UHEAP_TEST_BURST_TRUERANDOM(aRate, aBurst) \ |
|
163 __UHEAP_SETBURSTFAIL(RHeap::EBurstTrueRandom, aRate, aBurst); \ |
|
164 TEST_BURST_RANDOM(aRate, aBurst) |
|
165 |
|
166 #define __RHEAP_TEST_BURST_TRUERANDOM(aHeap, aRate, aBurst) \ |
|
167 __RHEAP_SETBURSTFAIL(aHeap, RHeap::EBurstTrueRandom, aRate, aBurst); \ |
|
168 TEST_BURST_RANDOM(aRate, aBurst) |
|
169 |
|
170 |
|
171 #define TEST_BURST_RANDOM(aRate, aBurst) \ |
|
172 failed = 0; \ |
|
173 for (i = 0; i < aRate * KHeapFailCycles; i++) \ |
|
174 { \ |
|
175 p = new TInt; \ |
|
176 if (p == NULL) \ |
|
177 {/* we've started failing so check that we fail burst times*/ \ |
|
178 failed++; \ |
|
179 for (TInt j = 1; j < aBurst; j++) \ |
|
180 { \ |
|
181 p = new TInt; \ |
|
182 test_Equal(NULL, p); \ |
|
183 } \ |
|
184 } \ |
|
185 delete p; \ |
|
186 } \ |
|
187 test_NotNull(failed); |
|
188 |
|
189 struct SBurstPanicParams |
|
190 { |
|
191 TInt iRate; |
|
192 TUint iBurst; |
|
193 }; |
|
194 |
|
195 TInt TestBurstPanicThread(TAny* aParams) |
|
196 { |
|
197 SBurstPanicParams* burstParams = (SBurstPanicParams*) aParams; |
|
198 __UHEAP_SETBURSTFAIL(RHeap::EBurstDeterministic, burstParams->iRate, burstParams->iBurst); \ |
|
199 return KErrNone; |
|
200 } |
|
201 |
|
202 #define __UHEAP_TEST_BURST_PANIC(aRate, aBurst) \ |
|
203 { \ |
|
204 RThread thread; \ |
|
205 TRequestStatus status; \ |
|
206 SBurstPanicParams threadParams; \ |
|
207 threadParams.iRate = aRate; \ |
|
208 threadParams.iBurst = aBurst; \ |
|
209 test_KErrNone(thread.Create(_L("TestBurstPanicThread"), TestBurstPanicThread, 0x1000, NULL, (TAny*)&threadParams)); \ |
|
210 thread.Logon(status); \ |
|
211 thread.Resume(); \ |
|
212 User::WaitForRequest(status); \ |
|
213 test_Equal(EExitPanic, thread.ExitType()); \ |
|
214 test_Equal(ETHeapBadDebugFailParameter, status.Int()); \ |
|
215 CLOSE_AND_WAIT(thread); \ |
|
216 } |
|
217 |
|
218 GLDEF_C TInt E32Main(void) |
|
219 { |
|
220 |
|
221 test.Title(); |
|
222 test.Start(_L("Test the heap debug failure mechanisms")); |
|
223 |
|
224 // Prepare for __UHEAP tests |
|
225 __UHEAP_RESET; |
|
226 __UHEAP_MARK; |
|
227 |
|
228 // Prepare for __RHEAP tests |
|
229 TInt pageSize; |
|
230 test_KErrNone(HAL::Get(HAL::EMemoryPageSize, pageSize)); |
|
231 |
|
232 RChunk heapChunk; |
|
233 test_KErrNone(heapChunk.CreateLocal(pageSize<<1, pageSize<<1)); |
|
234 RHeap* rHeap = UserHeap::ChunkHeap(NULL, 0, pageSize); |
|
235 test_NotNull(rHeap); |
|
236 __RHEAP_RESET(rHeap); |
|
237 __RHEAP_MARK(rHeap); |
|
238 |
|
239 |
|
240 // Prepare for __KHEAP tests by: |
|
241 // Turning off lazy dll unloading |
|
242 RLoader l; |
|
243 test(l.Connect()==KErrNone); |
|
244 test(l.CancelLazyDllUnload()==KErrNone); |
|
245 l.Close(); |
|
246 |
|
247 // Loading the kernel heap test driver |
|
248 test.Next(_L("Load/open d_kheap test driver")); |
|
249 TInt r = User::LoadLogicalDevice(KHeapTestDriverName); |
|
250 test( r==KErrNone || r==KErrAlreadyExists); |
|
251 if( KErrNone != (r=KHeapDevice.Open()) ) |
|
252 { |
|
253 User::FreeLogicalDevice(KHeapTestDriverName); |
|
254 test.Printf(_L("Could not open LDD")); |
|
255 test(0); |
|
256 } |
|
257 __KHEAP_RESET; |
|
258 __KHEAP_MARK; |
|
259 |
|
260 //============================================================================= |
|
261 test.Next(_L("Test __UHEAP EFailNext")); |
|
262 TInt *p; |
|
263 TInt *q; |
|
264 p=new int; |
|
265 test(p!=NULL); |
|
266 delete p; |
|
267 __UHEAP_FAILNEXT(1); |
|
268 p=new int; |
|
269 test(p==NULL); |
|
270 p=new int; |
|
271 test(p!=NULL); |
|
272 delete p; |
|
273 __UHEAP_FAILNEXT(2); |
|
274 p=new int; |
|
275 q=new int; |
|
276 test(p!=NULL); |
|
277 test(q==NULL); |
|
278 delete p; |
|
279 __UHEAP_FAILNEXT(10); |
|
280 TUint i; |
|
281 for (i=0; i<9; i++) |
|
282 { |
|
283 p=new int; |
|
284 test(p!=NULL); |
|
285 delete p; |
|
286 } |
|
287 p=new int; |
|
288 test(p==NULL); |
|
289 for (i=0; i<30; i++) |
|
290 { |
|
291 p=new int; |
|
292 test(p!=NULL); |
|
293 delete p; |
|
294 } |
|
295 |
|
296 // Test EFailNext with burst macro should default to burst of 1 |
|
297 __UHEAP_SETBURSTFAIL(RAllocator::EFailNext, 5, 5); |
|
298 for (i = 0; i < 4; i++) |
|
299 { |
|
300 p = new TInt; |
|
301 test_NotNull(p); |
|
302 delete p; |
|
303 } |
|
304 p = new TInt; |
|
305 test_Equal(NULL, p); |
|
306 p = new TInt; |
|
307 test_NotNull(p); |
|
308 delete p; |
|
309 |
|
310 |
|
311 //============================================================================= |
|
312 test.Next(_L("Test __UHEAP BurstFailNext")); |
|
313 __UHEAP_TEST_BURST_FAILNEXT(2, 1); |
|
314 __UHEAP_TEST_BURST_FAILNEXT(10, 12); |
|
315 __UHEAP_TEST_BURST_FAILNEXT(5, 50); |
|
316 __UHEAP_TEST_BURST_FAILNEXT(50, 5); |
|
317 |
|
318 // test using burst with non-burst macro should default to burst=1 |
|
319 __UHEAP_SETFAIL(RHeap::EBurstFailNext, 5); |
|
320 for (i = 0; i < 4; i++) |
|
321 { |
|
322 p = new TInt; |
|
323 test_NotNull(p); |
|
324 delete p; |
|
325 } |
|
326 q = new TInt; |
|
327 test_Equal(NULL, q); |
|
328 q = new TInt; |
|
329 test_NotNull(q); |
|
330 delete q; |
|
331 |
|
332 |
|
333 test.Next(_L("Test __RHEAP BurstFailNext")); |
|
334 RHeap* origHeap = User::SwitchHeap(rHeap); |
|
335 |
|
336 __RHEAP_TEST_BURST_FAILNEXT(rHeap, 2, 1); |
|
337 __RHEAP_TEST_BURST_FAILNEXT(rHeap, 10, 12); |
|
338 __RHEAP_TEST_BURST_FAILNEXT(rHeap, 5, 50); |
|
339 __RHEAP_TEST_BURST_FAILNEXT(rHeap, 50, 5); |
|
340 |
|
341 User::SwitchHeap(origHeap); |
|
342 |
|
343 test.Next(_L("Test __KHEAP BurstFailNext")); |
|
344 __KHEAP_TEST_BURST_FAILNEXT(1, 1); |
|
345 __KHEAP_TEST_BURST_FAILNEXT(10, 12); |
|
346 __KHEAP_TEST_BURST_FAILNEXT(5, 50); |
|
347 __KHEAP_TEST_BURST_FAILNEXT(50, 5); |
|
348 __KHEAP_RESET; |
|
349 |
|
350 |
|
351 //============================================================================= |
|
352 test.Next(_L("Test __UHEAP EDeterministic")); |
|
353 __UHEAP_SETFAIL(RHeap::EDeterministic, 1); |
|
354 for (i=0; i<20; i++) |
|
355 { |
|
356 p=new int; |
|
357 test(p==NULL); |
|
358 } |
|
359 __UHEAP_SETFAIL(RHeap::EDeterministic, 2); |
|
360 for (i=0; i<20; i++) |
|
361 { |
|
362 p=new int; |
|
363 q=new int; |
|
364 test(p!=NULL); |
|
365 test(q==NULL); |
|
366 delete p; |
|
367 } |
|
368 __UHEAP_SETFAIL(RHeap::EDeterministic, 11); |
|
369 for (i=1; i<=100; i++) |
|
370 { |
|
371 p=new int; |
|
372 if (i%11==0) |
|
373 test(p==NULL); |
|
374 else |
|
375 test(p!=NULL); |
|
376 delete p; |
|
377 } |
|
378 // Test using burst macro for non-burst fail type |
|
379 // The burst value will be ignored. |
|
380 __UHEAP_SETBURSTFAIL(RHeap::EDeterministic, 2, 3); |
|
381 for (i=0; i<20; i++) |
|
382 { |
|
383 p=new int; |
|
384 q=new int; |
|
385 test(p!=NULL); |
|
386 test(q==NULL); |
|
387 delete p; |
|
388 } |
|
389 |
|
390 //============================================================================= |
|
391 test.Next(_L("Test __UHEAP EBurstDeterministic")); |
|
392 __UHEAP_TEST_BURST_DETERMINISTIC(1, 1); |
|
393 __UHEAP_TEST_BURST_DETERMINISTIC(2, 1); |
|
394 __UHEAP_TEST_BURST_DETERMINISTIC(11, 2); |
|
395 __UHEAP_TEST_BURST_DETERMINISTIC(2, 3); // Test with burst > rate. |
|
396 |
|
397 // Test setting EBurstDeterministic with non-burst MACRO |
|
398 // it should still work but default to a burst rate of 1 |
|
399 __UHEAP_SETFAIL(RHeap::EBurstDeterministic, 2); |
|
400 for (i=0; i<20; i++) |
|
401 { |
|
402 p = new int; |
|
403 q = new int; |
|
404 test_NotNull(p); |
|
405 test_Equal(NULL, q); |
|
406 delete p; |
|
407 } |
|
408 |
|
409 test.Next(_L("Test __RHEAP EBurstDeterministic")); |
|
410 origHeap = User::SwitchHeap(rHeap); |
|
411 |
|
412 __UHEAP_TEST_BURST_DETERMINISTIC(1, 1); |
|
413 __UHEAP_TEST_BURST_DETERMINISTIC(2, 1); |
|
414 __UHEAP_TEST_BURST_DETERMINISTIC(11, 2); |
|
415 __UHEAP_TEST_BURST_DETERMINISTIC(2, 3); // Test with burst > rate. |
|
416 |
|
417 User::SwitchHeap(origHeap); |
|
418 |
|
419 |
|
420 test.Next(_L("Test __KHEAP EBurstDeterministic")); |
|
421 __KHEAP_TEST_BURST_DETERMINISTIC(1, 1); |
|
422 __KHEAP_TEST_BURST_DETERMINISTIC(2, 1); |
|
423 __KHEAP_TEST_BURST_DETERMINISTIC(11, 2); |
|
424 __KHEAP_TEST_BURST_DETERMINISTIC(2, 3); // Test with burst > rate. |
|
425 __KHEAP_RESET; |
|
426 |
|
427 //============================================================================= |
|
428 test.Next(_L("Test __UHEAP ERandom")); |
|
429 __UHEAP_SETFAIL(RHeap::ERandom, 1); |
|
430 for (i=1; i<=100; i++) |
|
431 { |
|
432 p=new int; |
|
433 test(p==NULL); |
|
434 } |
|
435 __UHEAP_SETFAIL(RHeap::ERandom, 2); |
|
436 for (i=1; i<=100; i++) |
|
437 { |
|
438 p=new int; |
|
439 q=new int; |
|
440 test(p==NULL || q==NULL); |
|
441 delete p; |
|
442 delete q; |
|
443 } |
|
444 __UHEAP_SETFAIL(RHeap::ERandom, 10); |
|
445 TInt failed=0; |
|
446 for (i=0; i<10; i++) |
|
447 { |
|
448 p=new int; |
|
449 if (p==NULL) failed++; |
|
450 delete p; |
|
451 } |
|
452 test(failed); |
|
453 for (i=0; i<10; i++) |
|
454 { |
|
455 p=new int; |
|
456 if (p==NULL) failed++; |
|
457 delete p; |
|
458 } |
|
459 test(failed>=2); |
|
460 |
|
461 // Test using the burst macro for ERandom. |
|
462 // Can't really check that it only fails once as being random |
|
463 // it may fail again immediately after a previous failure. |
|
464 __UHEAP_SETBURSTFAIL(RHeap::ERandom, 10, 5); |
|
465 TEST_BURST_RANDOM(10, 1); |
|
466 |
|
467 //============================================================================= |
|
468 test.Next(_L("Test __UHEAP EBurstRandom")); |
|
469 __UHEAP_TEST_BURST_RANDOM(10, 2); |
|
470 __UHEAP_TEST_BURST_RANDOM(15, 5); |
|
471 __UHEAP_TEST_BURST_RANDOM(10, 20); |
|
472 |
|
473 // Test using EBurstRandom with non-burst macro. |
|
474 // Can't really check that it only fails once as being random |
|
475 // it may fail again immediately after a previous failure. |
|
476 __UHEAP_SETFAIL(RHeap::EBurstRandom, 10); |
|
477 __UHEAP_TEST_BURST_RANDOM(10, 1); |
|
478 |
|
479 |
|
480 test.Next(_L("Test __RHEAP EBurstRandom")); |
|
481 origHeap = User::SwitchHeap(rHeap); |
|
482 |
|
483 __RHEAP_TEST_BURST_RANDOM(rHeap, 10, 2); |
|
484 __RHEAP_TEST_BURST_RANDOM(rHeap, 15, 5); |
|
485 __RHEAP_TEST_BURST_RANDOM(rHeap, 10, 20); |
|
486 |
|
487 User::SwitchHeap(origHeap); |
|
488 |
|
489 // No random modes for kernel heap |
|
490 |
|
491 //============================================================================= |
|
492 test.Next(_L("Test __UHEAP ETrueRandom")); |
|
493 __UHEAP_SETFAIL(RHeap::ETrueRandom, 10); |
|
494 failed=0; |
|
495 for (i=0; i<10; i++) |
|
496 { |
|
497 p=new int; |
|
498 if (p==NULL) failed++; |
|
499 delete p; |
|
500 } |
|
501 test(failed); |
|
502 for (i=0; i<10; i++) |
|
503 { |
|
504 p=new int; |
|
505 if (p==NULL) failed++; |
|
506 delete p; |
|
507 } |
|
508 test(failed>=2); |
|
509 |
|
510 // Test using ETrueRandom with burst macro. |
|
511 // Can't really check that it only fails once as being random |
|
512 // it may fail again immediately after a previous failure. |
|
513 __UHEAP_SETBURSTFAIL(RHeap::ETrueRandom, 10, 2); |
|
514 TEST_BURST_RANDOM(10, 1); |
|
515 |
|
516 //============================================================================= |
|
517 test.Next(_L("Test __UHEAP EBurstTrueRandom")); |
|
518 __UHEAP_TEST_BURST_TRUERANDOM(10, 2); |
|
519 __UHEAP_TEST_BURST_TRUERANDOM(15, 5); |
|
520 __UHEAP_TEST_BURST_TRUERANDOM(10, 20); |
|
521 |
|
522 // Test using EBurstRandom with non-burst macro. |
|
523 // Can't really check that it only fails once as being random |
|
524 // it may fail again immediately after a previous failure. |
|
525 __UHEAP_SETFAIL(RHeap::EBurstTrueRandom, 10); |
|
526 TEST_BURST_RANDOM(10, 1); |
|
527 |
|
528 test.Next(_L("Test __RHEAP EBurstTrueRandom")); |
|
529 origHeap = User::SwitchHeap(rHeap); |
|
530 |
|
531 __RHEAP_TEST_BURST_TRUERANDOM(rHeap, 10, 2); |
|
532 __RHEAP_TEST_BURST_TRUERANDOM(rHeap, 15, 5); |
|
533 __RHEAP_TEST_BURST_TRUERANDOM(rHeap, 10, 20); |
|
534 |
|
535 User::SwitchHeap(origHeap); |
|
536 |
|
537 // No random modes for kernel heap |
|
538 |
|
539 //============================================================================= |
|
540 test.Next(_L("Test __UHEAP ENone")); |
|
541 __UHEAP_SETFAIL(RHeap::ENone, 0); |
|
542 for (i=0; i<100; i++) |
|
543 { |
|
544 p=new int; |
|
545 test(p!=NULL); |
|
546 delete p; |
|
547 } |
|
548 |
|
549 // Test using ENone with burst macro. |
|
550 __UHEAP_SETBURSTFAIL(RHeap::ENone, 0, 0); |
|
551 for (i=0; i<100; i++) |
|
552 { |
|
553 p = new TInt; |
|
554 test_NotNull(p); |
|
555 delete p; |
|
556 } |
|
557 |
|
558 //============================================================================= |
|
559 test.Next(_L("Test __UHEAP Reset")); |
|
560 __UHEAP_SETFAIL(RHeap::EDeterministic, 1); |
|
561 for (i=0; i<10; i++) |
|
562 { |
|
563 p=new int; |
|
564 test(p==NULL); |
|
565 } |
|
566 __UHEAP_RESET; |
|
567 p=new int; |
|
568 test(p!=NULL); |
|
569 delete p; |
|
570 |
|
571 |
|
572 // Test using EReset with non-burst macro. |
|
573 __UHEAP_SETFAIL(RHeap::EDeterministic, 1); |
|
574 for (i=0; i<10; i++) |
|
575 { |
|
576 p=new int; |
|
577 test(p==NULL); |
|
578 } |
|
579 __UHEAP_SETFAIL(RHeap::EReset, 1); |
|
580 p=new int; |
|
581 test(p!=NULL); |
|
582 delete p; |
|
583 |
|
584 // Test using EReset with burst macro. |
|
585 __UHEAP_SETFAIL(RHeap::EDeterministic, 1); |
|
586 for (i=0; i<10; i++) |
|
587 { |
|
588 p=new int; |
|
589 test(p==NULL); |
|
590 } |
|
591 __UHEAP_SETBURSTFAIL(RHeap::EReset, 1, 1); |
|
592 p=new int; |
|
593 test(p!=NULL); |
|
594 delete p; |
|
595 |
|
596 //============================================================================= |
|
597 test.Next(_L("Test ETHeapBadDebugFailParameter panics")); |
|
598 __UHEAP_TEST_BURST_PANIC(50, KMaxTUint16 + 1); |
|
599 __UHEAP_TEST_BURST_PANIC(KMaxTUint16 + 1, 2); |
|
600 __UHEAP_TEST_BURST_PANIC(-50, 3); |
|
601 |
|
602 // Test maximum aRate and aBurst values don't panic. |
|
603 __UHEAP_TEST_BURST_FAILNEXT(2, KMaxTUint16); // Use failnext as quicker |
|
604 __UHEAP_TEST_BURST_FAILNEXT(KMaxTUint16, 2); |
|
605 |
|
606 //============================================================================= |
|
607 test.Next(_L("Test __UHEAP User::ReAlloc without cell moving")); |
|
608 TAny* a = User::Alloc(256); |
|
609 test(a!=NULL); |
|
610 __UHEAP_FAILNEXT(1); |
|
611 TAny* a2 = User::ReAlloc(a,192); |
|
612 test(a2==a); |
|
613 a2 = User::ReAlloc(a,128); |
|
614 test(a2==a); |
|
615 a2 = User::ReAlloc(a,256); |
|
616 test(a2==NULL); |
|
617 a2 = User::ReAlloc(a,256); |
|
618 test(a2==a); |
|
619 User::Free(a); |
|
620 |
|
621 //============================================================================= |
|
622 // Clean up |
|
623 __RHEAP_MARKEND(rHeap); |
|
624 rHeap->Close(); |
|
625 |
|
626 __KHEAP_MARKEND; |
|
627 // Ensure all kernel heap debug failures are not active for future tests etc. |
|
628 __KHEAP_RESET; |
|
629 KHeapDevice.Close(); |
|
630 User::FreeLogicalDevice(KHeapTestDriverName); |
|
631 |
|
632 __UHEAP_MARKEND; |
|
633 test.End(); |
|
634 return(KErrNone); |
|
635 } |
|
636 |
|
637 #else |
|
638 GLDEF_C TInt E32Main() |
|
639 // |
|
640 // __KHEAP_SETFAIL etc. not available in release mode, so don't test |
|
641 // |
|
642 { |
|
643 |
|
644 test.Title(); |
|
645 test.Start(_L("No tests in release mode")); |
|
646 test.End(); |
|
647 return(KErrNone); |
|
648 } |
|
649 #endif |
|
650 |