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