1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/pccd/d_medt1.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,266 @@
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_medt1.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.Tst1");
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 + }
1.130 +
1.131 +TInt DMediaDriverTest::DoCreate(TMediaDevice aMediaDevice)
1.132 +//
1.133 +// Create the media driver.
1.134 +//
1.135 + {
1.136 +
1.137 + if (!__IS_REMOVABLE(aMediaDevice))
1.138 + return(KErrNotSupported);
1.139 + SetTotalSizeInBytes(KTestDriverBufferMaxSize);
1.140 + return(KErrNone);
1.141 + }
1.142 +
1.143 +void DMediaDriverTest::DoRead(TInt64 &aPos,TInt aLength,TMediaDrvDescData &aTrg)
1.144 +//
1.145 +// Read from specified area of media.
1.146 +//
1.147 + {
1.148 +
1.149 + TInt ret=KErrNone;
1.150 + if (!aTrg.IsCurrentThread())
1.151 + ret=KErrGeneral;
1.152 + else
1.153 + {
1.154 + if ((ret=aTrg.CurrentThreadDescCheck(aLength))==KErrNone)
1.155 + {
1.156 + TDes8 &t=*((TDes8*)aTrg.iPtr);
1.157 + Mem::Copy((TAny*)(t.Ptr()+aTrg.iOffset),&iBuf[aPos.Low()],aLength);
1.158 + t.SetLength(aLength+aTrg.iOffset);
1.159 + }
1.160 + }
1.161 + Complete(KMediaDrvReadReq,ret);
1.162 + }
1.163 +
1.164 +const TInt KWriteAsyncTime=100000; // 100mS
1.165 +void DMediaDriverTest::DoWrite(TInt64 &aPos,TInt aLength,TMediaDrvDescData &aSrc)
1.166 +//
1.167 +// Write to specifed area of media.
1.168 +//
1.169 + {
1.170 +
1.171 + if (!aSrc.IsCurrentThread())
1.172 + Complete(KMediaDrvWriteReq,KErrGeneral);
1.173 + else
1.174 + {
1.175 + Mem::Copy(&iBuf[aPos.Low()],((TDesC8*)aSrc.iPtr)->Ptr()+aSrc.iOffset,aLength);
1.176 + iWriteTickLink.OneShotInMicroSeconds(KWriteAsyncTime,DMediaDriverTest::WriteCompleteCallBack,this);
1.177 + }
1.178 + }
1.179 +
1.180 +const TInt KFormatAsyncTime=5000000; // 5S
1.181 +void DMediaDriverTest::DoFormat(TInt64 &aPos,TInt aLength)
1.182 +//
1.183 +// Format the specified area of the media.
1.184 +//
1.185 + {
1.186 +
1.187 + Mem::Fill(&iBuf[aPos.Low()],aLength,0xFF);
1.188 + iFormatTickLink.OneShotInMicroSeconds(KFormatAsyncTime,DMediaDriverTest::FormatCompleteCallBack,this);
1.189 + }
1.190 +
1.191 +TInt DMediaDriverTest::Enlarge(TInt /*aLength*/)
1.192 +//
1.193 +// Enlarge the drive
1.194 +//
1.195 + {
1.196 +
1.197 + return(KErrNotSupported);
1.198 + }
1.199 +
1.200 +TInt DMediaDriverTest::ReduceSize(TInt64& /*aPos*/,TInt /*aLength*/)
1.201 +//
1.202 +// Reduce in size the drive
1.203 +//
1.204 + {
1.205 +
1.206 + return(KErrNotSupported);
1.207 + }
1.208 +
1.209 +void DMediaDriverTest::Close()
1.210 +//
1.211 +// Close the media driver
1.212 +//
1.213 + {}
1.214 +
1.215 +TInt DMediaDriverTest::PartitionInfo(TPartitionInfo &anInfo)
1.216 +//
1.217 +// Return partition information on the media.
1.218 +//
1.219 + {
1.220 +
1.221 + anInfo.iPartitionCount=1;
1.222 + anInfo.iEntry[0].iPartitionBaseAddr=0;
1.223 + anInfo.iEntry[0].iPartitionLen=anInfo.iMediaSizeInBytes=TotalSizeInBytes();
1.224 + return(KErrNone);
1.225 + }
1.226 +
1.227 +void DMediaDriverTest::Caps(TDes8& aCapsBuf)
1.228 +//
1.229 +// Return the capabilities of the media
1.230 + {
1.231 +
1.232 + TLocalDriveCapsV2 caps;
1.233 + caps.iType=EMediaRam;
1.234 + caps.iConnectionBusType=EConnectionBusInternal;
1.235 + caps.iDriveAtt=KDriveAttLocal|KDriveAttRemovable;
1.236 + caps.iMediaAtt=KMediaAttFormattable;
1.237 + caps.iFileSystemId=KDriveFileSysFAT;
1.238 + caps.iHiddenSectors=0;
1.239 + aCapsBuf.FillZ(aCapsBuf.MaxLength());
1.240 + aCapsBuf.Copy((TUint8 *)&caps,Min(aCapsBuf.MaxLength(),sizeof(caps)));
1.241 + }
1.242 +
1.243 +void DMediaDriverTest::WriteCompleteCallBack(TAny *aMediaDriver,TInt /*aDelay*/)
1.244 +//
1.245 +// Complete a write request
1.246 +//
1.247 + {
1.248 +
1.249 + DMediaDriverTest &md=*(DMediaDriverTest*)aMediaDriver;
1.250 + md.Complete(KMediaDrvWriteReq,KErrNone);
1.251 + return;
1.252 + }
1.253 +
1.254 +void DMediaDriverTest::FormatCompleteCallBack(TAny *aMediaDriver,TInt /*aDelay*/)
1.255 +//
1.256 +// Complete a format request
1.257 +//
1.258 + {
1.259 +
1.260 + DMediaDriverTest &md=*(DMediaDriverTest*)aMediaDriver;
1.261 + md.Complete(KMediaDrvFormatReq,KErrNone);
1.262 + return;
1.263 + }
1.264 +
1.265 +DECLARE_STANDARD_PDD()
1.266 + {
1.267 + return(new DPhysicalDeviceMediaTest);
1.268 + }
1.269 +