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