0
|
1 |
// Copyright (c) 1995-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_heapdb.cpp
|
|
15 |
// Tests the _DEBUG build dependent aspects of RHeap
|
|
16 |
// Overview:
|
|
17 |
// Tests debug build dependent aspects of RHeap.
|
|
18 |
// API Information:
|
|
19 |
// RHeap.
|
|
20 |
// Details:
|
|
21 |
// Test1:
|
|
22 |
// - Allocate a variety of user heap objects and verify the nesting level, allocation count,
|
|
23 |
// allocation level and length are correct. Also check for heap corruption.
|
|
24 |
// Test 2:
|
|
25 |
// - Some assorted indirect calls to alloc, and verify the nesting level, allocation count,
|
|
26 |
// allocation level and length are correct. Also check for heap corruption.
|
|
27 |
// Test3:
|
|
28 |
// - Allocate a variety of objects and verify that the UHEAP_CHECKALL count is correct.
|
|
29 |
// - Verify the nesting of UHEAP_MARK and UHEAP_MARKEND macros.
|
|
30 |
// - Check the validity of the current thread's default heap.
|
|
31 |
// Test4:
|
|
32 |
// - Allocate memory for different heaps, check the total number of allocated cells
|
|
33 |
// for different heaps and for the current nested level is as expected.
|
|
34 |
// Test5:
|
|
35 |
// - Simulate heap allocation failures, allocate the memory from user and
|
|
36 |
// kernel heap and check results are as expected.
|
|
37 |
// Platforms/Drives/Compatibility:
|
|
38 |
// All
|
|
39 |
// Assumptions/Requirement/Pre-requisites:
|
|
40 |
// Failures and causes:
|
|
41 |
// Base Port information:
|
|
42 |
//
|
|
43 |
//
|
|
44 |
|
|
45 |
#include <e32test.h>
|
|
46 |
#include <e32def.h>
|
|
47 |
#include <e32def_private.h>
|
189
|
48 |
#include "dla.h"
|
|
49 |
#include "slab.h"
|
|
50 |
#include "page_alloc.h"
|
|
51 |
#include "heap_hybrid.h"
|
|
52 |
#define KHEAPCELLINFO RHybridHeap::SHeapCellInfo
|
0
|
53 |
|
|
54 |
LOCAL_D RTest test(_L("T_HEAPDB"));
|
|
55 |
|
|
56 |
#if defined(_DEBUG)
|
|
57 |
|
189
|
58 |
KHEAPCELLINFO CellInfo[4];
|
0
|
59 |
|
|
60 |
class RTestHeap : public RHeap
|
|
61 |
{
|
|
62 |
public:
|
189
|
63 |
void AttachInfo(KHEAPCELLINFO* aInfo)
|
|
64 |
{
|
|
65 |
RHybridHeap::STestCommand cmd;
|
|
66 |
cmd.iData = aInfo;
|
|
67 |
cmd.iCommand = RHybridHeap::ETestData;
|
|
68 |
DebugFunction(RHeap::EHybridHeap, (TAny*)&cmd);
|
|
69 |
}
|
0
|
70 |
};
|
|
71 |
|
|
72 |
void AttachToHeap(RHeap* aHeap, TInt aInfo)
|
|
73 |
{
|
|
74 |
if (!aHeap)
|
|
75 |
aHeap = (RHeap*)&User::Allocator();
|
|
76 |
((RTestHeap*)aHeap)->AttachInfo(CellInfo + aInfo);
|
|
77 |
}
|
|
78 |
|
|
79 |
void TestCellInfo(TInt aInfo, TInt aNest, TInt aAllocCount, TInt aLevelAlloc, TInt aSize, TAny* aAddr)
|
|
80 |
{
|
189
|
81 |
(void) aSize;
|
|
82 |
KHEAPCELLINFO& ci = CellInfo[aInfo];
|
0
|
83 |
RHeap::SDebugCell& cell = *ci.iStranded;
|
|
84 |
test(cell.nestingLevel == aNest);
|
|
85 |
test(cell.allocCount == aAllocCount);
|
|
86 |
test(ci.iLevelAlloc == aLevelAlloc);
|
|
87 |
test((&cell+1) == aAddr);
|
|
88 |
}
|
|
89 |
|
|
90 |
const TInt KMaxFailureRate=100;
|
|
91 |
const TInt KThreadMemError=-50;
|
|
92 |
|
|
93 |
LOCAL_D TInt heapCount=1;
|
|
94 |
LOCAL_D RSemaphore threadSemaphore;
|
|
95 |
LOCAL_D TBool array1[KMaxFailureRate+1];
|
|
96 |
LOCAL_D TBool array2[KMaxFailureRate+1];
|
|
97 |
|
|
98 |
LOCAL_C TInt ThreadEntryPoint(TAny*)
|
|
99 |
{
|
|
100 |
threadSemaphore.Wait();
|
|
101 |
if (User::Alloc(4)==NULL)
|
|
102 |
return(KThreadMemError);
|
|
103 |
else
|
|
104 |
return(KErrNone);
|
|
105 |
}
|
|
106 |
|
|
107 |
class TestRHeapDebug
|
|
108 |
{
|
|
109 |
public:
|
|
110 |
void Test1(void);
|
|
111 |
void Test2(void);
|
|
112 |
void Test3(void);
|
|
113 |
void Test4(void);
|
|
114 |
void Test5(void);
|
|
115 |
};
|
|
116 |
|
|
117 |
LOCAL_C RHeap* allocHeap(TInt aSize)
|
|
118 |
//
|
|
119 |
// Allocate a chunk heap with max size aSize
|
|
120 |
//
|
|
121 |
{
|
|
122 |
|
|
123 |
TName n;
|
|
124 |
n.Format(_L("TESTHEAP%d"),heapCount++);
|
|
125 |
return(User::ChunkHeap(&n,aSize,aSize));
|
|
126 |
}
|
|
127 |
|
|
128 |
void TestRHeapDebug::Test1(void)
|
|
129 |
{
|
|
130 |
|
|
131 |
TAny* p;
|
|
132 |
|
|
133 |
///////////////////////
|
|
134 |
// Test heaven cell is found for each method of allocating memory
|
|
135 |
////////////////////////
|
|
136 |
|
|
137 |
// new(TInt aSize)
|
|
138 |
__UHEAP_MARK;
|
|
139 |
__UHEAP_CHECKALL(0);
|
|
140 |
__UHEAP_CHECK(0);
|
|
141 |
p=new TUint;
|
|
142 |
__UHEAP_CHECKALL(1);
|
|
143 |
__UHEAP_CHECK(1);
|
|
144 |
__UHEAP_MARKEND;
|
|
145 |
__UHEAP_CHECK(0);
|
|
146 |
__UHEAP_CHECKALL(1);
|
|
147 |
TestCellInfo(0, 1, 1, 1, User::AllocLen(p), p);
|
|
148 |
User::Free(p);
|
|
149 |
|
|
150 |
// new(TInt aSize,TInt anExtraSize)
|
|
151 |
__UHEAP_MARK;
|
|
152 |
p=new(4) TUint;
|
|
153 |
__UHEAP_MARKEND;
|
|
154 |
TestCellInfo(0, 1, 1, 1, User::AllocLen(p), p);
|
|
155 |
User::Free(p);
|
|
156 |
|
|
157 |
// new(TInt aSize,TLeave)
|
|
158 |
__UHEAP_MARK;
|
|
159 |
p=new(ELeave) TUint;
|
|
160 |
__UHEAP_MARKEND;
|
|
161 |
TestCellInfo(0, 1, 1, 1, User::AllocLen(p), p);
|
|
162 |
User::Free(p);
|
|
163 |
|
|
164 |
// Alloc
|
|
165 |
__UHEAP_MARK;
|
|
166 |
p=User::Alloc(32);
|
|
167 |
__UHEAP_MARKEND;
|
|
168 |
TestCellInfo(0, 1, 1, 1, User::AllocLen(p), p);
|
|
169 |
User::Free(p);
|
|
170 |
|
|
171 |
// AllocL
|
|
172 |
__UHEAP_MARK;
|
|
173 |
p=User::AllocL(32);
|
|
174 |
__UHEAP_MARKEND;
|
|
175 |
TestCellInfo(0, 1, 1, 1, User::AllocLen(p), p);
|
|
176 |
User::Free(p);
|
|
177 |
|
|
178 |
// ReAlloc with Null parameter
|
|
179 |
__UHEAP_MARK;
|
|
180 |
p=User::ReAlloc(NULL, 32);
|
|
181 |
__UHEAP_MARKEND;
|
|
182 |
TestCellInfo(0, 1, 1, 1, User::AllocLen(p), p);
|
|
183 |
User::Free(p);
|
|
184 |
|
|
185 |
// ReAllocL with Null parameter
|
|
186 |
__UHEAP_MARK;
|
|
187 |
p=User::ReAllocL(NULL, 32);
|
|
188 |
__UHEAP_MARKEND;
|
|
189 |
TestCellInfo(0, 1, 1, 1, User::AllocLen(p), p);
|
|
190 |
User::Free(p);
|
|
191 |
|
|
192 |
// ReAlloc with non Null parameter
|
|
193 |
__UHEAP_MARK;
|
|
194 |
p=User::Alloc(128);
|
|
195 |
p=User::ReAlloc(p, 4);
|
|
196 |
__UHEAP_MARKEND;
|
|
197 |
TestCellInfo(0, 1, 1, 1, User::AllocLen(p), p);
|
|
198 |
User::Free(p);
|
|
199 |
|
|
200 |
// ReAlloc with non Null parameter such that cell is moved in memory
|
|
201 |
__UHEAP_MARK;
|
|
202 |
p=User::Alloc(128);
|
|
203 |
TAny* temp=User::Alloc(128);
|
|
204 |
p=User::ReAlloc(p, 526);
|
|
205 |
User::Free(temp);
|
|
206 |
__UHEAP_MARKEND;
|
|
207 |
TestCellInfo(0, 1, 3, 1, User::AllocLen(p), p);
|
|
208 |
User::Free(p);
|
|
209 |
|
|
210 |
// ReAllocL with non Null parameter
|
|
211 |
__UHEAP_MARK;
|
|
212 |
p=User::Alloc(32);
|
|
213 |
p=User::ReAllocL(p, 128);
|
|
214 |
__UHEAP_MARKEND;
|
|
215 |
TestCellInfo(0, 1, 1, 1, User::AllocLen(p), p);
|
|
216 |
User::Free(p);
|
|
217 |
}
|
|
218 |
|
|
219 |
|
|
220 |
void TestRHeapDebug::Test2(void)
|
|
221 |
{
|
|
222 |
// Some assorted indirect calls to alloc
|
|
223 |
|
|
224 |
__UHEAP_MARK;
|
|
225 |
CBufFlat* pBuf=CBufFlat::NewL(10);
|
|
226 |
__UHEAP_MARKEND;
|
|
227 |
TestCellInfo(0, 1, 1, 1, User::AllocLen(pBuf), pBuf);
|
|
228 |
delete pBuf;
|
|
229 |
|
|
230 |
__UHEAP_MARK;
|
|
231 |
HBufC8* pHBufC=HBufC8::New(10);
|
|
232 |
__UHEAP_MARKEND;
|
|
233 |
TestCellInfo(0, 1, 1, 1, User::AllocLen(pHBufC), pHBufC);
|
|
234 |
delete pHBufC;
|
|
235 |
|
|
236 |
// can also create a HBufC8 from a descriptor by using TDesC::Alloc
|
|
237 |
}
|
|
238 |
|
|
239 |
|
|
240 |
void TestRHeapDebug::Test3(void)
|
|
241 |
{
|
|
242 |
|
|
243 |
// Check num of cells detected is correct and CHECKTOTALNUM is ok
|
|
244 |
// NOTE: CHECKTOTALNUM counts the TOTAL number of allocations in the heap regardless of
|
|
245 |
// any MARKSTARTs
|
|
246 |
// NOTE: the alloc count commences from the FIRST occurrence of a MARKSTART, so if one is nested
|
|
247 |
// in another the alloc count will only start from the second MARKSTART if it applies to a
|
|
248 |
// different heap.
|
|
249 |
__UHEAP_MARK;
|
|
250 |
__UHEAP_CHECKALL(0);
|
|
251 |
TAny* p1= new TUint;
|
|
252 |
__UHEAP_CHECKALL(1);
|
|
253 |
TAny* p2= new(20) TUint;
|
|
254 |
__UHEAP_CHECKALL(2);
|
|
255 |
TAny* p3= User::Alloc(15);
|
|
256 |
__UHEAP_CHECKALL(3);
|
|
257 |
__UHEAP_MARK;
|
|
258 |
__UHEAP_CHECK(0);
|
|
259 |
TAny* p4=User::Alloc(1);
|
|
260 |
TAny* p5 =new TUint;
|
|
261 |
__UHEAP_CHECK(2);
|
|
262 |
__UHEAP_CHECKALL(5);
|
|
263 |
__UHEAP_MARKEND;
|
|
264 |
TestCellInfo(0, 2, 4, 2, User::AllocLen(p4), p4);
|
|
265 |
__UHEAP_CHECKALL(5);
|
|
266 |
__UHEAP_CHECK(3);
|
|
267 |
__UHEAP_MARKENDC(3);
|
|
268 |
User::Free(p1);
|
|
269 |
User::Free(p2);
|
|
270 |
User::Free(p3);
|
|
271 |
User::Free(p4);
|
|
272 |
User::Free(p5);
|
|
273 |
|
|
274 |
// Check some nesting out
|
|
275 |
p1=new TUint;
|
|
276 |
__UHEAP_MARK;
|
|
277 |
p2=new TUint;
|
|
278 |
__UHEAP_MARK;
|
|
279 |
p3=new TUint;
|
|
280 |
__UHEAP_MARK;
|
|
281 |
p4=new TUint;
|
|
282 |
__UHEAP_MARKEND;
|
|
283 |
TestCellInfo(0, 3, 3, 1, User::AllocLen(p4), p4);
|
|
284 |
__UHEAP_MARKEND;
|
|
285 |
TestCellInfo(0, 2, 2, 1, User::AllocLen(p3), p3);
|
|
286 |
__UHEAP_MARKEND;
|
|
287 |
TestCellInfo(0, 1, 1, 1, User::AllocLen(p2), p2);
|
|
288 |
User::Free(p1);
|
|
289 |
User::Free(p2);
|
|
290 |
User::Free(p3);
|
|
291 |
User::Free(p4);
|
|
292 |
User::Check();
|
|
293 |
}
|
|
294 |
|
|
295 |
void TestRHeapDebug::Test4(void)
|
|
296 |
{
|
|
297 |
// Test with different heaps
|
|
298 |
TAny* p1=new TUint;
|
|
299 |
__UHEAP_MARK; // Default start
|
|
300 |
__UHEAP_CHECKALL(1);
|
|
301 |
__UHEAP_CHECK(0);
|
|
302 |
TAny* p2=new TUint;
|
|
303 |
RHeap* pHeap1=allocHeap(1000);
|
|
304 |
AttachToHeap(pHeap1,1);
|
|
305 |
__RHEAP_MARK(pHeap1); // Heap1 start
|
|
306 |
__RHEAP_CHECKALL(pHeap1,0);
|
|
307 |
__RHEAP_CHECK(pHeap1,0);
|
|
308 |
TAny* p3=pHeap1->Alloc(4);
|
|
309 |
__RHEAP_CHECKALL(pHeap1,1);
|
|
310 |
__RHEAP_CHECK(pHeap1,1);
|
|
311 |
__RHEAP_CHECKALL(pHeap1,1);
|
|
312 |
__UHEAP_CHECKALL(3);
|
|
313 |
RHeap* pHeap2=allocHeap(1000);
|
|
314 |
AttachToHeap(pHeap2,2);
|
|
315 |
RHeap* pHeap3=allocHeap(1000);
|
|
316 |
AttachToHeap(pHeap3,3);
|
|
317 |
__UHEAP_CHECKALL(5);
|
|
318 |
__RHEAP_MARK(pHeap2); // Heap2 start
|
|
319 |
__RHEAP_MARK(pHeap3); // Heap3 start
|
|
320 |
TAny* p4=pHeap2->Alloc(8);
|
|
321 |
TAny* p5=pHeap2->Alloc(37);
|
|
322 |
TAny* p6=pHeap3->Alloc(32);
|
|
323 |
TAny* p7=pHeap1->Alloc(43);
|
|
324 |
__UHEAP_CHECKALL(5);
|
|
325 |
__RHEAP_CHECKALL(pHeap1,2);
|
|
326 |
__RHEAP_CHECKALL(pHeap2,2);
|
|
327 |
__RHEAP_CHECKALL(pHeap3,1);
|
|
328 |
__RHEAP_MARKEND(pHeap3); // Heap3 end
|
|
329 |
TestCellInfo(3, 1, 1, 1, pHeap3->AllocLen(p6), p6);
|
|
330 |
__RHEAP_MARKEND(pHeap2); // Heap2 end
|
|
331 |
TestCellInfo(2, 1, 1, 2, pHeap2->AllocLen(p4), p4);
|
|
332 |
pHeap1->Free(p3);
|
|
333 |
__RHEAP_MARKEND(pHeap1); // Heap1 end
|
|
334 |
TestCellInfo(1, 1, 2, 1, pHeap1->AllocLen(p7), p7);
|
|
335 |
User::Free(p1);
|
|
336 |
User::Free(p2);
|
|
337 |
pHeap2->Free(p4);
|
|
338 |
pHeap2->Free(p5);
|
|
339 |
pHeap3->Free(p6);
|
|
340 |
pHeap1->Free(p7);
|
|
341 |
__UHEAP_CHECKALL(3);
|
|
342 |
pHeap2->Close();
|
|
343 |
pHeap3->Close();
|
|
344 |
__UHEAP_MARKEND;
|
|
345 |
pHeap1->Close();
|
|
346 |
__UHEAP_CHECKALL(0);
|
|
347 |
}
|
|
348 |
|
|
349 |
void TestRHeapDebug::Test5()
|
|
350 |
// Check the alloc failure macros
|
|
351 |
{
|
|
352 |
TAny *p, *p1;
|
|
353 |
RHeap* pHeap=allocHeap(1000);
|
|
354 |
|
|
355 |
// DETERMINISTIC FAILURE
|
|
356 |
__UHEAP_RESET;
|
|
357 |
__UHEAP_FAILNEXT(1);
|
|
358 |
test(User::Alloc(1)==NULL);
|
|
359 |
p=User::Alloc(1);
|
|
360 |
test(p!=NULL);
|
|
361 |
User::FreeZ(p);
|
|
362 |
__UHEAP_RESET;
|
|
363 |
|
|
364 |
__RHEAP_RESET(pHeap);
|
|
365 |
__RHEAP_FAILNEXT(pHeap,1);
|
|
366 |
test(pHeap->Alloc(1)==NULL);
|
|
367 |
p=pHeap->Alloc(1);
|
|
368 |
test(p!=NULL);
|
|
369 |
pHeap->FreeZ(p);
|
|
370 |
__RHEAP_RESET(pHeap);
|
|
371 |
|
|
372 |
__KHEAP_RESET;
|
|
373 |
__KHEAP_FAILNEXT(1);
|
|
374 |
RSemaphore semaphore;
|
|
375 |
test(semaphore.CreateLocal(1)==KErrNoMemory); // allocated from the kernel heap
|
|
376 |
test(semaphore.CreateLocal(1)==KErrNone);
|
|
377 |
semaphore.Close();
|
|
378 |
__KHEAP_RESET;
|
|
379 |
|
|
380 |
__UHEAP_SETFAIL(RHeap::EDeterministic,0);
|
|
381 |
test(User::Alloc(1)==NULL);
|
|
382 |
__UHEAP_RESET;
|
|
383 |
|
|
384 |
__RHEAP_SETFAIL(pHeap,RHeap::EDeterministic,0);
|
|
385 |
test(pHeap->Alloc(1)==NULL);
|
|
386 |
__RHEAP_RESET(pHeap);
|
|
387 |
|
|
388 |
__KHEAP_SETFAIL(RHeap::EDeterministic,0);
|
|
389 |
test(semaphore.CreateLocal(1)==KErrNoMemory);
|
|
390 |
__KHEAP_RESET;
|
|
391 |
|
|
392 |
TInt determinism;
|
|
393 |
for(determinism=1; determinism<=KMaxFailureRate; determinism++)
|
|
394 |
{
|
|
395 |
__UHEAP_SETFAIL(RHeap::EDeterministic,determinism);
|
|
396 |
__RHEAP_SETFAIL(pHeap,RHeap::EDeterministic,determinism);
|
|
397 |
for(TInt ii=1; ii<=determinism; ii++)
|
|
398 |
{
|
|
399 |
p=User::Alloc(1);
|
|
400 |
p1=pHeap->Alloc(1);
|
|
401 |
if(ii%determinism==0)
|
|
402 |
{
|
|
403 |
test(p==NULL);
|
|
404 |
test(p1==NULL);
|
|
405 |
}
|
|
406 |
else
|
|
407 |
{
|
|
408 |
test(p!=NULL);
|
|
409 |
test(p1!=NULL);
|
|
410 |
pHeap->Free(p1);
|
|
411 |
User::Free(p);
|
|
412 |
}
|
|
413 |
}
|
|
414 |
}
|
|
415 |
__UHEAP_RESET;
|
|
416 |
__RHEAP_RESET(pHeap);
|
|
417 |
|
|
418 |
// Test SetKernelAllocFail
|
|
419 |
// its not possible to test SetKernelAllocFail as above as it is not possible to control the
|
|
420 |
// number of calls to Alloc for the dernel heap - but the following will definitely fail:
|
|
421 |
__KHEAP_SETFAIL(RHeap::EDeterministic,1);
|
|
422 |
RSemaphore r;
|
|
423 |
test(r.CreateLocal(1)==KErrNoMemory); // allocated from the kernel heap
|
|
424 |
__KHEAP_SETFAIL(RHeap::EDeterministic,50);
|
|
425 |
test(r.CreateLocal(1)==KErrNone);
|
|
426 |
r.Close();
|
|
427 |
__KHEAP_RESET;
|
|
428 |
|
|
429 |
// RANDOM TESTS
|
|
430 |
TInt numOccurences1, numOccurences2;
|
|
431 |
|
|
432 |
__UHEAP_SETFAIL(RHeap::ERandom,1);
|
|
433 |
test(User::Alloc(1)==NULL);
|
|
434 |
__UHEAP_RESET;
|
|
435 |
|
|
436 |
__RHEAP_SETFAIL(pHeap,RHeap::ERandom,1);
|
|
437 |
test(pHeap->Alloc(1)==NULL);
|
|
438 |
__RHEAP_RESET(pHeap);
|
|
439 |
|
|
440 |
// __KHEAP_SETFAIL(RHeap::ERandom,1);
|
|
441 |
// test(semaphore.CreateLocal(1)==KErrNoMemory);
|
|
442 |
// __KHEAP_RESET;
|
|
443 |
|
|
444 |
__UHEAP_SETFAIL(RHeap::ETrueRandom,1);
|
|
445 |
test(User::Alloc(1)==NULL);
|
|
446 |
__UHEAP_RESET;
|
|
447 |
|
|
448 |
__RHEAP_SETFAIL(pHeap,RHeap::ETrueRandom,1);
|
|
449 |
test(pHeap->Alloc(1)==NULL);
|
|
450 |
__RHEAP_RESET(pHeap);
|
|
451 |
|
|
452 |
// __KHEAP_SETFAIL(RHeap::ETrueRandom,1);
|
|
453 |
// test(semaphore.CreateLocal(1)==KErrNoMemory);
|
|
454 |
// __KHEAP_RESET;
|
|
455 |
|
|
456 |
for(determinism=1; determinism<=KMaxFailureRate; determinism++)
|
|
457 |
{
|
|
458 |
__UHEAP_SETFAIL(RHeap::ERandom,determinism);
|
|
459 |
__RHEAP_SETFAIL(pHeap,RHeap::ERandom,determinism);
|
|
460 |
TInt ii;
|
|
461 |
for(ii=1; ii<=determinism; ii++)
|
|
462 |
{
|
|
463 |
p=User::Alloc(1);
|
|
464 |
p1=pHeap->Alloc(1);
|
|
465 |
array1[ii]=(p==NULL);
|
|
466 |
array2[ii]=(p==NULL);
|
|
467 |
if(p)
|
|
468 |
User::Free(p);
|
|
469 |
if(p1)
|
|
470 |
pHeap->Free(p1);
|
|
471 |
}
|
|
472 |
numOccurences1=0;
|
|
473 |
numOccurences2=0;
|
|
474 |
for(ii=1; ii<=determinism; ii++)
|
|
475 |
{
|
|
476 |
if(array1[ii])
|
|
477 |
numOccurences1++;
|
|
478 |
if(array2[ii])
|
|
479 |
numOccurences2++;
|
|
480 |
}
|
|
481 |
test(numOccurences1==1);
|
|
482 |
test(numOccurences2==1);
|
|
483 |
}
|
|
484 |
__UHEAP_RESET;
|
|
485 |
__RHEAP_RESET(pHeap);
|
|
486 |
|
|
487 |
__UHEAP_SETFAIL(RHeap::ERandom,5);
|
|
488 |
TInt ii;
|
|
489 |
for(ii=1; ii<=50; ii++)
|
|
490 |
{
|
|
491 |
p=User::Alloc(1);
|
|
492 |
array1[ii]=(p==NULL);
|
|
493 |
if(p)
|
|
494 |
User::Free(p);
|
|
495 |
}
|
|
496 |
numOccurences1=0;
|
|
497 |
numOccurences2=0;
|
|
498 |
for(ii=1; ii<=50; ii++)
|
|
499 |
{
|
|
500 |
if(array1[ii])
|
|
501 |
{
|
|
502 |
numOccurences1++;
|
|
503 |
numOccurences2++;
|
|
504 |
}
|
|
505 |
if(ii%5==0)
|
|
506 |
{
|
|
507 |
test(numOccurences1==1);
|
|
508 |
numOccurences1=0;
|
|
509 |
}
|
|
510 |
}
|
|
511 |
test(numOccurences2==50/5);
|
|
512 |
|
|
513 |
// Cannot really test random failure of the kernel heap accurately
|
|
514 |
|
|
515 |
pHeap->Close();
|
|
516 |
//client.Disconnect();
|
|
517 |
|
|
518 |
// Test failing the heap of a child thread
|
|
519 |
// 1st test that it allocates normally
|
|
520 |
TRequestStatus stat;
|
|
521 |
RThread thread;
|
|
522 |
test(threadSemaphore.CreateLocal(0)==KErrNone);
|
|
523 |
test(thread.Create(_L("Thread"),ThreadEntryPoint,KDefaultStackSize,0x200,0x200,NULL)==KErrNone);
|
|
524 |
thread.Logon(stat);
|
|
525 |
thread.Resume();
|
|
526 |
threadSemaphore.Signal();
|
|
527 |
User::WaitForRequest(stat);
|
|
528 |
test(thread.ExitReason()==KErrNone);
|
|
529 |
thread.Close();
|
|
530 |
#if defined(CAN_TEST_THREADS)
|
|
531 |
// Now make the thread's heap fail
|
|
532 |
test(thread.Create(_L("Thread"),ThreadEntryPoint,KDefaultStackSize,0x200,0x200,NULL)==KErrNone);
|
|
533 |
thread.Logon(stat);
|
|
534 |
thread.Resume();
|
|
535 |
TH_FAILNEXT(thread.Handle());
|
|
536 |
threadSemaphore.Signal();
|
|
537 |
User::WaitForRequest(stat);
|
|
538 |
test(thread.ExitReason()==KThreadMemError);
|
|
539 |
thread.Close();
|
|
540 |
threadSemaphore.Close();
|
|
541 |
#endif
|
|
542 |
}
|
|
543 |
|
|
544 |
GLDEF_C TInt E32Main(void)
|
|
545 |
{
|
|
546 |
|
|
547 |
test.Title();
|
|
548 |
AttachToHeap(NULL,0);
|
|
549 |
test.Start(_L("Test1"));
|
|
550 |
TestRHeapDebug T;
|
|
551 |
T.Test1();
|
|
552 |
test.Next(_L("Test2"));
|
|
553 |
T.Test2();
|
|
554 |
test.Next(_L("Test3"));
|
|
555 |
T.Test3();
|
|
556 |
test.Next(_L("Test4"));
|
|
557 |
T.Test4();
|
|
558 |
test.Next(_L("Test5"));
|
|
559 |
T.Test5();
|
|
560 |
test.End();
|
|
561 |
return(0);
|
|
562 |
}
|
|
563 |
#else
|
|
564 |
GLDEF_C TInt E32Main()
|
|
565 |
//
|
|
566 |
// Test unavailable in release build.
|
|
567 |
//
|
|
568 |
{
|
|
569 |
|
|
570 |
test.Title();
|
|
571 |
test.Start(_L("No tests for release builds"));
|
|
572 |
test.End();
|
|
573 |
return(0);
|
|
574 |
}
|
|
575 |
#endif
|
|
576 |
|
|
577 |
|
|
578 |
|