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