sl@0
|
1 |
// Copyright (c) 2005-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\mmu\t_demandpaging.cpp
|
sl@0
|
15 |
// Functional tests for demand paging. The test suite covers simple
|
sl@0
|
16 |
// paging operations as well as HAL configuration and tuning functions.
|
sl@0
|
17 |
// 001.01 DPTest::Attributes
|
sl@0
|
18 |
// 001.02 DPTest::FlushCache
|
sl@0
|
19 |
// 001.03 DPTest::CacheSize
|
sl@0
|
20 |
// 001.04 DPTest::SetCacheSize
|
sl@0
|
21 |
// 001.04.01 Changing size of flushed VM cache
|
sl@0
|
22 |
// 001.04.02 Changing size of full VM cache
|
sl@0
|
23 |
// 002 Loading test drivers
|
sl@0
|
24 |
// 003 Test thread realtime state
|
sl@0
|
25 |
// 003.01 Enable KREALTIME tracing
|
sl@0
|
26 |
// 003.02 Test ERealtimeStateOff
|
sl@0
|
27 |
// 003.03 Test ERealtimeStateOn
|
sl@0
|
28 |
// 003.04 Test ERealtimeStateWarn
|
sl@0
|
29 |
// 003.05 Test server with ERealtimeStateOff
|
sl@0
|
30 |
// 003.06 Test server with ERealtimeStateOn
|
sl@0
|
31 |
// 003.07 Test server with ERealtimeStateWarn
|
sl@0
|
32 |
// 003.08 Disable KREALTIME tracing
|
sl@0
|
33 |
// 004 Lock Test
|
sl@0
|
34 |
// 005 Lock Test again
|
sl@0
|
35 |
// 006 Test writing to paged ROM
|
sl@0
|
36 |
// 007 Test IPC read from paged memory
|
sl@0
|
37 |
// 007.01 Create server
|
sl@0
|
38 |
// 007.02 IPC read from ROM
|
sl@0
|
39 |
// 007.03 Stop server
|
sl@0
|
40 |
// 008 Test contiguous RAM allocation reclaims paged memory
|
sl@0
|
41 |
// 008.01 Start...
|
sl@0
|
42 |
// 008.02 Contiguous RAM test: alloc size = 128K align = 16
|
sl@0
|
43 |
// 008.03 Contiguous RAM test: alloc size = 128K align = 0
|
sl@0
|
44 |
// 008.04 Contiguous RAM test: alloc size = 64K align = 15
|
sl@0
|
45 |
// 008.05 Contiguous RAM test: alloc size = 64K align = 14
|
sl@0
|
46 |
// 008.06 Contiguous RAM test: alloc size = 64K align = 13
|
sl@0
|
47 |
// 008.07 Contiguous RAM test: alloc size = 64K align = 12
|
sl@0
|
48 |
// 008.08 Contiguous RAM test: alloc size = 64K align = 0
|
sl@0
|
49 |
// 008.09 Contiguous RAM test: alloc size = 8K align = 13
|
sl@0
|
50 |
// 008.10 Contiguous RAM test: alloc size = 8K align = 12
|
sl@0
|
51 |
// 008.11 Contiguous RAM test: alloc size = 8K align = 0
|
sl@0
|
52 |
// 008.12 Contiguous RAM test: alloc size = 4K align = 13
|
sl@0
|
53 |
// 008.13 Contiguous RAM test: alloc size = 4K align = 12
|
sl@0
|
54 |
// 008.14 Contiguous RAM test: alloc size = 4K align = 0
|
sl@0
|
55 |
// 009 Test no kernel faults when copying data from unpaged rom with mutex held
|
sl@0
|
56 |
// 010 Close test driver
|
sl@0
|
57 |
// 011 Test setting publish and subscribe properties from paged area
|
sl@0
|
58 |
// 012 Rom Paging Benchmark
|
sl@0
|
59 |
// 012.01 Benchmark ROM paging...
|
sl@0
|
60 |
//
|
sl@0
|
61 |
//
|
sl@0
|
62 |
|
sl@0
|
63 |
//! @SYMTestCaseID KBASE-T_DEMANDPAGING-0334
|
sl@0
|
64 |
//! @SYMTestType UT
|
sl@0
|
65 |
//! @SYMPREQ PREQ1110
|
sl@0
|
66 |
//! @SYMTestCaseDesc Demand Paging functional tests.
|
sl@0
|
67 |
//! @SYMTestActions 001 Test HAL interface
|
sl@0
|
68 |
//! @SYMTestExpectedResults All tests should pass.
|
sl@0
|
69 |
//! @SYMTestPriority High
|
sl@0
|
70 |
//! @SYMTestStatus Implemented
|
sl@0
|
71 |
|
sl@0
|
72 |
#define __E32TEST_EXTENSION__
|
sl@0
|
73 |
#include <e32test.h>
|
sl@0
|
74 |
#include <dptest.h>
|
sl@0
|
75 |
#include <e32kpan.h>
|
sl@0
|
76 |
#include <e32property.h>
|
sl@0
|
77 |
#include <e32rom.h>
|
sl@0
|
78 |
#include "d_memorytest.h"
|
sl@0
|
79 |
#include "d_demandpaging.h"
|
sl@0
|
80 |
#include "d_gobble.h"
|
sl@0
|
81 |
#include "mmudetect.h"
|
sl@0
|
82 |
#include "t_codepaging_dll.h"
|
sl@0
|
83 |
#include "freeram.h"
|
sl@0
|
84 |
|
sl@0
|
85 |
RTest test(_L("T_DEMANDPAGING"));
|
sl@0
|
86 |
|
sl@0
|
87 |
_LIT(KTCodePagingDll4, "t_codepaging_dll4.dll");
|
sl@0
|
88 |
const TInt KMinBufferSize = 16384;
|
sl@0
|
89 |
const TInt KMaxIPCSize = 256*1024;
|
sl@0
|
90 |
|
sl@0
|
91 |
TInt PageSize = 0;
|
sl@0
|
92 |
RDemandPagingTestLdd Ldd;
|
sl@0
|
93 |
RLibrary PagedLibrary;
|
sl@0
|
94 |
|
sl@0
|
95 |
// A buffer containing paged memory, contents may or may not be paged in
|
sl@0
|
96 |
const TUint8* LargeBuffer = NULL;
|
sl@0
|
97 |
TInt LargeBufferSize = 0;
|
sl@0
|
98 |
|
sl@0
|
99 |
// A buffer containing paged memeory, contents always paged out before access
|
sl@0
|
100 |
const TUint8* SmallBuffer = NULL;
|
sl@0
|
101 |
TInt SmallBufferSize = 0;
|
sl@0
|
102 |
|
sl@0
|
103 |
// A shared buffer mapped to the global address range
|
sl@0
|
104 |
TInt SharedBufferSize = KMaxIPCSize+4096;
|
sl@0
|
105 |
TLinAddr SharedBufferAddr = 0;
|
sl@0
|
106 |
TUint8* SharedBuffer = NULL;
|
sl@0
|
107 |
|
sl@0
|
108 |
// A descriptor whose header is in paged memory (actually just a pointer to a zero word)
|
sl@0
|
109 |
TDesC8* PagedHeaderDes = NULL;
|
sl@0
|
110 |
|
sl@0
|
111 |
// A data paged chunk used as a buffer, if data paging is supported
|
sl@0
|
112 |
_LIT(KChunkName, "t_demandpaging chunk");
|
sl@0
|
113 |
RChunk DataPagedChunk;
|
sl@0
|
114 |
TBool DataPagingSupported = EFalse;
|
sl@0
|
115 |
TUint8* DataPagedBuffer = NULL;
|
sl@0
|
116 |
|
sl@0
|
117 |
TUint8 ReadByte(volatile TUint8* aPtr)
|
sl@0
|
118 |
{
|
sl@0
|
119 |
return *aPtr;
|
sl@0
|
120 |
}
|
sl@0
|
121 |
|
sl@0
|
122 |
#define READ(a) ReadByte((volatile TUint8*)(a))
|
sl@0
|
123 |
|
sl@0
|
124 |
void ThrashPaging(TUint aMaxBytes=KMaxTUint)
|
sl@0
|
125 |
{
|
sl@0
|
126 |
TUint size = LargeBufferSize;
|
sl@0
|
127 |
if(size>aMaxBytes)
|
sl@0
|
128 |
size = aMaxBytes;
|
sl@0
|
129 |
|
sl@0
|
130 |
// read all ROM pages about 10 times each in a random order...
|
sl@0
|
131 |
TUint32 random=1;
|
sl@0
|
132 |
for(TInt i=size/(PageSize/10); i>0; --i)
|
sl@0
|
133 |
{
|
sl@0
|
134 |
READ(LargeBuffer+((TInt64(random)*TInt64(size))>>32));
|
sl@0
|
135 |
random = random*69069+1;
|
sl@0
|
136 |
}
|
sl@0
|
137 |
}
|
sl@0
|
138 |
|
sl@0
|
139 |
void FragmentPagingCache(TUint aMaxBytes)
|
sl@0
|
140 |
{
|
sl@0
|
141 |
DPTest::FlushCache();
|
sl@0
|
142 |
|
sl@0
|
143 |
TUint size = Min(LargeBufferSize, aMaxBytes);
|
sl@0
|
144 |
if(size<aMaxBytes)
|
sl@0
|
145 |
test.Printf(_L("WARNING: LargeBuffer not large enough! Have you built a full test ROM?\n"));
|
sl@0
|
146 |
|
sl@0
|
147 |
RChunk chunk;
|
sl@0
|
148 |
test(KErrNone==chunk.CreateDisconnectedLocal(0,0,size));
|
sl@0
|
149 |
|
sl@0
|
150 |
TUint32 random = 0;
|
sl@0
|
151 |
for(TUint i=0; i<size; i += PageSize)
|
sl@0
|
152 |
{
|
sl@0
|
153 |
random = random*69069+1;
|
sl@0
|
154 |
if(random<0x40000000)
|
sl@0
|
155 |
chunk.Commit(i,PageSize); // to make paging cache fragmented
|
sl@0
|
156 |
READ(LargeBuffer + i);
|
sl@0
|
157 |
}
|
sl@0
|
158 |
|
sl@0
|
159 |
CLOSE_AND_WAIT(chunk);
|
sl@0
|
160 |
|
sl@0
|
161 |
UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, 0, 0);
|
sl@0
|
162 |
}
|
sl@0
|
163 |
|
sl@0
|
164 |
|
sl@0
|
165 |
void RomPagingBenchmark()
|
sl@0
|
166 |
{
|
sl@0
|
167 |
TInt r=DPTest::FlushCache();
|
sl@0
|
168 |
if(r!=KErrNone)
|
sl@0
|
169 |
return;
|
sl@0
|
170 |
|
sl@0
|
171 |
test.Start(_L("Benchmark ROM paging..."));
|
sl@0
|
172 |
|
sl@0
|
173 |
// change live list to be a small as possible
|
sl@0
|
174 |
test(KErrNone==DPTest::SetCacheSize(1,1));
|
sl@0
|
175 |
|
sl@0
|
176 |
RTimer timer;
|
sl@0
|
177 |
test(KErrNone==timer.CreateLocal());
|
sl@0
|
178 |
TRequestStatus status;
|
sl@0
|
179 |
timer.After(status,1);
|
sl@0
|
180 |
User::WaitForRequest(status);
|
sl@0
|
181 |
|
sl@0
|
182 |
TPckgBuf<DPTest::TEventInfo> events0;
|
sl@0
|
183 |
DPTest::EventInfo(events0);
|
sl@0
|
184 |
|
sl@0
|
185 |
TInt KRunTime = 10*1000*1000;
|
sl@0
|
186 |
timer.After(status,KRunTime);
|
sl@0
|
187 |
while(status==KRequestPending)
|
sl@0
|
188 |
for(const TUint8* ptr=LargeBuffer; ptr<(LargeBuffer+LargeBufferSize); ptr+=PageSize)
|
sl@0
|
189 |
{
|
sl@0
|
190 |
READ(ptr);
|
sl@0
|
191 |
if(status!=KRequestPending)
|
sl@0
|
192 |
break;
|
sl@0
|
193 |
}
|
sl@0
|
194 |
|
sl@0
|
195 |
TPckgBuf<DPTest::TEventInfo> events1;
|
sl@0
|
196 |
DPTest::EventInfo(events1);
|
sl@0
|
197 |
|
sl@0
|
198 |
User::WaitForRequest(status);
|
sl@0
|
199 |
|
sl@0
|
200 |
TUint pages = events1().iPageInReadCount-events0().iPageInReadCount;
|
sl@0
|
201 |
test.Printf(_L("%d pages in %d seconds = %d us/page\n"),pages,KRunTime/1000/1000,KRunTime/pages);
|
sl@0
|
202 |
|
sl@0
|
203 |
// restore live list to default size...
|
sl@0
|
204 |
test(KErrNone==DPTest::SetCacheSize(0,0));
|
sl@0
|
205 |
|
sl@0
|
206 |
test.End();
|
sl@0
|
207 |
}
|
sl@0
|
208 |
|
sl@0
|
209 |
|
sl@0
|
210 |
void TestResizeVMCache()
|
sl@0
|
211 |
{
|
sl@0
|
212 |
TInt r = DPTest::SetCacheSize(0,0); // restore cache size to defaults
|
sl@0
|
213 |
test(r==KErrNone);
|
sl@0
|
214 |
TUint sizeMin = 0;
|
sl@0
|
215 |
TUint sizeMax = 0;
|
sl@0
|
216 |
TUint currentSize = 0;
|
sl@0
|
217 |
DPTest::CacheSize(sizeMin,sizeMax,currentSize);
|
sl@0
|
218 |
TUint originalMin = sizeMin;
|
sl@0
|
219 |
TUint originalMax = sizeMax;
|
sl@0
|
220 |
test.Printf(_L("original min=%u, original max=%u, current=%u\n"),originalMin/PageSize,originalMax/PageSize,currentSize/PageSize);
|
sl@0
|
221 |
|
sl@0
|
222 |
int K = currentSize/PageSize+4;
|
sl@0
|
223 |
|
sl@0
|
224 |
struct
|
sl@0
|
225 |
{
|
sl@0
|
226 |
TUint iMinPages;
|
sl@0
|
227 |
TUint iMaxPages;
|
sl@0
|
228 |
TInt iResult;
|
sl@0
|
229 |
}
|
sl@0
|
230 |
testArgs[] =
|
sl@0
|
231 |
{
|
sl@0
|
232 |
{ K, K, KErrNone},
|
sl@0
|
233 |
{ K-4, K, KErrNone},
|
sl@0
|
234 |
{ K, K, KErrNone},
|
sl@0
|
235 |
{ K, K*2, KErrNone},
|
sl@0
|
236 |
{ K, K, KErrNone},
|
sl@0
|
237 |
{ K-1, K, KErrNone},
|
sl@0
|
238 |
{ K, K, KErrNone},
|
sl@0
|
239 |
{ K, K+1, KErrNone},
|
sl@0
|
240 |
{ K, K, KErrNone},
|
sl@0
|
241 |
{ K+1, K, KErrArgument},
|
sl@0
|
242 |
{ K, K-1, KErrArgument},
|
sl@0
|
243 |
{ KMaxTInt, KMaxTInt, KErrNoMemory},
|
sl@0
|
244 |
{ K, K, KErrNone},
|
sl@0
|
245 |
|
sl@0
|
246 |
{ 0, 0, KErrNone}, // restore defaults
|
sl@0
|
247 |
{ 0, 0, KMaxTInt} // list end marker
|
sl@0
|
248 |
};
|
sl@0
|
249 |
|
sl@0
|
250 |
for(TInt j=0; j<2; ++j)
|
sl@0
|
251 |
{
|
sl@0
|
252 |
if(!j)
|
sl@0
|
253 |
{
|
sl@0
|
254 |
test.Start(_L("Changing size of flushed VM cache"));
|
sl@0
|
255 |
test.Printf(_L("Original cache size min == %u, max == %u\n"),originalMin/PageSize,originalMax/PageSize);
|
sl@0
|
256 |
}
|
sl@0
|
257 |
else
|
sl@0
|
258 |
test.Next(_L("Changing size of full VM cache"));
|
sl@0
|
259 |
TInt i=0;
|
sl@0
|
260 |
while(testArgs[i].iResult!=KMaxTInt)
|
sl@0
|
261 |
{
|
sl@0
|
262 |
TUint min=testArgs[i].iMinPages*PageSize;
|
sl@0
|
263 |
TUint max=testArgs[i].iMaxPages*PageSize;
|
sl@0
|
264 |
TInt result=testArgs[i].iResult;
|
sl@0
|
265 |
|
sl@0
|
266 |
ThrashPaging(max*2);
|
sl@0
|
267 |
if(!j)
|
sl@0
|
268 |
DPTest::FlushCache();
|
sl@0
|
269 |
|
sl@0
|
270 |
test.Printf(_L("DPTest::SetCacheSize min=%u, max=%u, expected result=%d\n"),min/PageSize,max/PageSize,result);
|
sl@0
|
271 |
TInt r=DPTest::SetCacheSize(min,max);
|
sl@0
|
272 |
if(r!=result)
|
sl@0
|
273 |
{
|
sl@0
|
274 |
test.Printf(_L("result=%d\n"),r);
|
sl@0
|
275 |
test(0);
|
sl@0
|
276 |
}
|
sl@0
|
277 |
if(r==KErrNone)
|
sl@0
|
278 |
{
|
sl@0
|
279 |
// we've successfully changed the cache size...
|
sl@0
|
280 |
if(max)
|
sl@0
|
281 |
{
|
sl@0
|
282 |
sizeMin = min;
|
sl@0
|
283 |
sizeMax = max;
|
sl@0
|
284 |
}
|
sl@0
|
285 |
else
|
sl@0
|
286 |
{
|
sl@0
|
287 |
sizeMin = originalMin;
|
sl@0
|
288 |
sizeMax = originalMax;
|
sl@0
|
289 |
}
|
sl@0
|
290 |
}
|
sl@0
|
291 |
if(r==KErrNoMemory)
|
sl@0
|
292 |
{
|
sl@0
|
293 |
// cache size after OOM is unpredictable, so reset our values
|
sl@0
|
294 |
DPTest::SetCacheSize(sizeMin,sizeMax);
|
sl@0
|
295 |
}
|
sl@0
|
296 |
else
|
sl@0
|
297 |
{
|
sl@0
|
298 |
// test 'get' function returns expected cache size
|
sl@0
|
299 |
r=DPTest::CacheSize(min,max,currentSize);
|
sl@0
|
300 |
test.Printf(_L("DPTest::CacheSize result=%d min=%u max=%u current=%u\n"),r,min/PageSize,max/PageSize,currentSize/PageSize);
|
sl@0
|
301 |
if(r!=KErrNone || min!=sizeMin || max!=sizeMax)
|
sl@0
|
302 |
test(0);
|
sl@0
|
303 |
test(currentSize >= min && currentSize <= max);
|
sl@0
|
304 |
}
|
sl@0
|
305 |
++i;
|
sl@0
|
306 |
}
|
sl@0
|
307 |
}
|
sl@0
|
308 |
|
sl@0
|
309 |
test.End();
|
sl@0
|
310 |
}
|
sl@0
|
311 |
|
sl@0
|
312 |
|
sl@0
|
313 |
|
sl@0
|
314 |
void TestResizeVMCache2()
|
sl@0
|
315 |
{
|
sl@0
|
316 |
TUint originalMin = 0;
|
sl@0
|
317 |
TUint originalMax = 0;
|
sl@0
|
318 |
TUint currentSize = 0;
|
sl@0
|
319 |
test_KErrNone(DPTest::CacheSize(originalMax, originalMax, currentSize));
|
sl@0
|
320 |
test_KErrNone(DPTest::SetCacheSize(1, originalMax));
|
sl@0
|
321 |
TUint sizeMin = 0;
|
sl@0
|
322 |
TUint sizeMax = 0;
|
sl@0
|
323 |
test_KErrNone(DPTest::CacheSize(sizeMin, sizeMax, currentSize));
|
sl@0
|
324 |
test(sizeMin > 1);
|
sl@0
|
325 |
test_KErrNone(DPTest::SetCacheSize(originalMin, originalMax));
|
sl@0
|
326 |
}
|
sl@0
|
327 |
|
sl@0
|
328 |
|
sl@0
|
329 |
void TestHAL()
|
sl@0
|
330 |
{
|
sl@0
|
331 |
test.Start(_L("DPTest::Attributes"));
|
sl@0
|
332 |
TUint32 attr=DPTest::Attributes();
|
sl@0
|
333 |
test.Printf(_L("Attributes = %08x\n"),attr);
|
sl@0
|
334 |
|
sl@0
|
335 |
test.Next(_L("DPTest::FlushCache"));
|
sl@0
|
336 |
TInt r=DPTest::FlushCache();
|
sl@0
|
337 |
if(r==KErrNotSupported)
|
sl@0
|
338 |
test.Printf(_L("Not Supported\n"));
|
sl@0
|
339 |
else if(r<0)
|
sl@0
|
340 |
{
|
sl@0
|
341 |
test.Printf(_L("Error = %d\n"),r);
|
sl@0
|
342 |
test(0);
|
sl@0
|
343 |
}
|
sl@0
|
344 |
|
sl@0
|
345 |
test.Next(_L("DPTest::CacheSize"));
|
sl@0
|
346 |
TUint oldMin = 0;
|
sl@0
|
347 |
TUint oldMax = 0;
|
sl@0
|
348 |
TUint currentSize = 0;
|
sl@0
|
349 |
r=DPTest::CacheSize(oldMin,oldMax,currentSize);
|
sl@0
|
350 |
if(r==KErrNotSupported)
|
sl@0
|
351 |
test.Printf(_L("Not Supported\n"));
|
sl@0
|
352 |
else if(r<0)
|
sl@0
|
353 |
{
|
sl@0
|
354 |
test.Printf(_L("Error = %d\n"),r);
|
sl@0
|
355 |
test(0);
|
sl@0
|
356 |
}
|
sl@0
|
357 |
else
|
sl@0
|
358 |
{
|
sl@0
|
359 |
test.Printf(_L("Size = %dk,%dk,%dk\n"),oldMin>>10,oldMax>>10,currentSize>>10);
|
sl@0
|
360 |
}
|
sl@0
|
361 |
|
sl@0
|
362 |
test.Next(_L("DPTest::SetCacheSize"));
|
sl@0
|
363 |
r=DPTest::SetCacheSize(oldMin,oldMax);
|
sl@0
|
364 |
if(r==KErrNotSupported)
|
sl@0
|
365 |
test.Printf(_L("Not Supported\n"));
|
sl@0
|
366 |
else if(r<0)
|
sl@0
|
367 |
{
|
sl@0
|
368 |
test.Printf(_L("Error = %d\n"),r);
|
sl@0
|
369 |
test(0);
|
sl@0
|
370 |
}
|
sl@0
|
371 |
if(r==KErrNone)
|
sl@0
|
372 |
{
|
sl@0
|
373 |
TestResizeVMCache();
|
sl@0
|
374 |
TestResizeVMCache2();
|
sl@0
|
375 |
}
|
sl@0
|
376 |
|
sl@0
|
377 |
test.End();
|
sl@0
|
378 |
}
|
sl@0
|
379 |
|
sl@0
|
380 |
// Test IPC and realtime state
|
sl@0
|
381 |
|
sl@0
|
382 |
enum TIpcDir
|
sl@0
|
383 |
{
|
sl@0
|
384 |
EServerRead,
|
sl@0
|
385 |
EServerWrite
|
sl@0
|
386 |
};
|
sl@0
|
387 |
|
sl@0
|
388 |
enum TIpcObjectPaged
|
sl@0
|
389 |
{
|
sl@0
|
390 |
ENothingPaged,
|
sl@0
|
391 |
EDesHeaderPaged,
|
sl@0
|
392 |
EDesContentPaged
|
sl@0
|
393 |
};
|
sl@0
|
394 |
|
sl@0
|
395 |
enum TRealtimeOutcome
|
sl@0
|
396 |
{
|
sl@0
|
397 |
ENoError,
|
sl@0
|
398 |
EBadDescriptor,
|
sl@0
|
399 |
EServerTerminated,
|
sl@0
|
400 |
ERealtimePanic
|
sl@0
|
401 |
};
|
sl@0
|
402 |
|
sl@0
|
403 |
class RTestSession : public RSessionBase
|
sl@0
|
404 |
{
|
sl@0
|
405 |
public:
|
sl@0
|
406 |
TInt Create(RServer2 aServer)
|
sl@0
|
407 |
{
|
sl@0
|
408 |
return CreateSession(aServer,TVersion(),-1);
|
sl@0
|
409 |
}
|
sl@0
|
410 |
inline TInt Send(const TIpcArgs& aArgs)
|
sl@0
|
411 |
{
|
sl@0
|
412 |
return RSessionBase::SendReceive(0,aArgs);
|
sl@0
|
413 |
}
|
sl@0
|
414 |
};
|
sl@0
|
415 |
|
sl@0
|
416 |
RServer2 TestServer;
|
sl@0
|
417 |
|
sl@0
|
418 |
TInt IpcTestServerFunc(TAny* aArg)
|
sl@0
|
419 |
{
|
sl@0
|
420 |
TIpcDir dir = (TIpcDir)(((TInt)aArg) & 0xff);
|
sl@0
|
421 |
TIpcObjectPaged paged = (TIpcObjectPaged)((((TInt)aArg) >> 8) & 0xff);
|
sl@0
|
422 |
User::TRealtimeState realtime = (User::TRealtimeState)((((TInt)aArg) >> 16) & 0xff);
|
sl@0
|
423 |
User::TRealtimeState clientRealtime = (User::TRealtimeState)((((TInt)aArg) >> 24) & 0xff);
|
sl@0
|
424 |
|
sl@0
|
425 |
TInt r;
|
sl@0
|
426 |
// We want the server to fault the client when it is realtime
|
sl@0
|
427 |
// and accessing paged out memory.
|
sl@0
|
428 |
r = TestServer.CreateGlobal(KNullDesC, EIpcSession_Sharable, EServerRole_Default, EServerOpt_PinClientDescriptorsDisable);
|
sl@0
|
429 |
if (r != KErrNone)
|
sl@0
|
430 |
return r;
|
sl@0
|
431 |
RThread::Rendezvous(KErrNone);
|
sl@0
|
432 |
|
sl@0
|
433 |
RMessage2 message;
|
sl@0
|
434 |
TestServer.Receive(message);
|
sl@0
|
435 |
if ((clientRealtime == User::ERealtimeStateOn) != message.ClientIsRealtime())
|
sl@0
|
436 |
return KErrGeneral;
|
sl@0
|
437 |
message.Complete(KErrNone); // complete connection request
|
sl@0
|
438 |
|
sl@0
|
439 |
TRequestStatus s;
|
sl@0
|
440 |
TestServer.Receive(message,s);
|
sl@0
|
441 |
User::WaitForRequest(s);
|
sl@0
|
442 |
if (s != KErrNone)
|
sl@0
|
443 |
return s.Int();
|
sl@0
|
444 |
|
sl@0
|
445 |
TInt32 unpagedContent;
|
sl@0
|
446 |
TPtr8 unpagedDes((TUint8*)&unpagedContent, 4, 4);
|
sl@0
|
447 |
TPtrC8 pagedContentBuf(SmallBuffer,sizeof(TInt));
|
sl@0
|
448 |
|
sl@0
|
449 |
TPtr8* dataPagedHeaderDes = (TPtr8*)DataPagedBuffer;
|
sl@0
|
450 |
if (DataPagingSupported)
|
sl@0
|
451 |
new (dataPagedHeaderDes) TPtr8((TUint8*)&unpagedContent, 4);
|
sl@0
|
452 |
|
sl@0
|
453 |
TPtr8 dataPagedContentDes(DataPagedBuffer + PageSize, 4);
|
sl@0
|
454 |
|
sl@0
|
455 |
r = DPTest::FlushCache();
|
sl@0
|
456 |
if(r != KErrNone)
|
sl@0
|
457 |
return r;
|
sl@0
|
458 |
|
sl@0
|
459 |
User::SetRealtimeState(realtime);
|
sl@0
|
460 |
if (dir == EServerRead)
|
sl@0
|
461 |
{
|
sl@0
|
462 |
switch (paged)
|
sl@0
|
463 |
{
|
sl@0
|
464 |
case ENothingPaged:
|
sl@0
|
465 |
r = message.Read(0,unpagedDes);
|
sl@0
|
466 |
break;
|
sl@0
|
467 |
|
sl@0
|
468 |
case EDesHeaderPaged:
|
sl@0
|
469 |
r = DataPagingSupported ? message.Read(0,*dataPagedHeaderDes) : KErrNotSupported;
|
sl@0
|
470 |
break;
|
sl@0
|
471 |
|
sl@0
|
472 |
case EDesContentPaged:
|
sl@0
|
473 |
r = DataPagingSupported ? message.Read(0,dataPagedContentDes) : KErrNotSupported;
|
sl@0
|
474 |
break;
|
sl@0
|
475 |
|
sl@0
|
476 |
default:
|
sl@0
|
477 |
r = KErrArgument;
|
sl@0
|
478 |
break;
|
sl@0
|
479 |
}
|
sl@0
|
480 |
}
|
sl@0
|
481 |
else if (dir == EServerWrite)
|
sl@0
|
482 |
{
|
sl@0
|
483 |
switch (paged)
|
sl@0
|
484 |
{
|
sl@0
|
485 |
case ENothingPaged:
|
sl@0
|
486 |
r = message.Write(0,unpagedDes);
|
sl@0
|
487 |
break;
|
sl@0
|
488 |
|
sl@0
|
489 |
case EDesHeaderPaged:
|
sl@0
|
490 |
r = message.Write(0,*PagedHeaderDes);
|
sl@0
|
491 |
break;
|
sl@0
|
492 |
|
sl@0
|
493 |
case EDesContentPaged:
|
sl@0
|
494 |
r = message.Write(0,pagedContentBuf);
|
sl@0
|
495 |
break;
|
sl@0
|
496 |
|
sl@0
|
497 |
default:
|
sl@0
|
498 |
r = KErrArgument;
|
sl@0
|
499 |
break;
|
sl@0
|
500 |
}
|
sl@0
|
501 |
}
|
sl@0
|
502 |
else
|
sl@0
|
503 |
r = KErrArgument;
|
sl@0
|
504 |
User::SetRealtimeState(User::ERealtimeStateOff);
|
sl@0
|
505 |
|
sl@0
|
506 |
message.Complete(KErrNone);
|
sl@0
|
507 |
return r;
|
sl@0
|
508 |
}
|
sl@0
|
509 |
|
sl@0
|
510 |
TInt IpcTestClientFunc(TAny* aArg)
|
sl@0
|
511 |
{
|
sl@0
|
512 |
TIpcDir dir = (TIpcDir)(((TInt)aArg) & 0xff);
|
sl@0
|
513 |
TIpcObjectPaged paged = (TIpcObjectPaged)((((TInt)aArg) >> 8) & 0xff);
|
sl@0
|
514 |
User::TRealtimeState realtime = (User::TRealtimeState)((((TInt)aArg) >> 16) & 0xff);
|
sl@0
|
515 |
|
sl@0
|
516 |
RTestSession session;
|
sl@0
|
517 |
TInt r = session.Create(TestServer);
|
sl@0
|
518 |
if(r != KErrNone)
|
sl@0
|
519 |
return r;
|
sl@0
|
520 |
|
sl@0
|
521 |
TInt32 unpagedContent;
|
sl@0
|
522 |
TPtr8 unpagedDes((TUint8*)&unpagedContent, 4, 4);
|
sl@0
|
523 |
TPtrC8 pagedContentBuf(SmallBuffer + PageSize, sizeof(TInt));
|
sl@0
|
524 |
|
sl@0
|
525 |
TPtr8* dataPagedHeaderDes = (TPtr8*)(DataPagedBuffer + (2 * PageSize));
|
sl@0
|
526 |
if (DataPagingSupported)
|
sl@0
|
527 |
new (dataPagedHeaderDes) TPtr8((TUint8*)&unpagedContent, 4);
|
sl@0
|
528 |
|
sl@0
|
529 |
TPtr8 dataPagedContentDes(DataPagedBuffer + (3 * PageSize), 4);
|
sl@0
|
530 |
|
sl@0
|
531 |
r = DPTest::FlushCache();
|
sl@0
|
532 |
if(r != KErrNone)
|
sl@0
|
533 |
return r;
|
sl@0
|
534 |
|
sl@0
|
535 |
User::SetRealtimeState(realtime);
|
sl@0
|
536 |
if (dir == EServerRead)
|
sl@0
|
537 |
{
|
sl@0
|
538 |
switch (paged)
|
sl@0
|
539 |
{
|
sl@0
|
540 |
case ENothingPaged:
|
sl@0
|
541 |
r = session.Send(TIpcArgs(&unpagedDes));
|
sl@0
|
542 |
break;
|
sl@0
|
543 |
|
sl@0
|
544 |
case EDesHeaderPaged:
|
sl@0
|
545 |
r = session.Send(TIpcArgs(PagedHeaderDes));
|
sl@0
|
546 |
break;
|
sl@0
|
547 |
|
sl@0
|
548 |
case EDesContentPaged:
|
sl@0
|
549 |
r = session.Send(TIpcArgs(&pagedContentBuf));
|
sl@0
|
550 |
break;
|
sl@0
|
551 |
|
sl@0
|
552 |
default:
|
sl@0
|
553 |
r = KErrArgument;
|
sl@0
|
554 |
break;
|
sl@0
|
555 |
}
|
sl@0
|
556 |
}
|
sl@0
|
557 |
else if (dir == EServerWrite)
|
sl@0
|
558 |
{
|
sl@0
|
559 |
switch (paged)
|
sl@0
|
560 |
{
|
sl@0
|
561 |
case ENothingPaged:
|
sl@0
|
562 |
r = session.Send(TIpcArgs(&unpagedDes));
|
sl@0
|
563 |
break;
|
sl@0
|
564 |
|
sl@0
|
565 |
case EDesHeaderPaged:
|
sl@0
|
566 |
r = DataPagingSupported ? session.Send(TIpcArgs(dataPagedHeaderDes)) : KErrNotSupported;
|
sl@0
|
567 |
break;
|
sl@0
|
568 |
|
sl@0
|
569 |
case EDesContentPaged:
|
sl@0
|
570 |
r = DataPagingSupported ? session.Send(TIpcArgs(&dataPagedContentDes)) : KErrNotSupported;
|
sl@0
|
571 |
break;
|
sl@0
|
572 |
|
sl@0
|
573 |
default:
|
sl@0
|
574 |
r = KErrArgument;
|
sl@0
|
575 |
break;
|
sl@0
|
576 |
}
|
sl@0
|
577 |
}
|
sl@0
|
578 |
else
|
sl@0
|
579 |
r = KErrArgument;
|
sl@0
|
580 |
User::SetRealtimeState(User::ERealtimeStateOff);
|
sl@0
|
581 |
|
sl@0
|
582 |
session.Close();
|
sl@0
|
583 |
return r;
|
sl@0
|
584 |
}
|
sl@0
|
585 |
|
sl@0
|
586 |
void TestRealtimeOutcome(RThread aThread, TRealtimeOutcome aOutcome)
|
sl@0
|
587 |
{
|
sl@0
|
588 |
switch(aOutcome)
|
sl@0
|
589 |
{
|
sl@0
|
590 |
case ENoError:
|
sl@0
|
591 |
test_Equal(EExitKill, aThread.ExitType());
|
sl@0
|
592 |
test_KErrNone(aThread.ExitReason());
|
sl@0
|
593 |
break;
|
sl@0
|
594 |
|
sl@0
|
595 |
case EBadDescriptor:
|
sl@0
|
596 |
test_Equal(EExitKill, aThread.ExitType());
|
sl@0
|
597 |
test_Equal(KErrBadDescriptor, aThread.ExitReason());
|
sl@0
|
598 |
break;
|
sl@0
|
599 |
|
sl@0
|
600 |
case EServerTerminated:
|
sl@0
|
601 |
test_Equal(EExitKill, aThread.ExitType());
|
sl@0
|
602 |
test_Equal(KErrServerTerminated, aThread.ExitReason());
|
sl@0
|
603 |
break;
|
sl@0
|
604 |
|
sl@0
|
605 |
case ERealtimePanic:
|
sl@0
|
606 |
test_Equal(EExitPanic, aThread.ExitType());
|
sl@0
|
607 |
test(aThread.ExitCategory()==_L("KERN-EXEC"));
|
sl@0
|
608 |
test_Equal(EIllegalFunctionForRealtimeThread, aThread.ExitReason());
|
sl@0
|
609 |
break;
|
sl@0
|
610 |
|
sl@0
|
611 |
default:
|
sl@0
|
612 |
test(EFalse);
|
sl@0
|
613 |
}
|
sl@0
|
614 |
}
|
sl@0
|
615 |
|
sl@0
|
616 |
void TestPagedIpc(TIpcDir aIpcDir,
|
sl@0
|
617 |
TIpcObjectPaged aClientPaged,
|
sl@0
|
618 |
TIpcObjectPaged aServerPaged,
|
sl@0
|
619 |
User::TRealtimeState aClientState,
|
sl@0
|
620 |
User::TRealtimeState aServerState,
|
sl@0
|
621 |
TRealtimeOutcome aClientOutcome,
|
sl@0
|
622 |
TRealtimeOutcome aServerOutcome)
|
sl@0
|
623 |
{
|
sl@0
|
624 |
test.Printf(_L("TestPagedIpc %d %d %d %d %d %d %d\n"), aIpcDir, aClientPaged, aServerPaged,
|
sl@0
|
625 |
aClientState, aServerState, aClientOutcome, aServerOutcome);
|
sl@0
|
626 |
|
sl@0
|
627 |
RThread serverThread;
|
sl@0
|
628 |
RThread clientThread;
|
sl@0
|
629 |
TRequestStatus serverStatus;
|
sl@0
|
630 |
TRequestStatus clientStatus;
|
sl@0
|
631 |
|
sl@0
|
632 |
TInt serverArg = aIpcDir | (aServerPaged << 8) | (aServerState << 16) | (aClientState << 24);
|
sl@0
|
633 |
test_KErrNone(serverThread.Create(KNullDesC, &IpcTestServerFunc, 0x1000, NULL, (TAny*)serverArg));
|
sl@0
|
634 |
TName name;
|
sl@0
|
635 |
name = serverThread.Name();
|
sl@0
|
636 |
test.Printf(_L(" server: %S\n"), &name);
|
sl@0
|
637 |
serverThread.Rendezvous(serverStatus);
|
sl@0
|
638 |
serverThread.Resume();
|
sl@0
|
639 |
User::WaitForRequest(serverStatus);
|
sl@0
|
640 |
test_KErrNone(serverStatus.Int());
|
sl@0
|
641 |
serverThread.Logon(serverStatus);
|
sl@0
|
642 |
|
sl@0
|
643 |
TInt clientArg = aIpcDir | (aClientPaged << 8) | (aClientState << 16);
|
sl@0
|
644 |
test_KErrNone(clientThread.Create(KNullDesC, &IpcTestClientFunc, 0x1000, NULL, (TAny*)clientArg));
|
sl@0
|
645 |
name = clientThread.Name();
|
sl@0
|
646 |
test.Printf(_L(" client: %S\n"), &name);
|
sl@0
|
647 |
clientThread.Logon(clientStatus);
|
sl@0
|
648 |
clientThread.Resume();
|
sl@0
|
649 |
|
sl@0
|
650 |
User::WaitForRequest(serverStatus);
|
sl@0
|
651 |
test.Printf(_L(" server exit type is %d %d\n"), serverThread.ExitType(), serverThread.ExitReason());
|
sl@0
|
652 |
TestServer.Close(); // because handle is process-relative, it's not closed if the server dies
|
sl@0
|
653 |
|
sl@0
|
654 |
User::WaitForRequest(clientStatus);
|
sl@0
|
655 |
test.Printf(_L(" client exit type is %d %d\n"), clientThread.ExitType(), clientThread.ExitReason());
|
sl@0
|
656 |
|
sl@0
|
657 |
TestRealtimeOutcome(serverThread, aServerOutcome);
|
sl@0
|
658 |
TestRealtimeOutcome(clientThread, aClientOutcome);
|
sl@0
|
659 |
|
sl@0
|
660 |
CLOSE_AND_WAIT(serverThread);
|
sl@0
|
661 |
CLOSE_AND_WAIT(clientThread);
|
sl@0
|
662 |
}
|
sl@0
|
663 |
|
sl@0
|
664 |
TInt TestThreadFunction(TAny* aType)
|
sl@0
|
665 |
{
|
sl@0
|
666 |
// Ensure that pageable memory is paged out
|
sl@0
|
667 |
TInt r=DPTest::FlushCache();
|
sl@0
|
668 |
if(r!=KErrNone)
|
sl@0
|
669 |
return r;
|
sl@0
|
670 |
|
sl@0
|
671 |
// Access pageable data whilst thread is in specified realttime state.
|
sl@0
|
672 |
User::SetRealtimeState((User::TRealtimeState)(TInt)aType);
|
sl@0
|
673 |
READ(SmallBuffer);
|
sl@0
|
674 |
return KErrNone;
|
sl@0
|
675 |
}
|
sl@0
|
676 |
|
sl@0
|
677 |
TInt RunTestThread(User::TRealtimeState aType, TRealtimeOutcome aOutcome)
|
sl@0
|
678 |
{
|
sl@0
|
679 |
RThread thread;
|
sl@0
|
680 |
TInt r=thread.Create(KNullDesC, &TestThreadFunction, 0x1000, NULL, (TAny*)aType);
|
sl@0
|
681 |
if(r!=KErrNone)
|
sl@0
|
682 |
return r;
|
sl@0
|
683 |
TRequestStatus s;
|
sl@0
|
684 |
thread.Logon(s);
|
sl@0
|
685 |
if(s.Int()!=KRequestPending)
|
sl@0
|
686 |
return s.Int();
|
sl@0
|
687 |
thread.Resume();
|
sl@0
|
688 |
User::WaitForRequest(s);
|
sl@0
|
689 |
TestRealtimeOutcome(thread, aOutcome);
|
sl@0
|
690 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
691 |
return KErrNone;
|
sl@0
|
692 |
}
|
sl@0
|
693 |
|
sl@0
|
694 |
void TestRealtimeState()
|
sl@0
|
695 |
{
|
sl@0
|
696 |
// make sure live list is big enough
|
sl@0
|
697 |
test(KErrNone==DPTest::SetCacheSize(256*PageSize,256*PageSize));
|
sl@0
|
698 |
|
sl@0
|
699 |
test.Start(_L("Enable KREALTIME tracing"));
|
sl@0
|
700 |
Ldd.SetRealtimeTrace(ETrue);
|
sl@0
|
701 |
|
sl@0
|
702 |
test.Next(_L("Test ERealtimeStateOff"));
|
sl@0
|
703 |
RunTestThread(User::ERealtimeStateOff, ENoError);
|
sl@0
|
704 |
|
sl@0
|
705 |
test.Next(_L("Test ERealtimeStateOn"));
|
sl@0
|
706 |
RunTestThread(User::ERealtimeStateOn, ERealtimePanic);
|
sl@0
|
707 |
|
sl@0
|
708 |
test.Next(_L("Test ERealtimeStateWarn"));
|
sl@0
|
709 |
RunTestThread(User::ERealtimeStateWarn, ENoError);
|
sl@0
|
710 |
|
sl@0
|
711 |
test.Next(_L("Test combinations of IPC with realtime state"));
|
sl@0
|
712 |
|
sl@0
|
713 |
// ipc dir: client paged: server paged: client state: server state: client outcome: server outcome:
|
sl@0
|
714 |
TestPagedIpc(EServerRead, ENothingPaged, ENothingPaged, User::ERealtimeStateOff, User::ERealtimeStateOff, ENoError, ENoError);
|
sl@0
|
715 |
TestPagedIpc(EServerRead, EDesHeaderPaged, ENothingPaged, User::ERealtimeStateOff, User::ERealtimeStateOff, ENoError, ENoError);
|
sl@0
|
716 |
TestPagedIpc(EServerRead, EDesContentPaged, ENothingPaged, User::ERealtimeStateOff, User::ERealtimeStateOff, ENoError, ENoError);
|
sl@0
|
717 |
TestPagedIpc(EServerWrite, ENothingPaged, ENothingPaged, User::ERealtimeStateOff, User::ERealtimeStateOff, ENoError, ENoError);
|
sl@0
|
718 |
TestPagedIpc(EServerWrite, ENothingPaged, EDesHeaderPaged, User::ERealtimeStateOff, User::ERealtimeStateOff, ENoError, ENoError);
|
sl@0
|
719 |
TestPagedIpc(EServerWrite, ENothingPaged, EDesContentPaged, User::ERealtimeStateOff, User::ERealtimeStateOff, ENoError, ENoError);
|
sl@0
|
720 |
|
sl@0
|
721 |
if (DataPagingSupported)
|
sl@0
|
722 |
{
|
sl@0
|
723 |
TestPagedIpc(EServerRead, ENothingPaged, ENothingPaged, User::ERealtimeStateOff, User::ERealtimeStateOff, ENoError, ENoError);
|
sl@0
|
724 |
TestPagedIpc(EServerRead, ENothingPaged, EDesHeaderPaged, User::ERealtimeStateOff, User::ERealtimeStateOff, ENoError, ENoError);
|
sl@0
|
725 |
TestPagedIpc(EServerRead, ENothingPaged, EDesContentPaged, User::ERealtimeStateOff, User::ERealtimeStateOff, ENoError, ENoError);
|
sl@0
|
726 |
TestPagedIpc(EServerWrite, ENothingPaged, ENothingPaged, User::ERealtimeStateOff, User::ERealtimeStateOff, ENoError, ENoError);
|
sl@0
|
727 |
TestPagedIpc(EServerWrite, EDesHeaderPaged, ENothingPaged, User::ERealtimeStateOff, User::ERealtimeStateOff, ENoError, ENoError);
|
sl@0
|
728 |
TestPagedIpc(EServerWrite, EDesContentPaged, ENothingPaged, User::ERealtimeStateOff, User::ERealtimeStateOff, ENoError, ENoError);
|
sl@0
|
729 |
}
|
sl@0
|
730 |
|
sl@0
|
731 |
TestPagedIpc(EServerRead, ENothingPaged, ENothingPaged, User::ERealtimeStateOff, User::ERealtimeStateWarn, ENoError, ENoError);
|
sl@0
|
732 |
TestPagedIpc(EServerRead, EDesHeaderPaged, ENothingPaged, User::ERealtimeStateOff, User::ERealtimeStateWarn, ENoError, ENoError);
|
sl@0
|
733 |
TestPagedIpc(EServerRead, EDesContentPaged, ENothingPaged, User::ERealtimeStateOff, User::ERealtimeStateWarn, ENoError, ENoError);
|
sl@0
|
734 |
TestPagedIpc(EServerWrite, ENothingPaged, ENothingPaged, User::ERealtimeStateOff, User::ERealtimeStateWarn, ENoError, ENoError);
|
sl@0
|
735 |
TestPagedIpc(EServerWrite, ENothingPaged, EDesHeaderPaged, User::ERealtimeStateOff, User::ERealtimeStateWarn, ENoError, ENoError);
|
sl@0
|
736 |
TestPagedIpc(EServerWrite, ENothingPaged, EDesContentPaged, User::ERealtimeStateOff, User::ERealtimeStateWarn, ENoError, ENoError);
|
sl@0
|
737 |
|
sl@0
|
738 |
if (DataPagingSupported)
|
sl@0
|
739 |
{
|
sl@0
|
740 |
TestPagedIpc(EServerRead, ENothingPaged, ENothingPaged, User::ERealtimeStateOff, User::ERealtimeStateWarn, ENoError, ENoError);
|
sl@0
|
741 |
TestPagedIpc(EServerRead, ENothingPaged, EDesHeaderPaged, User::ERealtimeStateOff, User::ERealtimeStateWarn, ENoError, ENoError);
|
sl@0
|
742 |
TestPagedIpc(EServerRead, ENothingPaged, EDesContentPaged, User::ERealtimeStateOff, User::ERealtimeStateWarn, ENoError, ENoError);
|
sl@0
|
743 |
TestPagedIpc(EServerWrite, ENothingPaged, ENothingPaged, User::ERealtimeStateOff, User::ERealtimeStateWarn, ENoError, ENoError);
|
sl@0
|
744 |
TestPagedIpc(EServerWrite, EDesHeaderPaged, ENothingPaged, User::ERealtimeStateOff, User::ERealtimeStateWarn, ENoError, ENoError);
|
sl@0
|
745 |
TestPagedIpc(EServerWrite, EDesContentPaged, ENothingPaged, User::ERealtimeStateOff, User::ERealtimeStateWarn, ENoError, ENoError);
|
sl@0
|
746 |
}
|
sl@0
|
747 |
|
sl@0
|
748 |
TestPagedIpc(EServerRead, ENothingPaged, ENothingPaged, User::ERealtimeStateOff, User::ERealtimeStateOn, ENoError, ENoError);
|
sl@0
|
749 |
TestPagedIpc(EServerRead, EDesHeaderPaged, ENothingPaged, User::ERealtimeStateOff, User::ERealtimeStateOn, ENoError, ENoError);
|
sl@0
|
750 |
TestPagedIpc(EServerRead, EDesContentPaged, ENothingPaged, User::ERealtimeStateOff, User::ERealtimeStateOn, ERealtimePanic, EBadDescriptor);
|
sl@0
|
751 |
TestPagedIpc(EServerWrite, ENothingPaged, ENothingPaged, User::ERealtimeStateOff, User::ERealtimeStateOn, ENoError, ENoError);
|
sl@0
|
752 |
TestPagedIpc(EServerWrite, ENothingPaged, EDesHeaderPaged, User::ERealtimeStateOff, User::ERealtimeStateOn, EServerTerminated, ERealtimePanic);
|
sl@0
|
753 |
TestPagedIpc(EServerWrite, ENothingPaged, EDesContentPaged, User::ERealtimeStateOff, User::ERealtimeStateOn, EServerTerminated, ERealtimePanic);
|
sl@0
|
754 |
|
sl@0
|
755 |
if (DataPagingSupported)
|
sl@0
|
756 |
{
|
sl@0
|
757 |
TestPagedIpc(EServerRead, ENothingPaged, ENothingPaged, User::ERealtimeStateOff, User::ERealtimeStateOn, ENoError, ENoError);
|
sl@0
|
758 |
TestPagedIpc(EServerRead, ENothingPaged, EDesHeaderPaged, User::ERealtimeStateOff, User::ERealtimeStateOn, EServerTerminated, ERealtimePanic);
|
sl@0
|
759 |
TestPagedIpc(EServerRead, ENothingPaged, EDesContentPaged, User::ERealtimeStateOff, User::ERealtimeStateOn, EServerTerminated, ERealtimePanic);
|
sl@0
|
760 |
TestPagedIpc(EServerWrite, ENothingPaged, ENothingPaged, User::ERealtimeStateOff, User::ERealtimeStateOn, ENoError, ENoError);
|
sl@0
|
761 |
TestPagedIpc(EServerWrite, EDesHeaderPaged, ENothingPaged, User::ERealtimeStateOff, User::ERealtimeStateOn, ENoError, ENoError);
|
sl@0
|
762 |
TestPagedIpc(EServerWrite, EDesContentPaged, ENothingPaged, User::ERealtimeStateOff, User::ERealtimeStateOn, ERealtimePanic, EBadDescriptor);
|
sl@0
|
763 |
}
|
sl@0
|
764 |
|
sl@0
|
765 |
test.End();
|
sl@0
|
766 |
|
sl@0
|
767 |
// retore size of live list
|
sl@0
|
768 |
test(KErrNone==DPTest::SetCacheSize(0,0));
|
sl@0
|
769 |
}
|
sl@0
|
770 |
|
sl@0
|
771 |
void TestLock()
|
sl@0
|
772 |
{
|
sl@0
|
773 |
// make sure live list is big enough
|
sl@0
|
774 |
test(KErrNone==DPTest::SetCacheSize(128 * PageSize, 256 * PageSize));
|
sl@0
|
775 |
|
sl@0
|
776 |
TInt r = Ldd.LockTest(SmallBuffer,SmallBufferSize);
|
sl@0
|
777 |
if(r==KErrNone)
|
sl@0
|
778 |
{
|
sl@0
|
779 |
test.Next(_L("Lock Test again"));
|
sl@0
|
780 |
r = Ldd.LockTest(SmallBuffer,SmallBufferSize);
|
sl@0
|
781 |
}
|
sl@0
|
782 |
if(r)
|
sl@0
|
783 |
{
|
sl@0
|
784 |
test.Printf(_L("failed at D_DEMANPAGING.CPP line %d\n"),r);
|
sl@0
|
785 |
test(0);
|
sl@0
|
786 |
}
|
sl@0
|
787 |
|
sl@0
|
788 |
// restore live list to default size...
|
sl@0
|
789 |
test(KErrNone==DPTest::SetCacheSize(0,0));
|
sl@0
|
790 |
}
|
sl@0
|
791 |
|
sl@0
|
792 |
const TInt KSmallPropertySize = 512;
|
sl@0
|
793 |
const TInt KLargePropertySize = 16384;
|
sl@0
|
794 |
|
sl@0
|
795 |
struct SSetPropertyInfo
|
sl@0
|
796 |
{
|
sl@0
|
797 |
TUid iCategory;
|
sl@0
|
798 |
TInt iKey;
|
sl@0
|
799 |
TUint8* iData;
|
sl@0
|
800 |
TInt iLength;
|
sl@0
|
801 |
};
|
sl@0
|
802 |
|
sl@0
|
803 |
TInt SetPropertyThreadFunction(TAny* aArg)
|
sl@0
|
804 |
{
|
sl@0
|
805 |
SSetPropertyInfo* info = (SSetPropertyInfo*)aArg;
|
sl@0
|
806 |
TInt r;
|
sl@0
|
807 |
r = DPTest::FlushCache();
|
sl@0
|
808 |
if (r != KErrNone)
|
sl@0
|
809 |
return r;
|
sl@0
|
810 |
TPtrC8 data(info->iData, info->iLength);
|
sl@0
|
811 |
r = RProperty::Set(info->iCategory, info->iKey, data);
|
sl@0
|
812 |
if (r != KErrNone)
|
sl@0
|
813 |
return r;
|
sl@0
|
814 |
RBuf8 buffer;
|
sl@0
|
815 |
r = buffer.Create(KLargePropertySize);
|
sl@0
|
816 |
if (r != KErrNone)
|
sl@0
|
817 |
return r;
|
sl@0
|
818 |
r = RProperty::Get(info->iCategory, info->iKey, buffer);
|
sl@0
|
819 |
if (r == KErrNone && buffer != data)
|
sl@0
|
820 |
r = KErrGeneral;
|
sl@0
|
821 |
buffer.Close();
|
sl@0
|
822 |
return r;
|
sl@0
|
823 |
}
|
sl@0
|
824 |
|
sl@0
|
825 |
void TestPublishAndSubscribe()
|
sl@0
|
826 |
{
|
sl@0
|
827 |
RProcess thisProcess;
|
sl@0
|
828 |
TUid category = thisProcess.SecureId();
|
sl@0
|
829 |
|
sl@0
|
830 |
TSecurityPolicy alwaysPass(TSecurityPolicy::EAlwaysPass);
|
sl@0
|
831 |
test(RProperty::Define(category, 0, RProperty::EByteArray, alwaysPass, alwaysPass) == KErrNone);
|
sl@0
|
832 |
test(RProperty::Define(category, 1, RProperty::ELargeByteArray, alwaysPass, alwaysPass) == KErrNone);
|
sl@0
|
833 |
|
sl@0
|
834 |
TPtrC8 smallData(SmallBuffer, KSmallPropertySize);
|
sl@0
|
835 |
TPtrC8 largeData(SmallBuffer, KLargePropertySize);
|
sl@0
|
836 |
|
sl@0
|
837 |
RBuf8 buffer;
|
sl@0
|
838 |
test(buffer.Create(KLargePropertySize) == KErrNone);
|
sl@0
|
839 |
|
sl@0
|
840 |
// Set small property from paged data, method 1
|
sl@0
|
841 |
test(DPTest::FlushCache() == KErrNone);
|
sl@0
|
842 |
test(RProperty::Set(category, 0, smallData) == KErrNone);
|
sl@0
|
843 |
test(RProperty::Get(category, 0, buffer) == KErrNone);
|
sl@0
|
844 |
test(buffer == smallData);
|
sl@0
|
845 |
|
sl@0
|
846 |
// Set small property from paged data, method 2
|
sl@0
|
847 |
RProperty smallProp;
|
sl@0
|
848 |
test(smallProp.Attach(category, 0) == KErrNone);
|
sl@0
|
849 |
test(DPTest::FlushCache() == KErrNone);
|
sl@0
|
850 |
test(smallProp.Set(smallData) == KErrNone);
|
sl@0
|
851 |
test(smallProp.Get(buffer) == KErrNone);
|
sl@0
|
852 |
test(buffer == smallData);
|
sl@0
|
853 |
|
sl@0
|
854 |
// Set large property from paged data, method 1
|
sl@0
|
855 |
test(DPTest::FlushCache() == KErrNone);
|
sl@0
|
856 |
test(RProperty::Set(category, 1, largeData) == KErrNone);
|
sl@0
|
857 |
test(RProperty::Get(category, 1, buffer) == KErrNone);
|
sl@0
|
858 |
test(buffer == largeData);
|
sl@0
|
859 |
|
sl@0
|
860 |
// Set large property from paged data, method 2
|
sl@0
|
861 |
RProperty largeProp;
|
sl@0
|
862 |
test(largeProp.Attach(category, 1) == KErrNone);
|
sl@0
|
863 |
test(DPTest::FlushCache() == KErrNone);
|
sl@0
|
864 |
test(largeProp.Set(largeData) == KErrNone);
|
sl@0
|
865 |
test(largeProp.Get(buffer) == KErrNone);
|
sl@0
|
866 |
test(buffer == largeData);
|
sl@0
|
867 |
|
sl@0
|
868 |
// Set small property from unmapped address
|
sl@0
|
869 |
RThread thread;
|
sl@0
|
870 |
#if !defined( __VC32__)
|
sl@0
|
871 |
SSetPropertyInfo info = { category, 0, 0, KSmallPropertySize };
|
sl@0
|
872 |
#else
|
sl@0
|
873 |
SSetPropertyInfo info = { category.iUid, 0, 0, KSmallPropertySize };
|
sl@0
|
874 |
#endif
|
sl@0
|
875 |
test(thread.Create(_L("SetPropertyThread"), SetPropertyThreadFunction, 4096, NULL, &info) == KErrNone);
|
sl@0
|
876 |
thread.Resume();
|
sl@0
|
877 |
TRequestStatus status;
|
sl@0
|
878 |
thread.Logon(status);
|
sl@0
|
879 |
User::WaitForRequest(status);
|
sl@0
|
880 |
test(thread.ExitType()==EExitPanic);
|
sl@0
|
881 |
test(thread.ExitCategory()==_L("KERN-EXEC"));
|
sl@0
|
882 |
test(thread.ExitReason()==ECausedException);
|
sl@0
|
883 |
thread.Close();
|
sl@0
|
884 |
|
sl@0
|
885 |
// Set large property from unmapped address
|
sl@0
|
886 |
info.iKey = 1;
|
sl@0
|
887 |
info.iLength = KLargePropertySize;
|
sl@0
|
888 |
test(thread.Create(_L("SetPropertyThread"), SetPropertyThreadFunction, 4096, NULL, &info) == KErrNone);
|
sl@0
|
889 |
thread.Resume();
|
sl@0
|
890 |
thread.Logon(status);
|
sl@0
|
891 |
User::WaitForRequest(status);
|
sl@0
|
892 |
test(thread.ExitType()==EExitPanic);
|
sl@0
|
893 |
test(thread.ExitCategory()==_L("KERN-EXEC"));
|
sl@0
|
894 |
test(thread.ExitReason()==ECausedException);
|
sl@0
|
895 |
thread.Close();
|
sl@0
|
896 |
|
sl@0
|
897 |
test(RProperty::Delete(category, 0) == KErrNone);
|
sl@0
|
898 |
test(RProperty::Delete(category, 1) == KErrNone);
|
sl@0
|
899 |
}
|
sl@0
|
900 |
|
sl@0
|
901 |
void TestWriteToPagedArea()
|
sl@0
|
902 |
{
|
sl@0
|
903 |
RMemoryTestLdd memoryTest;
|
sl@0
|
904 |
test(KErrNone==memoryTest.Open());
|
sl@0
|
905 |
|
sl@0
|
906 |
TModuleMemoryInfo exeInfo;
|
sl@0
|
907 |
test(KErrNone==RProcess().GetMemoryInfo(exeInfo));
|
sl@0
|
908 |
test.Printf(_L("test program code is %x+%x"),exeInfo.iCodeBase,exeInfo.iCodeSize);
|
sl@0
|
909 |
|
sl@0
|
910 |
TUint8* ptr = const_cast<TUint8*>(LargeBuffer);
|
sl@0
|
911 |
TUint8* end = ptr + LargeBufferSize;
|
sl@0
|
912 |
while(ptr<end)
|
sl@0
|
913 |
{
|
sl@0
|
914 |
if(ptr>=(TUint8*)_ALIGN_DOWN(exeInfo.iCodeBase,PageSize) && ptr<(TUint8*)_ALIGN_UP(exeInfo.iCodeBase+exeInfo.iCodeSize,PageSize))
|
sl@0
|
915 |
{
|
sl@0
|
916 |
// avoid testing the ROM which contains this test program
|
sl@0
|
917 |
ptr += PageSize;
|
sl@0
|
918 |
continue;
|
sl@0
|
919 |
}
|
sl@0
|
920 |
|
sl@0
|
921 |
DPTest::FlushCache();
|
sl@0
|
922 |
|
sl@0
|
923 |
TInt stateBits = UserSvr::HalFunction(EHalGroupVM, EVMPageState, ptr, 0);
|
sl@0
|
924 |
test(stateBits>=0);
|
sl@0
|
925 |
// write to paged out memory should cause exception...
|
sl@0
|
926 |
test(KErrBadDescriptor==memoryTest.WriteMemory(ptr,0));
|
sl@0
|
927 |
// page state should be unchanged...
|
sl@0
|
928 |
TInt newStateBits = UserSvr::HalFunction(EHalGroupVM, EVMPageState, ptr, 0);
|
sl@0
|
929 |
if(stateBits!=newStateBits)
|
sl@0
|
930 |
{
|
sl@0
|
931 |
test.Printf(_L("ptr=%x stateBits=%x newStateBits=%x"),ptr,stateBits,newStateBits);
|
sl@0
|
932 |
test(0);
|
sl@0
|
933 |
}
|
sl@0
|
934 |
// page-in in memory...
|
sl@0
|
935 |
TUint32 value = *(TUint32*)ptr;
|
sl@0
|
936 |
// write to paged out memory should still cause exception...
|
sl@0
|
937 |
test(KErrBadDescriptor==memoryTest.WriteMemory(ptr,~value));
|
sl@0
|
938 |
// memory should be unchanged...
|
sl@0
|
939 |
test(value==*(TUint32*)ptr);
|
sl@0
|
940 |
ptr += PageSize;
|
sl@0
|
941 |
}
|
sl@0
|
942 |
|
sl@0
|
943 |
memoryTest.Close();
|
sl@0
|
944 |
}
|
sl@0
|
945 |
|
sl@0
|
946 |
void TestContiguousRamAlloc()
|
sl@0
|
947 |
{
|
sl@0
|
948 |
test.Start(_L("Start..."));
|
sl@0
|
949 |
|
sl@0
|
950 |
const TInt KCacheSize = 1024*1024;
|
sl@0
|
951 |
|
sl@0
|
952 |
DPTest::SetCacheSize(0, KCacheSize); // make sure paging cache is a reasonable size
|
sl@0
|
953 |
|
sl@0
|
954 |
TInt testData[][2] = /* array of page size (in units of 'half pages') and align values */
|
sl@0
|
955 |
{
|
sl@0
|
956 |
{64,5},
|
sl@0
|
957 |
{64,0},
|
sl@0
|
958 |
{32,4},
|
sl@0
|
959 |
{32,3},
|
sl@0
|
960 |
{32,2},
|
sl@0
|
961 |
{32,1},
|
sl@0
|
962 |
{32,0},
|
sl@0
|
963 |
{4,2},
|
sl@0
|
964 |
{4,1},
|
sl@0
|
965 |
{4,0},
|
sl@0
|
966 |
{2,2},
|
sl@0
|
967 |
{2,1},
|
sl@0
|
968 |
{2,0},
|
sl@0
|
969 |
{1,0},
|
sl@0
|
970 |
{0,0}
|
sl@0
|
971 |
};
|
sl@0
|
972 |
TInt pageShift = 1;
|
sl@0
|
973 |
while((1<<pageShift)<PageSize)
|
sl@0
|
974 |
++pageShift;
|
sl@0
|
975 |
|
sl@0
|
976 |
TInt* params = (TInt*)&testData;
|
sl@0
|
977 |
while(*params)
|
sl@0
|
978 |
{
|
sl@0
|
979 |
TInt size = *params++<<(pageShift-1); //Size is units of half pages, so one less shift to get required memory size
|
sl@0
|
980 |
TInt align = *params++;
|
sl@0
|
981 |
if(align)
|
sl@0
|
982 |
align += pageShift - 1;
|
sl@0
|
983 |
TBuf<256> title;
|
sl@0
|
984 |
title.AppendFormat(_L("Contiguous RAM test: alloc size = %dK align = %d"),size>>10, align);
|
sl@0
|
985 |
test.Next(title);
|
sl@0
|
986 |
FragmentPagingCache(KCacheSize);
|
sl@0
|
987 |
TInt r = Ldd.DoConsumeContiguousRamTest(align, size);
|
sl@0
|
988 |
if(r)
|
sl@0
|
989 |
{
|
sl@0
|
990 |
test.Printf(_L("failed at D_DEMANPAGING.CPP line %d\n"),r);
|
sl@0
|
991 |
test(0);
|
sl@0
|
992 |
}
|
sl@0
|
993 |
}
|
sl@0
|
994 |
|
sl@0
|
995 |
DPTest::SetCacheSize(0,0); // back to defaults
|
sl@0
|
996 |
test.End();
|
sl@0
|
997 |
}
|
sl@0
|
998 |
|
sl@0
|
999 |
void TestReadHoldingMutex()
|
sl@0
|
1000 |
{
|
sl@0
|
1001 |
TUint8 localBuf[16];
|
sl@0
|
1002 |
TUint8* localPtr = localBuf;
|
sl@0
|
1003 |
if(DPTest::Attributes() & DPTest::EDataPaging) // if data paging supported...
|
sl@0
|
1004 |
localPtr = 0; // use zero to make driver use kernel memory as data destination
|
sl@0
|
1005 |
test(Ldd.ReadHoldingMutexTest(localPtr) == KErrNone);
|
sl@0
|
1006 |
}
|
sl@0
|
1007 |
|
sl@0
|
1008 |
#if 0 // rom dump code...
|
sl@0
|
1009 |
#include <f32file.h>
|
sl@0
|
1010 |
RFs fs;
|
sl@0
|
1011 |
RFile file;
|
sl@0
|
1012 |
test(KErrNone==fs.Connect());
|
sl@0
|
1013 |
test(KErrNone==file.Replace(fs, _L("d:\\ROMDUMP"),EFileWrite));
|
sl@0
|
1014 |
TRomHeader* romHeader = (TRomHeader*)UserSvr::RomHeaderAddress();
|
sl@0
|
1015 |
TPtrC8 rom((TUint8*)romHeader,romHeader->iRomSize);
|
sl@0
|
1016 |
test(KErrNone==file.Write(rom));
|
sl@0
|
1017 |
file.Close();
|
sl@0
|
1018 |
fs.Close();
|
sl@0
|
1019 |
return 0;
|
sl@0
|
1020 |
#endif
|
sl@0
|
1021 |
|
sl@0
|
1022 |
|
sl@0
|
1023 |
class RMySession : public RSessionBase
|
sl@0
|
1024 |
{
|
sl@0
|
1025 |
public:
|
sl@0
|
1026 |
TInt Connect(RServer2 aSrv,TRequestStatus& aStat)
|
sl@0
|
1027 |
{
|
sl@0
|
1028 |
TInt r=CreateSession(aSrv,TVersion(),-1,EIpcSession_Sharable,NULL,&aStat);
|
sl@0
|
1029 |
if(!r) ShareAuto(); return r;
|
sl@0
|
1030 |
}
|
sl@0
|
1031 |
TInt Send(TInt function,const TIpcArgs& args)
|
sl@0
|
1032 |
{return SendReceive(function,args);}
|
sl@0
|
1033 |
};
|
sl@0
|
1034 |
|
sl@0
|
1035 |
|
sl@0
|
1036 |
TUint8* TestBuffer = 0;
|
sl@0
|
1037 |
RMySession MySession;
|
sl@0
|
1038 |
|
sl@0
|
1039 |
LOCAL_C TInt TestServerThread(TAny* aSize)
|
sl@0
|
1040 |
{
|
sl@0
|
1041 |
TInt r = TestServer.CreateGlobal(KNullDesC, EIpcSession_GlobalSharable);
|
sl@0
|
1042 |
if(r==KErrNone)
|
sl@0
|
1043 |
{
|
sl@0
|
1044 |
TestBuffer = (TUint8*)User::Alloc(KMaxIPCSize);
|
sl@0
|
1045 |
if(!TestBuffer)
|
sl@0
|
1046 |
r = KErrNoMemory;
|
sl@0
|
1047 |
}
|
sl@0
|
1048 |
TPtr8 buffer(TestBuffer,KMaxIPCSize);
|
sl@0
|
1049 |
RThread::Rendezvous(r);
|
sl@0
|
1050 |
if (r != KErrNone)
|
sl@0
|
1051 |
return r;
|
sl@0
|
1052 |
|
sl@0
|
1053 |
RMessage2 m;
|
sl@0
|
1054 |
TestServer.Receive(m);
|
sl@0
|
1055 |
m.Complete(KErrNone); // connect message
|
sl@0
|
1056 |
|
sl@0
|
1057 |
TBool running = ETrue;
|
sl@0
|
1058 |
while (running)
|
sl@0
|
1059 |
{
|
sl@0
|
1060 |
TestServer.Receive(m);
|
sl@0
|
1061 |
RDebug::Printf("Server received: %d", m.Function());
|
sl@0
|
1062 |
|
sl@0
|
1063 |
TInt r = KErrNone;
|
sl@0
|
1064 |
switch(m.Function())
|
sl@0
|
1065 |
{
|
sl@0
|
1066 |
case 0:
|
sl@0
|
1067 |
// Kill server
|
sl@0
|
1068 |
running = EFalse;
|
sl@0
|
1069 |
break;
|
sl@0
|
1070 |
|
sl@0
|
1071 |
case 2:
|
sl@0
|
1072 |
buffer.Set(SharedBuffer,KMaxIPCSize,KMaxIPCSize);
|
sl@0
|
1073 |
// fall through...
|
sl@0
|
1074 |
case 1:
|
sl@0
|
1075 |
// Perform CRC of data passed
|
sl@0
|
1076 |
{
|
sl@0
|
1077 |
DPTest::FlushCache();
|
sl@0
|
1078 |
r=m.Read(0,buffer);
|
sl@0
|
1079 |
if (r!=KErrNone)
|
sl@0
|
1080 |
break;
|
sl@0
|
1081 |
TUint32 crc=0;
|
sl@0
|
1082 |
Mem::Crc32(crc,buffer.Ptr(),buffer.Size());
|
sl@0
|
1083 |
r = crc;
|
sl@0
|
1084 |
}
|
sl@0
|
1085 |
break;
|
sl@0
|
1086 |
|
sl@0
|
1087 |
case 4:
|
sl@0
|
1088 |
buffer.Set(SharedBuffer,KMaxIPCSize,KMaxIPCSize);
|
sl@0
|
1089 |
// fall through...
|
sl@0
|
1090 |
case 3:
|
sl@0
|
1091 |
// Write data to client descriptor
|
sl@0
|
1092 |
{
|
sl@0
|
1093 |
DPTest::FlushCache();
|
sl@0
|
1094 |
RDebug::Printf("Server writing %08x+%x", m.Int1(), m.Int2());
|
sl@0
|
1095 |
TPtrC8 ptr((TUint8*)m.Int1(),m.Int2());
|
sl@0
|
1096 |
r=m.Write(0,ptr);
|
sl@0
|
1097 |
}
|
sl@0
|
1098 |
break;
|
sl@0
|
1099 |
|
sl@0
|
1100 |
default:
|
sl@0
|
1101 |
// Just complete anything else
|
sl@0
|
1102 |
break;
|
sl@0
|
1103 |
}
|
sl@0
|
1104 |
m.Complete(r);
|
sl@0
|
1105 |
}
|
sl@0
|
1106 |
|
sl@0
|
1107 |
RDebug::Printf("Server exiting");
|
sl@0
|
1108 |
User::Free(TestBuffer);
|
sl@0
|
1109 |
TestBuffer = NULL;
|
sl@0
|
1110 |
TestServer.Close();
|
sl@0
|
1111 |
return KErrNone;
|
sl@0
|
1112 |
}
|
sl@0
|
1113 |
|
sl@0
|
1114 |
void TestIPC()
|
sl@0
|
1115 |
{
|
sl@0
|
1116 |
__KHEAP_MARK;
|
sl@0
|
1117 |
|
sl@0
|
1118 |
const TUint8* start = LargeBuffer + 0x3df; // make range not page aligned
|
sl@0
|
1119 |
const TUint8* end = start + Min(LargeBufferSize, KMaxIPCSize * 10) - 0x130; // make range not page aligned
|
sl@0
|
1120 |
const TUint8* pos;
|
sl@0
|
1121 |
|
sl@0
|
1122 |
test.Start(_L("Create server"));
|
sl@0
|
1123 |
RThread t;
|
sl@0
|
1124 |
TInt r=t.Create(KNullDesC,TestServerThread,0x1000,KMaxIPCSize+0x1000,KMaxIPCSize+0x1000,(void*)0);
|
sl@0
|
1125 |
test(r==KErrNone);
|
sl@0
|
1126 |
t.SetPriority(EPriorityMore);
|
sl@0
|
1127 |
TRequestStatus s;
|
sl@0
|
1128 |
t.Rendezvous(s);
|
sl@0
|
1129 |
t.Resume();
|
sl@0
|
1130 |
User::WaitForRequest(s);
|
sl@0
|
1131 |
test(TestServer.Handle() != KNullHandle);
|
sl@0
|
1132 |
|
sl@0
|
1133 |
test(MySession.Connect(TestServer,s) == KErrNone);
|
sl@0
|
1134 |
User::WaitForRequest(s); // connected
|
sl@0
|
1135 |
|
sl@0
|
1136 |
TInt bufferType; // 0=server uses heap, 1=server uses SharedBuffer
|
sl@0
|
1137 |
for(bufferType=0; bufferType<=1; ++bufferType)
|
sl@0
|
1138 |
{
|
sl@0
|
1139 |
test.Next(_L("IPC read from ROM"));
|
sl@0
|
1140 |
pos = start;
|
sl@0
|
1141 |
while(pos<end)
|
sl@0
|
1142 |
{
|
sl@0
|
1143 |
TInt size = end-pos;
|
sl@0
|
1144 |
if(size>KMaxIPCSize)
|
sl@0
|
1145 |
size = KMaxIPCSize;
|
sl@0
|
1146 |
RDebug::Printf("read %x+%x",pos,size);
|
sl@0
|
1147 |
TPtrC8 ptr(pos,size);
|
sl@0
|
1148 |
TInt r = MySession.Send(1+bufferType,TIpcArgs(&ptr));
|
sl@0
|
1149 |
DPTest::FlushCache();
|
sl@0
|
1150 |
TUint32 crc=0;
|
sl@0
|
1151 |
Mem::Crc32(crc,pos,size);
|
sl@0
|
1152 |
RDebug::Printf("crc %08x %08x",r,crc);
|
sl@0
|
1153 |
if((TUint32)r!=crc)
|
sl@0
|
1154 |
{
|
sl@0
|
1155 |
RDebug::Printf("FAIL");
|
sl@0
|
1156 |
DPTest::FlushCache();
|
sl@0
|
1157 |
TInt count = 0;
|
sl@0
|
1158 |
for(TInt i=0; i<size; i+=4)
|
sl@0
|
1159 |
{
|
sl@0
|
1160 |
TUint32 a = pos[i];
|
sl@0
|
1161 |
TUint32 b = TestBuffer[i];
|
sl@0
|
1162 |
if(a!=b)
|
sl@0
|
1163 |
RDebug::Printf("%08x %02x!=%02x",pos+i,a,b);
|
sl@0
|
1164 |
if (++count > 100)
|
sl@0
|
1165 |
break;
|
sl@0
|
1166 |
}
|
sl@0
|
1167 |
}
|
sl@0
|
1168 |
test((TUint32)r==crc);
|
sl@0
|
1169 |
pos+=size;
|
sl@0
|
1170 |
}
|
sl@0
|
1171 |
|
sl@0
|
1172 |
test.Next(_L("IPC write from ROM"));
|
sl@0
|
1173 |
pos = start;
|
sl@0
|
1174 |
while(pos<end)
|
sl@0
|
1175 |
{
|
sl@0
|
1176 |
TInt size = end-pos;
|
sl@0
|
1177 |
if(size>KMaxIPCSize)
|
sl@0
|
1178 |
size = KMaxIPCSize;
|
sl@0
|
1179 |
RDebug::Printf("write %x+%x",pos,size);
|
sl@0
|
1180 |
memclr(TestBuffer, KMaxIPCSize);
|
sl@0
|
1181 |
TPtr8 ptr(TestBuffer,KMaxIPCSize); // reuse the server's buffer
|
sl@0
|
1182 |
TInt r = MySession.Send(3+bufferType,TIpcArgs(&ptr,pos,size));
|
sl@0
|
1183 |
test_KErrNone(r);
|
sl@0
|
1184 |
DPTest::FlushCache();
|
sl@0
|
1185 |
TUint32 crc=0;
|
sl@0
|
1186 |
Mem::Crc32(crc,pos,size);
|
sl@0
|
1187 |
TUint32 crc2=0;
|
sl@0
|
1188 |
Mem::Crc32(crc2,TestBuffer,size);
|
sl@0
|
1189 |
RDebug::Printf("crc %08x %08x",crc,crc2);
|
sl@0
|
1190 |
if((TUint32)crc!=crc2)
|
sl@0
|
1191 |
{
|
sl@0
|
1192 |
RDebug::Printf("FAIL");
|
sl@0
|
1193 |
DPTest::FlushCache();
|
sl@0
|
1194 |
TInt count = 0;
|
sl@0
|
1195 |
for(TInt i=0; i<size; i+=4)
|
sl@0
|
1196 |
{
|
sl@0
|
1197 |
TUint32 a = pos[i];
|
sl@0
|
1198 |
TUint32 b = TestBuffer[i];
|
sl@0
|
1199 |
if(a!=b)
|
sl@0
|
1200 |
RDebug::Printf("%08x %02x!=%02x",pos+i,a,b);
|
sl@0
|
1201 |
if (++count > 100)
|
sl@0
|
1202 |
break;
|
sl@0
|
1203 |
}
|
sl@0
|
1204 |
}
|
sl@0
|
1205 |
test((TUint32)crc==crc2);
|
sl@0
|
1206 |
pos+=size;
|
sl@0
|
1207 |
}
|
sl@0
|
1208 |
}
|
sl@0
|
1209 |
|
sl@0
|
1210 |
if (DPTest::Attributes() & DPTest::ERomPaging)
|
sl@0
|
1211 |
{
|
sl@0
|
1212 |
test.Next(_L("Test passing descriptor headers in paged-out memory"));
|
sl@0
|
1213 |
__KHEAP_MARK;
|
sl@0
|
1214 |
|
sl@0
|
1215 |
DPTest::FlushCache();
|
sl@0
|
1216 |
TInt r = MySession.Send(5,TIpcArgs(PagedHeaderDes));
|
sl@0
|
1217 |
test_Equal(KErrNone, r);
|
sl@0
|
1218 |
|
sl@0
|
1219 |
UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, 0, 0);
|
sl@0
|
1220 |
__KHEAP_MARKEND;
|
sl@0
|
1221 |
}
|
sl@0
|
1222 |
|
sl@0
|
1223 |
test.Next(_L("Stop server"));
|
sl@0
|
1224 |
MySession.Send(0,TIpcArgs(0));
|
sl@0
|
1225 |
MySession.Close();
|
sl@0
|
1226 |
t.Logon(s);
|
sl@0
|
1227 |
User::WaitForRequest(s);
|
sl@0
|
1228 |
test_Equal(EExitKill, t.ExitType());
|
sl@0
|
1229 |
test_Equal(KErrNone, t.ExitReason());
|
sl@0
|
1230 |
CLOSE_AND_WAIT(t);
|
sl@0
|
1231 |
test.End();
|
sl@0
|
1232 |
|
sl@0
|
1233 |
UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, 0, 0);
|
sl@0
|
1234 |
__KHEAP_MARKEND;
|
sl@0
|
1235 |
}
|
sl@0
|
1236 |
|
sl@0
|
1237 |
|
sl@0
|
1238 |
TInt E32Main()
|
sl@0
|
1239 |
{
|
sl@0
|
1240 |
test.Title();
|
sl@0
|
1241 |
|
sl@0
|
1242 |
test_KErrNone(UserSvr::HalFunction(EHalGroupKernel,EKernelHalPageSizeInBytes,&PageSize,0));
|
sl@0
|
1243 |
|
sl@0
|
1244 |
if (DPTest::Attributes() & DPTest::ERomPaging)
|
sl@0
|
1245 |
test.Printf(_L("Rom paging supported\n"));
|
sl@0
|
1246 |
if (DPTest::Attributes() & DPTest::ECodePaging)
|
sl@0
|
1247 |
test.Printf(_L("Code paging supported\n"));
|
sl@0
|
1248 |
if (DPTest::Attributes() & DPTest::EDataPaging)
|
sl@0
|
1249 |
{
|
sl@0
|
1250 |
test.Printf(_L("Data paging supported\n"));
|
sl@0
|
1251 |
DataPagingSupported = ETrue;
|
sl@0
|
1252 |
TChunkCreateInfo createInfo;
|
sl@0
|
1253 |
createInfo.SetNormal(KMinBufferSize, KMinBufferSize);
|
sl@0
|
1254 |
createInfo.SetPaging(TChunkCreateInfo::EPaged);
|
sl@0
|
1255 |
createInfo.SetOwner(EOwnerProcess);
|
sl@0
|
1256 |
createInfo.SetGlobal(KChunkName);
|
sl@0
|
1257 |
test_KErrNone(DataPagedChunk.Create(createInfo));
|
sl@0
|
1258 |
test(DataPagedChunk.IsPaged()); // this is only ever called if data paging is supported
|
sl@0
|
1259 |
DataPagedBuffer = (TUint8*)DataPagedChunk.Base();
|
sl@0
|
1260 |
}
|
sl@0
|
1261 |
|
sl@0
|
1262 |
test.Start(_L("Test HAL interface"));
|
sl@0
|
1263 |
TestHAL();
|
sl@0
|
1264 |
|
sl@0
|
1265 |
if (DPTest::Attributes() & DPTest::ERomPaging)
|
sl@0
|
1266 |
{
|
sl@0
|
1267 |
// Use paged part of rom for testing
|
sl@0
|
1268 |
TRomHeader* romHeader = (TRomHeader*)UserSvr::RomHeaderAddress();
|
sl@0
|
1269 |
test(romHeader->iPageableRomStart);
|
sl@0
|
1270 |
// todo: for some reason the first part of page of paged rom doesn't seem to get paged out
|
sl@0
|
1271 |
// when we flush the paging cache, hence LargeBuffer starts some way into this
|
sl@0
|
1272 |
LargeBuffer = (TUint8*)romHeader + romHeader->iPageableRomStart + 64 * PageSize;
|
sl@0
|
1273 |
LargeBufferSize = romHeader->iPageableRomSize - 64 * PageSize;
|
sl@0
|
1274 |
test(LargeBufferSize > 0);
|
sl@0
|
1275 |
// Find a zero word in rom to set PagedHeaderDes to
|
sl@0
|
1276 |
TUint* ptr = (TUint*)LargeBuffer;
|
sl@0
|
1277 |
TUint* end = (TUint*)(LargeBuffer + LargeBufferSize);
|
sl@0
|
1278 |
while (*ptr && ptr < end)
|
sl@0
|
1279 |
++ptr;
|
sl@0
|
1280 |
test(*ptr == 0);
|
sl@0
|
1281 |
test.Printf(_L("Found zero word at %08x\n"), ptr);
|
sl@0
|
1282 |
PagedHeaderDes = (TDesC8*)ptr;
|
sl@0
|
1283 |
}
|
sl@0
|
1284 |
else if (DPTest::Attributes() & DPTest::ECodePaging)
|
sl@0
|
1285 |
{
|
sl@0
|
1286 |
// Use code paged DLL for testing
|
sl@0
|
1287 |
test_KErrNone(PagedLibrary.Load(KTCodePagingDll4));
|
sl@0
|
1288 |
TGetAddressOfDataFunction func = (TGetAddressOfDataFunction)PagedLibrary.Lookup(KGetAddressOfDataFunctionOrdinal);
|
sl@0
|
1289 |
LargeBuffer = (TUint8*)func(LargeBufferSize);
|
sl@0
|
1290 |
test_NotNull(LargeBuffer);
|
sl@0
|
1291 |
PagedHeaderDes = (TDesC8*)LargeBuffer + 4;
|
sl@0
|
1292 |
}
|
sl@0
|
1293 |
else if (DPTest::Attributes() & DPTest::EDataPaging)
|
sl@0
|
1294 |
{
|
sl@0
|
1295 |
// Use data paged chunk for testing
|
sl@0
|
1296 |
LargeBuffer = DataPagedBuffer;
|
sl@0
|
1297 |
LargeBufferSize = KMinBufferSize;
|
sl@0
|
1298 |
}
|
sl@0
|
1299 |
else
|
sl@0
|
1300 |
{
|
sl@0
|
1301 |
test.Printf(_L("Demand Paging not supported\n"));
|
sl@0
|
1302 |
test.End();
|
sl@0
|
1303 |
return 0;
|
sl@0
|
1304 |
}
|
sl@0
|
1305 |
|
sl@0
|
1306 |
test(LargeBufferSize >= KMinBufferSize);
|
sl@0
|
1307 |
SmallBuffer = LargeBuffer;
|
sl@0
|
1308 |
SmallBufferSize = KMinBufferSize;
|
sl@0
|
1309 |
|
sl@0
|
1310 |
test.Next(_L("Loading test drivers"));
|
sl@0
|
1311 |
TInt r = User::LoadLogicalDevice(KDemandPagingTestLddName);
|
sl@0
|
1312 |
test(r==KErrNone || r==KErrAlreadyExists);
|
sl@0
|
1313 |
test(Ldd.Open()==KErrNone);
|
sl@0
|
1314 |
|
sl@0
|
1315 |
test_KErrNone(Ldd.CreatePlatHwChunk(SharedBufferSize, SharedBufferAddr));
|
sl@0
|
1316 |
SharedBuffer = (TUint8*)SharedBufferAddr;
|
sl@0
|
1317 |
|
sl@0
|
1318 |
RDebug::Printf("SmallBuffer=%x, LargeBuffer=%x, SharedBuffer=%x\n",
|
sl@0
|
1319 |
SmallBuffer, LargeBuffer, SharedBuffer);
|
sl@0
|
1320 |
|
sl@0
|
1321 |
test.Next(_L("Gobble RAM"));
|
sl@0
|
1322 |
r = User::LoadLogicalDevice(KGobblerLddFileName);
|
sl@0
|
1323 |
test(r==KErrNone || r==KErrAlreadyExists);
|
sl@0
|
1324 |
RGobbler gobbler;
|
sl@0
|
1325 |
r = gobbler.Open();
|
sl@0
|
1326 |
test(r==KErrNone);
|
sl@0
|
1327 |
TUint32 taken = gobbler.GobbleRAM(64*1024*1024); // leave 64MB of free RAM
|
sl@0
|
1328 |
test.Printf(_L("Gobbled: %dK\n"), taken/1024);
|
sl@0
|
1329 |
test.Printf(_L("Free RAM 0x%08X bytes\n"),FreeRam());
|
sl@0
|
1330 |
|
sl@0
|
1331 |
test.Next(_L("Test contiguous RAM allocation reclaims paged memory"));
|
sl@0
|
1332 |
TestContiguousRamAlloc();
|
sl@0
|
1333 |
|
sl@0
|
1334 |
test.Next(_L("Test thread realtime state"));
|
sl@0
|
1335 |
TestRealtimeState();
|
sl@0
|
1336 |
|
sl@0
|
1337 |
test.Next(_L("Lock Test"));
|
sl@0
|
1338 |
TestLock();
|
sl@0
|
1339 |
|
sl@0
|
1340 |
test.Next(_L("Test writing to paged area"));
|
sl@0
|
1341 |
TestWriteToPagedArea();
|
sl@0
|
1342 |
|
sl@0
|
1343 |
test.Next(_L("Test IPC read from paged memory"));
|
sl@0
|
1344 |
TestIPC();
|
sl@0
|
1345 |
|
sl@0
|
1346 |
test.Next(_L("Test no kernel faults when copying data from unpaged rom with mutex held"));
|
sl@0
|
1347 |
TestReadHoldingMutex();
|
sl@0
|
1348 |
|
sl@0
|
1349 |
test.Next(_L("Close test driver"));
|
sl@0
|
1350 |
Ldd.DestroyPlatHwChunk();
|
sl@0
|
1351 |
Ldd.Close();
|
sl@0
|
1352 |
|
sl@0
|
1353 |
test.Next(_L("Test setting publish and subscribe properties from paged area"));
|
sl@0
|
1354 |
TestPublishAndSubscribe();
|
sl@0
|
1355 |
|
sl@0
|
1356 |
if (DPTest::Attributes() & DPTest::ERomPaging)
|
sl@0
|
1357 |
{
|
sl@0
|
1358 |
test.Next(_L("Rom Paging Benchmark"));
|
sl@0
|
1359 |
RomPagingBenchmark();
|
sl@0
|
1360 |
}
|
sl@0
|
1361 |
|
sl@0
|
1362 |
PagedLibrary.Close();
|
sl@0
|
1363 |
gobbler.Close();
|
sl@0
|
1364 |
test.End();
|
sl@0
|
1365 |
|
sl@0
|
1366 |
return 0;
|
sl@0
|
1367 |
}
|