author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 03 May 2010 13:47:38 +0300 | |
changeset 102 | ef2a444a7410 |
parent 90 | 947f0dc9f7a8 |
child 109 | b3a1d9898418 |
permissions | -rw-r--r-- |
0 | 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_idrv.cpp |
|
15 |
// Overview: |
|
16 |
// Tests for the internal RAM drive |
|
17 |
// API Information: |
|
18 |
// TBusLocalDrive |
|
19 |
// Details: |
|
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 |
|
23 |
// are as expected. |
|
24 |
// - Read and write the drive using various drive sizes, verify results |
|
25 |
// are as expected. |
|
26 |
// - Format the drive, verify results. |
|
27 |
// - Set original size and reformat. |
|
28 |
// Platforms/Drives/Compatibility: |
|
29 |
// All. |
|
30 |
// Assumptions/Requirement/Pre-requisites: |
|
31 |
// Failures and causes: |
|
32 |
// Base Port information: |
|
33 |
// |
|
34 |
// |
|
35 |
||
36 |
#include <e32test.h> |
|
37 |
#include <e32svr.h> |
|
38 |
#include <e32hal.h> |
|
39 |
#include <e32uid.h> |
|
40 |
#include "../mmu/mmudetect.h" |
|
41 |
#include <f32file.h> |
|
42 |
||
43 |
#define PDD_NAME _L("MEDINT") |
|
44 |
||
45 |
const TInt KTestDriveLen=0x00040000; //256K |
|
46 |
const TInt KSmallDriveInc=0x00000400; //1K |
|
47 |
const TInt KBigDriveLen=0x00100000; //1M - WINS |
|
48 |
const TInt KTestBufLen=256; |
|
49 |
||
50 |
||
51 |
RTest test(_L("T_IDRV")); |
|
52 |
||
53 |
void Format(TInt aDrive, RFs& aFs) |
|
54 |
// |
|
55 |
// Format current drive |
|
56 |
// |
|
57 |
{ |
|
58 |
test.Next(_L("Format")); |
|
59 |
TBuf<4> driveBuf=_L("?:\\"); |
|
60 |
driveBuf[0]=(TText)(aDrive+'A'); |
|
61 |
RFormat format; |
|
62 |
TInt count; |
|
63 |
TInt r=format.Open(aFs,driveBuf,EHighDensity,count); |
|
64 |
test(r==KErrNone); |
|
65 |
while(count) |
|
66 |
{ |
|
67 |
TInt r=format.Next(count); |
|
68 |
test(r==KErrNone); |
|
69 |
} |
|
70 |
format.Close(); |
|
71 |
} |
|
72 |
||
73 |
GLDEF_C TInt E32Main() |
|
74 |
{ |
|
75 |
||
76 |
test.Title(); |
|
77 |
if (!HaveVirtMem()) |
|
78 |
{ |
|
79 |
test.Printf(_L("Needs MMU\n")); |
|
80 |
return 0; |
|
81 |
} |
|
82 |
#if defined(__EPOC32__) && defined(__CPU_X86) |
|
83 |
test.Printf(_L("Doesn't run on X86\n")); |
|
84 |
#else |
|
85 |
||
86 |
TBusLocalDrive theInternalDrive; |
|
87 |
TInt msgHandle = KLocalMessageHandle; |
|
88 |
||
89 |
UserSvr::UnlockRamDrive(); |
|
90 |
||
91 |
test.Printf(_L("Warning - this will destroy internal drive.\r\n")); |
|
92 |
TChar c= 'C'; |
|
93 |
c.UpperCase(); |
|
94 |
if (c!='C') |
|
95 |
return(0); |
|
96 |
||
97 |
test.Start(_L("Check loader running")); |
|
98 |
||
99 |
test.Next(_L("Load Internal Ram Media Driver")); |
|
100 |
TInt r=User::LoadPhysicalDevice(PDD_NAME); |
|
101 |
test(r==KErrNone || r==KErrAlreadyExists); |
|
102 |
||
103 |
test.Next(_L("Find internal drive")); |
|
104 |
||
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
105 |
TInt drive; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
106 |
for (drive = 0; drive < KMaxLocalDrives; drive++) |
0 | 107 |
{ |
108 |
TBool changedFlag; |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
109 |
if (theInternalDrive.Connect(drive, changedFlag) != KErrNone) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
110 |
continue; |
0 | 111 |
|
112 |
TLocalDriveCapsV2 info; |
|
113 |
TPckg<TLocalDriveCapsV2> infoPckg(info); |
|
114 |
theInternalDrive.Caps(infoPckg); |
|
115 |
||
116 |
if (info.iType == EMediaRam) |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
117 |
break; // found it |
0 | 118 |
|
119 |
theInternalDrive.Disconnect(); |
|
120 |
} |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
121 |
test(drive < KMaxLocalDrives); // iterated over all, found none |
0 | 122 |
|
123 |
test.Next(_L("Capabilities")); |
|
124 |
TLocalDriveCapsV2 info; |
|
125 |
TPckg<TLocalDriveCapsV2> infoPckg(info); |
|
126 |
test(theInternalDrive.Caps(infoPckg)==KErrNone); |
|
127 |
TUint saveSize=I64LOW(info.iSize); |
|
128 |
test(info.iType==EMediaRam); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
129 |
test(info.iConnectionBusType==EConnectionBusInternal); |
0 | 130 |
test(info.iDriveAtt==(KDriveAttLocal|KDriveAttInternal)); |
131 |
test(info.iMediaAtt==(KMediaAttVariableSize|KMediaAttFormattable)); |
|
132 |
test(info.iFileSystemId==KDriveFileSysFAT); |
|
133 |
||
134 |
test.Printf(_L("Current drive size: %lx\n"),info.iSize); |
|
135 |
||
136 |
test.Next(_L("Set size to zero")); |
|
137 |
test(theInternalDrive.ReduceSize(0,saveSize)==KErrNone); |
|
138 |
test(theInternalDrive.Caps(infoPckg)==KErrNone); |
|
139 |
test(info.iSize==0); |
|
140 |
test(theInternalDrive.ReduceSize(0,-1)==KErrArgument); |
|
141 |
test(theInternalDrive.Enlarge(-1)==KErrArgument); |
|
142 |
||
143 |
test.Next(_L("Increase to large size")); |
|
144 |
#if defined (__WINS__) |
|
145 |
TUint cSize=KBigDriveLen; |
|
146 |
#else |
|
147 |
TMemoryInfoV1Buf memBuf; |
|
148 |
TMemoryInfoV1 &mi=memBuf(); |
|
149 |
UserHal::MemoryInfo(memBuf); |
|
150 |
// TUint cSize=(mi.iTotalRamInBytes-KTestDriveLen); // Leave last 256K - used by Kernel etc. |
|
151 |
// TUint cSize=mi.iTotalRamInBytes>>1; // Half ram |
|
152 |
// TUint cSize=mi.iTotalRamInBytes>>2; // Quarter ram |
|
153 |
TUint cSize=mi.iTotalRamInBytes>>3; // Eighth ram |
|
154 |
#endif |
|
155 |
test.Printf(_L("(Increasing to %dbytes)\r\n"),cSize); |
|
156 |
test(theInternalDrive.Enlarge(cSize)==KErrNone); |
|
157 |
// test(theInternalDrive.Enlarge(cSize-saveSize)==KErrNone); // ??? |
|
158 |
test(theInternalDrive.Caps(infoPckg)==KErrNone); |
|
159 |
test(I64LOW(info.iSize)==cSize); |
|
160 |
||
161 |
test.Next(_L("Increase by 1K")); |
|
162 |
cSize+=KSmallDriveInc; |
|
163 |
test(theInternalDrive.Enlarge(KSmallDriveInc)==KErrNone); |
|
164 |
test(theInternalDrive.Caps(infoPckg)==KErrNone); |
|
165 |
test(I64LOW(info.iSize)==cSize); |
|
166 |
||
167 |
test.Next(_L("Reduce to 256K")); |
|
168 |
test(theInternalDrive.ReduceSize(0,(cSize-KTestDriveLen))==KErrNone); |
|
169 |
cSize=KTestDriveLen; |
|
170 |
test(theInternalDrive.Caps(infoPckg)==KErrNone); |
|
171 |
test(I64LOW(info.iSize)==(TUint)KTestDriveLen); |
|
172 |
||
173 |
test.Next(_L("Write/Read")); |
|
174 |
TBuf8<KTestBufLen> wrBuf(KTestBufLen),rdBuf; |
|
175 |
TUint i,j,len; |
|
176 |
for (i=0 ; i<(TUint)KTestBufLen ; i++) |
|
177 |
wrBuf[i]=(TUint8)i; |
|
178 |
for (i=0,j=0;i<(TUint)KTestDriveLen;i+=len,j++) |
|
179 |
{ |
|
180 |
len=Min(KTestBufLen,(KTestDriveLen-i)); |
|
181 |
rdBuf.Fill(0,len); |
|
182 |
wrBuf[0]=(TUint8)j; |
|
183 |
test(theInternalDrive.Write(i,len,&wrBuf,msgHandle,0)==KErrNone); |
|
184 |
test(theInternalDrive.Read(i,len,&rdBuf,msgHandle,0)==KErrNone); |
|
185 |
wrBuf.SetLength(len); |
|
186 |
test(rdBuf.Compare(wrBuf)==0); |
|
187 |
} |
|
188 |
||
189 |
test.Next(_L("Reduce size - 256 bytes from start")); |
|
190 |
test(theInternalDrive.ReduceSize(0,KTestBufLen)==KErrNone); |
|
191 |
test(theInternalDrive.Caps(infoPckg)==KErrNone); |
|
192 |
cSize-=KTestBufLen; |
|
193 |
test(I64LOW(info.iSize)==(TUint)cSize); |
|
194 |
for (i=0,j=1;i<cSize;i+=len,j++) |
|
195 |
{ |
|
196 |
len=Min(KTestBufLen,(cSize-i)); |
|
197 |
rdBuf.Fill(0,len); |
|
198 |
wrBuf[0]=(TUint8)j; |
|
199 |
test(theInternalDrive.Read(i,len,&rdBuf,msgHandle,0)==KErrNone); |
|
200 |
wrBuf.SetLength(len); |
|
201 |
test(rdBuf.Compare(wrBuf)==0); |
|
202 |
} |
|
203 |
||
204 |
test.Next(_L("Reduce size - (4K+127) bytes from middle")); |
|
205 |
TInt reduction=((KTestBufLen<<4)+((KTestBufLen>>1)-1)); |
|
206 |
test(theInternalDrive.ReduceSize(KTestBufLen,reduction)==KErrNone); |
|
207 |
test(theInternalDrive.Caps(infoPckg)==KErrNone); |
|
208 |
cSize-=reduction; |
|
209 |
test(I64LOW(info.iSize)==(TUint)cSize); |
|
210 |
TBuf8<KTestBufLen> odBuf(KTestBufLen); // To verify new pattern |
|
211 |
for (i=0 ; i<(TUint)KTestBufLen ; i++) |
|
212 |
{ |
|
213 |
if (i<=(KTestBufLen>>1)) |
|
214 |
odBuf[i]=(TUint8)(i+((KTestBufLen>>1)-1)); |
|
215 |
else |
|
216 |
odBuf[i]=(TUint8)(i-((KTestBufLen>>1)+1)); |
|
217 |
} |
|
218 |
for (i=0,j=1;i<cSize;i+=len,j++) |
|
219 |
{ |
|
220 |
len=Min(KTestBufLen,(cSize-i)); |
|
221 |
rdBuf.Fill(0,len); |
|
222 |
test(theInternalDrive.Read(i,len,&rdBuf,msgHandle,0)==KErrNone); |
|
223 |
if (j==2) |
|
224 |
j+=17; |
|
225 |
if (j==1) |
|
226 |
{ |
|
227 |
wrBuf[0]=(TUint8)j; |
|
228 |
wrBuf.SetLength(len); |
|
229 |
test(rdBuf.Compare(wrBuf)==0); |
|
230 |
} |
|
231 |
else |
|
232 |
{ |
|
233 |
odBuf.SetLength(KTestBufLen); |
|
234 |
odBuf[((KTestBufLen>>1)+1)]=(TUint8)j; |
|
235 |
odBuf.SetLength(len); |
|
236 |
test(rdBuf.Compare(odBuf)==0); |
|
237 |
} |
|
238 |
} |
|
239 |
||
240 |
test.Next(_L("Reduce size - (8K-1) bytes from end")); |
|
241 |
reduction=((KTestBufLen<<5)-1); |
|
242 |
test(theInternalDrive.ReduceSize((cSize-reduction),reduction)==KErrNone); |
|
243 |
test(theInternalDrive.Caps(infoPckg)==KErrNone); |
|
244 |
cSize-=reduction; |
|
245 |
test(info.iSize==cSize); |
|
246 |
for (i=0,j=1;i<cSize;i+=len,j++) |
|
247 |
{ |
|
248 |
len=Min(KTestBufLen,(cSize-i)); |
|
249 |
rdBuf.Fill(0,len); |
|
250 |
test(theInternalDrive.Read(i,len,&rdBuf,msgHandle,0)==KErrNone); |
|
251 |
if (j==2) |
|
252 |
j+=17; |
|
253 |
if (j==1) |
|
254 |
{ |
|
255 |
wrBuf[0]=(TUint8)j; |
|
256 |
wrBuf.SetLength(len); |
|
257 |
test(rdBuf.Compare(wrBuf)==0); |
|
258 |
} |
|
259 |
else |
|
260 |
{ |
|
261 |
odBuf.SetLength(KTestBufLen); |
|
262 |
odBuf[((KTestBufLen>>1)+1)]=(TUint8)j; |
|
263 |
odBuf.SetLength(len); |
|
264 |
test(rdBuf.Compare(odBuf)==0); |
|
265 |
} |
|
266 |
} |
|
267 |
||
268 |
test.Next(_L("Format")); |
|
269 |
wrBuf.Fill(0,KTestBufLen); |
|
270 |
TFormatInfo fi; |
|
271 |
TInt ret; |
|
272 |
while((ret=theInternalDrive.Format(fi))!=KErrEof) |
|
273 |
test(ret==KErrNone); |
|
274 |
for (i=0;i<cSize;i+=len) |
|
275 |
{ |
|
276 |
len=Min(KTestBufLen,(cSize-i)); |
|
277 |
rdBuf.Fill(0xAA,len); |
|
278 |
test(theInternalDrive.Read(i,len,&rdBuf,msgHandle,0)==KErrNone); |
|
279 |
wrBuf.SetLength(len); |
|
280 |
test(rdBuf.Compare(wrBuf)==0); |
|
281 |
} |
|
282 |
||
283 |
test.Next(_L("Restore original size")); |
|
284 |
TInt sizeDif=cSize-saveSize; |
|
285 |
if (sizeDif>0) |
|
286 |
test(theInternalDrive.ReduceSize(0,sizeDif)==KErrNone); |
|
287 |
else |
|
288 |
test(theInternalDrive.Enlarge(sizeDif*-1)==KErrNone); |
|
289 |
||
290 |
test.Next(_L("Disconnect from internal drive")); |
|
291 |
theInternalDrive.Disconnect(); |
|
292 |
||
293 |
RFs fs; |
|
294 |
test(fs.Connect()==KErrNone); |
|
295 |
for(drive=25 ; drive>=0; --drive) |
|
296 |
{ |
|
297 |
TDriveInfo info; |
|
298 |
if(fs.Drive(info,drive)==KErrNone) |
|
299 |
if(info.iType==EMediaRam) |
|
300 |
{ |
|
301 |
TBuf<256> text; |
|
302 |
text.Append(_L("Formatting drive ")); |
|
303 |
text.Append(TText(drive+'A')); |
|
304 |
text.Append(_L(": ...")); |
|
305 |
test.Next(text); |
|
306 |
Format(drive,fs); |
|
307 |
break; |
|
308 |
} |
|
309 |
} |
|
310 |
||
311 |
test.End(); |
|
312 |
||
313 |
#endif // x86 |
|
314 |
return(0); |
|
315 |
} |
|
316 |