author | Mike Kinghan <mikek@symbian.org> |
Mon, 19 Jul 2010 08:40:05 +0100 | |
branch | GCC_SURGE |
changeset 209 | 6035754ebf88 |
parent 109 | b3a1d9898418 |
child 257 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2008-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\demandpaging\t_chunkheapcreate.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
// |
|
19 |
#define __E32TEST_EXTENSION__ |
|
20 |
#include <e32test.h> |
|
21 |
#include <dptest.h> |
|
22 |
#include <e32hal.h> |
|
23 |
#include <u32exec.h> |
|
24 |
#include <e32svr.h> |
|
25 |
#include <e32panic.h> |
|
26 |
#include "u32std.h" |
|
27 |
||
28 |
#include "t_dpcmn.h" |
|
29 |
||
30 |
enum |
|
31 |
{ |
|
32 |
ETestLocal, |
|
33 |
ETestGlobal, |
|
34 |
ETestExisting, |
|
35 |
}; |
|
36 |
||
37 |
static TPtrC gGlobalDes = _L("GlobalHeap"); |
|
38 |
||
39 |
void UseOrCreateChunk(TChunkHeapCreateInfo aCreateInfo, TInt aTestType) |
|
40 |
{ |
|
41 |
switch(aTestType) |
|
42 |
{ |
|
43 |
case ETestLocal: |
|
44 |
aCreateInfo.SetCreateChunk(NULL); |
|
45 |
break; |
|
46 |
||
47 |
case ETestGlobal: |
|
48 |
aCreateInfo.SetCreateChunk(&gGlobalDes); |
|
49 |
break; |
|
50 |
||
51 |
case ETestExisting: |
|
52 |
aCreateInfo.SetUseChunk(gChunk); |
|
53 |
break; |
|
54 |
} |
|
55 |
} |
|
56 |
||
57 |
/** |
|
58 |
Attempt to create a global or local UserHeap with the given attributes |
|
59 |
||
60 |
@return ETrue The chunk is paged or unpaged as expected. |
|
61 |
*/ |
|
62 |
TInt UserHeapAtt(TBool aPaged, TChunkHeapCreateInfo& aCreateInfo) |
|
63 |
{ |
|
64 |
UpdatePaged(aPaged); |
|
65 |
||
66 |
RHeap* heap = UserHeap::ChunkHeap(aCreateInfo); |
|
67 |
test_NotNull(heap); |
|
68 |
RChunk chunk; |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
69 |
chunk.SetHandle(((TestHybridHeap*) heap)->ChunkHandle()); |
0 | 70 |
TBool paged = chunk.IsPaged(); |
71 |
chunk.Close(); |
|
72 |
return (aPaged == paged); |
|
73 |
} |
|
74 |
||
75 |
TInt PanicUserHeap(TAny*) |
|
76 |
{ |
|
77 |
TChunkHeapCreateInfo createInfo(0, gPageSize); |
|
78 |
createInfo.SetCreateChunk(NULL); |
|
79 |
createInfo.SetMode((TUint)~UserHeap::EChunkHeapMask); |
|
80 |
test(UserHeapAtt(gProcessPaged, createInfo)); |
|
81 |
return KErrGeneral; // Shouldn't reach here. |
|
82 |
} |
|
83 |
||
84 |
TInt PanicChunkHeapCreate(TAny* aCreateInfo) |
|
85 |
{ |
|
86 |
TChunkHeapCreateInfo createInfo((*(TChunkHeapCreateInfo*) aCreateInfo)); |
|
87 |
UserHeap::ChunkHeap(createInfo); |
|
88 |
return KErrGeneral; // Should never reahc here |
|
89 |
} |
|
90 |
||
91 |
// |
|
92 |
// TestChunkHeapCreate |
|
93 |
// |
|
94 |
//---------------------------------------------------------------------------------------------- |
|
95 |
//! @SYMTestCaseID KBASE-T_CHUNKHEAPCREATE-xxxx |
|
96 |
//! @SYMTestType UT |
|
97 |
//! @SYMPREQ PREQ1954 |
|
98 |
//! @SYMTestCaseDesc Testing TChunkHeapCreateInfo |
|
99 |
//! Verify the chunk heap creation implementation |
|
100 |
//! @SYMTestActions |
|
101 |
//! 1. Create a local chunk by calling SetCreateChunk(NULL). |
|
102 |
//! Following this check the paging status of the chunk heap. |
|
103 |
//! 2. Create a local chunk by calling SetCreateChunk(NULL). Set the chunk heap to EPaged. |
|
104 |
//! Following this check the paging status of the chunk heap. |
|
105 |
//! 3. Create a local chunk by calling SetCreateChunk(NULL). Set the chunk heap to EUnPaged. |
|
106 |
//! Following this check the paging status of the chunk heap. |
|
107 |
//! 4. Create a heap within a local chunk and set the minimum length of the heap to be greater |
|
108 |
//! than the maximum length of the heap |
|
109 |
//! 5. Create a heap within a local chunk and set the minimum length of the heap to -1 |
|
110 |
//! 6. Create a heap within a local chunk and set the maximum length of the heap to |
|
111 |
//! less than KMinHeapSize |
|
112 |
//! 7. Call TChunkHeapCreateInfo::SetUseChunk() on a created local chunk calling SetCreateChunk(NULL) |
|
113 |
//! before hand. Following this call UserHeap::ChunkHeap() and compare the heap and the chunk handles |
|
114 |
//! 8. Call TChunkHeapCreateInfo::SetUseChunk() on a created local chunk calling SetCreateChunk(NULL) |
|
115 |
//! after. Following this call UserHeap::ChunkHeap() and compare the heap and the chunk handles |
|
116 |
//! 9. Call TChunkHeapCreateInfo::SetSingleThread() on a created local chunk specifying EFalse. |
|
117 |
//! Following this call UserHeap::ChunkHeap(); |
|
118 |
//! 10. Call TChunkHeapCreateInfo::SetSingleThread() on a created local chunk specifying ETrue. |
|
119 |
//! Following this call UserHeap::ChunkHeap(); |
|
120 |
//! 11. Call TChunkHeapCreateInfo::SetAlignment() on a created local chunk specifying aAlign to |
|
121 |
//! be a valid value. Following this call UserHeap::ChunkHeap(); |
|
122 |
//! 12. Call TChunkHeapCreateInfo::SetAlignment() on a created local chunk specifying aAlign to be |
|
123 |
//! an invalid value (-1). Following this call UserHeap::ChunkHeap(); |
|
124 |
//! 13. Call TChunkHeapCreateInfo::SetGrowBy() on a created local chunk specifying aGrowBy to be |
|
125 |
//! a valid value. Following this call UserHeap::ChunkHeap(). Following this create and array of |
|
126 |
//! integers on the heap and check the size of the chunk. |
|
127 |
//! 14. Call TChunkHeapCreateInfo::SetGrowBy() on a created local chunk specifying aGrowBy to |
|
128 |
//! be greater than the maximum size of the chunk. Following this call UserHeap::ChunkHeap(); |
|
129 |
//! 15. Call TChunkHeapCreateInfo::SetOffset() on a created local chunk specifying aOffset to |
|
130 |
//! be a valid value. Following this call UserHeap::ChunkHeap(); |
|
131 |
//! 16. Call TChunkHeapCreateInfo:: SetMode () on a created local chunk specifying aMode to |
|
132 |
//! be an invalid value. Following this call UserHeap::ChunkHeap(); |
|
133 |
//! |
|
134 |
//! @SYMTestExpectedResults All tests should pass. |
|
135 |
//! @SYMTestPriority High |
|
136 |
//! @SYMTestStatus Implemented |
|
137 |
//---------------------------------------------------------------------------------------------- |
|
138 |
void TestChunkHeapCreate(TInt aTestType) |
|
139 |
{ |
|
140 |
||
141 |
||
142 |
test.Start(_L("Test UserHeap::ChunkHeap() data paging attributes")); |
|
143 |
{ |
|
144 |
TChunkHeapCreateInfo createInfo(0, gPageSize); |
|
145 |
||
146 |
UseOrCreateChunk(createInfo, aTestType); |
|
147 |
||
148 |
test(UserHeapAtt(gProcessPaged, createInfo)); |
|
149 |
||
150 |
createInfo.SetPaging(TChunkHeapCreateInfo::EPaged); |
|
151 |
test(UserHeapAtt(ETrue, createInfo)); |
|
152 |
||
153 |
createInfo.SetPaging(TChunkHeapCreateInfo::EUnpaged); |
|
154 |
test(UserHeapAtt(EFalse, createInfo)); |
|
155 |
} |
|
156 |
||
157 |
test.Next(_L("Test maxHeapSize < minHeapSize")); |
|
158 |
{ |
|
159 |
TChunkHeapCreateInfo createInfo(KMinHeapSize + gPageSize, KMinHeapSize); |
|
160 |
UseOrCreateChunk(createInfo, aTestType); |
|
161 |
RThread thread; |
|
162 |
test_KErrNone(thread.Create(_L("Panic UserHeap"), PanicChunkHeapCreate, KDefaultStackSize, KMinHeapSize, |
|
163 |
KMinHeapSize, (TAny*) &createInfo)); |
|
164 |
||
165 |
test_KErrNone(TestThreadExit(thread, EExitPanic, ETHeapCreateMaxLessThanMin)); |
|
166 |
} |
|
167 |
||
168 |
test.Next(_L("Test invalid minHeapSize")); |
|
169 |
{ |
|
170 |
TChunkHeapCreateInfo createInfo(-1, KMinHeapSize); |
|
171 |
UseOrCreateChunk(createInfo, aTestType); |
|
172 |
RThread thread; |
|
173 |
test_KErrNone(thread.Create(_L("Panic UserHeap"), PanicChunkHeapCreate, KDefaultStackSize, KMinHeapSize, |
|
174 |
KMinHeapSize, (TAny*) &createInfo)); |
|
175 |
||
176 |
test_KErrNone(TestThreadExit(thread, EExitPanic, ETHeapMinLengthNegative)); |
|
177 |
} |
|
178 |
||
179 |
test.Next(_L("Test invalid maxHeapSize")); |
|
180 |
{ |
|
181 |
RHeap* heap; |
|
182 |
TChunkHeapCreateInfo createInfo(0, 0); |
|
183 |
UseOrCreateChunk(createInfo, aTestType); |
|
184 |
heap = (RHeap*)UserHeap::ChunkHeap(createInfo); |
|
185 |
if (heap == NULL) |
|
186 |
{ |
|
187 |
test.Printf(_L("RHeap not created")); |
|
188 |
} |
|
189 |
TUint maxLength = heap->MaxLength(); |
|
190 |
test.Printf(_L("heap max length = 0x%x\n"), maxLength); |
|
191 |
||
192 |
// Need to round up to page size as RHeap maxLength is rounded |
|
193 |
// up to the nearest page size |
|
194 |
TUint expectedMaxSize = _ALIGN_UP(KMinHeapSize, gPageSize); |
|
195 |
test_Equal(expectedMaxSize, maxLength); |
|
196 |
heap->Close(); |
|
197 |
} |
|
198 |
||
199 |
test.Next(_L("Test SetUseChunk - calling SetCreate before")); |
|
200 |
{ |
|
201 |
RHeap* heap; |
|
202 |
RChunk chunky; |
|
203 |
||
204 |
TChunkCreateInfo chunkCreateInfo; |
|
205 |
chunkCreateInfo.SetNormal(gPageSize, gPageSize); |
|
206 |
test_KErrNone(chunky.Create(chunkCreateInfo)); |
|
207 |
||
208 |
TChunkHeapCreateInfo createInfo(0, gPageSize); |
|
209 |
||
210 |
createInfo.SetCreateChunk(NULL); |
|
211 |
createInfo.SetUseChunk(chunky); |
|
212 |
heap = (RHeap*)UserHeap::ChunkHeap(createInfo); |
|
213 |
if (heap == NULL) |
|
214 |
{ |
|
215 |
test.Printf(_L("RHeap not created\n")); |
|
216 |
} |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
217 |
test.Printf(_L("chunkHandle = %d heapHandle = %d\n"),chunky.Handle(), ((TestHybridHeap*) heap)->ChunkHandle()); |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
218 |
test_Equal(chunky.Handle(), ((TestHybridHeap*) heap)->ChunkHandle()); |
0 | 219 |
heap->Close(); |
220 |
} |
|
221 |
||
222 |
test.Next(_L("Test SetUseChunk - calling SetCreate after")); |
|
223 |
{ |
|
224 |
RHeap* heap; |
|
225 |
RChunk chunky; |
|
226 |
||
227 |
TChunkCreateInfo chunkCreateInfo; |
|
228 |
chunkCreateInfo.SetNormal(gPageSize, gPageSize); |
|
229 |
test_KErrNone(chunky.Create(chunkCreateInfo)); |
|
230 |
||
231 |
TChunkHeapCreateInfo createInfo(0, gPageSize); |
|
232 |
createInfo.SetUseChunk(chunky); |
|
233 |
createInfo.SetCreateChunk(NULL); |
|
234 |
||
235 |
heap = (RHeap*)UserHeap::ChunkHeap(createInfo); |
|
236 |
if (heap == NULL) |
|
237 |
{ |
|
238 |
test.Printf(_L("RHeap not created\n")); |
|
239 |
} |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
240 |
test.Printf(_L("chunkHandle = %d heapHandle = %d\n"),chunky.Handle(), ((TestHybridHeap*) heap)->ChunkHandle()); |
0 | 241 |
TBool isSame = EFalse; |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
242 |
if (chunky.Handle() == ((TestHybridHeap*) heap)->ChunkHandle()) |
0 | 243 |
isSame = ETrue; |
244 |
test_Equal(EFalse, isSame); |
|
245 |
heap->Close(); |
|
246 |
} |
|
247 |
||
248 |
test.Next(_L("Test SetSingleThread - ETrue")); |
|
249 |
{ |
|
250 |
RHeap* heap; |
|
251 |
TChunkHeapCreateInfo createInfo(0, gPageSize); |
|
252 |
UseOrCreateChunk(createInfo, aTestType); |
|
253 |
createInfo.SetSingleThread(ETrue); |
|
254 |
heap = (RHeap*)UserHeap::ChunkHeap(createInfo); |
|
255 |
test_NotNull(heap); |
|
256 |
heap->Close(); |
|
257 |
} |
|
258 |
||
259 |
test.Next(_L("Test SetSingleThread - EFalse")); |
|
260 |
{ |
|
261 |
RHeap* heap; |
|
262 |
TChunkHeapCreateInfo createInfo(0, gPageSize); |
|
263 |
UseOrCreateChunk(createInfo, aTestType); |
|
264 |
createInfo.SetSingleThread(EFalse); |
|
265 |
heap = (RHeap*)UserHeap::ChunkHeap(createInfo); |
|
266 |
test_NotNull(heap); |
|
267 |
heap->Close(); |
|
268 |
} |
|
269 |
||
270 |
test.Next(_L("Test SetAlignment 0")); |
|
271 |
{ |
|
272 |
RHeap* heap; |
|
273 |
TChunkHeapCreateInfo createInfo(0, gPageSize); |
|
274 |
UseOrCreateChunk(createInfo, aTestType); |
|
275 |
createInfo.SetAlignment(0); |
|
276 |
heap = (RHeap*)UserHeap::ChunkHeap(createInfo); |
|
277 |
test_NotNull(heap); |
|
278 |
heap->Close(); |
|
279 |
} |
|
280 |
||
281 |
||
282 |
test.Next(_L("Test SetAlignment -1")); |
|
283 |
{ |
|
284 |
TChunkHeapCreateInfo createInfo(0, gPageSize); |
|
285 |
UseOrCreateChunk(createInfo, aTestType); |
|
286 |
createInfo.SetAlignment(-1); |
|
287 |
||
288 |
RThread thread; |
|
289 |
test_KErrNone(thread.Create(_L("Panic UserHeap"), PanicChunkHeapCreate, KDefaultStackSize, KMinHeapSize, |
|
290 |
KMinHeapSize, (TAny*) &createInfo)); |
|
291 |
||
292 |
test_KErrNone(TestThreadExit(thread, EExitPanic, ETHeapNewBadAlignment)); |
|
293 |
} |
|
294 |
||
295 |
||
296 |
test.Next(_L("Test SetGrowby")); |
|
297 |
{ |
|
298 |
RHeap* heap; |
|
299 |
TChunkHeapCreateInfo createInfo(0, gPageSize * 10); |
|
300 |
UseOrCreateChunk(createInfo, aTestType); |
|
301 |
createInfo.SetGrowBy(gPageSize); |
|
302 |
createInfo.SetMode(UserHeap::EChunkHeapSwitchTo); |
|
303 |
heap = (RHeap*)UserHeap::ChunkHeap(createInfo); |
|
304 |
test_NotNull(heap); |
|
305 |
RChunk chunk; |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
306 |
chunk.SetHandle(((TestHybridHeap*) heap)->ChunkHandle()); |
0 | 307 |
TInt* numBuf = new TInt[gPageSize]; |
308 |
test_NotNull(numBuf); |
|
309 |
test.Printf(_L("chunkSize = %d\n"), chunk.Size()); |
|
310 |
test(chunk.Size() > KMinHeapGrowBy); |
|
311 |
delete numBuf; |
|
312 |
heap->Close(); |
|
313 |
} |
|
314 |
||
315 |
test.Next(_L("Test SetGrowby growBy > maxSize")); |
|
316 |
{ |
|
317 |
RHeap* heap; |
|
318 |
TChunkHeapCreateInfo createInfo(0, gPageSize * 5); |
|
319 |
UseOrCreateChunk(createInfo, aTestType); |
|
320 |
createInfo.SetGrowBy(gPageSize * 6); |
|
321 |
createInfo.SetMode(UserHeap::EChunkHeapSwitchTo); |
|
322 |
heap = (RHeap*)UserHeap::ChunkHeap(createInfo); |
|
323 |
test_NotNull(heap); |
|
324 |
RChunk chunk; |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
325 |
chunk.SetHandle(((TestHybridHeap*) heap)->ChunkHandle()); |
0 | 326 |
TInt* numBuf = new TInt[gPageSize]; |
327 |
test_Equal(NULL, numBuf); |
|
328 |
||
329 |
delete numBuf; |
|
330 |
heap->Close(); |
|
331 |
} |
|
332 |
||
333 |
||
334 |
test.Next(_L("Test SetOffset ")); |
|
335 |
{ |
|
336 |
RHeap* heap; |
|
337 |
TChunkHeapCreateInfo createInfo(0, gPageSize * 10); |
|
338 |
UseOrCreateChunk(createInfo, aTestType); |
|
339 |
createInfo.SetOffset(8); |
|
340 |
createInfo.SetMode(UserHeap::EChunkHeapSwitchTo); |
|
341 |
heap = (RHeap*)UserHeap::ChunkHeap(createInfo); |
|
342 |
TInt heapAddr = (TInt)heap; |
|
343 |
RChunk chunk; |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
344 |
chunk.SetHandle(((TestHybridHeap*) heap)->ChunkHandle()); |
0 | 345 |
test_Equal((TInt)chunk.Base() + 8, heapAddr); |
346 |
test_NotNull(heap); |
|
347 |
heap->Close(); |
|
348 |
} |
|
349 |
||
350 |
test.Next(_L("Test UserHeap::ChunkHeap() SetMode() invalid")); |
|
351 |
{ |
|
352 |
TChunkHeapCreateInfo createInfo(0, gPageSize); |
|
353 |
UseOrCreateChunk(createInfo, aTestType); |
|
354 |
||
355 |
// Test creating a UserHeap with invalid attributes panics. |
|
356 |
RThread thread; |
|
357 |
test_KErrNone(thread.Create(_L("Panic UserHeap"), PanicUserHeap, KDefaultStackSize, |
|
358 |
KMinHeapSize, KMinHeapSize, NULL)); |
|
359 |
test_KErrNone(TestThreadExit(thread, EExitPanic, EHeapCreateInvalidMode)); |
|
360 |
} |
|
361 |
||
362 |
test.End(); |
|
363 |
} |
|
364 |
||
365 |
TInt TestingTChunkHeapCreate() |
|
366 |
{ |
|
367 |
test.Start(_L("Test TChunkHeapCreateInfo - heap within local chunk")); |
|
368 |
TestChunkHeapCreate(ETestLocal); |
|
369 |
||
370 |
test.Next(_L("Test TChunkHeapCreateInfo - heap within global chunk")); |
|
371 |
TestChunkHeapCreate(ETestGlobal); |
|
372 |
||
373 |
test.Next(_L("Test TChunkHeapCreateInfo - heap within existing chunk")); |
|
374 |
TestChunkHeapCreate(ETestExisting); |
|
375 |
||
376 |
test.End(); |
|
377 |
return 0; |
|
378 |
} |