sl@0
|
1 |
// Copyright (c) 2008-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\demandpaging\t_pagingexample.cpp
|
sl@0
|
15 |
// Test device driver migration examples
|
sl@0
|
16 |
//
|
sl@0
|
17 |
//
|
sl@0
|
18 |
|
sl@0
|
19 |
#define __E32TEST_EXTENSION__
|
sl@0
|
20 |
#include <e32test.h>
|
sl@0
|
21 |
#include <dptest.h>
|
sl@0
|
22 |
#include <e32hal.h>
|
sl@0
|
23 |
#include <u32exec.h>
|
sl@0
|
24 |
#include <e32svr.h>
|
sl@0
|
25 |
#include <e32panic.h>
|
sl@0
|
26 |
#include <e32rom.h>
|
sl@0
|
27 |
#include <e32kpan.h>
|
sl@0
|
28 |
#include "../mmu/t_codepaging_dll.h"
|
sl@0
|
29 |
#include "d_pagingexample.h"
|
sl@0
|
30 |
|
sl@0
|
31 |
const TInt KBufferSize = KMaxTransferSize;
|
sl@0
|
32 |
_LIT(KTCodePagingDll4, "t_codepaging_dll4.dll");
|
sl@0
|
33 |
|
sl@0
|
34 |
struct TTestData
|
sl@0
|
35 |
{
|
sl@0
|
36 |
TRequestStatus iStatus;
|
sl@0
|
37 |
RPagingExample::TConfigData iConfig;
|
sl@0
|
38 |
RPagingExample::TValueStruct iValue;
|
sl@0
|
39 |
TInt iIntValue1;
|
sl@0
|
40 |
TInt iIntValue2;
|
sl@0
|
41 |
TPtr8 iPtr;
|
sl@0
|
42 |
TUint8 iBuffer[KBufferSize];
|
sl@0
|
43 |
public:
|
sl@0
|
44 |
TTestData() : iPtr(NULL, 0) { }
|
sl@0
|
45 |
};
|
sl@0
|
46 |
|
sl@0
|
47 |
RTest test(_L("T_PAGINGEXAMPLE"));
|
sl@0
|
48 |
TInt PageSize = 0;
|
sl@0
|
49 |
RLibrary PagedLibrary;
|
sl@0
|
50 |
TTestData* UnpagedInputData = NULL;
|
sl@0
|
51 |
TTestData* UnpagedOutputData = NULL;
|
sl@0
|
52 |
TTestData* PagedInputData = NULL;
|
sl@0
|
53 |
TTestData* PagedOutputData = NULL;
|
sl@0
|
54 |
|
sl@0
|
55 |
void InitInputData(TTestData* aData)
|
sl@0
|
56 |
{
|
sl@0
|
57 |
aData->iConfig.iParam1 = 2;
|
sl@0
|
58 |
aData->iConfig.iParam2 = 3;
|
sl@0
|
59 |
aData->iConfig.iParam3 = 5;
|
sl@0
|
60 |
aData->iConfig.iParam4 = 7;
|
sl@0
|
61 |
for (TInt i = 0 ; i < KBufferSize ; ++i)
|
sl@0
|
62 |
aData->iBuffer[i] = (TUint8)(i + 123);
|
sl@0
|
63 |
}
|
sl@0
|
64 |
|
sl@0
|
65 |
void DoTestDriver(const TDesC& aDriverName, const TTestData* aInputData, TTestData* aOutputData)
|
sl@0
|
66 |
{
|
sl@0
|
67 |
test.Start(_L("Load logical device"));
|
sl@0
|
68 |
TInt r = User::LoadLogicalDevice(aDriverName);
|
sl@0
|
69 |
test(r==KErrNone || r==KErrAlreadyExists);
|
sl@0
|
70 |
|
sl@0
|
71 |
test.Next(_L("Open logical device"));
|
sl@0
|
72 |
RPagingExample ldd;
|
sl@0
|
73 |
test_KErrNone(ldd.Open(aDriverName));
|
sl@0
|
74 |
|
sl@0
|
75 |
test.Next(_L("Set config"));
|
sl@0
|
76 |
DPTest::FlushCache();
|
sl@0
|
77 |
test_KErrNone(ldd.SetConfig(aInputData->iConfig));
|
sl@0
|
78 |
|
sl@0
|
79 |
test.Next(_L("Get config"));
|
sl@0
|
80 |
Mem::FillZ(&aOutputData->iConfig, sizeof(RPagingExample::TConfigData));
|
sl@0
|
81 |
DPTest::FlushCache();
|
sl@0
|
82 |
test_KErrNone(ldd.GetConfig(aOutputData->iConfig));
|
sl@0
|
83 |
test_Equal(0, Mem::Compare((TUint8*)&aInputData->iConfig, sizeof(RPagingExample::TConfigData),
|
sl@0
|
84 |
(TUint8*)&aOutputData->iConfig, sizeof(RPagingExample::TConfigData)));
|
sl@0
|
85 |
|
sl@0
|
86 |
TRequestStatus& status = aOutputData->iStatus;
|
sl@0
|
87 |
|
sl@0
|
88 |
test.Next(_L("Notify"));
|
sl@0
|
89 |
DPTest::FlushCache();
|
sl@0
|
90 |
ldd.Notify(status);
|
sl@0
|
91 |
DPTest::FlushCache();
|
sl@0
|
92 |
User::WaitForRequest(status);
|
sl@0
|
93 |
test_Equal(KErrNone, status.Int());
|
sl@0
|
94 |
|
sl@0
|
95 |
test.Next(_L("Async get value"));
|
sl@0
|
96 |
memclr(&aOutputData->iValue, sizeof(RPagingExample::TValueStruct));
|
sl@0
|
97 |
DPTest::FlushCache();
|
sl@0
|
98 |
ldd.AsyncGetValue(status, aOutputData->iValue);
|
sl@0
|
99 |
DPTest::FlushCache();
|
sl@0
|
100 |
User::WaitForRequest(status);
|
sl@0
|
101 |
test_Equal(KErrNone, status.Int());
|
sl@0
|
102 |
test_Equal(1, aOutputData->iValue.iValue1);
|
sl@0
|
103 |
test(aOutputData->iValue.iValue2 == _L8("shrt"));
|
sl@0
|
104 |
|
sl@0
|
105 |
test.Next(_L("Cancel async get value"));
|
sl@0
|
106 |
ldd.AsyncGetValue(status, aOutputData->iValue);
|
sl@0
|
107 |
ldd.Cancel();
|
sl@0
|
108 |
User::WaitForRequest(status);
|
sl@0
|
109 |
test_Equal(KErrCancel, status.Int());
|
sl@0
|
110 |
|
sl@0
|
111 |
test.Next(_L("Async get value 2"));
|
sl@0
|
112 |
aOutputData->iIntValue1 = 0;
|
sl@0
|
113 |
aOutputData->iIntValue2 = 0;
|
sl@0
|
114 |
DPTest::FlushCache();
|
sl@0
|
115 |
ldd.AsyncGetValue2(status, aOutputData->iIntValue1, aOutputData->iIntValue2);
|
sl@0
|
116 |
DPTest::FlushCache();
|
sl@0
|
117 |
User::WaitForRequest(status);
|
sl@0
|
118 |
test_Equal(KErrNone, status.Int());
|
sl@0
|
119 |
test_Equal(1, aOutputData->iIntValue1);
|
sl@0
|
120 |
test_Equal(2, aOutputData->iIntValue2);
|
sl@0
|
121 |
|
sl@0
|
122 |
test.Next(_L("Cancel async get value 2"));
|
sl@0
|
123 |
ldd.AsyncGetValue2(status, aOutputData->iIntValue1, aOutputData->iIntValue2);
|
sl@0
|
124 |
ldd.Cancel();
|
sl@0
|
125 |
User::WaitForRequest(status);
|
sl@0
|
126 |
test_Equal(KErrCancel, status.Int());
|
sl@0
|
127 |
|
sl@0
|
128 |
test.Next(_L("Write buffer too short"));
|
sl@0
|
129 |
ldd.Write(status, NULL, 0);
|
sl@0
|
130 |
User::WaitForRequest(status);
|
sl@0
|
131 |
test_Equal(KErrArgument, status.Int());
|
sl@0
|
132 |
|
sl@0
|
133 |
test.Next(_L("Write buffer too long"));
|
sl@0
|
134 |
ldd.Write(status, NULL, KMaxTransferSize + 1);
|
sl@0
|
135 |
User::WaitForRequest(status);
|
sl@0
|
136 |
test_Equal(KErrArgument, status.Int());
|
sl@0
|
137 |
|
sl@0
|
138 |
test.Next(_L("Write"));
|
sl@0
|
139 |
DPTest::FlushCache();
|
sl@0
|
140 |
ldd.Write(status, aInputData->iBuffer, KBufferSize);
|
sl@0
|
141 |
DPTest::FlushCache();
|
sl@0
|
142 |
User::WaitForRequest(status);
|
sl@0
|
143 |
test_KErrNone(status.Int());
|
sl@0
|
144 |
|
sl@0
|
145 |
test.Next(_L("Cancel write"));
|
sl@0
|
146 |
ldd.Write(status, aInputData->iBuffer, KBufferSize);
|
sl@0
|
147 |
ldd.Cancel();
|
sl@0
|
148 |
User::WaitForRequest(status);
|
sl@0
|
149 |
test_Equal(KErrCancel, status.Int());
|
sl@0
|
150 |
|
sl@0
|
151 |
test.Next(_L("Read buffer too short"));
|
sl@0
|
152 |
ldd.Read(status, NULL, 0);
|
sl@0
|
153 |
User::WaitForRequest(status);
|
sl@0
|
154 |
test_Equal(KErrArgument, status.Int());
|
sl@0
|
155 |
|
sl@0
|
156 |
test.Next(_L("Read buffer too long"));
|
sl@0
|
157 |
ldd.Read(status, NULL, KMaxTransferSize + 1);
|
sl@0
|
158 |
User::WaitForRequest(status);
|
sl@0
|
159 |
test_Equal(KErrArgument, status.Int());
|
sl@0
|
160 |
|
sl@0
|
161 |
test.Next(_L("Read"));
|
sl@0
|
162 |
Mem::FillZ(aOutputData->iBuffer, KBufferSize);
|
sl@0
|
163 |
DPTest::FlushCache();
|
sl@0
|
164 |
ldd.Read(status, aOutputData->iBuffer, KBufferSize);
|
sl@0
|
165 |
DPTest::FlushCache();
|
sl@0
|
166 |
User::WaitForRequest(status);
|
sl@0
|
167 |
test_KErrNone(status.Int());
|
sl@0
|
168 |
test_Equal(0, Mem::Compare(aInputData->iBuffer, KBufferSize,
|
sl@0
|
169 |
aOutputData->iBuffer, KBufferSize));
|
sl@0
|
170 |
|
sl@0
|
171 |
test.Next(_L("Cancel read"));
|
sl@0
|
172 |
ldd.Read(status, aOutputData->iBuffer, KBufferSize);
|
sl@0
|
173 |
ldd.Cancel();
|
sl@0
|
174 |
User::WaitForRequest(status);
|
sl@0
|
175 |
test_Equal(KErrCancel, status.Int());
|
sl@0
|
176 |
|
sl@0
|
177 |
test.Next(_L("Cancel nothing"));
|
sl@0
|
178 |
ldd.Cancel();
|
sl@0
|
179 |
|
sl@0
|
180 |
test.Next(_L("Write while write pending"));
|
sl@0
|
181 |
TRequestStatus status2;
|
sl@0
|
182 |
ldd.Write(status, aInputData->iBuffer, KBufferSize);
|
sl@0
|
183 |
ldd.Write(status2, aInputData->iBuffer, KBufferSize);
|
sl@0
|
184 |
User::WaitForRequest(status);
|
sl@0
|
185 |
test_KErrNone(status.Int());
|
sl@0
|
186 |
User::WaitForRequest(status2);
|
sl@0
|
187 |
test_Equal(KErrInUse, status2.Int());
|
sl@0
|
188 |
|
sl@0
|
189 |
test.Next(_L("Read while read pending"));
|
sl@0
|
190 |
ldd.Read(status, aOutputData->iBuffer, KBufferSize);
|
sl@0
|
191 |
ldd.Read(status2, aOutputData->iBuffer, KBufferSize);
|
sl@0
|
192 |
User::WaitForRequest(status);
|
sl@0
|
193 |
test_KErrNone(status.Int());
|
sl@0
|
194 |
User::WaitForRequest(status2);
|
sl@0
|
195 |
test_Equal(KErrInUse, status2.Int());
|
sl@0
|
196 |
|
sl@0
|
197 |
test.Next(_L("Write des"));
|
sl@0
|
198 |
TPtrC8 writeDes(aInputData->iBuffer + 1, KBufferSize - 1);
|
sl@0
|
199 |
DPTest::FlushCache();
|
sl@0
|
200 |
ldd.WriteDes(status, writeDes);
|
sl@0
|
201 |
DPTest::FlushCache();
|
sl@0
|
202 |
User::WaitForRequest(status);
|
sl@0
|
203 |
test_KErrNone(status.Int());
|
sl@0
|
204 |
|
sl@0
|
205 |
test.Next(_L("Cancel write des"));
|
sl@0
|
206 |
ldd.WriteDes(status, writeDes);
|
sl@0
|
207 |
ldd.Cancel();
|
sl@0
|
208 |
User::WaitForRequest(status);
|
sl@0
|
209 |
test_Equal(KErrCancel, status.Int());
|
sl@0
|
210 |
|
sl@0
|
211 |
test.Next(_L("Read des"));
|
sl@0
|
212 |
TPtr8 readDes(aOutputData->iBuffer, KBufferSize - 1);
|
sl@0
|
213 |
Mem::FillZ(aOutputData->iBuffer, KBufferSize);
|
sl@0
|
214 |
DPTest::FlushCache();
|
sl@0
|
215 |
ldd.ReadDes(status, readDes);
|
sl@0
|
216 |
DPTest::FlushCache();
|
sl@0
|
217 |
User::WaitForRequest(status);
|
sl@0
|
218 |
test_KErrNone(status.Int());
|
sl@0
|
219 |
test(readDes == writeDes);
|
sl@0
|
220 |
|
sl@0
|
221 |
test.Next(_L("Read des 2")); // has paged header but unpaged contnet, if output data is paged
|
sl@0
|
222 |
aOutputData->iPtr.Set(UnpagedOutputData->iBuffer, 0, KBufferSize - 1);
|
sl@0
|
223 |
Mem::FillZ(UnpagedOutputData->iBuffer, KBufferSize);
|
sl@0
|
224 |
DPTest::FlushCache();
|
sl@0
|
225 |
ldd.ReadDes(status, aOutputData->iPtr);
|
sl@0
|
226 |
DPTest::FlushCache();
|
sl@0
|
227 |
User::WaitForRequest(status);
|
sl@0
|
228 |
test_KErrNone(status.Int());
|
sl@0
|
229 |
test(aOutputData->iPtr == writeDes);
|
sl@0
|
230 |
|
sl@0
|
231 |
test.Next(_L("Cancel read des"));
|
sl@0
|
232 |
ldd.ReadDes(status, readDes);
|
sl@0
|
233 |
ldd.Cancel();
|
sl@0
|
234 |
User::WaitForRequest(status);
|
sl@0
|
235 |
test_Equal(KErrCancel, status.Int());
|
sl@0
|
236 |
|
sl@0
|
237 |
test.Next(_L("Read and write at the same time"));
|
sl@0
|
238 |
ldd.Write(status, aInputData->iBuffer, KBufferSize);
|
sl@0
|
239 |
ldd.Read(status2, aOutputData->iBuffer, KBufferSize);
|
sl@0
|
240 |
DPTest::FlushCache();
|
sl@0
|
241 |
User::WaitForRequest(status);
|
sl@0
|
242 |
test_KErrNone(status.Int());
|
sl@0
|
243 |
User::WaitForRequest(status2);
|
sl@0
|
244 |
test_KErrNone(status2.Int());
|
sl@0
|
245 |
|
sl@0
|
246 |
test.Next(_L("Cancel read and write"));
|
sl@0
|
247 |
ldd.Write(status, aInputData->iBuffer, KBufferSize);
|
sl@0
|
248 |
ldd.Read(status2, aOutputData->iBuffer, KBufferSize);
|
sl@0
|
249 |
ldd.Cancel();
|
sl@0
|
250 |
User::WaitForRequest(status);
|
sl@0
|
251 |
test_Equal(KErrCancel, status.Int());
|
sl@0
|
252 |
User::WaitForRequest(status2);
|
sl@0
|
253 |
test_Equal(KErrCancel, status2.Int());
|
sl@0
|
254 |
|
sl@0
|
255 |
test.Next(_L("Close and free logical device"));
|
sl@0
|
256 |
ldd.Close();
|
sl@0
|
257 |
test_KErrNone(User::FreeLogicalDevice(aDriverName));
|
sl@0
|
258 |
|
sl@0
|
259 |
test.End();
|
sl@0
|
260 |
}
|
sl@0
|
261 |
|
sl@0
|
262 |
void TestDriver(const TDesC& aDriverName, TBool aMigrated)
|
sl@0
|
263 |
{
|
sl@0
|
264 |
TBuf<64> string;
|
sl@0
|
265 |
string.Format(_L("Testing driver %S"), &aDriverName);
|
sl@0
|
266 |
test.Next(string);
|
sl@0
|
267 |
|
sl@0
|
268 |
test.Start(_L("Test reading from unpaged memory and writing to unpaged memory"));
|
sl@0
|
269 |
DoTestDriver(aDriverName, UnpagedInputData, UnpagedOutputData);
|
sl@0
|
270 |
|
sl@0
|
271 |
if (aMigrated && PagedInputData)
|
sl@0
|
272 |
{
|
sl@0
|
273 |
if (PagedOutputData)
|
sl@0
|
274 |
{
|
sl@0
|
275 |
test.Next(_L("Test reading from paged memory and writing to paged memory"));
|
sl@0
|
276 |
DoTestDriver(aDriverName, PagedInputData, PagedOutputData);
|
sl@0
|
277 |
}
|
sl@0
|
278 |
else
|
sl@0
|
279 |
{
|
sl@0
|
280 |
test.Next(_L("Test reading from paged memory and writing to unpaged memory"));
|
sl@0
|
281 |
DoTestDriver(aDriverName, PagedInputData, UnpagedOutputData);
|
sl@0
|
282 |
}
|
sl@0
|
283 |
}
|
sl@0
|
284 |
|
sl@0
|
285 |
// todo: test pinning failures
|
sl@0
|
286 |
|
sl@0
|
287 |
test.End();
|
sl@0
|
288 |
}
|
sl@0
|
289 |
|
sl@0
|
290 |
enum TTestAction
|
sl@0
|
291 |
{
|
sl@0
|
292 |
ETestRequestComplete,
|
sl@0
|
293 |
ETestRawRead,
|
sl@0
|
294 |
ETestRawWrite,
|
sl@0
|
295 |
ETestDesRead,
|
sl@0
|
296 |
ETestDesWrite
|
sl@0
|
297 |
};
|
sl@0
|
298 |
|
sl@0
|
299 |
enum TTestAccess
|
sl@0
|
300 |
{
|
sl@0
|
301 |
EAccessUnpaged,
|
sl@0
|
302 |
EAccessPaged
|
sl@0
|
303 |
};
|
sl@0
|
304 |
|
sl@0
|
305 |
enum TTestOutcome
|
sl@0
|
306 |
{
|
sl@0
|
307 |
EOutcomeSuccess,
|
sl@0
|
308 |
EOutcomeRealtimePanic
|
sl@0
|
309 |
};
|
sl@0
|
310 |
|
sl@0
|
311 |
TInt RealtimeTestFunc(TAny* aArg)
|
sl@0
|
312 |
{
|
sl@0
|
313 |
TTestAction action = (TTestAction)((TUint)aArg & 255);
|
sl@0
|
314 |
TTestAccess access = (TTestAccess)((TUint)aArg >> 8);
|
sl@0
|
315 |
|
sl@0
|
316 |
TTestData* inputData = access == EAccessPaged ? PagedInputData : UnpagedInputData;
|
sl@0
|
317 |
TTestData* outputData = access == EAccessPaged ? PagedOutputData : UnpagedOutputData;
|
sl@0
|
318 |
|
sl@0
|
319 |
RPagingExample ldd;
|
sl@0
|
320 |
TInt r = ldd.Open(KPagingExample1PreLdd);
|
sl@0
|
321 |
if (r != KErrNone)
|
sl@0
|
322 |
return r;
|
sl@0
|
323 |
ldd.SetDfcThreadRealtimeState(ETrue);
|
sl@0
|
324 |
|
sl@0
|
325 |
TRequestStatus unpagedStatus;
|
sl@0
|
326 |
TRequestStatus* status = &unpagedStatus;
|
sl@0
|
327 |
|
sl@0
|
328 |
switch(action)
|
sl@0
|
329 |
{
|
sl@0
|
330 |
case ETestRequestComplete:
|
sl@0
|
331 |
{
|
sl@0
|
332 |
RDebug::Printf("Test RequestComplete");
|
sl@0
|
333 |
status = &outputData->iStatus;
|
sl@0
|
334 |
RPagingExample::TValueStruct value;
|
sl@0
|
335 |
DPTest::FlushCache();
|
sl@0
|
336 |
ldd.AsyncGetValue(*status, value);
|
sl@0
|
337 |
DPTest::FlushCache();
|
sl@0
|
338 |
}
|
sl@0
|
339 |
break;
|
sl@0
|
340 |
|
sl@0
|
341 |
case ETestRawRead:
|
sl@0
|
342 |
RDebug::Printf("Test ThreadRawRead");
|
sl@0
|
343 |
ldd.Write(*status, inputData->iBuffer, KBufferSize);
|
sl@0
|
344 |
DPTest::FlushCache();
|
sl@0
|
345 |
break;
|
sl@0
|
346 |
|
sl@0
|
347 |
case ETestRawWrite:
|
sl@0
|
348 |
RDebug::Printf("Test ThreadRawWrite");
|
sl@0
|
349 |
ldd.Read(*status, outputData->iBuffer, KBufferSize);
|
sl@0
|
350 |
DPTest::FlushCache();
|
sl@0
|
351 |
break;
|
sl@0
|
352 |
|
sl@0
|
353 |
case ETestDesRead:
|
sl@0
|
354 |
{
|
sl@0
|
355 |
RDebug::Printf("Test ThreadDesRead");
|
sl@0
|
356 |
TPtrC8 writeDes(inputData->iBuffer, KBufferSize);
|
sl@0
|
357 |
ldd.WriteDes(*status, writeDes);
|
sl@0
|
358 |
DPTest::FlushCache();
|
sl@0
|
359 |
}
|
sl@0
|
360 |
break;
|
sl@0
|
361 |
|
sl@0
|
362 |
case ETestDesWrite:
|
sl@0
|
363 |
{
|
sl@0
|
364 |
RDebug::Printf("Test ThreadDesWrite");
|
sl@0
|
365 |
TPtr8 readDes(outputData->iBuffer, KBufferSize);
|
sl@0
|
366 |
ldd.ReadDes(*status, readDes);
|
sl@0
|
367 |
DPTest::FlushCache();
|
sl@0
|
368 |
}
|
sl@0
|
369 |
break;
|
sl@0
|
370 |
default:
|
sl@0
|
371 |
return KErrArgument;
|
sl@0
|
372 |
}
|
sl@0
|
373 |
User::WaitForAnyRequest();
|
sl@0
|
374 |
r = status->Int();
|
sl@0
|
375 |
ldd.Close();
|
sl@0
|
376 |
return r;
|
sl@0
|
377 |
}
|
sl@0
|
378 |
|
sl@0
|
379 |
void RunRealtimeTestThread(TTestAction aTestAction, TTestAccess aAccess, TTestOutcome aExpectedOutcome)
|
sl@0
|
380 |
{
|
sl@0
|
381 |
RThread thread;
|
sl@0
|
382 |
TUint arg = aTestAction | (aAccess << 8);
|
sl@0
|
383 |
test_KErrNone(thread.Create(KNullDesC, RealtimeTestFunc, 4096, NULL, (TAny*)arg));
|
sl@0
|
384 |
TRequestStatus status;
|
sl@0
|
385 |
thread.Logon(status);
|
sl@0
|
386 |
thread.Resume();
|
sl@0
|
387 |
User::WaitForRequest(status);
|
sl@0
|
388 |
switch (aExpectedOutcome)
|
sl@0
|
389 |
{
|
sl@0
|
390 |
case EOutcomeSuccess:
|
sl@0
|
391 |
test_Equal(EExitKill, thread.ExitType());
|
sl@0
|
392 |
test_Equal(KErrNone, thread.ExitReason());
|
sl@0
|
393 |
break;
|
sl@0
|
394 |
|
sl@0
|
395 |
case EOutcomeRealtimePanic:
|
sl@0
|
396 |
test_Equal(EExitPanic, thread.ExitType());
|
sl@0
|
397 |
test_Equal(EIllegalFunctionForRealtimeThread, thread.ExitReason());
|
sl@0
|
398 |
break;
|
sl@0
|
399 |
|
sl@0
|
400 |
default:
|
sl@0
|
401 |
test(EFalse);
|
sl@0
|
402 |
}
|
sl@0
|
403 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
404 |
}
|
sl@0
|
405 |
|
sl@0
|
406 |
void TestPagedAccessInRealtimeThread()
|
sl@0
|
407 |
{
|
sl@0
|
408 |
// Test driver access to paged memory from realtime DFC thread. This can happen if a client
|
sl@0
|
409 |
// passes paged memory to a driver that doesn't expect it, and has set its realtime state to
|
sl@0
|
410 |
// enfore this. The client should be panicked in this case.
|
sl@0
|
411 |
|
sl@0
|
412 |
test.Start(_L("Test memory access from realtime threads"));
|
sl@0
|
413 |
test.Next(_L("Load logical device"));
|
sl@0
|
414 |
TInt r = User::LoadLogicalDevice(KPagingExample1PreLdd);
|
sl@0
|
415 |
test(r==KErrNone || r==KErrAlreadyExists);
|
sl@0
|
416 |
|
sl@0
|
417 |
test.Next(_L("Test access to unpaged memory from realtime thread"));
|
sl@0
|
418 |
RunRealtimeTestThread(ETestRequestComplete, EAccessUnpaged, EOutcomeSuccess);
|
sl@0
|
419 |
RunRealtimeTestThread(ETestRawRead, EAccessUnpaged, EOutcomeSuccess);
|
sl@0
|
420 |
RunRealtimeTestThread(ETestRawWrite, EAccessUnpaged, EOutcomeSuccess);
|
sl@0
|
421 |
RunRealtimeTestThread(ETestDesRead, EAccessUnpaged, EOutcomeSuccess);
|
sl@0
|
422 |
RunRealtimeTestThread(ETestDesWrite, EAccessUnpaged, EOutcomeSuccess);
|
sl@0
|
423 |
|
sl@0
|
424 |
test.Next(_L("Test access to paged memory from realtime thread"));
|
sl@0
|
425 |
if (PagedInputData)
|
sl@0
|
426 |
{
|
sl@0
|
427 |
RunRealtimeTestThread(ETestRawRead, EAccessPaged, EOutcomeRealtimePanic);
|
sl@0
|
428 |
RunRealtimeTestThread(ETestDesRead, EAccessPaged, EOutcomeRealtimePanic);
|
sl@0
|
429 |
}
|
sl@0
|
430 |
if (PagedOutputData)
|
sl@0
|
431 |
{
|
sl@0
|
432 |
RunRealtimeTestThread(ETestRequestComplete, EAccessPaged, EOutcomeRealtimePanic);
|
sl@0
|
433 |
RunRealtimeTestThread(ETestRawWrite, EAccessPaged, EOutcomeRealtimePanic);
|
sl@0
|
434 |
RunRealtimeTestThread(ETestDesWrite, EAccessPaged, EOutcomeRealtimePanic);
|
sl@0
|
435 |
}
|
sl@0
|
436 |
|
sl@0
|
437 |
test.Next(_L("Close and free logical device"));
|
sl@0
|
438 |
test_KErrNone(User::FreeLogicalDevice(KPagingExample1PreLdd));
|
sl@0
|
439 |
|
sl@0
|
440 |
test.End();
|
sl@0
|
441 |
}
|
sl@0
|
442 |
|
sl@0
|
443 |
TInt E32Main()
|
sl@0
|
444 |
{
|
sl@0
|
445 |
test.Title();
|
sl@0
|
446 |
|
sl@0
|
447 |
test.Start(_L("Test device driver migration examples"));
|
sl@0
|
448 |
|
sl@0
|
449 |
UnpagedInputData = (TTestData*)User::Alloc(sizeof(TTestData));
|
sl@0
|
450 |
test_NotNull(UnpagedInputData);
|
sl@0
|
451 |
UnpagedOutputData = (TTestData*)User::Alloc(sizeof(TTestData));
|
sl@0
|
452 |
test_NotNull(UnpagedOutputData);
|
sl@0
|
453 |
|
sl@0
|
454 |
test_KErrNone(UserSvr::HalFunction(EHalGroupKernel,EKernelHalPageSizeInBytes,&PageSize,0));
|
sl@0
|
455 |
|
sl@0
|
456 |
RChunk chunk;
|
sl@0
|
457 |
if (DPTest::Attributes() & DPTest::EDataPaging)
|
sl@0
|
458 |
{
|
sl@0
|
459 |
TChunkCreateInfo info;
|
sl@0
|
460 |
TInt size = (sizeof(TTestData) + PageSize - 1) & ~(PageSize - 1);
|
sl@0
|
461 |
info.SetNormal(size, size);
|
sl@0
|
462 |
info.SetPaging(TChunkCreateInfo::EPaged);
|
sl@0
|
463 |
test_KErrNone(chunk.Create(info));
|
sl@0
|
464 |
test(chunk.IsPaged());
|
sl@0
|
465 |
PagedOutputData = (TTestData*)chunk.Base();
|
sl@0
|
466 |
test.Printf(_L("Using data pagd output buffer at %08x\n"), PagedOutputData);
|
sl@0
|
467 |
}
|
sl@0
|
468 |
|
sl@0
|
469 |
if (DPTest::Attributes() & DPTest::ERomPaging)
|
sl@0
|
470 |
{
|
sl@0
|
471 |
// use paged part of rom for read-only data
|
sl@0
|
472 |
TRomHeader* romHeader = (TRomHeader*)UserSvr::RomHeaderAddress();
|
sl@0
|
473 |
test(romHeader->iPageableRomStart);
|
sl@0
|
474 |
// todo: for some reason the first part of page of paged rom doesn't seem to get paged out
|
sl@0
|
475 |
// when we flush the paging cache, hence PagedInputData starts some way into this
|
sl@0
|
476 |
PagedInputData = (TTestData*)((TUint8*)romHeader + romHeader->iPageableRomStart + 64 * PageSize);
|
sl@0
|
477 |
TInt romDataSize = romHeader->iPageableRomSize - 64 * PageSize;
|
sl@0
|
478 |
test(romDataSize >= (TInt)sizeof(TTestData));
|
sl@0
|
479 |
test.Printf(_L("Using rom paged input data at %08x\n"), PagedInputData);
|
sl@0
|
480 |
}
|
sl@0
|
481 |
else if (DPTest::Attributes() & DPTest::ECodePaging)
|
sl@0
|
482 |
{
|
sl@0
|
483 |
// use code paged DLL for read-only buffer
|
sl@0
|
484 |
test_KErrNone(PagedLibrary.Load(KTCodePagingDll4));
|
sl@0
|
485 |
TGetAddressOfDataFunction func = (TGetAddressOfDataFunction)PagedLibrary.Lookup(KGetAddressOfDataFunctionOrdinal);
|
sl@0
|
486 |
TInt codeDataSize;
|
sl@0
|
487 |
PagedInputData = (TTestData*)func(codeDataSize);
|
sl@0
|
488 |
test_NotNull(PagedInputData);
|
sl@0
|
489 |
test(codeDataSize >= (TInt)sizeof(TTestData));
|
sl@0
|
490 |
test.Printf(_L("Using code paged input data at %08x\n"), PagedInputData);
|
sl@0
|
491 |
}
|
sl@0
|
492 |
|
sl@0
|
493 |
InitInputData(UnpagedInputData);
|
sl@0
|
494 |
|
sl@0
|
495 |
TestDriver(KPagingExample1PreLdd, EFalse);
|
sl@0
|
496 |
TestDriver(KPagingExample1PostLdd, ETrue);
|
sl@0
|
497 |
TestDriver(KPagingExample2PreLdd, EFalse);
|
sl@0
|
498 |
TestDriver(KPagingExample2PostLdd, ETrue);
|
sl@0
|
499 |
TestPagedAccessInRealtimeThread();
|
sl@0
|
500 |
|
sl@0
|
501 |
PagedLibrary.Close();
|
sl@0
|
502 |
User::Free(UnpagedInputData);
|
sl@0
|
503 |
User::Free(UnpagedOutputData);
|
sl@0
|
504 |
|
sl@0
|
505 |
test.End();
|
sl@0
|
506 |
return 0;
|
sl@0
|
507 |
}
|