Update contrib.
1 // Copyright (c) 1996-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\pccd\t_idrv.cpp
16 // Tests for the internal RAM drive
20 // - Load a Physical Device Driver for the RAM Media Driver.
21 // - Find the internal drive: type == EMediaRam
22 // - Display and adjust various drive capabilities, verify results
24 // - Read and write the drive using various drive sizes, verify results
26 // - Format the drive, verify results.
27 // - Set original size and reformat.
28 // Platforms/Drives/Compatibility:
30 // Assumptions/Requirement/Pre-requisites:
31 // Failures and causes:
32 // Base Port information:
40 #include "../mmu/mmudetect.h"
43 #define PDD_NAME _L("MEDINT")
45 const TInt KTestDriveLen=0x00040000; //256K
46 const TInt KSmallDriveInc=0x00000400; //1K
47 const TInt KBigDriveLen=0x00100000; //1M - WINS
48 const TInt KTestBufLen=256;
51 RTest test(_L("T_IDRV"));
53 void Format(TInt aDrive, RFs& aFs)
55 // Format current drive
58 test.Next(_L("Format"));
59 TBuf<4> driveBuf=_L("?:\\");
60 driveBuf[0]=(TText)(aDrive+'A');
63 TInt r=format.Open(aFs,driveBuf,EHighDensity,count);
67 TInt r=format.Next(count);
73 GLDEF_C TInt E32Main()
79 test.Printf(_L("Needs MMU\n"));
82 #if defined(__EPOC32__) && defined(__CPU_X86)
83 test.Printf(_L("Doesn't run on X86\n"));
86 TBusLocalDrive theInternalDrive;
87 TInt msgHandle = KLocalMessageHandle;
89 UserSvr::UnlockRamDrive();
91 test.Printf(_L("Warning - this will destroy internal drive.\r\n"));
97 test.Start(_L("Check loader running"));
99 test.Next(_L("Load Internal Ram Media Driver"));
100 TInt r=User::LoadPhysicalDevice(PDD_NAME);
101 test(r==KErrNone || r==KErrAlreadyExists);
103 test.Next(_L("Find internal drive"));
105 TDriveInfoV1Buf driveInfoBuf;
106 UserHal::DriveInfo(driveInfoBuf);
107 TDriveInfoV1& driveInfo = driveInfoBuf();
110 for ( ; drive < driveInfo.iTotalSupportedDrives; ++drive)
113 theInternalDrive.Connect(drive, changedFlag);
115 TLocalDriveCapsV2 info;
116 TPckg<TLocalDriveCapsV2> infoPckg(info);
117 theInternalDrive.Caps(infoPckg);
119 if (info.iType == EMediaRam)
124 theInternalDrive.Disconnect();
126 test(drive < driveInfo.iTotalSupportedDrives);
128 test.Next(_L("Capabilities"));
129 TLocalDriveCapsV2 info;
130 TPckg<TLocalDriveCapsV2> infoPckg(info);
131 test(theInternalDrive.Caps(infoPckg)==KErrNone);
132 TUint saveSize=I64LOW(info.iSize);
133 test(info.iType==EMediaRam);
134 test(info.iConnectionBusType==EConnectionBusInternal);
135 test(info.iDriveAtt==(KDriveAttLocal|KDriveAttInternal));
136 test(info.iMediaAtt==(KMediaAttVariableSize|KMediaAttFormattable));
137 test(info.iFileSystemId==KDriveFileSysFAT);
139 test.Printf(_L("Current drive size: %lx\n"),info.iSize);
141 test.Next(_L("Set size to zero"));
142 test(theInternalDrive.ReduceSize(0,saveSize)==KErrNone);
143 test(theInternalDrive.Caps(infoPckg)==KErrNone);
145 test(theInternalDrive.ReduceSize(0,-1)==KErrArgument);
146 test(theInternalDrive.Enlarge(-1)==KErrArgument);
148 test.Next(_L("Increase to large size"));
149 #if defined (__WINS__)
150 TUint cSize=KBigDriveLen;
152 TMemoryInfoV1Buf memBuf;
153 TMemoryInfoV1 &mi=memBuf();
154 UserHal::MemoryInfo(memBuf);
155 // TUint cSize=(mi.iTotalRamInBytes-KTestDriveLen); // Leave last 256K - used by Kernel etc.
156 // TUint cSize=mi.iTotalRamInBytes>>1; // Half ram
157 // TUint cSize=mi.iTotalRamInBytes>>2; // Quarter ram
158 TUint cSize=mi.iTotalRamInBytes>>3; // Eighth ram
160 test.Printf(_L("(Increasing to %dbytes)\r\n"),cSize);
161 test(theInternalDrive.Enlarge(cSize)==KErrNone);
162 // test(theInternalDrive.Enlarge(cSize-saveSize)==KErrNone); // ???
163 test(theInternalDrive.Caps(infoPckg)==KErrNone);
164 test(I64LOW(info.iSize)==cSize);
166 test.Next(_L("Increase by 1K"));
167 cSize+=KSmallDriveInc;
168 test(theInternalDrive.Enlarge(KSmallDriveInc)==KErrNone);
169 test(theInternalDrive.Caps(infoPckg)==KErrNone);
170 test(I64LOW(info.iSize)==cSize);
172 test.Next(_L("Reduce to 256K"));
173 test(theInternalDrive.ReduceSize(0,(cSize-KTestDriveLen))==KErrNone);
175 test(theInternalDrive.Caps(infoPckg)==KErrNone);
176 test(I64LOW(info.iSize)==(TUint)KTestDriveLen);
178 test.Next(_L("Write/Read"));
179 TBuf8<KTestBufLen> wrBuf(KTestBufLen),rdBuf;
181 for (i=0 ; i<(TUint)KTestBufLen ; i++)
183 for (i=0,j=0;i<(TUint)KTestDriveLen;i+=len,j++)
185 len=Min(KTestBufLen,(KTestDriveLen-i));
188 test(theInternalDrive.Write(i,len,&wrBuf,msgHandle,0)==KErrNone);
189 test(theInternalDrive.Read(i,len,&rdBuf,msgHandle,0)==KErrNone);
190 wrBuf.SetLength(len);
191 test(rdBuf.Compare(wrBuf)==0);
194 test.Next(_L("Reduce size - 256 bytes from start"));
195 test(theInternalDrive.ReduceSize(0,KTestBufLen)==KErrNone);
196 test(theInternalDrive.Caps(infoPckg)==KErrNone);
198 test(I64LOW(info.iSize)==(TUint)cSize);
199 for (i=0,j=1;i<cSize;i+=len,j++)
201 len=Min(KTestBufLen,(cSize-i));
204 test(theInternalDrive.Read(i,len,&rdBuf,msgHandle,0)==KErrNone);
205 wrBuf.SetLength(len);
206 test(rdBuf.Compare(wrBuf)==0);
209 test.Next(_L("Reduce size - (4K+127) bytes from middle"));
210 TInt reduction=((KTestBufLen<<4)+((KTestBufLen>>1)-1));
211 test(theInternalDrive.ReduceSize(KTestBufLen,reduction)==KErrNone);
212 test(theInternalDrive.Caps(infoPckg)==KErrNone);
214 test(I64LOW(info.iSize)==(TUint)cSize);
215 TBuf8<KTestBufLen> odBuf(KTestBufLen); // To verify new pattern
216 for (i=0 ; i<(TUint)KTestBufLen ; i++)
218 if (i<=(KTestBufLen>>1))
219 odBuf[i]=(TUint8)(i+((KTestBufLen>>1)-1));
221 odBuf[i]=(TUint8)(i-((KTestBufLen>>1)+1));
223 for (i=0,j=1;i<cSize;i+=len,j++)
225 len=Min(KTestBufLen,(cSize-i));
227 test(theInternalDrive.Read(i,len,&rdBuf,msgHandle,0)==KErrNone);
233 wrBuf.SetLength(len);
234 test(rdBuf.Compare(wrBuf)==0);
238 odBuf.SetLength(KTestBufLen);
239 odBuf[((KTestBufLen>>1)+1)]=(TUint8)j;
240 odBuf.SetLength(len);
241 test(rdBuf.Compare(odBuf)==0);
245 test.Next(_L("Reduce size - (8K-1) bytes from end"));
246 reduction=((KTestBufLen<<5)-1);
247 test(theInternalDrive.ReduceSize((cSize-reduction),reduction)==KErrNone);
248 test(theInternalDrive.Caps(infoPckg)==KErrNone);
250 test(info.iSize==cSize);
251 for (i=0,j=1;i<cSize;i+=len,j++)
253 len=Min(KTestBufLen,(cSize-i));
255 test(theInternalDrive.Read(i,len,&rdBuf,msgHandle,0)==KErrNone);
261 wrBuf.SetLength(len);
262 test(rdBuf.Compare(wrBuf)==0);
266 odBuf.SetLength(KTestBufLen);
267 odBuf[((KTestBufLen>>1)+1)]=(TUint8)j;
268 odBuf.SetLength(len);
269 test(rdBuf.Compare(odBuf)==0);
273 test.Next(_L("Format"));
274 wrBuf.Fill(0,KTestBufLen);
277 while((ret=theInternalDrive.Format(fi))!=KErrEof)
279 for (i=0;i<cSize;i+=len)
281 len=Min(KTestBufLen,(cSize-i));
282 rdBuf.Fill(0xAA,len);
283 test(theInternalDrive.Read(i,len,&rdBuf,msgHandle,0)==KErrNone);
284 wrBuf.SetLength(len);
285 test(rdBuf.Compare(wrBuf)==0);
288 test.Next(_L("Restore original size"));
289 TInt sizeDif=cSize-saveSize;
291 test(theInternalDrive.ReduceSize(0,sizeDif)==KErrNone);
293 test(theInternalDrive.Enlarge(sizeDif*-1)==KErrNone);
295 test.Next(_L("Disconnect from internal drive"));
296 theInternalDrive.Disconnect();
299 test(fs.Connect()==KErrNone);
300 for(drive=25 ; drive>=0; --drive)
303 if(fs.Drive(info,drive)==KErrNone)
304 if(info.iType==EMediaRam)
307 text.Append(_L("Formatting drive "));
308 text.Append(TText(drive+'A'));
309 text.Append(_L(": ..."));