|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // e32test\pccd\t_media.cpp |
|
15 // Test the Compact Flash card (ATA) media driver |
|
16 // |
|
17 // |
|
18 |
|
19 #include <e32test.h> |
|
20 #include <e32svr.h> |
|
21 #include "u32std.h" |
|
22 #include "../misc/prbs.h" |
|
23 |
|
24 const TInt KSectorSize=512; |
|
25 |
|
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]; |
|
30 |
|
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]; |
|
36 |
|
37 inline TUint RoundDownToSector(TUint aPos) |
|
38 { return aPos&~0x1ff; } |
|
39 inline TUint RoundUpToSector(TUint aPos) |
|
40 { return (aPos+0x1ff)&~0x1ff; } |
|
41 |
|
42 LOCAL_C void TestPattern(TUint8* aBuf, TInt aLength) |
|
43 { |
|
44 while(aLength--) |
|
45 *aBuf++=(TUint8)Random(Seed); |
|
46 } |
|
47 |
|
48 LOCAL_C void Write(TUint aPos, TInt aLength, const TUint8* aBuffer) |
|
49 { |
|
50 TPtrC8 p(aBuffer,aLength); |
|
51 TInt r=TheDrive.Write(aPos,p); |
|
52 if (r!=KErrNone) |
|
53 { |
|
54 test.Printf(_L("Write failed with error %d\n"),r); |
|
55 test.Printf(_L("Pos=%08x, Length=%x\n"),aPos,aLength); |
|
56 test(0); |
|
57 } |
|
58 } |
|
59 |
|
60 LOCAL_C void DebugDump(TUint aPos, TInt aLength, const TUint8* aBuf, const TDesC& aTitle) |
|
61 { |
|
62 RDebug::Print(aTitle); |
|
63 TUint end=aPos+aLength; |
|
64 TInt i; |
|
65 TInt j=0; |
|
66 while(aPos<end) |
|
67 { |
|
68 TBuf<80> buf; |
|
69 buf.NumFixedWidthUC(aPos,EHex,8); |
|
70 buf+=_L(": "); |
|
71 for (i=0; i<16; i++) |
|
72 { |
|
73 buf.AppendNumFixedWidthUC(aBuf[j+i],EHex,2); |
|
74 buf+=_L(" "); |
|
75 } |
|
76 RDebug::Print(buf); |
|
77 aPos+=16; |
|
78 j+=16; |
|
79 if ((aPos&(KSectorSize-1))==0) |
|
80 RDebug::Print(_L("")); |
|
81 } |
|
82 } |
|
83 |
|
84 LOCAL_C void Verify(TUint aPos, TInt aLength, const TUint8* aRef) |
|
85 { |
|
86 TPtr8 p(VerifyBuffer,0,64*KSectorSize); |
|
87 TInt r=TheDrive.Read(aPos,aLength,p); |
|
88 if (r!=KErrNone) |
|
89 { |
|
90 test.Printf(_L("Read failed with error %d\n"),r); |
|
91 test.Printf(_L("Pos=%08x, Length=%x\n"),aPos,aLength); |
|
92 test(0); |
|
93 } |
|
94 if (p.Length()!=aLength) |
|
95 { |
|
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); |
|
98 test(0); |
|
99 } |
|
100 r=Mem::Compare(VerifyBuffer,aLength,aRef,aLength); |
|
101 if (r==0) |
|
102 return; |
|
103 TInt i=0; |
|
104 while(i<aLength && VerifyBuffer[i]==aRef[i]) |
|
105 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 ")); |
|
109 TInt k=test.Getch(); |
|
110 if (k==EKeyEnter) |
|
111 { |
|
112 DebugDump(aPos,aLength,VerifyBuffer,_L("Actual:")); |
|
113 DebugDump(aPos,aLength,aRef,_L("Expected:")); |
|
114 } |
|
115 test(0); |
|
116 } |
|
117 |
|
118 LOCAL_C void DoTest(TUint aBasePos, TInt anOffset, TInt aSize) |
|
119 { |
|
120 TBuf<80> buf; |
|
121 buf.Format(_L("Offset %3x Size %04x"),anOffset,aSize); |
|
122 test.Next(buf); |
|
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); |
|
140 } |
|
141 |
|
142 GLDEF_C TInt E32Main() |
|
143 { |
|
144 Seed[0]=0xadf85458; |
|
145 Seed[1]=0; |
|
146 test.Title(); |
|
147 |
|
148 TChar driveToTest; |
|
149 |
|
150 // Get the list of drives |
|
151 TDriveInfoV1Buf diBuf; |
|
152 UserHal::DriveInfo(diBuf); |
|
153 TDriveInfoV1 &di=diBuf(); |
|
154 TInt driveCount = di.iTotalSupportedDrives; |
|
155 |
|
156 test.Printf(_L("\nDRIVES USED AT PRESENT :\r\n")); |
|
157 for (TInt i=0; i < driveCount; i++) |
|
158 { |
|
159 TBool flag=EFalse; |
|
160 RLocalDrive d; |
|
161 TInt r=d.Connect(i,flag); |
|
162 //Not all the drives are used at present |
|
163 if (r == KErrNotSupported) |
|
164 continue; |
|
165 |
|
166 test.Printf(_L("%d : DRIVE NAME :%- 16S\r\n"), i, &di.iDriveName[i]); |
|
167 } |
|
168 |
|
169 test.Printf(_L("\n<<<Hit required drive number to continue>>>\r\n")); |
|
170 |
|
171 driveToTest=(TUint)test.Getch(); |
|
172 |
|
173 TInt driveNumber=((TUint)driveToTest) - '0'; |
|
174 |
|
175 TBuf<0x100> buf; |
|
176 buf.Format(_L("Connect to local drive (%d)"),driveNumber); |
|
177 test.Start(buf); |
|
178 |
|
179 TInt r=TheDrive.Connect(driveNumber,MediaChange); |
|
180 test(r==KErrNone); |
|
181 |
|
182 test.Next(_L("Get capabilities")); |
|
183 TLocalDriveCapsV2 driveCaps; |
|
184 TPckg<TLocalDriveCapsV2> capsPckg(driveCaps); |
|
185 r=TheDrive.Caps(capsPckg); |
|
186 test(r==KErrNone); |
|
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("Battery state = %d\n"),driveCaps.iBattery); |
|
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")); |
|
197 test.Getch(); |
|
198 TUint basePos=RoundDownToSector(driveSize)-128*KSectorSize; |
|
199 test.Printf(_L("Base position = %08x\n"),basePos); |
|
200 |
|
201 TInt offset; |
|
202 TInt size; |
|
203 for (size=KSectorSize/4; size<=23*KSectorSize/2; size+=KSectorSize/4) |
|
204 { |
|
205 for (offset=0; offset<KSectorSize; offset+=KSectorSize/2) |
|
206 { |
|
207 DoTest(basePos,offset,size); |
|
208 } |
|
209 } |
|
210 |
|
211 for (size=12*KSectorSize; size<=33*KSectorSize; size+=KSectorSize/2) |
|
212 { |
|
213 for (offset=0; offset<KSectorSize; offset+=KSectorSize/2) |
|
214 { |
|
215 DoTest(basePos,offset,size); |
|
216 } |
|
217 } |
|
218 |
|
219 buf.Format(_L("Disconnect from local drive (%d)"),driveNumber); |
|
220 test.Next(buf); |
|
221 TheDrive.Disconnect(); |
|
222 test.End(); |
|
223 return 0; |
|
224 } |