sl@0
|
1 |
// Copyright (c) 1995-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_kheap.cpp
|
sl@0
|
15 |
// Overview:
|
sl@0
|
16 |
// Test clean-up after kernel heap allocation failures.
|
sl@0
|
17 |
// API Information:
|
sl@0
|
18 |
// RProcess, RThread, RServer, RMutex, RChunk, RSemaphore, RTimer.
|
sl@0
|
19 |
// Details:
|
sl@0
|
20 |
// - Tests allocation of kernel objects in low memory conditions and checks for
|
sl@0
|
21 |
// leaks (OOM testing). The following objects are tested, with all
|
sl@0
|
22 |
// combinations of attributes where applicable:
|
sl@0
|
23 |
// - thread-relative timer.
|
sl@0
|
24 |
// - local, global semaphore to the process, thread.
|
sl@0
|
25 |
// - local, global mutex to the current process, thread.
|
sl@0
|
26 |
// - server, handle to a file server session.
|
sl@0
|
27 |
// - handle to a change notifier, a thread death notifier.
|
sl@0
|
28 |
// - logical device driver, XIP and non-XIP (on hardware).
|
sl@0
|
29 |
// - logical channel (hardware only excluding integrator).
|
sl@0
|
30 |
// - chunks
|
sl@0
|
31 |
// - chunks containg heaps (ie User::HeapChunk)
|
sl@0
|
32 |
// - threads
|
sl@0
|
33 |
// - Test that the kernel correctly zeros memory on allocation and reallocation
|
sl@0
|
34 |
// Platforms/Drives/Compatibility:
|
sl@0
|
35 |
// All.
|
sl@0
|
36 |
// Assumptions/Requirement/Pre-requisites:
|
sl@0
|
37 |
// Failures and causes:
|
sl@0
|
38 |
// Base Port information:
|
sl@0
|
39 |
//
|
sl@0
|
40 |
//
|
sl@0
|
41 |
|
sl@0
|
42 |
//! @file
|
sl@0
|
43 |
//! @SYMTestCaseID KBASE-T_KHEAP-0163
|
sl@0
|
44 |
//! @SYMREQ N/A
|
sl@0
|
45 |
//! @SYMTestPriority High
|
sl@0
|
46 |
//! @SYMTestActions Test allocation of Kernel objects in low memory conditions.
|
sl@0
|
47 |
//! @SYMTestExpectedResults Test runs until this message is emitted: RTEST: SUCCESS : T_KHEAP test completed O.K.
|
sl@0
|
48 |
//! @SYMTestType UT
|
sl@0
|
49 |
#define __E32TEST_EXTENSION__
|
sl@0
|
50 |
#include <e32test.h>
|
sl@0
|
51 |
#include <f32file.h>
|
sl@0
|
52 |
#include <hal.h>
|
sl@0
|
53 |
#include <e32svr.h>
|
sl@0
|
54 |
#include <f32dbg.h>
|
sl@0
|
55 |
#include "d_kheap.h"
|
sl@0
|
56 |
|
sl@0
|
57 |
RTest test(_L("T_KHeap"));
|
sl@0
|
58 |
RLoader LoaderSession;
|
sl@0
|
59 |
|
sl@0
|
60 |
#ifdef _DEBUG
|
sl@0
|
61 |
_LIT(KTestLdd0FileName, "D_LDD.LDD");
|
sl@0
|
62 |
_LIT(KTestLdd1FileName, "D_LDD_RAM.LDD");
|
sl@0
|
63 |
_LIT(KTestLddName, "Test");
|
sl@0
|
64 |
|
sl@0
|
65 |
#include "../mmu/mmudetect.h"
|
sl@0
|
66 |
#include "../mmu/d_memorytest.h"
|
sl@0
|
67 |
|
sl@0
|
68 |
TInt gPageSize;
|
sl@0
|
69 |
TBool LargeChunkOK=EFalse;
|
sl@0
|
70 |
const TInt KLargeChunk=0x80000000;
|
sl@0
|
71 |
const TInt KOwnerThread=0x40000000;
|
sl@0
|
72 |
const TInt KMaxKernelAllocations=1024;
|
sl@0
|
73 |
_LIT(KName,"TestObj");
|
sl@0
|
74 |
typedef TInt (*TTestFunction)(TInt);
|
sl@0
|
75 |
|
sl@0
|
76 |
TUint32 WaitABit;
|
sl@0
|
77 |
|
sl@0
|
78 |
RMemoryTestLdd TestLdd;
|
sl@0
|
79 |
RKHeapDevice KHeapDevice;
|
sl@0
|
80 |
|
sl@0
|
81 |
void TraceOn()
|
sl@0
|
82 |
{
|
sl@0
|
83 |
User::SetDebugMask(0xefdfffff);
|
sl@0
|
84 |
}
|
sl@0
|
85 |
|
sl@0
|
86 |
void TraceOff()
|
sl@0
|
87 |
{
|
sl@0
|
88 |
User::SetDebugMask(0x80000000);
|
sl@0
|
89 |
}
|
sl@0
|
90 |
|
sl@0
|
91 |
TInt TestTimer(TInt)
|
sl@0
|
92 |
{
|
sl@0
|
93 |
RTimer t;
|
sl@0
|
94 |
TInt r=t.CreateLocal();
|
sl@0
|
95 |
if (r==KErrNone)
|
sl@0
|
96 |
t.Close();
|
sl@0
|
97 |
return r;
|
sl@0
|
98 |
}
|
sl@0
|
99 |
|
sl@0
|
100 |
TInt TestLocalSem(TInt a)
|
sl@0
|
101 |
{
|
sl@0
|
102 |
TOwnerType ot=(TOwnerType)a;
|
sl@0
|
103 |
RSemaphore s;
|
sl@0
|
104 |
TInt r=s.CreateLocal(0, ot);
|
sl@0
|
105 |
if (r==KErrNone)
|
sl@0
|
106 |
s.Close();
|
sl@0
|
107 |
return r;
|
sl@0
|
108 |
}
|
sl@0
|
109 |
|
sl@0
|
110 |
TInt TestGlobalSem(TInt a)
|
sl@0
|
111 |
{
|
sl@0
|
112 |
TOwnerType ot=(TOwnerType)a;
|
sl@0
|
113 |
RSemaphore s;
|
sl@0
|
114 |
TInt r=s.CreateGlobal(KName, 0, ot);
|
sl@0
|
115 |
if (r==KErrNone)
|
sl@0
|
116 |
s.Close();
|
sl@0
|
117 |
return r;
|
sl@0
|
118 |
}
|
sl@0
|
119 |
|
sl@0
|
120 |
TInt TestLocalMutex(TInt a)
|
sl@0
|
121 |
{
|
sl@0
|
122 |
TOwnerType ot=(TOwnerType)a;
|
sl@0
|
123 |
RMutex m;
|
sl@0
|
124 |
TInt r=m.CreateLocal(ot);
|
sl@0
|
125 |
if (r==KErrNone)
|
sl@0
|
126 |
m.Close();
|
sl@0
|
127 |
return r;
|
sl@0
|
128 |
}
|
sl@0
|
129 |
|
sl@0
|
130 |
TInt TestGlobalMutex(TInt a)
|
sl@0
|
131 |
{
|
sl@0
|
132 |
TOwnerType ot=(TOwnerType)a;
|
sl@0
|
133 |
RMutex m;
|
sl@0
|
134 |
TInt r=m.CreateGlobal(KName, ot);
|
sl@0
|
135 |
if (r==KErrNone)
|
sl@0
|
136 |
m.Close();
|
sl@0
|
137 |
return r;
|
sl@0
|
138 |
}
|
sl@0
|
139 |
|
sl@0
|
140 |
TInt TestServer(TInt)
|
sl@0
|
141 |
{
|
sl@0
|
142 |
RServer2 s;
|
sl@0
|
143 |
TInt r=s.CreateGlobal(KName);
|
sl@0
|
144 |
if (r==KErrNone)
|
sl@0
|
145 |
s.Close();
|
sl@0
|
146 |
return r;
|
sl@0
|
147 |
}
|
sl@0
|
148 |
|
sl@0
|
149 |
TInt TestSession(TInt)
|
sl@0
|
150 |
{
|
sl@0
|
151 |
RFs fs;
|
sl@0
|
152 |
TInt r=fs.Connect();
|
sl@0
|
153 |
if (r==KErrNone)
|
sl@0
|
154 |
{
|
sl@0
|
155 |
r=fs.ShareAuto();
|
sl@0
|
156 |
fs.Close();
|
sl@0
|
157 |
}
|
sl@0
|
158 |
User::After(WaitABit); // allow asynchronous cleanup to happen
|
sl@0
|
159 |
return r;
|
sl@0
|
160 |
}
|
sl@0
|
161 |
|
sl@0
|
162 |
TInt TestChangeNotifier(TInt)
|
sl@0
|
163 |
{
|
sl@0
|
164 |
RChangeNotifier n;
|
sl@0
|
165 |
TInt r=n.Create();
|
sl@0
|
166 |
if (r==KErrNone)
|
sl@0
|
167 |
n.Close();
|
sl@0
|
168 |
return r;
|
sl@0
|
169 |
}
|
sl@0
|
170 |
|
sl@0
|
171 |
TInt TestUndertaker(TInt)
|
sl@0
|
172 |
{
|
sl@0
|
173 |
RUndertaker u;
|
sl@0
|
174 |
TInt r=u.Create();
|
sl@0
|
175 |
if (r==KErrNone)
|
sl@0
|
176 |
u.Close();
|
sl@0
|
177 |
return r;
|
sl@0
|
178 |
}
|
sl@0
|
179 |
|
sl@0
|
180 |
TInt TestLogicalDevice(TInt aDevice)
|
sl@0
|
181 |
{
|
sl@0
|
182 |
const TDesC* fileName = NULL;
|
sl@0
|
183 |
const TDesC* objName = &KTestLddName();
|
sl@0
|
184 |
switch (aDevice)
|
sl@0
|
185 |
{
|
sl@0
|
186 |
case 0:
|
sl@0
|
187 |
fileName = &KTestLdd0FileName();
|
sl@0
|
188 |
break;
|
sl@0
|
189 |
case 1:
|
sl@0
|
190 |
fileName = &KTestLdd1FileName();
|
sl@0
|
191 |
break;
|
sl@0
|
192 |
default:
|
sl@0
|
193 |
test(0);
|
sl@0
|
194 |
}
|
sl@0
|
195 |
TInt r = User::LoadLogicalDevice(*fileName);
|
sl@0
|
196 |
test_KErrNone(LoaderSession.CancelLazyDllUnload()); // make sure transient loader session has been destroyed
|
sl@0
|
197 |
if (r==KErrNone)
|
sl@0
|
198 |
{
|
sl@0
|
199 |
r = User::FreeLogicalDevice(*objName);
|
sl@0
|
200 |
test_KErrNone(r);
|
sl@0
|
201 |
}
|
sl@0
|
202 |
return r;
|
sl@0
|
203 |
}
|
sl@0
|
204 |
|
sl@0
|
205 |
TInt TestLogicalChannel(TInt)
|
sl@0
|
206 |
{
|
sl@0
|
207 |
RKHeapDevice d;
|
sl@0
|
208 |
TInt r=d.Open();
|
sl@0
|
209 |
if (r==KErrNone)
|
sl@0
|
210 |
d.Close();
|
sl@0
|
211 |
return r;
|
sl@0
|
212 |
}
|
sl@0
|
213 |
|
sl@0
|
214 |
TInt TestChunk(TInt att)
|
sl@0
|
215 |
{
|
sl@0
|
216 |
TChunkCreateInfo createInfo;
|
sl@0
|
217 |
TInt maxSize = (att & KLargeChunk)? (33*1048576) : gPageSize;
|
sl@0
|
218 |
createInfo.SetOwner((att & KOwnerThread)? EOwnerThread : EOwnerProcess);
|
sl@0
|
219 |
|
sl@0
|
220 |
if (att & TChunkCreate::EGlobal)
|
sl@0
|
221 |
createInfo.SetGlobal(KName());
|
sl@0
|
222 |
|
sl@0
|
223 |
switch (att & (TChunkCreate::ENormal | TChunkCreate::EDoubleEnded | TChunkCreate::EDisconnected))
|
sl@0
|
224 |
{
|
sl@0
|
225 |
case TChunkCreate::ENormal:
|
sl@0
|
226 |
createInfo.SetNormal(gPageSize, maxSize);
|
sl@0
|
227 |
break;
|
sl@0
|
228 |
case TChunkCreate::EDoubleEnded:
|
sl@0
|
229 |
createInfo.SetDoubleEnded(0, gPageSize, maxSize);
|
sl@0
|
230 |
break;
|
sl@0
|
231 |
case TChunkCreate::EDisconnected:
|
sl@0
|
232 |
createInfo.SetDisconnected(0, gPageSize, maxSize);
|
sl@0
|
233 |
break;
|
sl@0
|
234 |
default:
|
sl@0
|
235 |
test(EFalse);
|
sl@0
|
236 |
break;
|
sl@0
|
237 |
}
|
sl@0
|
238 |
RChunk c;
|
sl@0
|
239 |
TInt r=c.Create(createInfo);
|
sl@0
|
240 |
if (r==KErrNone)
|
sl@0
|
241 |
c.Close();
|
sl@0
|
242 |
return r;
|
sl@0
|
243 |
}
|
sl@0
|
244 |
|
sl@0
|
245 |
TInt TestHeap(TInt att)
|
sl@0
|
246 |
{
|
sl@0
|
247 |
if (att < 2)
|
sl@0
|
248 |
{
|
sl@0
|
249 |
RHeap* h = UserHeap::ChunkHeap(&KNullDesC(), 0x1000, 0x10000, 1, 4, att);
|
sl@0
|
250 |
if (h)
|
sl@0
|
251 |
h->Close();
|
sl@0
|
252 |
return h ? KErrNone : KErrNoMemory;
|
sl@0
|
253 |
}
|
sl@0
|
254 |
RChunk c;
|
sl@0
|
255 |
TInt r = c.CreateLocal(0, 0x100000);
|
sl@0
|
256 |
if (r != KErrNone)
|
sl@0
|
257 |
return r;
|
sl@0
|
258 |
RHeap* h = UserHeap::ChunkHeap(c, 0x1000, 1, 0, 4, att&1, (att&2) ? UserHeap::EChunkHeapDuplicate : 0);
|
sl@0
|
259 |
if ((att & 2) || !h)
|
sl@0
|
260 |
c.Close();
|
sl@0
|
261 |
if (h)
|
sl@0
|
262 |
h->Close();
|
sl@0
|
263 |
return h ? KErrNone : KErrNoMemory;
|
sl@0
|
264 |
}
|
sl@0
|
265 |
|
sl@0
|
266 |
TInt TestThreadFunction(TAny* a)
|
sl@0
|
267 |
{
|
sl@0
|
268 |
TInt x=(TInt)a;
|
sl@0
|
269 |
return (x+1)*(x+1);
|
sl@0
|
270 |
}
|
sl@0
|
271 |
|
sl@0
|
272 |
TInt TestThread(TInt att)
|
sl@0
|
273 |
//
|
sl@0
|
274 |
// bit 0 -> EOwnerThread
|
sl@0
|
275 |
// bit 1 -> use name
|
sl@0
|
276 |
// bit 2 -> let it run
|
sl@0
|
277 |
// bit 3 -> use own heap
|
sl@0
|
278 |
//
|
sl@0
|
279 |
{
|
sl@0
|
280 |
TOwnerType ot=(att&1)?EOwnerThread:EOwnerProcess;
|
sl@0
|
281 |
const TDesC* name=(att&2)?&KName():&KNullDesC();
|
sl@0
|
282 |
TBool run=att&4;
|
sl@0
|
283 |
TBool ownheap=att&8;
|
sl@0
|
284 |
RThread t;
|
sl@0
|
285 |
TInt r=0;
|
sl@0
|
286 |
if (ownheap)
|
sl@0
|
287 |
r=t.Create(*name, TestThreadFunction, 0x1000, 0x1000, 0x10000, (TAny*)att, ot);
|
sl@0
|
288 |
else
|
sl@0
|
289 |
r=t.Create(*name, TestThreadFunction, 0x1000, NULL, (TAny*)att, ot);
|
sl@0
|
290 |
if (r!=KErrNone)
|
sl@0
|
291 |
{
|
sl@0
|
292 |
UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, 0, 0);
|
sl@0
|
293 |
return r;
|
sl@0
|
294 |
}
|
sl@0
|
295 |
t.SetPriority(EPriorityMore);
|
sl@0
|
296 |
TRequestStatus s;
|
sl@0
|
297 |
t.Logon(s);
|
sl@0
|
298 |
if (run)
|
sl@0
|
299 |
t.Resume();
|
sl@0
|
300 |
else
|
sl@0
|
301 |
t.Kill((att+1)*(att+1));
|
sl@0
|
302 |
User::WaitForRequest(s);
|
sl@0
|
303 |
if (s==KErrNoMemory) // if logon failed due to OOM ...
|
sl@0
|
304 |
User::After(WaitABit); // ... allow thread to terminate before checking exit type
|
sl@0
|
305 |
test(t.ExitType()==EExitKill);
|
sl@0
|
306 |
r=s.Int();
|
sl@0
|
307 |
if (r>=0)
|
sl@0
|
308 |
{
|
sl@0
|
309 |
test(r==(att+1)*(att+1));
|
sl@0
|
310 |
r=KErrNone;
|
sl@0
|
311 |
}
|
sl@0
|
312 |
t.Close();
|
sl@0
|
313 |
User::After(WaitABit); // let supervisor run - can't use destruct notifier since it involves memory allocation
|
sl@0
|
314 |
return r;
|
sl@0
|
315 |
}
|
sl@0
|
316 |
|
sl@0
|
317 |
void DoTest(TTestFunction aFunc, TInt aParam)
|
sl@0
|
318 |
{
|
sl@0
|
319 |
test.Printf(_L("DoTest f=%08x p=%08x\n"),aFunc,aParam);
|
sl@0
|
320 |
__KHEAP_MARK;
|
sl@0
|
321 |
__KHEAP_FAILNEXT(1);
|
sl@0
|
322 |
test_Equal(KErrNoMemory, (*aFunc)(aParam));
|
sl@0
|
323 |
test_KErrNone(UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, (TAny*)5000, 0));
|
sl@0
|
324 |
__KHEAP_MARKEND;
|
sl@0
|
325 |
__KHEAP_RESET;
|
sl@0
|
326 |
__KHEAP_MARK;
|
sl@0
|
327 |
test_KErrNone((*aFunc)(aParam));
|
sl@0
|
328 |
test_KErrNone(UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, (TAny*)5000, 0));
|
sl@0
|
329 |
__KHEAP_MARKEND;
|
sl@0
|
330 |
|
sl@0
|
331 |
TInt i;
|
sl@0
|
332 |
TInt r=KErrNoMemory;
|
sl@0
|
333 |
for (i=0; i<KMaxKernelAllocations && r==KErrNoMemory; i++)
|
sl@0
|
334 |
{
|
sl@0
|
335 |
__KHEAP_MARK;
|
sl@0
|
336 |
__KHEAP_FAILNEXT(i);
|
sl@0
|
337 |
r=(*aFunc)(aParam);
|
sl@0
|
338 |
test_KErrNone(UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, (TAny*)5000, 0));
|
sl@0
|
339 |
__KHEAP_MARKEND;
|
sl@0
|
340 |
__KHEAP_RESET;
|
sl@0
|
341 |
}
|
sl@0
|
342 |
test.Printf(_L("Took %d tries\n"),i);
|
sl@0
|
343 |
test_KErrNone(r);
|
sl@0
|
344 |
}
|
sl@0
|
345 |
|
sl@0
|
346 |
_LIT(KLddName, "ECOMM");
|
sl@0
|
347 |
#ifdef __EPOC32__
|
sl@0
|
348 |
_LIT(KPddName, "EUART");
|
sl@0
|
349 |
#else
|
sl@0
|
350 |
_LIT(KPddName, "ECDRV");
|
sl@0
|
351 |
#endif
|
sl@0
|
352 |
TInt LoadDeviceDrivers()
|
sl@0
|
353 |
//
|
sl@0
|
354 |
// Load ECOMM.LDD and all PDDs with name EUART?.PDD
|
sl@0
|
355 |
//
|
sl@0
|
356 |
{
|
sl@0
|
357 |
TInt c=0;
|
sl@0
|
358 |
TInt r;
|
sl@0
|
359 |
TInt i;
|
sl@0
|
360 |
TFileName n=KPddName();
|
sl@0
|
361 |
TInt p=n.Length();
|
sl@0
|
362 |
for (i=-1; i<10; ++i)
|
sl@0
|
363 |
{
|
sl@0
|
364 |
if (i==0)
|
sl@0
|
365 |
n.Append('0');
|
sl@0
|
366 |
else if (i>0)
|
sl@0
|
367 |
n[p]=TText('0'+i);
|
sl@0
|
368 |
r=User::LoadPhysicalDevice(n);
|
sl@0
|
369 |
if (r==KErrNone || r==KErrAlreadyExists)
|
sl@0
|
370 |
{
|
sl@0
|
371 |
c++;
|
sl@0
|
372 |
test.Printf(_L("Loaded PDD %S\n"),&n);
|
sl@0
|
373 |
}
|
sl@0
|
374 |
}
|
sl@0
|
375 |
r=User::LoadLogicalDevice(KLddName);
|
sl@0
|
376 |
if (r==KErrNone || r==KErrAlreadyExists)
|
sl@0
|
377 |
{
|
sl@0
|
378 |
c+=255;
|
sl@0
|
379 |
test.Printf(_L("Loaded LDD %S\n"),&KLddName());
|
sl@0
|
380 |
}
|
sl@0
|
381 |
return c;
|
sl@0
|
382 |
}
|
sl@0
|
383 |
|
sl@0
|
384 |
void TestKernAllocZerosMemory()
|
sl@0
|
385 |
{
|
sl@0
|
386 |
test.Next(_L("Kern::Alloc memory initialisation"));
|
sl@0
|
387 |
test_KErrNone(TestLdd.Open());
|
sl@0
|
388 |
__KHEAP_MARK;
|
sl@0
|
389 |
TInt r=TestLdd.TestAllocZerosMemory();
|
sl@0
|
390 |
__KHEAP_MARKEND;
|
sl@0
|
391 |
if (r)
|
sl@0
|
392 |
test.Printf(_L("TestAllocZerosMemory returned %08x\n"), r);
|
sl@0
|
393 |
test_KErrNone(r);
|
sl@0
|
394 |
__KHEAP_MARK;
|
sl@0
|
395 |
r=TestLdd.TestReAllocZerosMemory();
|
sl@0
|
396 |
__KHEAP_MARKEND;
|
sl@0
|
397 |
if (r)
|
sl@0
|
398 |
test.Printf(_L("TestReAllocZerosMemory returned %08x\n"), r);
|
sl@0
|
399 |
test_KErrNone(r);
|
sl@0
|
400 |
}
|
sl@0
|
401 |
|
sl@0
|
402 |
TInt TestCreateSharedChunk(TInt)
|
sl@0
|
403 |
{
|
sl@0
|
404 |
TInt r = KHeapDevice.CreateSharedChunk();
|
sl@0
|
405 |
User::After(WaitABit); // let supervisor run - can't use destruct notifier since it involves memory allocation
|
sl@0
|
406 |
return r;
|
sl@0
|
407 |
}
|
sl@0
|
408 |
#ifdef __EPOC32__
|
sl@0
|
409 |
TInt TestCreateHwChunk(TInt a)
|
sl@0
|
410 |
{
|
sl@0
|
411 |
TInt r = KHeapDevice.CreateHwChunk();
|
sl@0
|
412 |
User::After(WaitABit); // let supervisor run - can't use destruct notifier since it involves memory allocation
|
sl@0
|
413 |
return r;
|
sl@0
|
414 |
}
|
sl@0
|
415 |
#endif
|
sl@0
|
416 |
|
sl@0
|
417 |
GLDEF_C TInt E32Main()
|
sl@0
|
418 |
//
|
sl@0
|
419 |
// Test kernel alloc heaven with all out of memory possibilities
|
sl@0
|
420 |
//
|
sl@0
|
421 |
{
|
sl@0
|
422 |
|
sl@0
|
423 |
/* Objects
|
sl@0
|
424 |
* Thread tested here
|
sl@0
|
425 |
* Process tested by loader tests
|
sl@0
|
426 |
* Chunk tested here
|
sl@0
|
427 |
* Library tested by loader tests
|
sl@0
|
428 |
* Semaphore tested here
|
sl@0
|
429 |
* Mutex tested here
|
sl@0
|
430 |
* Server tested here
|
sl@0
|
431 |
* Session tested here
|
sl@0
|
432 |
* LDev tested by loader tests (to do)
|
sl@0
|
433 |
* PDev tested by loader tests (to do)
|
sl@0
|
434 |
* LChan tested here
|
sl@0
|
435 |
* ChangeNot tested here
|
sl@0
|
436 |
* Undertaker tested here
|
sl@0
|
437 |
*/
|
sl@0
|
438 |
|
sl@0
|
439 |
test.Title();
|
sl@0
|
440 |
test.Start(_L("Testing kernel OOM handling"));
|
sl@0
|
441 |
|
sl@0
|
442 |
TInt factor = UserSvr::HalFunction(EHalGroupVariant, EVariantHalTimeoutExpansion, 0, 0);
|
sl@0
|
443 |
if (factor<=0)
|
sl@0
|
444 |
factor = 1;
|
sl@0
|
445 |
if (factor>1024)
|
sl@0
|
446 |
factor = 1024;
|
sl@0
|
447 |
WaitABit = 200000 * (TUint32)factor;
|
sl@0
|
448 |
|
sl@0
|
449 |
#ifdef __EPOC32__ // no WINS serial drivers yet
|
sl@0
|
450 |
test.Next(_L("Load comms drivers"));
|
sl@0
|
451 |
test(LoadDeviceDrivers()>=256);
|
sl@0
|
452 |
#endif
|
sl@0
|
453 |
test_KErrNone(UserHal::PageSizeInBytes(gPageSize));
|
sl@0
|
454 |
|
sl@0
|
455 |
// Keep a session to the loader
|
sl@0
|
456 |
TInt r;
|
sl@0
|
457 |
r = LoaderSession.Connect();
|
sl@0
|
458 |
test_KErrNone(r);
|
sl@0
|
459 |
|
sl@0
|
460 |
// Turn off lazy dll unloading
|
sl@0
|
461 |
test_KErrNone(LoaderSession.CancelLazyDllUnload());
|
sl@0
|
462 |
|
sl@0
|
463 |
if (TestChunk(KLargeChunk) == KErrNone)
|
sl@0
|
464 |
{
|
sl@0
|
465 |
LargeChunkOK = ETrue;
|
sl@0
|
466 |
}
|
sl@0
|
467 |
test.Next(_L("Load/open d_kheap test driver"));
|
sl@0
|
468 |
r = User::LoadLogicalDevice(KHeapTestDriverName);
|
sl@0
|
469 |
test( r==KErrNone || r==KErrAlreadyExists);
|
sl@0
|
470 |
if( KErrNone != (r=KHeapDevice.Open()) )
|
sl@0
|
471 |
{
|
sl@0
|
472 |
User::FreeLogicalDevice(KHeapTestDriverName);
|
sl@0
|
473 |
test.Printf(_L("Could not open LDD"));
|
sl@0
|
474 |
test(0);
|
sl@0
|
475 |
}
|
sl@0
|
476 |
|
sl@0
|
477 |
test.Next(_L("Timer"));
|
sl@0
|
478 |
DoTest(TestTimer, 0);
|
sl@0
|
479 |
test.Next(_L("Local semaphore"));
|
sl@0
|
480 |
DoTest(TestLocalSem, EOwnerProcess);
|
sl@0
|
481 |
test.Next(_L("Global semaphore"));
|
sl@0
|
482 |
DoTest(TestGlobalSem, EOwnerProcess);
|
sl@0
|
483 |
test.Next(_L("Local semaphore"));
|
sl@0
|
484 |
DoTest(TestLocalSem, EOwnerThread);
|
sl@0
|
485 |
test.Next(_L("Global semaphore"));
|
sl@0
|
486 |
DoTest(TestGlobalSem, EOwnerThread);
|
sl@0
|
487 |
test.Next(_L("Local mutex"));
|
sl@0
|
488 |
DoTest(TestLocalMutex, EOwnerProcess);
|
sl@0
|
489 |
test.Next(_L("Global mutex"));
|
sl@0
|
490 |
DoTest(TestGlobalMutex, EOwnerProcess);
|
sl@0
|
491 |
test.Next(_L("Local mutex"));
|
sl@0
|
492 |
DoTest(TestLocalMutex, EOwnerThread);
|
sl@0
|
493 |
test.Next(_L("Global mutex"));
|
sl@0
|
494 |
DoTest(TestGlobalMutex, EOwnerThread);
|
sl@0
|
495 |
test.Next(_L("Server"));
|
sl@0
|
496 |
DoTest(TestServer, 0);
|
sl@0
|
497 |
test.Next(_L("Session"));
|
sl@0
|
498 |
DoTest(TestSession, 0);
|
sl@0
|
499 |
test.Next(_L("Change notifier"));
|
sl@0
|
500 |
DoTest(TestChangeNotifier, 0);
|
sl@0
|
501 |
test.Next(_L("Undertaker"));
|
sl@0
|
502 |
DoTest(TestUndertaker, 0);
|
sl@0
|
503 |
test.Next(_L("Logical Device (XIP)"));
|
sl@0
|
504 |
DoTest(TestLogicalDevice, 0);
|
sl@0
|
505 |
#ifdef __EPOC32__
|
sl@0
|
506 |
test.Next(_L("Logical Device (Non-XIP)"));
|
sl@0
|
507 |
//The first time a non-XIP LDD is loaded , Kernel permanently allocates some memory.
|
sl@0
|
508 |
//The next line makes sure it happens before we start testing OOM condition.
|
sl@0
|
509 |
TestLogicalDevice(1);
|
sl@0
|
510 |
//Further non-XIP LDDs loadings must not leak the memory.
|
sl@0
|
511 |
DoTest(TestLogicalDevice, 1);
|
sl@0
|
512 |
|
sl@0
|
513 |
// Temporary hack to avoid clash with debug output on Integrator
|
sl@0
|
514 |
TInt muid;
|
sl@0
|
515 |
r = HAL::Get(HAL::EMachineUid, muid);
|
sl@0
|
516 |
test_KErrNone(r);
|
sl@0
|
517 |
if (muid != HAL::EMachineUid_Integrator)
|
sl@0
|
518 |
{
|
sl@0
|
519 |
test.Next(_L("Logical Channel"));
|
sl@0
|
520 |
r = User::LoadLogicalDevice(KHeapTestDriverName);
|
sl@0
|
521 |
test(r==KErrNone || r==KErrAlreadyExists);
|
sl@0
|
522 |
DoTest(TestLogicalChannel, 0);
|
sl@0
|
523 |
}
|
sl@0
|
524 |
#endif
|
sl@0
|
525 |
TUint32 att;
|
sl@0
|
526 |
TUint32 attlim=LargeChunkOK?0x100:0x80;
|
sl@0
|
527 |
test.Next(_L("Chunk"));
|
sl@0
|
528 |
for (att=0; att<attlim; ++att)
|
sl@0
|
529 |
{
|
sl@0
|
530 |
if ((att&0x0f)>2)
|
sl@0
|
531 |
continue;
|
sl@0
|
532 |
TInt arg=att&~0xc0;
|
sl@0
|
533 |
if (att&0x40) arg|=KOwnerThread;
|
sl@0
|
534 |
if (att&0x80) arg|=KLargeChunk;
|
sl@0
|
535 |
DoTest(TestChunk, arg);
|
sl@0
|
536 |
}
|
sl@0
|
537 |
|
sl@0
|
538 |
test.Next(_L("Heap"));
|
sl@0
|
539 |
for (att=0; att<8; ++att)
|
sl@0
|
540 |
{
|
sl@0
|
541 |
if (att==2 || att==3)
|
sl@0
|
542 |
continue;
|
sl@0
|
543 |
DoTest(TestHeap, att);
|
sl@0
|
544 |
}
|
sl@0
|
545 |
|
sl@0
|
546 |
test.Next(_L("Thread"));
|
sl@0
|
547 |
for (att=0; att<16; ++att)
|
sl@0
|
548 |
{
|
sl@0
|
549 |
DoTest(TestThread, att);
|
sl@0
|
550 |
}
|
sl@0
|
551 |
|
sl@0
|
552 |
TestKernAllocZerosMemory();
|
sl@0
|
553 |
|
sl@0
|
554 |
test.Next(_L("Shared Chunk"));
|
sl@0
|
555 |
DoTest(TestCreateSharedChunk, 0);
|
sl@0
|
556 |
#ifdef __EPOC32__
|
sl@0
|
557 |
test.Next(_L("Hw Chunk"));
|
sl@0
|
558 |
DoTest(TestCreateHwChunk, 0);
|
sl@0
|
559 |
#endif
|
sl@0
|
560 |
|
sl@0
|
561 |
test.Next(_L("Close/unload d_kheap test driver"));
|
sl@0
|
562 |
KHeapDevice.Close();
|
sl@0
|
563 |
User::FreeLogicalDevice(KHeapTestDriverName);
|
sl@0
|
564 |
LoaderSession.Close();
|
sl@0
|
565 |
test.End();
|
sl@0
|
566 |
return 0;
|
sl@0
|
567 |
}
|
sl@0
|
568 |
#else
|
sl@0
|
569 |
GLDEF_C TInt E32Main()
|
sl@0
|
570 |
//
|
sl@0
|
571 |
// _KHEAP_SETFAIL etc. not available in release mode, so don't test
|
sl@0
|
572 |
//
|
sl@0
|
573 |
{
|
sl@0
|
574 |
|
sl@0
|
575 |
test.Title();
|
sl@0
|
576 |
test.Start(_L("No tests in release mode"));
|
sl@0
|
577 |
test.End();
|
sl@0
|
578 |
return 0;
|
sl@0
|
579 |
}
|
sl@0
|
580 |
#endif
|
sl@0
|
581 |
|
sl@0
|
582 |
|