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