1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/pccd/d_medt2.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,271 @@
1.4 +// Copyright (c) 1998-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\pccd\d_medt2.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#if defined(_UNICODE)
1.22 +#if !defined(UNICODE)
1.23 +#define UNICODE
1.24 +#endif
1.25 +#endif
1.26 +#include <kernel/kernel.h>
1.27 +const TInt KTestDriverBufferMaxSize=0x1000; // 4K
1.28 +
1.29 +class DPhysicalDeviceMediaTest : public DPhysicalDeviceMedia
1.30 + {
1.31 +public:
1.32 + DPhysicalDeviceMediaTest();
1.33 + virtual TInt Install();
1.34 + virtual TInt Remove();
1.35 + virtual void GetCaps(TDes8 &aDes) const;
1.36 + virtual CBase *CreateL(TInt aDevice,const TDesC *anInfo,const TVersion &aVer);
1.37 + virtual TInt Priority();
1.38 + };
1.39 +
1.40 +class DMediaDriverTest : public DMediaDriver
1.41 + {
1.42 +public:
1.43 + DMediaDriverTest();
1.44 + TInt DoCreate(TMediaDevice aMediaDevice);
1.45 + void DoRead(TInt64 &aPos,TInt aLength,TMediaDrvDescData &aTrg);
1.46 + void DoWrite(TInt64 &aPos,TInt aLength,TMediaDrvDescData &aSrc);
1.47 + void DoFormat(TInt64 &aPos,TInt aLength);
1.48 + TInt Enlarge(TInt aLength);
1.49 + TInt ReduceSize(TInt64 &aPos,TInt aLength);
1.50 + void Close();
1.51 + TInt PartitionInfo(TPartitionInfo &anInfo);
1.52 + void Caps(TDes8& aCapsBuf);
1.53 +private:
1.54 + static void WriteCompleteCallBack(TAny *aMediaDriver,TInt aDelay);
1.55 + static void FormatCompleteCallBack(TAny *aMediaDriver,TInt aDelay);
1.56 +private:
1.57 + TUint8 iBuf[KTestDriverBufferMaxSize];
1.58 + TTickLink iWriteTickLink;
1.59 + TTickLink iFormatTickLink;
1.60 + };
1.61 +
1.62 +DPhysicalDeviceMediaTest::DPhysicalDeviceMediaTest()
1.63 +//
1.64 +// Constructor
1.65 +//
1.66 + {
1.67 + iUnitsMask=0x1; // Support only one
1.68 + iVersion=TVersion(KMediaDriverInterfaceMajorVersionNumber,KMediaDriverInterfaceMinorVersionNumber,KMediaDriverInterfaceBuildVersionNumber);
1.69 + }
1.70 +
1.71 +TInt DPhysicalDeviceMediaTest::Install()
1.72 +//
1.73 +// Install the test Media PDD.
1.74 +//
1.75 + {
1.76 +
1.77 + TPtrC name=_L("Media.Tst2");
1.78 + return(SetName(&name));
1.79 + }
1.80 +
1.81 +TInt DPhysicalDeviceMediaTest::Remove()
1.82 +//
1.83 +// Remove the test Media PDD.
1.84 +//
1.85 + {
1.86 + return(KErrNone);
1.87 + }
1.88 +
1.89 +void DPhysicalDeviceMediaTest::GetCaps(TDes8 &/* aDes */) const
1.90 +//
1.91 +// Return the media drivers capabilities.
1.92 +//
1.93 + {
1.94 + }
1.95 +
1.96 +CBase *DPhysicalDeviceMediaTest::CreateL(TInt aDevice,const TDesC * /* anInfo */,const TVersion &aVer)
1.97 +//
1.98 +// Create a test media driver.
1.99 +//
1.100 + {
1.101 + if (User::QueryVersionSupported(iVersion,aVer)==EFalse)
1.102 + User::Leave(KErrNotSupported);
1.103 + DMediaDriverTest *mD=new(ELeave) DMediaDriverTest;
1.104 + TInt ret=mD->DoCreate((TMediaDevice)aDevice);
1.105 + if (ret!=KErrNone)
1.106 + {
1.107 + delete mD;
1.108 + User::Leave(ret);
1.109 + }
1.110 + return(mD);
1.111 + }
1.112 +
1.113 +TInt DPhysicalDeviceMediaTest::Priority()
1.114 +//
1.115 +// Return the priority of this media driver
1.116 +//
1.117 + {
1.118 +
1.119 + return(KMediaDriverPriorityLow);
1.120 + }
1.121 +
1.122 +DMediaDriverTest::DMediaDriverTest()
1.123 +//
1.124 +// Constructor.
1.125 +//
1.126 + {
1.127 +
1.128 +// Mem::FillZ(&iBuf[0],sizeof(iBuf));
1.129 + iFlags=KMediaDrvMultipleReqs;
1.130 + }
1.131 +
1.132 +TInt DMediaDriverTest::DoCreate(TMediaDevice aMediaDevice)
1.133 +//
1.134 +// Create the media driver.
1.135 +//
1.136 + {
1.137 +
1.138 + if (!__IS_REMOVABLE(aMediaDevice))
1.139 + return(KErrNotSupported);
1.140 + SetTotalSizeInBytes(KTestDriverBufferMaxSize);
1.141 + return(KErrNone);
1.142 + }
1.143 +
1.144 +void DMediaDriverTest::DoRead(TInt64 &aPos,TInt aLength,TMediaDrvDescData &aTrg)
1.145 +//
1.146 +// Read from specified area of media.
1.147 +//
1.148 + {
1.149 +
1.150 + TInt ret=KErrNone;
1.151 + if (!aTrg.IsCurrentThread())
1.152 + ret=KErrGeneral;
1.153 + else
1.154 + {
1.155 + if ((ret=aTrg.CurrentThreadDescCheck(aLength))==KErrNone)
1.156 + {
1.157 + TDes8 &t=*((TDes8*)aTrg.iPtr);
1.158 + Mem::Copy((TAny*)(t.Ptr()+aTrg.iOffset),&iBuf[aPos.Low()],aLength);
1.159 + t.SetLength(aLength+aTrg.iOffset);
1.160 + }
1.161 + }
1.162 + Complete(KMediaDrvReadReq,ret);
1.163 + }
1.164 +
1.165 +const TInt KWriteAsyncTime=100000; // 100mS
1.166 +void DMediaDriverTest::DoWrite(TInt64 &aPos,TInt aLength,TMediaDrvDescData &aSrc)
1.167 +//
1.168 +// Write to specifed area of media.
1.169 +//
1.170 + {
1.171 +
1.172 + if (!aSrc.IsCurrentThread())
1.173 + Complete(KMediaDrvWriteReq,KErrGeneral);
1.174 + else
1.175 + {
1.176 + Mem::Copy(&iBuf[aPos.Low()],((TDesC8*)aSrc.iPtr)->Ptr()+aSrc.iOffset,aLength);
1.177 + iWriteTickLink.OneShotInMicroSeconds(KWriteAsyncTime,DMediaDriverTest::WriteCompleteCallBack,this);
1.178 + }
1.179 + }
1.180 +
1.181 +const TInt KFormatAsyncTime=5000000; // 5S
1.182 +void DMediaDriverTest::DoFormat(TInt64 &aPos,TInt aLength)
1.183 +//
1.184 +// Format the specified area of the media.
1.185 +//
1.186 + {
1.187 +
1.188 + Mem::Fill(&iBuf[aPos.Low()],aLength,0xFF);
1.189 + iFormatTickLink.OneShotInMicroSeconds(KFormatAsyncTime,DMediaDriverTest::FormatCompleteCallBack,this);
1.190 + }
1.191 +
1.192 +TInt DMediaDriverTest::Enlarge(TInt /*aLength*/)
1.193 +//
1.194 +// Enlarge the drive
1.195 +//
1.196 + {
1.197 +
1.198 + return(KErrNotSupported);
1.199 + }
1.200 +
1.201 +TInt DMediaDriverTest::ReduceSize(TInt64& /*aPos*/,TInt /*aLength*/)
1.202 +//
1.203 +// Reduce in size the drive
1.204 +//
1.205 + {
1.206 +
1.207 + return(KErrNotSupported);
1.208 + }
1.209 +
1.210 +void DMediaDriverTest::Close()
1.211 +//
1.212 +// Close the media driver
1.213 +//
1.214 + {
1.215 +
1.216 + iWriteTickLink.Cancel();
1.217 + iFormatTickLink.Cancel();
1.218 + }
1.219 +
1.220 +TInt DMediaDriverTest::PartitionInfo(TPartitionInfo &anInfo)
1.221 +//
1.222 +// Return partition information on the media.
1.223 +//
1.224 + {
1.225 +
1.226 + anInfo.iPartitionCount=1;
1.227 + anInfo.iEntry[0].iPartitionBaseAddr=0;
1.228 + anInfo.iEntry[0].iPartitionLen=anInfo.iMediaSizeInBytes=TotalSizeInBytes();
1.229 + return(KErrNone);
1.230 + }
1.231 +
1.232 +void DMediaDriverTest::Caps(TDes8& aCapsBuf)
1.233 +//
1.234 +// Return the capabilities of the media
1.235 + {
1.236 +
1.237 + TLocalDriveCapsV2 caps;
1.238 + caps.iType=EMediaFlash; // Pretend its a Flash device
1.239 + caps.iConnectionBusType=EConnectionBusInternal;
1.240 + caps.iDriveAtt=KDriveAttLocal|KDriveAttRemovable;
1.241 + caps.iMediaAtt=KMediaAttFormattable;
1.242 + caps.iFileSystemId=KDriveFileSysFAT;
1.243 + caps.iHiddenSectors=0;
1.244 + aCapsBuf.FillZ(aCapsBuf.MaxLength());
1.245 + aCapsBuf.Copy((TUint8 *)&caps,Min(aCapsBuf.MaxLength(),sizeof(caps)));
1.246 + }
1.247 +
1.248 +void DMediaDriverTest::WriteCompleteCallBack(TAny *aMediaDriver,TInt /*aDelay*/)
1.249 +//
1.250 +// Complete a write request
1.251 +//
1.252 + {
1.253 +
1.254 + DMediaDriverTest &md=*(DMediaDriverTest*)aMediaDriver;
1.255 + md.Complete(KMediaDrvWriteReq,KErrNone);
1.256 + return;
1.257 + }
1.258 +
1.259 +void DMediaDriverTest::FormatCompleteCallBack(TAny *aMediaDriver,TInt /*aDelay*/)
1.260 +//
1.261 +// Complete a format request
1.262 +//
1.263 + {
1.264 +
1.265 + DMediaDriverTest &md=*(DMediaDriverTest*)aMediaDriver;
1.266 + md.Complete(KMediaDrvFormatReq,KErrNone);
1.267 + return;
1.268 + }
1.269 +
1.270 +DECLARE_STANDARD_PDD()
1.271 + {
1.272 + return new DPhysicalDeviceMediaTest;
1.273 + }
1.274 +