author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 14 May 2010 17:13:29 +0300 | |
changeset 109 | b3a1d9898418 |
parent 0 | a41df078684a |
child 257 | 3e88ff8f41d5 |
child 293 | 0659d0e1a03c |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2003-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_sharedio.cpp |
|
15 |
// Overview: |
|
16 |
// Verifies the correct implementation of Shared IO Buffers |
|
17 |
// API information: |
|
18 |
// DSharedIoBuffer |
|
19 |
// Details: |
|
20 |
// 1. Loading the shared IO buffer test device driver |
|
21 |
// 2. Create buffer of a specified size |
|
22 |
// - it passes a request to the device driver to create a buffer |
|
23 |
// - the driver creates a shared io buffer and it zero fills it |
|
24 |
// - it checks the size is as specified |
|
25 |
// 3. Map in buffer |
|
26 |
// - it passes a request to the device driver to map the buffer created at |
|
27 |
// step 1 into this user process |
|
28 |
// - the driver maps the buffer into this user process |
|
29 |
// - checks if UserToKernel and KernelToUser methods work as expected |
|
30 |
// - fills a buffer |
|
31 |
// - returns the user address and size to the user process |
|
32 |
// - using the address and size returned by the driver, the user process |
|
33 |
// checks the buffer is filled as expected |
|
34 |
// 4. Fill and check shared buffer |
|
35 |
// - user process fills the buffer and driver checks it |
|
36 |
// - driver fills the buffer and user process checks it |
|
37 |
// 5. Map Out Buffer |
|
38 |
// - requests to the driver that the buffer should be unmapped from this |
|
39 |
// process' address space |
|
40 |
// - the driver checks that iUserAddress becomes NULL after unmapping |
|
41 |
// 6. Destroy Buffer |
|
42 |
// - requests to the driver to destroy the buffer |
|
43 |
// 7. Create a buffer with a physical address |
|
44 |
// (not performed on WINS) |
|
45 |
// - requests to the driver to create a buffer by specifying a physical address |
|
46 |
// - the driver allocates a physical address |
|
47 |
// - creates a shared IO buffer over that physical address |
|
48 |
// - fills the buffer with a pattern |
|
49 |
// - destroys the buffer |
|
50 |
// - creates a hardware chunk over the same physical address |
|
51 |
// - checks the buffer contains the pattern |
|
52 |
// - closes the chunk |
|
53 |
// 8. Check using the same buffer by 2 different user processes |
|
54 |
// (not performed on WINS) |
|
55 |
// - process 1 maps a global buffer (the global buffer will be |
|
56 |
// created in the context of process 1) |
|
57 |
// - fills it |
|
58 |
// - unmaps it |
|
59 |
// - process 2 maps the global buffer |
|
60 |
// - checks if it's filled accordingly |
|
61 |
// - unmaps it |
|
62 |
// - destroys the global buffer |
|
63 |
// 9. Checking buffers are protected at context switching |
|
64 |
// (not relevant on WINS) |
|
65 |
// - creates a shared buffer and map it into this process |
|
66 |
// - creates a new process |
|
67 |
// - the new process tries to access the buffer mapped into the first process |
|
68 |
// by zeroing the raw buffer passed from the first process. This relies on the |
|
69 |
// fact that each shared buffer is created in the Home Section, so they will be |
|
70 |
// available at the same address |
|
71 |
// - tests if the new process was panicked due to access violation |
|
72 |
// - tests if the contents of the buffer haven't been changed |
|
73 |
// 10.Checking writing to unmapped buffer |
|
74 |
// (not performed on WINS) |
|
75 |
// - creates a new process |
|
76 |
// - the new process creates a buffer, maps it and unmaps it |
|
77 |
// - the new process tries to use the buffer after unmapping |
|
78 |
// - the parent process logs the exit type and reason and checks |
|
79 |
// these are EExitPanic and 3 (Kern 3 - access violation) |
|
80 |
// 11.Checking address lookup is implemented |
|
81 |
// (not relevant on WINS) |
|
82 |
// - creates a new process |
|
83 |
// - the new process will ask the device driver to read and write a descriptor |
|
84 |
// in the old process, the kernel will perform an address lookup before |
|
85 |
// reading or writing the descriptor, to make sure the address location does |
|
86 |
// belong to the old process. The descriptor is a TPtr pointing to a buffer |
|
87 |
// located in a shared io buffer. |
|
88 |
// - device driver will return an error in case address lookup fails or ThreadRead |
|
89 |
// or ThreadWrite fail |
|
90 |
// - the new process returns the error code returned by the device driver |
|
91 |
// - the old process tests for the exit code for the new process being KErrNone and |
|
92 |
// that the thread is not panicked, and also that the values written and read |
|
93 |
// are those expected. |
|
94 |
// 12.Closing test driver |
|
95 |
// - Trivial, but it will test if a created & mapped shared io buffer gets released |
|
96 |
// successfully when the logical channel is closed (which in turn will delete the |
|
97 |
// shared io buffer associated with the channel) |
|
98 |
// The test comes in 4 flavours, in order to test memory protection when context switching |
|
99 |
// between different types of processes. |
|
100 |
// T_SHAREDIO: |
|
101 |
// Main process is a moving process which creates another moving process. |
|
102 |
// T_SHAREDIO2: |
|
103 |
// Main process is a fixed process which creates a moving process. |
|
104 |
// T_SHAREDIO3: |
|
105 |
// Main process is a fixed process which creates another fixed process. |
|
106 |
// T_SHAREDIO4: |
|
107 |
// Main process is a moving process which creates a fixed process. |
|
108 |
// Platforms/Drives/Compatibility: |
|
109 |
// All (some steps will not be performed on emulator) |
|
110 |
// Assumptions/Requirement/Pre-requisites: |
|
111 |
// The test needs D_SHAREDIO.LDD, the device driver that actually operates the API. |
|
112 |
// Failures and causes: |
|
113 |
// Failures of this test will indicate defects in the implementation of Shared Io Buffers. |
|
114 |
// Base Port information: |
|
115 |
// No? |
|
116 |
// |
|
117 |
// |
|
118 |
||
119 |
#define __E32TEST_EXTENSION__ |
|
120 |
||
121 |
#include <e32test.h> |
|
122 |
#include <e32math.h> |
|
123 |
#include "d_sharedio.h" |
|
124 |
#include <e32hal.h> |
|
125 |
#include "u32std.h" |
|
126 |
#include <u32hal.h> |
|
127 |
#include <e32svr.h> |
|
128 |
#include <f32dbg.h> |
|
129 |
#include <e32def.h> |
|
130 |
#include <e32def_private.h> |
|
131 |
||
132 |
LOCAL_D RTest test(_L("T_SHAREDIO")); |
|
133 |
||
134 |
const TInt KTestBufferSize = 0x100000; |
|
135 |
||
136 |
TUint MemModelAttributes; |
|
137 |
TBool PhysicalCommitSupported; |
|
138 |
||
139 |
RTestLdd ldd; |
|
140 |
||
141 |
TUint32 TestBufferSizes[]={0x1000, 0x10453, 0x100000, 0x100001, 0x203000, 0}; |
|
142 |
||
143 |
TInt checkBuffer(TAny* buffer, TUint32 aSize, TUint32 key) |
|
144 |
{ |
|
145 |
TInt r=KErrNone; |
|
146 |
TUint8* m=(TUint8*)buffer; |
|
147 |
for(TUint32 size=0;size<aSize;size++,key+=5,m++) |
|
148 |
{ |
|
149 |
if(*m!=(TUint8)(key%256)) |
|
150 |
{ |
|
151 |
r=KErrCorrupt; |
|
152 |
break; |
|
153 |
} |
|
154 |
} |
|
155 |
return r; |
|
156 |
} |
|
157 |
||
158 |
TInt fillBuffer(TAny* buffer, TUint32 aSize, TUint32 key) |
|
159 |
{ |
|
160 |
TUint8* m=(TUint8*)buffer; |
|
161 |
for(TUint32 size=0;size<aSize;size++,key+=5,m++) |
|
162 |
{ |
|
163 |
*m=(TUint8)(key%256); |
|
164 |
} |
|
165 |
return KErrNone; |
|
166 |
} |
|
167 |
||
168 |
TBool CheckBuffer(TAny* aBuffer,TInt aSize) |
|
169 |
{ |
|
170 |
TAny** p = (TAny**)aBuffer; |
|
171 |
TAny** end = (TAny**)((TInt)p+aSize); |
|
172 |
while(p<end) |
|
173 |
{ |
|
174 |
if(*p!=p) |
|
175 |
return EFalse; |
|
176 |
++p; |
|
177 |
} |
|
178 |
return ETrue; |
|
179 |
} |
|
180 |
||
181 |
enum TTestProcessFunctions |
|
182 |
{ |
|
183 |
ETestProcess1, |
|
184 |
ETestProcess2, |
|
185 |
ETestProcess3, |
|
186 |
}; |
|
187 |
||
188 |
class RTestProcess : public RProcess |
|
189 |
{ |
|
190 |
public: |
|
191 |
void Create(TTestProcessFunctions aFunction,TInt aArg1=-1,TInt aArg2=-1); |
|
192 |
}; |
|
193 |
||
194 |
void RTestProcess::Create(TTestProcessFunctions aFunction,TInt aArg1,TInt aArg2) |
|
195 |
{ |
|
196 |
if(aArg1==-1) |
|
197 |
aArg1 = RProcess().Id(); |
|
198 |
TBuf<512> commandLine; |
|
199 |
commandLine.Num((TInt)aFunction); |
|
200 |
commandLine.Append(_L(" ")); |
|
201 |
commandLine.AppendNum(aArg1); |
|
202 |
commandLine.Append(_L(" ")); |
|
203 |
commandLine.AppendNum(aArg2); |
|
204 |
#ifdef __FIXED__ |
|
205 |
//fixed process creating a moving process |
|
206 |
TFileName filename(RProcess().FileName()); |
|
207 |
TInt pos=filename.LocateReverse(TChar('\\')); |
|
208 |
filename.SetLength(pos+1); |
|
209 |
filename+=_L("T_SHAREDIO.EXE"); |
|
210 |
TInt r = RProcess::Create(filename,commandLine); |
|
211 |
#else |
|
212 |
#ifdef __SECOND_FIXED__ |
|
213 |
//fixed process creating another fixed process |
|
214 |
TFileName filename(RProcess().FileName()); |
|
215 |
TInt pos=filename.LocateReverse(TChar('\\')); |
|
216 |
filename.SetLength(pos+1); |
|
217 |
filename+=_L("T_SHAREDIO2.EXE"); |
|
218 |
TInt r = RProcess::Create(filename,commandLine); |
|
219 |
#else |
|
220 |
#ifdef __MOVING_FIXED__ |
|
221 |
//moving process creating a fixed process |
|
222 |
TFileName filename(RProcess().FileName()); |
|
223 |
TInt pos=filename.LocateReverse(TChar('\\')); |
|
224 |
filename.SetLength(pos+1); |
|
225 |
filename+=_L("T_SHAREDIO2.EXE"); |
|
226 |
TInt r = RProcess::Create(filename,commandLine); |
|
227 |
#else |
|
228 |
//moving process creating a moving process |
|
229 |
TInt r = RProcess::Create(RProcess().FileName(),commandLine); |
|
230 |
#endif |
|
231 |
#endif |
|
232 |
#endif |
|
233 |
test(r==KErrNone); |
|
234 |
SetJustInTime(EFalse); |
|
235 |
} |
|
236 |
||
237 |
const TInt KProcessRendezvous = KRequestPending+1; |
|
238 |
||
239 |
TInt DoTestProcess(TInt aTestNum,TInt aArg1,TInt aArg2) |
|
240 |
{ |
|
241 |
(void)aArg1; |
|
242 |
(void)aArg2; |
|
243 |
||
244 |
RTestLdd ldd; |
|
245 |
TInt r; |
|
246 |
r=User::LoadLogicalDevice(KSharedIoTestLddName); |
|
247 |
if(r!=KErrNone && r!=KErrAlreadyExists) |
|
248 |
return KErrGeneral; |
|
249 |
r=ldd.Open(); |
|
250 |
if(r!=KErrNone) |
|
251 |
return r; |
|
252 |
||
253 |
switch(aTestNum) |
|
254 |
{ |
|
255 |
case ETestProcess1: |
|
256 |
{ |
|
257 |
TAny* gbuffer; |
|
258 |
TUint32 gsize; |
|
259 |
r=User::GetTIntParameter(1,(TInt&)gbuffer); |
|
260 |
if(r!=KErrNone) |
|
261 |
return r; |
|
262 |
r=User::GetTIntParameter(2,(TInt&)gsize); |
|
263 |
if(r!=KErrNone) |
|
264 |
return r; |
|
265 |
||
266 |
r=checkBuffer(gbuffer,gsize,23454); |
|
267 |
if(r!=KErrNone) |
|
268 |
return r; |
|
269 |
r=ldd.MapOutGlobalBuffer(); |
|
270 |
if(r!=KErrNone) |
|
271 |
return r; |
|
272 |
||
273 |
r=ldd.CreateBuffer(KTestBufferSize); |
|
274 |
if(r!=KErrNone) |
|
275 |
return r; |
|
276 |
||
277 |
TAny* buffer; |
|
278 |
TUint32 size; |
|
279 |
r=ldd.MapInBuffer(&buffer,&size); |
|
280 |
if(r!=KErrNone) |
|
281 |
return r; |
|
282 |
||
283 |
if(!CheckBuffer(buffer,size)) |
|
284 |
return KErrGeneral; |
|
285 |
||
286 |
r=ldd.MapOutBuffer(); |
|
287 |
if(r!=KErrNone) |
|
288 |
return r; |
|
289 |
||
290 |
RProcess::Rendezvous(KProcessRendezvous); |
|
291 |
||
292 |
*(TInt*)buffer = 0; // Should cause exception |
|
293 |
break; |
|
294 |
} |
|
295 |
case ETestProcess2: |
|
296 |
{ |
|
297 |
TInt size=aArg2; |
|
298 |
TUint8* p=(TUint8*)aArg1; |
|
299 |
||
300 |
RProcess::Rendezvous(KProcessRendezvous); |
|
301 |
for(TInt i=0;i<size;i++) |
|
302 |
p[i]=0; // Should cause exception |
|
303 |
break; |
|
304 |
} |
|
305 |
case ETestProcess3: |
|
306 |
{ |
|
307 |
TAny* buffer; |
|
308 |
TUint32 size; |
|
309 |
||
310 |
r=ldd.CreateBuffer(KTestBufferSize); |
|
311 |
if(r!=KErrNone) |
|
312 |
return r; |
|
313 |
||
314 |
r=ldd.MapInBuffer(&buffer,&size); |
|
315 |
if(r!=KErrNone) |
|
316 |
return r; |
|
317 |
||
318 |
if(!CheckBuffer(buffer,size)) |
|
319 |
return KErrGeneral; |
|
320 |
||
321 |
*(TInt*)buffer=KMagic1; |
|
322 |
TPckg<TInt> buf(*(TInt*)buffer); |
|
323 |
r=ldd.ThreadRW(buf); |
|
324 |
if(r!=KErrNone) |
|
325 |
return r; |
|
326 |
||
327 |
if(*(TInt*)buffer!=KMagic2) |
|
328 |
return KErrCorrupt; |
|
329 |
||
330 |
r=ldd.ThreadRW(*(TDes8*)aArg1,aArg2); |
|
331 |
if(r!=KErrNone) |
|
332 |
return r; |
|
333 |
||
334 |
r=ldd.MapOutBuffer(); |
|
335 |
if(r!=KErrNone) |
|
336 |
return r; |
|
337 |
||
338 |
break; |
|
339 |
} |
|
340 |
default: |
|
341 |
User::Panic(_L("T_SHAREDIO"),1); |
|
342 |
} |
|
343 |
||
344 |
ldd.Close(); |
|
345 |
return KErrNone; |
|
346 |
} |
|
347 |
||
348 |
void CreateWithOOMCheck(TInt aSize, TBool aPhysicalAddress) |
|
349 |
{ |
|
350 |
TInt failResult=KErrGeneral; |
|
351 |
||
352 |
for(TInt failCount=1; failCount<1000; failCount++) |
|
353 |
{ |
|
354 |
test.Printf(_L("alloc fail count = %d\n"),failCount); |
|
355 |
||
356 |
User::__DbgSetAllocFail(ETrue,RAllocator::EFailNext,failCount); |
|
357 |
__KHEAP_MARK; |
|
358 |
||
359 |
if (aPhysicalAddress) |
|
360 |
failResult=ldd.CreateBufferPhysAddr(aSize); |
|
361 |
else |
|
362 |
failResult=ldd.CreateBuffer(aSize); |
|
363 |
||
364 |
if(failResult==KErrNone) |
|
365 |
break; |
|
366 |
||
367 |
test(failResult==KErrNoMemory); |
|
368 |
__KHEAP_MARKEND; |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
369 |
} |
0 | 370 |
|
371 |
__KHEAP_RESET; |
|
372 |
||
373 |
test.Next(_L("Destroy buffer")); |
|
374 |
if (aPhysicalAddress) |
|
375 |
ldd.DestroyBufferPhysAddr(); |
|
376 |
else |
|
377 |
ldd.DestroyBuffer(); |
|
378 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
379 |
__KHEAP_MARKEND; |
0 | 380 |
} |
381 |
||
382 |
GLDEF_C TInt E32Main() |
|
383 |
{ |
|
384 |
TBuf16<512> cmd; |
|
385 |
User::CommandLine(cmd); |
|
386 |
if(cmd.Length() && TChar(cmd[0]).IsDigit()) |
|
387 |
{ |
|
388 |
TInt function = -1; |
|
389 |
TInt arg1 = -1; |
|
390 |
TInt arg2 = -1; |
|
391 |
TLex lex(cmd); |
|
392 |
lex.Val(function); |
|
393 |
lex.SkipSpace(); |
|
394 |
lex.Val(arg1); |
|
395 |
lex.SkipSpace(); |
|
396 |
lex.Val(arg2); |
|
397 |
return DoTestProcess(function,arg1,arg2); |
|
398 |
} |
|
399 |
||
400 |
MemModelAttributes=UserSvr::HalFunction(EHalGroupKernel, EKernelHalMemModelInfo, NULL, NULL); |
|
401 |
TUint mm=MemModelAttributes&EMemModelTypeMask; |
|
402 |
PhysicalCommitSupported = mm!=EMemModelTypeDirect && mm!=EMemModelTypeEmul; |
|
403 |
||
404 |
// Turn off lazy dll unloading |
|
405 |
RLoader l; |
|
406 |
test(l.Connect()==KErrNone); |
|
407 |
test(l.CancelLazyDllUnload()==KErrNone); |
|
408 |
l.Close(); |
|
409 |
||
410 |
test.Title(); |
|
411 |
||
412 |
#if defined(__FIXED__) || defined(__SECOND_FIXED__) || defined(__MOVING_FIXED__) |
|
413 |
if(mm!=EMemModelTypeMoving) |
|
414 |
{ |
|
415 |
test.Printf(_L("TESTS NOT RUN - Only applicable to moving memory model\r\n")); |
|
416 |
return 0; |
|
417 |
} |
|
418 |
#endif |
|
419 |
||
420 |
test.Start(_L("Loading test driver...")); |
|
421 |
||
422 |
TInt r; |
|
423 |
r=User::LoadLogicalDevice(KSharedIoTestLddName); |
|
424 |
test(r==KErrNone || r==KErrAlreadyExists); |
|
425 |
r=User::LoadLogicalDevice(KSharedIoTestLddName); |
|
426 |
test(r==KErrAlreadyExists); |
|
427 |
r=ldd.Open(); |
|
428 |
test(r==KErrNone); |
|
429 |
||
430 |
TAny* buffer; |
|
431 |
TUint32 size; |
|
432 |
TUint32 key; |
|
433 |
||
434 |
TInt testBufferSize=0; |
|
435 |
for(; TestBufferSizes[testBufferSize]!=0; ++testBufferSize) |
|
436 |
{ |
|
437 |
test.Printf(_L("Test buffer size = %08x\n"),TestBufferSizes[testBufferSize]); |
|
438 |
||
439 |
test.Next(_L("Create buffer")); |
|
440 |
r=ldd.CreateBuffer(TestBufferSizes[testBufferSize]); |
|
441 |
if(r!=KErrNone) |
|
442 |
test.Printf(_L("Creating buffer failed client r=%d"), r); |
|
443 |
test(r==KErrNone); |
|
444 |
||
445 |
test.Next(_L("Map In Buffer")); |
|
446 |
r=ldd.MapInBuffer(&buffer,&size); |
|
447 |
||
448 |
test.Next(_L("CheckBuffer")); |
|
449 |
test(CheckBuffer(buffer,size)); |
|
450 |
test(r==KErrNone); |
|
451 |
test.Next(_L("Fill and check shared buffer")); |
|
452 |
key=Math::Random(); |
|
453 |
fillBuffer(buffer,size,key); |
|
454 |
test(ldd.CheckBuffer(key)==KErrNone); |
|
455 |
||
456 |
key=Math::Random(); |
|
457 |
test(ldd.FillBuffer(key)==KErrNone); |
|
458 |
test(checkBuffer(buffer,size,key)==KErrNone); |
|
459 |
||
460 |
test.Next(_L("Map Out Buffer")); |
|
461 |
r=ldd.MapOutBuffer(); |
|
462 |
test(r==KErrNone); |
|
463 |
||
464 |
test.Next(_L("Destroy Buffer")); |
|
465 |
r=ldd.DestroyBuffer(); |
|
466 |
test(r==KErrNone); |
|
467 |
||
468 |
test.Next(_L("Create a buffer under OOM conditions")); |
|
469 |
CreateWithOOMCheck(TestBufferSizes[testBufferSize], EFalse); |
|
470 |
||
471 |
if(PhysicalCommitSupported) |
|
472 |
{ |
|
473 |
test.Next(_L("Create a buffer with a physical address under OOM conditions")); |
|
474 |
CreateWithOOMCheck(TestBufferSizes[testBufferSize], ETrue); |
|
475 |
||
476 |
test.Next(_L("Create a buffer with a physical address")); |
|
477 |
r=ldd.CreateBufferPhysAddr(0x1000); |
|
478 |
test(r==KErrNone); |
|
479 |
||
480 |
test.Next(_L("Map In physical address Buffer")); |
|
481 |
r=ldd.MapInBuffer(&buffer,&size); |
|
482 |
test(r==KErrNone); |
|
483 |
||
484 |
test.Next(_L("Fill and check physical address shared buffer")); |
|
485 |
key=Math::Random(); |
|
486 |
fillBuffer(buffer,size,key); |
|
487 |
test(ldd.CheckBuffer(key)==KErrNone); |
|
488 |
||
489 |
key=Math::Random(); |
|
490 |
test(ldd.FillBuffer(key)==KErrNone); |
|
491 |
test(checkBuffer(buffer,size,key)==KErrNone); |
|
492 |
||
493 |
test.Next(_L("Map Out physical address Buffer")); |
|
494 |
r=ldd.MapOutBuffer(); |
|
495 |
test(r==KErrNone); |
|
496 |
||
497 |
test.Next(_L("Destroy a buffer with a physical address")); |
|
498 |
r=ldd.DestroyBufferPhysAddr(); |
|
499 |
test(r==KErrNone); |
|
500 |
} |
|
501 |
||
502 |
test.Next(_L("Check using the same buffer by 2 different user processes")); |
|
503 |
TAny* gbuffer; |
|
504 |
TUint32 gsize; |
|
505 |
r=ldd.MapInGlobalBuffer(RProcess().Id(),gbuffer,gsize); |
|
506 |
test(r==KErrNone); |
|
507 |
||
508 |
fillBuffer(gbuffer,gsize,23454); |
|
509 |
||
510 |
r=ldd.MapOutGlobalBuffer(); |
|
511 |
test(r==KErrNone); |
|
512 |
||
513 |
r=ldd.CreateBuffer(TestBufferSizes[testBufferSize]); |
|
514 |
test(r==KErrNone); |
|
515 |
||
516 |
r=ldd.MapInBuffer(&buffer,&size); |
|
517 |
test(r==KErrNone); |
|
518 |
||
519 |
test(CheckBuffer(buffer,size)); |
|
520 |
||
521 |
key=Math::Random(); |
|
522 |
fillBuffer(buffer,size,key); |
|
523 |
test(ldd.CheckBuffer(key)==KErrNone); |
|
524 |
||
525 |
RTestProcess rogueP; |
|
526 |
TRequestStatus rendezvous; |
|
527 |
TRequestStatus logon; |
|
528 |
||
529 |
if(MemModelAttributes&EMemModelAttrProcessProt) |
|
530 |
{ |
|
531 |
test.Next(_L("Checking buffers are protected at context switching")); |
|
532 |
rogueP.Create(ETestProcess2,(TInt)buffer,(TInt)size); |
|
533 |
rogueP.Logon(logon); |
|
534 |
rogueP.Rendezvous(rendezvous); |
|
535 |
rogueP.Resume(); |
|
536 |
User::WaitForRequest(rendezvous); |
|
537 |
test(rendezvous==KProcessRendezvous); |
|
538 |
User::WaitForRequest(logon); |
|
539 |
test(rogueP.ExitType()==EExitPanic); |
|
540 |
test(logon==3); |
|
541 |
test(ldd.CheckBuffer(key)==KErrNone); |
|
542 |
} |
|
543 |
||
544 |
r=ldd.MapOutBuffer(); |
|
545 |
test(r==KErrNone); |
|
546 |
||
547 |
r=ldd.DestroyBuffer(); |
|
548 |
test(r==KErrNone); |
|
549 |
||
550 |
RTestProcess process; |
|
551 |
||
552 |
if((MemModelAttributes&EMemModelAttrKernProt) && (MemModelAttributes&EMemModelTypeMask)!=EMemModelTypeDirect) |
|
553 |
{ |
|
554 |
test.Next(_L("Checking writing to unmapped buffer")); |
|
555 |
process.Create(ETestProcess1); |
|
556 |
process.Logon(logon); |
|
557 |
process.Rendezvous(rendezvous); |
|
558 |
test(ldd.MapInGlobalBuffer(process.Id(),gbuffer,gsize)==KErrNone); |
|
559 |
test(process.SetParameter(1,(TInt)gbuffer)==KErrNone); |
|
560 |
test(process.SetParameter(2,(TInt)gsize)==KErrNone); |
|
561 |
process.Resume(); |
|
562 |
User::WaitForRequest(rendezvous); |
|
563 |
test(rendezvous==KProcessRendezvous); |
|
564 |
User::WaitForRequest(logon); |
|
565 |
test(process.ExitType()==EExitPanic); |
|
566 |
test(logon==3); |
|
567 |
process.Close(); |
|
568 |
} |
|
569 |
||
570 |
r=ldd.CreateBuffer(TestBufferSizes[testBufferSize]); |
|
571 |
if(r!=KErrNone) |
|
572 |
return r; |
|
573 |
||
574 |
r=ldd.MapInBuffer(&buffer,&size); |
|
575 |
if(r!=KErrNone) |
|
576 |
return r; |
|
577 |
||
578 |
if(!CheckBuffer(buffer,size)) |
|
579 |
return KErrGeneral; |
|
580 |
||
581 |
*(TInt*)buffer=KMagic1; |
|
582 |
TPckg<TInt> buf(*(TInt*)buffer); |
|
583 |
||
584 |
RTestProcess proc; |
|
585 |
test.Next(_L("Checking address lookup is implemented")); |
|
586 |
proc.Create(ETestProcess3,(TInt)&buf,RThread().Id()); |
|
587 |
proc.Logon(logon); |
|
588 |
proc.Resume(); |
|
589 |
User::WaitForRequest(logon); |
|
590 |
||
591 |
test(proc.ExitType()==EExitKill); |
|
592 |
test(logon==0); |
|
593 |
test(*(TInt*)buffer==KMagic2); |
|
594 |
||
595 |
ldd.DestroyBuffer(); |
|
596 |
||
597 |
// Check process death whilst buffer is mapped in |
|
598 |
// Test case for defect DEF051851 - Shared IO Buffer fault when process dies |
|
599 |
test.Next(_L("Checking process death whilst buffer is mapped in")); |
|
600 |
process.Create(ETestProcess1); |
|
601 |
process.Logon(logon); |
|
602 |
test.Start(_L("Map buffer into another process")); |
|
603 |
test(ldd.MapInGlobalBuffer(process.Id(),gbuffer,gsize)==KErrNone); |
|
604 |
test.Next(_L("Kill other process")); |
|
605 |
process.Kill(99); |
|
606 |
User::WaitForRequest(logon); |
|
607 |
test(process.ExitType()==EExitKill); |
|
608 |
test(logon==99); |
|
609 |
process.Close(); |
|
610 |
test.Next(_L("Map out buffer")); |
|
611 |
r=ldd.MapOutGlobalBuffer(); |
|
612 |
test.Printf(_L("result = %d\n"),r); |
|
613 |
test(r==KErrNone); |
|
614 |
||
615 |
test.Next(_L("Map buffer into this process")); |
|
616 |
test(ldd.MapInGlobalBuffer(RProcess().Id(),gbuffer,gsize)==KErrNone); |
|
617 |
test.Next(_L("Map out buffer from this process")); |
|
618 |
r=ldd.MapOutGlobalBuffer(); |
|
619 |
test.Printf(_L("result = %d\n"),r); |
|
620 |
test(r==KErrNone); |
|
621 |
||
622 |
process.Create(ETestProcess1); |
|
623 |
process.Logon(logon); |
|
624 |
test.Next(_L("Map buffer into another process")); |
|
625 |
test(ldd.MapInGlobalBuffer(process.Id(),gbuffer,gsize)==KErrNone); |
|
626 |
test.Next(_L("Kill other process")); |
|
627 |
process.Kill(99); |
|
628 |
User::WaitForRequest(logon); |
|
629 |
test(process.ExitType()==EExitKill); |
|
630 |
test(logon==99); |
|
631 |
process.Close(); |
|
632 |
test.Next(_L("Map out buffer")); |
|
633 |
r=ldd.MapOutGlobalBuffer(); |
|
634 |
test.Printf(_L("result = %d\n"),r); |
|
635 |
test(r==KErrNone); |
|
636 |
test.End(); |
|
637 |
} // loop for next buffer size |
|
638 |
||
639 |
test.Next(_L("Create and map in buffer")); |
|
640 |
r=ldd.CreateBuffer(KTestBufferSize); |
|
641 |
test(r==KErrNone); |
|
642 |
r=ldd.MapInBuffer(&buffer,&size); |
|
643 |
test(r==KErrNone); |
|
644 |
||
645 |
// Test for DEF053512 - Can't delete SharedIo buffers in DLogicalDevice destructor |
|
646 |
||
647 |
test.Next(_L("Map in global buffer")); |
|
648 |
TAny* gbuffer; |
|
649 |
TUint32 gsize; |
|
650 |
test(ldd.MapInGlobalBuffer(RProcess().Id(),gbuffer,gsize)==KErrNone); |
|
651 |
||
652 |
test.Next(_L("Closing channel (with a buffer still mapped in)")); |
|
653 |
ldd.Close(); |
|
654 |
||
655 |
// Test for DEF053512 - Can't delete SharedIo buffers in DLogicalDevice destructor |
|
656 |
||
657 |
test.Next(_L("Unload driver (whilst global buffer still mapped in)")); |
|
658 |
r=User::FreeLogicalDevice(KSharedIoTestLddName); |
|
659 |
test(r==KErrNone); |
|
660 |
||
661 |
test.End(); |
|
662 |
||
663 |
||
664 |
||
665 |
return(0); |
|
666 |
} |
|
667 |
||
668 |