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_media.cpp
15 // Test the Compact Flash card (ATA) media driver
22 #include "../misc/prbs.h"
24 const TInt KSectorSize=512;
26 LOCAL_D RTest test(_L("T_MEDIA"));
27 LOCAL_D TBusLocalDrive TheDrive;
28 LOCAL_D TBool MediaChange=EFalse;
29 LOCAL_D TUint Seed[2];
31 LOCAL_D TUint8 Background1[64*KSectorSize];
32 LOCAL_D TUint8 Background2[64*KSectorSize];
33 LOCAL_D TUint8 Foreground1[64*KSectorSize];
34 LOCAL_D TUint8 Foreground2[64*KSectorSize];
35 LOCAL_D TUint8 VerifyBuffer[64*KSectorSize];
37 inline TUint RoundDownToSector(TUint aPos)
38 { return aPos&~0x1ff; }
39 inline TUint RoundUpToSector(TUint aPos)
40 { return (aPos+0x1ff)&~0x1ff; }
42 LOCAL_C void TestPattern(TUint8* aBuf, TInt aLength)
45 *aBuf++=(TUint8)Random(Seed);
48 LOCAL_C void Write(TUint aPos, TInt aLength, const TUint8* aBuffer)
50 TPtrC8 p(aBuffer,aLength);
51 TInt r=TheDrive.Write(aPos,p);
54 test.Printf(_L("Write failed with error %d\n"),r);
55 test.Printf(_L("Pos=%08x, Length=%x\n"),aPos,aLength);
60 LOCAL_C void DebugDump(TUint aPos, TInt aLength, const TUint8* aBuf, const TDesC& aTitle)
62 RDebug::Print(aTitle);
63 TUint end=aPos+aLength;
69 buf.NumFixedWidthUC(aPos,EHex,8);
73 buf.AppendNumFixedWidthUC(aBuf[j+i],EHex,2);
79 if ((aPos&(KSectorSize-1))==0)
80 RDebug::Print(_L(""));
84 LOCAL_C void Verify(TUint aPos, TInt aLength, const TUint8* aRef)
86 TPtr8 p(VerifyBuffer,0,64*KSectorSize);
87 TInt r=TheDrive.Read(aPos,aLength,p);
90 test.Printf(_L("Read failed with error %d\n"),r);
91 test.Printf(_L("Pos=%08x, Length=%x\n"),aPos,aLength);
94 if (p.Length()!=aLength)
96 test.Printf(_L("Incorrect length after read: Was %08x Expected %08x\n"),p.Length(),aLength);
97 test.Printf(_L("Pos=%08x, Length=%x\n"),aPos,aLength);
100 r=Mem::Compare(VerifyBuffer,aLength,aRef,aLength);
104 while(i<aLength && VerifyBuffer[i]==aRef[i])
106 test.Printf(_L("Verify error: aPos=%08x, aLength=%08x\n"),aPos,aLength);
107 test.Printf(_L("First difference at offset %x\n"),i);
108 test.Printf(_L("Press <ENTER> for debug dump "));
112 DebugDump(aPos,aLength,VerifyBuffer,_L("Actual:"));
113 DebugDump(aPos,aLength,aRef,_L("Expected:"));
118 LOCAL_C void DoTest(TUint aBasePos, TInt anOffset, TInt aSize)
121 buf.Format(_L("Offset %3x Size %04x"),anOffset,aSize);
123 TUint block1=aBasePos;
124 TUint block2=aBasePos+64*KSectorSize;
125 TUint totalSectorSize=RoundUpToSector(anOffset+aSize);
126 TestPattern(Background1,totalSectorSize);
127 TestPattern(Background2,totalSectorSize);
128 TestPattern(Foreground1,totalSectorSize);
129 TestPattern(Foreground2,totalSectorSize);
130 Write(block1,totalSectorSize,Background1);
131 Write(block2,totalSectorSize,Background2);
132 Verify(block1,totalSectorSize,Background1);
133 Verify(block2,totalSectorSize,Background2);
134 Write(block1+anOffset,aSize,Foreground1);
135 Write(block2+anOffset,aSize,Foreground2);
136 Mem::Copy(Background1+anOffset,Foreground1,aSize);
137 Mem::Copy(Background2+anOffset,Foreground2,aSize);
138 Verify(block1,totalSectorSize,Background1);
139 Verify(block2,totalSectorSize,Background2);
142 GLDEF_C TInt E32Main()
150 // Get the list of drives
151 TDriveInfoV1Buf diBuf;
152 UserHal::DriveInfo(diBuf);
153 TDriveInfoV1 &di=diBuf();
154 TInt driveCount = di.iTotalSupportedDrives;
156 test.Printf(_L("\nDRIVES USED AT PRESENT :\r\n"));
157 for (TInt i=0; i < driveCount; i++)
161 TInt r=d.Connect(i,flag);
162 //Not all the drives are used at present
163 if (r == KErrNotSupported)
166 test.Printf(_L("%d : DRIVE NAME :%- 16S\r\n"), i, &di.iDriveName[i]);
169 test.Printf(_L("\n<<<Hit required drive number to continue>>>\r\n"));
171 driveToTest=(TUint)test.Getch();
173 TInt driveNumber=((TUint)driveToTest) - '0';
176 buf.Format(_L("Connect to local drive (%d)"),driveNumber);
179 TInt r=TheDrive.Connect(driveNumber,MediaChange);
182 test.Next(_L("Get capabilities"));
183 TLocalDriveCapsV2 driveCaps;
184 TPckg<TLocalDriveCapsV2> capsPckg(driveCaps);
185 r=TheDrive.Caps(capsPckg);
187 TUint driveSize=I64LOW(driveCaps.iSize);
188 test.Printf(_L("Drive size = %08x (%dK)\n"),driveSize,driveSize>>10);
189 test.Printf(_L("Media type = %d\n"),driveCaps.iType);
190 test.Printf(_L("Connection Bus = %d\n"),driveCaps.iConnectionBusType);
191 test.Printf(_L("Drive attributes = %08x\n"),driveCaps.iDriveAtt);
192 test.Printf(_L("Media attributes = %08x\n"),driveCaps.iMediaAtt);
193 test.Printf(_L("Base address = %08x\n"),driveCaps.iBaseAddress);
194 test.Printf(_L("File system ID = %08x\n"),driveCaps.iFileSystemId);
195 test.Printf(_L("Hidden sectors = %08x\n"),driveCaps.iHiddenSectors);
196 test.Printf(_L("Press any key...\n"));
198 TUint basePos=RoundDownToSector(driveSize)-128*KSectorSize;
199 test.Printf(_L("Base position = %08x\n"),basePos);
203 for (size=KSectorSize/4; size<=23*KSectorSize/2; size+=KSectorSize/4)
205 for (offset=0; offset<KSectorSize; offset+=KSectorSize/2)
207 DoTest(basePos,offset,size);
211 for (size=12*KSectorSize; size<=33*KSectorSize; size+=KSectorSize/2)
213 for (offset=0; offset<KSectorSize; offset+=KSectorSize/2)
215 DoTest(basePos,offset,size);
219 buf.Format(_L("Disconnect from local drive (%d)"),driveNumber);
221 TheDrive.Disconnect();