1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/mmu/t_sharedio.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,673 @@
1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32test\mmu\t_sharedio.cpp
1.18 +// Overview:
1.19 +// Verifies the correct implementation of Shared IO Buffers
1.20 +// API information:
1.21 +// DSharedIoBuffer
1.22 +// Details:
1.23 +// 1. Loading the shared IO buffer test device driver
1.24 +// 2. Create buffer of a specified size
1.25 +// - it passes a request to the device driver to create a buffer
1.26 +// - the driver creates a shared io buffer and it zero fills it
1.27 +// - it checks the size is as specified
1.28 +// 3. Map in buffer
1.29 +// - it passes a request to the device driver to map the buffer created at
1.30 +// step 1 into this user process
1.31 +// - the driver maps the buffer into this user process
1.32 +// - checks if UserToKernel and KernelToUser methods work as expected
1.33 +// - fills a buffer
1.34 +// - returns the user address and size to the user process
1.35 +// - using the address and size returned by the driver, the user process
1.36 +// checks the buffer is filled as expected
1.37 +// 4. Fill and check shared buffer
1.38 +// - user process fills the buffer and driver checks it
1.39 +// - driver fills the buffer and user process checks it
1.40 +// 5. Map Out Buffer
1.41 +// - requests to the driver that the buffer should be unmapped from this
1.42 +// process' address space
1.43 +// - the driver checks that iUserAddress becomes NULL after unmapping
1.44 +// 6. Destroy Buffer
1.45 +// - requests to the driver to destroy the buffer
1.46 +// 7. Create a buffer with a physical address
1.47 +// (not performed on WINS)
1.48 +// - requests to the driver to create a buffer by specifying a physical address
1.49 +// - the driver allocates a physical address
1.50 +// - creates a shared IO buffer over that physical address
1.51 +// - fills the buffer with a pattern
1.52 +// - destroys the buffer
1.53 +// - creates a hardware chunk over the same physical address
1.54 +// - checks the buffer contains the pattern
1.55 +// - closes the chunk
1.56 +// 8. Check using the same buffer by 2 different user processes
1.57 +// (not performed on WINS)
1.58 +// - process 1 maps a global buffer (the global buffer will be
1.59 +// created in the context of process 1)
1.60 +// - fills it
1.61 +// - unmaps it
1.62 +// - process 2 maps the global buffer
1.63 +// - checks if it's filled accordingly
1.64 +// - unmaps it
1.65 +// - destroys the global buffer
1.66 +// 9. Checking buffers are protected at context switching
1.67 +// (not relevant on WINS)
1.68 +// - creates a shared buffer and map it into this process
1.69 +// - creates a new process
1.70 +// - the new process tries to access the buffer mapped into the first process
1.71 +// by zeroing the raw buffer passed from the first process. This relies on the
1.72 +// fact that each shared buffer is created in the Home Section, so they will be
1.73 +// available at the same address
1.74 +// - tests if the new process was panicked due to access violation
1.75 +// - tests if the contents of the buffer haven't been changed
1.76 +// 10.Checking writing to unmapped buffer
1.77 +// (not performed on WINS)
1.78 +// - creates a new process
1.79 +// - the new process creates a buffer, maps it and unmaps it
1.80 +// - the new process tries to use the buffer after unmapping
1.81 +// - the parent process logs the exit type and reason and checks
1.82 +// these are EExitPanic and 3 (Kern 3 - access violation)
1.83 +// 11.Checking address lookup is implemented
1.84 +// (not relevant on WINS)
1.85 +// - creates a new process
1.86 +// - the new process will ask the device driver to read and write a descriptor
1.87 +// in the old process, the kernel will perform an address lookup before
1.88 +// reading or writing the descriptor, to make sure the address location does
1.89 +// belong to the old process. The descriptor is a TPtr pointing to a buffer
1.90 +// located in a shared io buffer.
1.91 +// - device driver will return an error in case address lookup fails or ThreadRead
1.92 +// or ThreadWrite fail
1.93 +// - the new process returns the error code returned by the device driver
1.94 +// - the old process tests for the exit code for the new process being KErrNone and
1.95 +// that the thread is not panicked, and also that the values written and read
1.96 +// are those expected.
1.97 +// 12.Closing test driver
1.98 +// - Trivial, but it will test if a created & mapped shared io buffer gets released
1.99 +// successfully when the logical channel is closed (which in turn will delete the
1.100 +// shared io buffer associated with the channel)
1.101 +// The test comes in 4 flavours, in order to test memory protection when context switching
1.102 +// between different types of processes.
1.103 +// T_SHAREDIO:
1.104 +// Main process is a moving process which creates another moving process.
1.105 +// T_SHAREDIO2:
1.106 +// Main process is a fixed process which creates a moving process.
1.107 +// T_SHAREDIO3:
1.108 +// Main process is a fixed process which creates another fixed process.
1.109 +// T_SHAREDIO4:
1.110 +// Main process is a moving process which creates a fixed process.
1.111 +// Platforms/Drives/Compatibility:
1.112 +// All (some steps will not be performed on emulator)
1.113 +// Assumptions/Requirement/Pre-requisites:
1.114 +// The test needs D_SHAREDIO.LDD, the device driver that actually operates the API.
1.115 +// Failures and causes:
1.116 +// Failures of this test will indicate defects in the implementation of Shared Io Buffers.
1.117 +// Base Port information:
1.118 +// No?
1.119 +//
1.120 +//
1.121 +
1.122 +#define __E32TEST_EXTENSION__
1.123 +
1.124 +#include <e32test.h>
1.125 +#include <e32math.h>
1.126 +#include "d_sharedio.h"
1.127 +#include <e32hal.h>
1.128 +#include "u32std.h"
1.129 +#include <u32hal.h>
1.130 +#include <e32svr.h>
1.131 +#include <f32dbg.h>
1.132 +#include <e32def.h>
1.133 +#include <e32def_private.h>
1.134 +#include "freeram.h"
1.135 +
1.136 +LOCAL_D RTest test(_L("T_SHAREDIO"));
1.137 +
1.138 +const TInt KTestBufferSize = 0x100000;
1.139 +
1.140 +TUint MemModelAttributes;
1.141 +TBool PhysicalCommitSupported;
1.142 +
1.143 +RTestLdd ldd;
1.144 +
1.145 +TUint32 TestBufferSizes[]={0x1000, 0x10453, 0x100000, 0x100001, 0x203000, 0};
1.146 +
1.147 +TInt checkBuffer(TAny* buffer, TUint32 aSize, TUint32 key)
1.148 + {
1.149 + TInt r=KErrNone;
1.150 + TUint8* m=(TUint8*)buffer;
1.151 + for(TUint32 size=0;size<aSize;size++,key+=5,m++)
1.152 + {
1.153 + if(*m!=(TUint8)(key%256))
1.154 + {
1.155 + r=KErrCorrupt;
1.156 + break;
1.157 + }
1.158 + }
1.159 + return r;
1.160 + }
1.161 +
1.162 +TInt fillBuffer(TAny* buffer, TUint32 aSize, TUint32 key)
1.163 + {
1.164 + TUint8* m=(TUint8*)buffer;
1.165 + for(TUint32 size=0;size<aSize;size++,key+=5,m++)
1.166 + {
1.167 + *m=(TUint8)(key%256);
1.168 + }
1.169 + return KErrNone;
1.170 + }
1.171 +
1.172 +TBool CheckBuffer(TAny* aBuffer,TInt aSize)
1.173 + {
1.174 + TAny** p = (TAny**)aBuffer;
1.175 + TAny** end = (TAny**)((TInt)p+aSize);
1.176 + while(p<end)
1.177 + {
1.178 + if(*p!=p)
1.179 + return EFalse;
1.180 + ++p;
1.181 + }
1.182 + return ETrue;
1.183 + }
1.184 +
1.185 +enum TTestProcessFunctions
1.186 + {
1.187 + ETestProcess1,
1.188 + ETestProcess2,
1.189 + ETestProcess3,
1.190 + };
1.191 +
1.192 +class RTestProcess : public RProcess
1.193 + {
1.194 +public:
1.195 + void Create(TTestProcessFunctions aFunction,TInt aArg1=-1,TInt aArg2=-1);
1.196 + };
1.197 +
1.198 +void RTestProcess::Create(TTestProcessFunctions aFunction,TInt aArg1,TInt aArg2)
1.199 + {
1.200 + if(aArg1==-1)
1.201 + aArg1 = RProcess().Id();
1.202 + TBuf<512> commandLine;
1.203 + commandLine.Num((TInt)aFunction);
1.204 + commandLine.Append(_L(" "));
1.205 + commandLine.AppendNum(aArg1);
1.206 + commandLine.Append(_L(" "));
1.207 + commandLine.AppendNum(aArg2);
1.208 +#ifdef __FIXED__
1.209 + //fixed process creating a moving process
1.210 + TFileName filename(RProcess().FileName());
1.211 + TInt pos=filename.LocateReverse(TChar('\\'));
1.212 + filename.SetLength(pos+1);
1.213 + filename+=_L("T_SHAREDIO.EXE");
1.214 + TInt r = RProcess::Create(filename,commandLine);
1.215 +#else
1.216 +#ifdef __SECOND_FIXED__
1.217 + //fixed process creating another fixed process
1.218 + TFileName filename(RProcess().FileName());
1.219 + TInt pos=filename.LocateReverse(TChar('\\'));
1.220 + filename.SetLength(pos+1);
1.221 + filename+=_L("T_SHAREDIO2.EXE");
1.222 + TInt r = RProcess::Create(filename,commandLine);
1.223 +#else
1.224 +#ifdef __MOVING_FIXED__
1.225 + //moving process creating a fixed process
1.226 + TFileName filename(RProcess().FileName());
1.227 + TInt pos=filename.LocateReverse(TChar('\\'));
1.228 + filename.SetLength(pos+1);
1.229 + filename+=_L("T_SHAREDIO2.EXE");
1.230 + TInt r = RProcess::Create(filename,commandLine);
1.231 +#else
1.232 + //moving process creating a moving process
1.233 + TInt r = RProcess::Create(RProcess().FileName(),commandLine);
1.234 +#endif
1.235 +#endif
1.236 +#endif
1.237 + test(r==KErrNone);
1.238 + SetJustInTime(EFalse);
1.239 + }
1.240 +
1.241 +const TInt KProcessRendezvous = KRequestPending+1;
1.242 +
1.243 +TInt DoTestProcess(TInt aTestNum,TInt aArg1,TInt aArg2)
1.244 + {
1.245 + (void)aArg1;
1.246 + (void)aArg2;
1.247 +
1.248 + RTestLdd ldd;
1.249 + TInt r;
1.250 + r=User::LoadLogicalDevice(KSharedIoTestLddName);
1.251 + if(r!=KErrNone && r!=KErrAlreadyExists)
1.252 + return KErrGeneral;
1.253 + r=ldd.Open();
1.254 + if(r!=KErrNone)
1.255 + return r;
1.256 +
1.257 + switch(aTestNum)
1.258 + {
1.259 + case ETestProcess1:
1.260 + {
1.261 + TAny* gbuffer;
1.262 + TUint32 gsize;
1.263 + r=User::GetTIntParameter(1,(TInt&)gbuffer);
1.264 + if(r!=KErrNone)
1.265 + return r;
1.266 + r=User::GetTIntParameter(2,(TInt&)gsize);
1.267 + if(r!=KErrNone)
1.268 + return r;
1.269 +
1.270 + r=checkBuffer(gbuffer,gsize,23454);
1.271 + if(r!=KErrNone)
1.272 + return r;
1.273 + r=ldd.MapOutGlobalBuffer();
1.274 + if(r!=KErrNone)
1.275 + return r;
1.276 +
1.277 + r=ldd.CreateBuffer(KTestBufferSize);
1.278 + if(r!=KErrNone)
1.279 + return r;
1.280 +
1.281 + TAny* buffer;
1.282 + TUint32 size;
1.283 + r=ldd.MapInBuffer(&buffer,&size);
1.284 + if(r!=KErrNone)
1.285 + return r;
1.286 +
1.287 + if(!CheckBuffer(buffer,size))
1.288 + return KErrGeneral;
1.289 +
1.290 + r=ldd.MapOutBuffer();
1.291 + if(r!=KErrNone)
1.292 + return r;
1.293 +
1.294 + RProcess::Rendezvous(KProcessRendezvous);
1.295 +
1.296 + *(TInt*)buffer = 0; // Should cause exception
1.297 + break;
1.298 + }
1.299 + case ETestProcess2:
1.300 + {
1.301 + TInt size=aArg2;
1.302 + TUint8* p=(TUint8*)aArg1;
1.303 +
1.304 + RProcess::Rendezvous(KProcessRendezvous);
1.305 + for(TInt i=0;i<size;i++)
1.306 + p[i]=0; // Should cause exception
1.307 + break;
1.308 + }
1.309 + case ETestProcess3:
1.310 + {
1.311 + TAny* buffer;
1.312 + TUint32 size;
1.313 +
1.314 + r=ldd.CreateBuffer(KTestBufferSize);
1.315 + if(r!=KErrNone)
1.316 + return r;
1.317 +
1.318 + r=ldd.MapInBuffer(&buffer,&size);
1.319 + if(r!=KErrNone)
1.320 + return r;
1.321 +
1.322 + if(!CheckBuffer(buffer,size))
1.323 + return KErrGeneral;
1.324 +
1.325 + *(TInt*)buffer=KMagic1;
1.326 + TPckg<TInt> buf(*(TInt*)buffer);
1.327 + r=ldd.ThreadRW(buf);
1.328 + if(r!=KErrNone)
1.329 + return r;
1.330 +
1.331 + if(*(TInt*)buffer!=KMagic2)
1.332 + return KErrCorrupt;
1.333 +
1.334 + r=ldd.ThreadRW(*(TDes8*)aArg1,aArg2);
1.335 + if(r!=KErrNone)
1.336 + return r;
1.337 +
1.338 + r=ldd.MapOutBuffer();
1.339 + if(r!=KErrNone)
1.340 + return r;
1.341 +
1.342 + break;
1.343 + }
1.344 + default:
1.345 + User::Panic(_L("T_SHAREDIO"),1);
1.346 + }
1.347 +
1.348 + ldd.Close();
1.349 + return KErrNone;
1.350 + }
1.351 +
1.352 +void CreateWithOOMCheck(TInt aSize, TBool aPhysicalAddress)
1.353 + {
1.354 + TInt failResult=KErrGeneral;
1.355 +
1.356 + TInt freeRam = FreeRam(); //This will also add a delay
1.357 +
1.358 + for(TInt failCount=1; failCount<1000; failCount++)
1.359 + {
1.360 + test.Printf(_L("alloc fail count = %d\n"),failCount);
1.361 +
1.362 + User::__DbgSetAllocFail(ETrue,RAllocator::EFailNext,failCount);
1.363 + __KHEAP_MARK;
1.364 +
1.365 + if (aPhysicalAddress)
1.366 + failResult=ldd.CreateBufferPhysAddr(aSize);
1.367 + else
1.368 + failResult=ldd.CreateBuffer(aSize);
1.369 +
1.370 + if(failResult==KErrNone)
1.371 + break;
1.372 +
1.373 + test(failResult==KErrNoMemory);
1.374 + __KHEAP_MARKEND;
1.375 +
1.376 + test(freeRam == FreeRam()); //This will also add a delay
1.377 + }
1.378 + User::__DbgSetAllocFail(ETrue,RAllocator::ENone,0);
1.379 + __KHEAP_RESET;
1.380 +
1.381 + test.Next(_L("Destroy buffer"));
1.382 + if (aPhysicalAddress)
1.383 + ldd.DestroyBufferPhysAddr();
1.384 + else
1.385 + ldd.DestroyBuffer();
1.386 +
1.387 + test(freeRam == FreeRam()); //This will also add a delay
1.388 + }
1.389 +
1.390 +GLDEF_C TInt E32Main()
1.391 + {
1.392 + TBuf16<512> cmd;
1.393 + User::CommandLine(cmd);
1.394 + if(cmd.Length() && TChar(cmd[0]).IsDigit())
1.395 + {
1.396 + TInt function = -1;
1.397 + TInt arg1 = -1;
1.398 + TInt arg2 = -1;
1.399 + TLex lex(cmd);
1.400 + lex.Val(function);
1.401 + lex.SkipSpace();
1.402 + lex.Val(arg1);
1.403 + lex.SkipSpace();
1.404 + lex.Val(arg2);
1.405 + return DoTestProcess(function,arg1,arg2);
1.406 + }
1.407 +
1.408 + MemModelAttributes=UserSvr::HalFunction(EHalGroupKernel, EKernelHalMemModelInfo, NULL, NULL);
1.409 + TUint mm=MemModelAttributes&EMemModelTypeMask;
1.410 + PhysicalCommitSupported = mm!=EMemModelTypeDirect && mm!=EMemModelTypeEmul;
1.411 +
1.412 +// Turn off lazy dll unloading
1.413 + RLoader l;
1.414 + test(l.Connect()==KErrNone);
1.415 + test(l.CancelLazyDllUnload()==KErrNone);
1.416 + l.Close();
1.417 +
1.418 + test.Title();
1.419 +
1.420 +#if defined(__FIXED__) || defined(__SECOND_FIXED__) || defined(__MOVING_FIXED__)
1.421 + if(mm!=EMemModelTypeMoving)
1.422 + {
1.423 + test.Printf(_L("TESTS NOT RUN - Only applicable to moving memory model\r\n"));
1.424 + return 0;
1.425 + }
1.426 +#endif
1.427 +
1.428 + test.Start(_L("Loading test driver..."));
1.429 +
1.430 + TInt r;
1.431 + r=User::LoadLogicalDevice(KSharedIoTestLddName);
1.432 + test(r==KErrNone || r==KErrAlreadyExists);
1.433 + r=User::LoadLogicalDevice(KSharedIoTestLddName);
1.434 + test(r==KErrAlreadyExists);
1.435 + r=ldd.Open();
1.436 + test(r==KErrNone);
1.437 +
1.438 + TAny* buffer;
1.439 + TUint32 size;
1.440 + TUint32 key;
1.441 +
1.442 + TInt testBufferSize=0;
1.443 + for(; TestBufferSizes[testBufferSize]!=0; ++testBufferSize)
1.444 + {
1.445 + test.Printf(_L("Test buffer size = %08x\n"),TestBufferSizes[testBufferSize]);
1.446 +
1.447 + test.Next(_L("Create buffer"));
1.448 + r=ldd.CreateBuffer(TestBufferSizes[testBufferSize]);
1.449 + if(r!=KErrNone)
1.450 + test.Printf(_L("Creating buffer failed client r=%d"), r);
1.451 + test(r==KErrNone);
1.452 +
1.453 + test.Next(_L("Map In Buffer"));
1.454 + r=ldd.MapInBuffer(&buffer,&size);
1.455 +
1.456 + test.Next(_L("CheckBuffer"));
1.457 + test(CheckBuffer(buffer,size));
1.458 + test(r==KErrNone);
1.459 + test.Next(_L("Fill and check shared buffer"));
1.460 + key=Math::Random();
1.461 + fillBuffer(buffer,size,key);
1.462 + test(ldd.CheckBuffer(key)==KErrNone);
1.463 +
1.464 + key=Math::Random();
1.465 + test(ldd.FillBuffer(key)==KErrNone);
1.466 + test(checkBuffer(buffer,size,key)==KErrNone);
1.467 +
1.468 + test.Next(_L("Map Out Buffer"));
1.469 + r=ldd.MapOutBuffer();
1.470 + test(r==KErrNone);
1.471 +
1.472 + test.Next(_L("Destroy Buffer"));
1.473 + r=ldd.DestroyBuffer();
1.474 + test(r==KErrNone);
1.475 +
1.476 + test.Next(_L("Create a buffer under OOM conditions"));
1.477 + CreateWithOOMCheck(TestBufferSizes[testBufferSize], EFalse);
1.478 +
1.479 + if(PhysicalCommitSupported)
1.480 + {
1.481 + test.Next(_L("Create a buffer with a physical address under OOM conditions"));
1.482 + CreateWithOOMCheck(TestBufferSizes[testBufferSize], ETrue);
1.483 +
1.484 + test.Next(_L("Create a buffer with a physical address"));
1.485 + r=ldd.CreateBufferPhysAddr(0x1000);
1.486 + test(r==KErrNone);
1.487 +
1.488 + test.Next(_L("Map In physical address Buffer"));
1.489 + r=ldd.MapInBuffer(&buffer,&size);
1.490 + test(r==KErrNone);
1.491 +
1.492 + test.Next(_L("Fill and check physical address shared buffer"));
1.493 + key=Math::Random();
1.494 + fillBuffer(buffer,size,key);
1.495 + test(ldd.CheckBuffer(key)==KErrNone);
1.496 +
1.497 + key=Math::Random();
1.498 + test(ldd.FillBuffer(key)==KErrNone);
1.499 + test(checkBuffer(buffer,size,key)==KErrNone);
1.500 +
1.501 + test.Next(_L("Map Out physical address Buffer"));
1.502 + r=ldd.MapOutBuffer();
1.503 + test(r==KErrNone);
1.504 +
1.505 + test.Next(_L("Destroy a buffer with a physical address"));
1.506 + r=ldd.DestroyBufferPhysAddr();
1.507 + test(r==KErrNone);
1.508 + }
1.509 +
1.510 + test.Next(_L("Check using the same buffer by 2 different user processes"));
1.511 + TAny* gbuffer;
1.512 + TUint32 gsize;
1.513 + r=ldd.MapInGlobalBuffer(RProcess().Id(),gbuffer,gsize);
1.514 + test(r==KErrNone);
1.515 +
1.516 + fillBuffer(gbuffer,gsize,23454);
1.517 +
1.518 + r=ldd.MapOutGlobalBuffer();
1.519 + test(r==KErrNone);
1.520 +
1.521 + r=ldd.CreateBuffer(TestBufferSizes[testBufferSize]);
1.522 + test(r==KErrNone);
1.523 +
1.524 + r=ldd.MapInBuffer(&buffer,&size);
1.525 + test(r==KErrNone);
1.526 +
1.527 + test(CheckBuffer(buffer,size));
1.528 +
1.529 + key=Math::Random();
1.530 + fillBuffer(buffer,size,key);
1.531 + test(ldd.CheckBuffer(key)==KErrNone);
1.532 +
1.533 + RTestProcess rogueP;
1.534 + TRequestStatus rendezvous;
1.535 + TRequestStatus logon;
1.536 +
1.537 + if(MemModelAttributes&EMemModelAttrProcessProt)
1.538 + {
1.539 + test.Next(_L("Checking buffers are protected at context switching"));
1.540 + rogueP.Create(ETestProcess2,(TInt)buffer,(TInt)size);
1.541 + rogueP.Logon(logon);
1.542 + rogueP.Rendezvous(rendezvous);
1.543 + rogueP.Resume();
1.544 + User::WaitForRequest(rendezvous);
1.545 + test(rendezvous==KProcessRendezvous);
1.546 + User::WaitForRequest(logon);
1.547 + test(rogueP.ExitType()==EExitPanic);
1.548 + test(logon==3);
1.549 + test(ldd.CheckBuffer(key)==KErrNone);
1.550 + }
1.551 +
1.552 + r=ldd.MapOutBuffer();
1.553 + test(r==KErrNone);
1.554 +
1.555 + r=ldd.DestroyBuffer();
1.556 + test(r==KErrNone);
1.557 +
1.558 + RTestProcess process;
1.559 +
1.560 + if((MemModelAttributes&EMemModelAttrKernProt) && (MemModelAttributes&EMemModelTypeMask)!=EMemModelTypeDirect)
1.561 + {
1.562 + test.Next(_L("Checking writing to unmapped buffer"));
1.563 + process.Create(ETestProcess1);
1.564 + process.Logon(logon);
1.565 + process.Rendezvous(rendezvous);
1.566 + test(ldd.MapInGlobalBuffer(process.Id(),gbuffer,gsize)==KErrNone);
1.567 + test(process.SetParameter(1,(TInt)gbuffer)==KErrNone);
1.568 + test(process.SetParameter(2,(TInt)gsize)==KErrNone);
1.569 + process.Resume();
1.570 + User::WaitForRequest(rendezvous);
1.571 + test(rendezvous==KProcessRendezvous);
1.572 + User::WaitForRequest(logon);
1.573 + test(process.ExitType()==EExitPanic);
1.574 + test(logon==3);
1.575 + process.Close();
1.576 + }
1.577 +
1.578 + r=ldd.CreateBuffer(TestBufferSizes[testBufferSize]);
1.579 + if(r!=KErrNone)
1.580 + return r;
1.581 +
1.582 + r=ldd.MapInBuffer(&buffer,&size);
1.583 + if(r!=KErrNone)
1.584 + return r;
1.585 +
1.586 + if(!CheckBuffer(buffer,size))
1.587 + return KErrGeneral;
1.588 +
1.589 + *(TInt*)buffer=KMagic1;
1.590 + TPckg<TInt> buf(*(TInt*)buffer);
1.591 +
1.592 + RTestProcess proc;
1.593 + test.Next(_L("Checking address lookup is implemented"));
1.594 + proc.Create(ETestProcess3,(TInt)&buf,RThread().Id());
1.595 + proc.Logon(logon);
1.596 + proc.Resume();
1.597 + User::WaitForRequest(logon);
1.598 +
1.599 + test(proc.ExitType()==EExitKill);
1.600 + test(logon==0);
1.601 + test(*(TInt*)buffer==KMagic2);
1.602 +
1.603 + ldd.DestroyBuffer();
1.604 +
1.605 + // Check process death whilst buffer is mapped in
1.606 + // Test case for defect DEF051851 - Shared IO Buffer fault when process dies
1.607 + test.Next(_L("Checking process death whilst buffer is mapped in"));
1.608 + process.Create(ETestProcess1);
1.609 + process.Logon(logon);
1.610 + test.Start(_L("Map buffer into another process"));
1.611 + test(ldd.MapInGlobalBuffer(process.Id(),gbuffer,gsize)==KErrNone);
1.612 + test.Next(_L("Kill other process"));
1.613 + process.Kill(99);
1.614 + User::WaitForRequest(logon);
1.615 + test(process.ExitType()==EExitKill);
1.616 + test(logon==99);
1.617 + process.Close();
1.618 + test.Next(_L("Map out buffer"));
1.619 + r=ldd.MapOutGlobalBuffer();
1.620 + test.Printf(_L("result = %d\n"),r);
1.621 + test(r==KErrNone);
1.622 +
1.623 + test.Next(_L("Map buffer into this process"));
1.624 + test(ldd.MapInGlobalBuffer(RProcess().Id(),gbuffer,gsize)==KErrNone);
1.625 + test.Next(_L("Map out buffer from this process"));
1.626 + r=ldd.MapOutGlobalBuffer();
1.627 + test.Printf(_L("result = %d\n"),r);
1.628 + test(r==KErrNone);
1.629 +
1.630 + process.Create(ETestProcess1);
1.631 + process.Logon(logon);
1.632 + test.Next(_L("Map buffer into another process"));
1.633 + test(ldd.MapInGlobalBuffer(process.Id(),gbuffer,gsize)==KErrNone);
1.634 + test.Next(_L("Kill other process"));
1.635 + process.Kill(99);
1.636 + User::WaitForRequest(logon);
1.637 + test(process.ExitType()==EExitKill);
1.638 + test(logon==99);
1.639 + process.Close();
1.640 + test.Next(_L("Map out buffer"));
1.641 + r=ldd.MapOutGlobalBuffer();
1.642 + test.Printf(_L("result = %d\n"),r);
1.643 + test(r==KErrNone);
1.644 + test.End();
1.645 + } // loop for next buffer size
1.646 +
1.647 + test.Next(_L("Create and map in buffer"));
1.648 + r=ldd.CreateBuffer(KTestBufferSize);
1.649 + test(r==KErrNone);
1.650 + r=ldd.MapInBuffer(&buffer,&size);
1.651 + test(r==KErrNone);
1.652 +
1.653 +// Test for DEF053512 - Can't delete SharedIo buffers in DLogicalDevice destructor
1.654 +
1.655 + test.Next(_L("Map in global buffer"));
1.656 + TAny* gbuffer;
1.657 + TUint32 gsize;
1.658 + test(ldd.MapInGlobalBuffer(RProcess().Id(),gbuffer,gsize)==KErrNone);
1.659 +
1.660 + test.Next(_L("Closing channel (with a buffer still mapped in)"));
1.661 + ldd.Close();
1.662 +
1.663 +// Test for DEF053512 - Can't delete SharedIo buffers in DLogicalDevice destructor
1.664 +
1.665 + test.Next(_L("Unload driver (whilst global buffer still mapped in)"));
1.666 + r=User::FreeLogicalDevice(KSharedIoTestLddName);
1.667 + test(r==KErrNone);
1.668 +
1.669 + test.End();
1.670 +
1.671 +
1.672 +
1.673 + return(0);
1.674 + }
1.675 +
1.676 +