0
|
1 |
// Copyright (c) 1997-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 |
// f32test\server\t_main.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#define __E32TEST_EXTENSION__
|
|
19 |
|
|
20 |
#include <f32file.h>
|
|
21 |
#include <e32test.h>
|
|
22 |
#include <e32hal.h>
|
|
23 |
#include <e32math.h>
|
|
24 |
#include <f32dbg.h>
|
|
25 |
#include "t_server.h"
|
|
26 |
#include "t_chlffs.h"
|
|
27 |
|
|
28 |
GLDEF_D RFs TheFs;
|
|
29 |
GLDEF_D TFileName gSessionPath;
|
|
30 |
GLDEF_D TFileName gExeFileName(RProcess().FileName());
|
|
31 |
GLDEF_D TInt gAllocFailOff=KAllocFailureOff;
|
|
32 |
GLDEF_D TInt gAllocFailOn=KAllocFailureOff;
|
|
33 |
GLDEF_D TInt64 gSeed=51703;
|
|
34 |
|
|
35 |
GLDEF_D TChar gDriveToTest;
|
|
36 |
GLDEF_D TVolumeInfo gVolInfo; // volume info for current drive
|
|
37 |
GLDEF_D TFileCacheFlags gDriveCacheFlags;
|
|
38 |
|
|
39 |
_LIT(KPrivate, "\\Private\\");
|
|
40 |
|
|
41 |
|
|
42 |
////////////////////////////////////////////////////////////
|
|
43 |
// Template functions encapsulating ControlIo magic
|
|
44 |
//
|
|
45 |
GLDEF_D template <class C>
|
|
46 |
GLDEF_C TInt controlIo(RFs &fs, TInt drv, TInt fkn, C &c)
|
|
47 |
{
|
|
48 |
TPtr8 ptrC((TUint8 *)&c, sizeof(C), sizeof(C));
|
|
49 |
|
|
50 |
TInt r = fs.ControlIo(drv, fkn, ptrC);
|
|
51 |
|
|
52 |
return r;
|
|
53 |
}
|
|
54 |
|
|
55 |
GLDEF_C void CreateShortName(TDes& aFileName,TInt64& aSeed)
|
|
56 |
//
|
|
57 |
// Create a random, dos legal 8.3 char name
|
|
58 |
//
|
|
59 |
{
|
|
60 |
|
|
61 |
TInt length=Math::Rand(aSeed)%11;
|
|
62 |
if (length==0)
|
|
63 |
length=1;
|
|
64 |
else if (length==3) // don't create three letter names like 'AUX' or 'PRN'
|
|
65 |
length++;
|
|
66 |
else if (length>8) // end in '.' if no extension
|
|
67 |
length++;
|
|
68 |
|
|
69 |
aFileName.SetLength(length);
|
|
70 |
for(TInt i=0;i<length;i++)
|
|
71 |
{
|
|
72 |
if (i==9)
|
|
73 |
{
|
|
74 |
aFileName[i]='.';
|
|
75 |
continue;
|
|
76 |
}
|
|
77 |
TInt letter=Math::Rand(aSeed)%26;
|
|
78 |
aFileName[i]=(TText)('A'+letter);
|
|
79 |
}
|
|
80 |
}
|
|
81 |
|
|
82 |
_LIT(KFatName, "Fat");
|
|
83 |
_LIT(KFat32Name, "Fat32");
|
|
84 |
|
|
85 |
static
|
|
86 |
TBool isFAT(RFs &aFsSession, TInt aDrive)
|
|
87 |
{
|
|
88 |
TFileName f;
|
|
89 |
TInt r = aFsSession.FileSystemName(f, aDrive);
|
|
90 |
test_Value(r, r == KErrNone || r == KErrNotFound);
|
|
91 |
return (f.CompareF(KFatName) == 0 || f.CompareF(KFat32Name) == 0);
|
|
92 |
}
|
|
93 |
|
|
94 |
static
|
|
95 |
TUint16 getRootEntCnt(RFs &aFsSession, TInt aDrive)
|
|
96 |
{
|
|
97 |
RRawDisk rdisk;
|
|
98 |
TUint16 rootEntCnt;
|
|
99 |
TPtr8 reader((TUint8*)&rootEntCnt, sizeof(rootEntCnt));
|
|
100 |
|
|
101 |
test_KErrNone(rdisk.Open(aFsSession, aDrive));
|
|
102 |
test_KErrNone(rdisk.Read(17, reader)); // "BPB_RootEntCnt" field at offset 17
|
|
103 |
rdisk.Close();
|
|
104 |
|
|
105 |
return rootEntCnt;
|
|
106 |
}
|
|
107 |
|
|
108 |
GLDEF_C TBool IsFileSystemFAT(RFs &aFsSession,TInt aDrive)
|
|
109 |
//
|
|
110 |
// return true if FAT on aDrive
|
|
111 |
//
|
|
112 |
{
|
|
113 |
return (isFAT(aFsSession, aDrive) && getRootEntCnt(aFsSession, aDrive) != 0);
|
|
114 |
}
|
|
115 |
|
|
116 |
GLDEF_C TBool IsFileSystemFAT32(RFs &aFsSession,TInt aDrive)
|
|
117 |
//
|
|
118 |
// return true if FAT32 on aDrive
|
|
119 |
//
|
|
120 |
{
|
|
121 |
return (isFAT(aFsSession, aDrive) && getRootEntCnt(aFsSession, aDrive) == 0);
|
|
122 |
}
|
|
123 |
|
|
124 |
GLDEF_C void CreateLongName(TDes& aFileName,TInt64& aSeed,TInt aLength)
|
|
125 |
//
|
|
126 |
// Create a random, dos legal 8.3 char name
|
|
127 |
//
|
|
128 |
{
|
|
129 |
|
|
130 |
TInt length;
|
|
131 |
if (aLength>0)
|
|
132 |
length=aLength;
|
|
133 |
else
|
|
134 |
{
|
|
135 |
length=Math::Rand(aSeed)%128;
|
|
136 |
length+=Math::Rand(aSeed)%128;
|
|
137 |
length+=Math::Rand(aSeed)%128;
|
|
138 |
length+=Math::Rand(aSeed)%128;
|
|
139 |
length-=256;
|
|
140 |
length=Abs(length);
|
|
141 |
if (length==0)
|
|
142 |
length=1;
|
|
143 |
if (length>220)
|
|
144 |
length=31;
|
|
145 |
}
|
|
146 |
if (length==3) // don't create three letter names like 'AUX' or 'PRN'
|
|
147 |
length++;
|
|
148 |
|
|
149 |
aFileName.SetLength(length);
|
|
150 |
TInt spaceChar=-1;
|
|
151 |
TInt i;
|
|
152 |
for(i=0;i<length;i++)
|
|
153 |
{
|
|
154 |
StartAgain:
|
|
155 |
TChar letter=0;
|
|
156 |
TBool illegalChar=ETrue;
|
|
157 |
|
|
158 |
while(illegalChar)
|
|
159 |
{
|
|
160 |
#if defined(__WINS__)
|
|
161 |
if (gSessionPath[0]=='C')
|
|
162 |
letter=(TChar)('A'+Math::Rand(aSeed)%26);
|
|
163 |
else
|
|
164 |
letter=(TChar)Math::Rand(aSeed)%256;
|
|
165 |
#else
|
|
166 |
letter=(TChar)Math::Rand(aSeed)%256;
|
|
167 |
#endif
|
|
168 |
TBool space=letter.IsSpace();
|
|
169 |
if (space && spaceChar==-1)
|
|
170 |
spaceChar=i;
|
|
171 |
else if (!space && spaceChar!=-1)
|
|
172 |
spaceChar=-1;
|
|
173 |
|
|
174 |
switch(letter)
|
|
175 |
{
|
|
176 |
case '<':
|
|
177 |
case '>':
|
|
178 |
case ':':
|
|
179 |
case '"':
|
|
180 |
case '/':
|
|
181 |
case '|':
|
|
182 |
case '*':
|
|
183 |
case '?':
|
|
184 |
case '\\':
|
|
185 |
case '\0':
|
|
186 |
break;
|
|
187 |
default:
|
|
188 |
illegalChar=EFalse;
|
|
189 |
};
|
|
190 |
}
|
|
191 |
aFileName[i]=(TText)letter;
|
|
192 |
}
|
|
193 |
|
|
194 |
if (spaceChar!=-1)
|
|
195 |
{
|
|
196 |
i=spaceChar;
|
|
197 |
goto StartAgain;
|
|
198 |
}
|
|
199 |
}
|
|
200 |
|
|
201 |
GLDEF_C void CheckEntry(const TDesC& aName,TUint anAttributes,const TTime& aModified)
|
|
202 |
//
|
|
203 |
// Checks the values associated with an entry
|
|
204 |
//
|
|
205 |
{
|
|
206 |
|
|
207 |
TEntry entry;
|
|
208 |
TInt r=TheFs.Entry(aName,entry);
|
|
209 |
test_KErrNone(r);
|
|
210 |
test(entry.iAtt==anAttributes);
|
|
211 |
if (aModified!=TTime(0))
|
|
212 |
test(entry.iModified==aModified);
|
|
213 |
}
|
|
214 |
|
|
215 |
GLDEF_C void CheckDisk()
|
|
216 |
//
|
|
217 |
// Do a checkdisk and report failure
|
|
218 |
//
|
|
219 |
{
|
|
220 |
test.Next(_L("Check Disk"));
|
|
221 |
TInt r=TheFs.CheckDisk(gSessionPath);
|
|
222 |
if (r!=KErrNone && r!=KErrNotSupported && r!=KErrPermissionDenied)
|
|
223 |
ReportCheckDiskFailure(r);
|
|
224 |
}
|
|
225 |
|
|
226 |
GLDEF_C void ReportCheckDiskFailure(TInt aRet)
|
|
227 |
//
|
|
228 |
// Report the failure of checkdisk
|
|
229 |
//
|
|
230 |
{
|
|
231 |
|
|
232 |
test.Printf(_L("CHECKDISK FAILED: "));
|
|
233 |
switch(aRet)
|
|
234 |
{
|
|
235 |
case 1: test.Printf(_L("File cluster chain contains a bad value (<2 or >maxCluster)\n")); break;
|
|
236 |
case 2: test.Printf(_L("Two files are linked to the same cluster\n")); break;
|
|
237 |
case 3: test.Printf(_L("Unallocated cluster contains a value != 0\n")); break;
|
|
238 |
case 4: test.Printf(_L("Size of file != number of clusters in chain\n")); break;
|
|
239 |
default: test.Printf(_L("Undefined Error value %d\n"),aRet);
|
|
240 |
}
|
|
241 |
test(EFalse);
|
|
242 |
}
|
|
243 |
|
|
244 |
GLDEF_C void TurnAllocFailureOff()
|
|
245 |
//
|
|
246 |
// Switch off all allocFailure
|
|
247 |
//
|
|
248 |
{
|
|
249 |
|
|
250 |
test.Printf(_L("Disable Alloc Failure\n"));
|
|
251 |
TheFs.SetAllocFailure(gAllocFailOff);
|
|
252 |
gAllocFailOn=KAllocFailureOff; // Disable gAllocFailOn
|
|
253 |
}
|
|
254 |
|
|
255 |
GLDEF_C void TurnAllocFailureOn()
|
|
256 |
//
|
|
257 |
// Switch off all allocFailure
|
|
258 |
//
|
|
259 |
{
|
|
260 |
|
|
261 |
test.Printf(_L("Enable Alloc Failure\n"));
|
|
262 |
gAllocFailOn=KAllocFailureOn; // Enable gAllocFailOn
|
|
263 |
TheFs.SetAllocFailure(gAllocFailOn);
|
|
264 |
}
|
|
265 |
|
|
266 |
GLDEF_C void MakeFile(const TDesC& aFileName,const TUidType& aUidType,const TDesC8& aFileContents)
|
|
267 |
//
|
|
268 |
// Make a file and write uid and data
|
|
269 |
//
|
|
270 |
{
|
|
271 |
|
|
272 |
RFile file;
|
|
273 |
TInt r=file.Replace(TheFs,aFileName,0);
|
|
274 |
if (r==KErrPathNotFound)
|
|
275 |
{
|
|
276 |
r=TheFs.MkDirAll(aFileName);
|
|
277 |
test_KErrNone(r);
|
|
278 |
r=file.Replace(TheFs,aFileName,0);
|
|
279 |
}
|
|
280 |
test_KErrNone(r);
|
|
281 |
TCheckedUid checkedUid(aUidType);
|
|
282 |
TPtrC8 uidData((TUint8*)&checkedUid,sizeof(TCheckedUid));
|
|
283 |
r=file.Write(uidData);
|
|
284 |
test_KErrNone(r);
|
|
285 |
r=file.Write(aFileContents);
|
|
286 |
test_KErrNone(r);
|
|
287 |
file.Close();
|
|
288 |
}
|
|
289 |
|
|
290 |
GLDEF_C void MakeFile(const TDesC& aFileName,const TDesC8& aFileContents)
|
|
291 |
//
|
|
292 |
// Make a file and write something in it
|
|
293 |
//
|
|
294 |
{
|
|
295 |
|
|
296 |
RFile file;
|
|
297 |
TInt r=file.Replace(TheFs,aFileName,0);
|
|
298 |
if (r==KErrPathNotFound)
|
|
299 |
{
|
|
300 |
r=TheFs.MkDirAll(aFileName);
|
|
301 |
test_KErrNone(r);
|
|
302 |
r=file.Replace(TheFs,aFileName,0);
|
|
303 |
}
|
|
304 |
test_KErrNone(r);
|
|
305 |
r=file.Write(aFileContents);
|
|
306 |
test_KErrNone(r);
|
|
307 |
file.Close();
|
|
308 |
}
|
|
309 |
|
|
310 |
GLDEF_C void MakeFile(const TDesC& aFileName,TInt anAttributes)
|
|
311 |
//
|
|
312 |
// Make a file and write something in it
|
|
313 |
//
|
|
314 |
{
|
|
315 |
|
|
316 |
RFile file;
|
|
317 |
TInt r=file.Replace(TheFs,aFileName,0);
|
|
318 |
if (r==KErrPathNotFound)
|
|
319 |
{
|
|
320 |
r=TheFs.MkDirAll(aFileName);
|
|
321 |
test_KErrNone(r);
|
|
322 |
r=file.Replace(TheFs,aFileName,0);
|
|
323 |
}
|
|
324 |
test_KErrNone(r);
|
|
325 |
file.Close();
|
|
326 |
r=TheFs.SetAtt(aFileName,anAttributes,0);
|
|
327 |
test_KErrNone(r);
|
|
328 |
}
|
|
329 |
|
|
330 |
GLDEF_C void SetSessionPath(const TDesC& aPathName)
|
|
331 |
//
|
|
332 |
// Set the session path and update gSessionPath
|
|
333 |
//
|
|
334 |
{
|
|
335 |
|
|
336 |
TInt r=TheFs.SetSessionPath(aPathName);
|
|
337 |
test_KErrNone(r);
|
|
338 |
r=TheFs.SessionPath(gSessionPath);
|
|
339 |
test_KErrNone(r);
|
|
340 |
}
|
|
341 |
|
|
342 |
GLDEF_C void MakeFile(const TDesC& aFileName)
|
|
343 |
//
|
|
344 |
// Make a file
|
|
345 |
//
|
|
346 |
{
|
|
347 |
|
|
348 |
MakeFile(aFileName,_L8(""));
|
|
349 |
}
|
|
350 |
|
|
351 |
GLDEF_C void MakeDir(const TDesC& aDirName)
|
|
352 |
//
|
|
353 |
// Make a directory
|
|
354 |
//
|
|
355 |
{
|
|
356 |
|
|
357 |
TInt r=TheFs.MkDirAll(aDirName);
|
|
358 |
if (r!=KErrNone && r!=KErrAlreadyExists)
|
|
359 |
{
|
|
360 |
test.Printf(_L("%c: MakeDir Error %d\n"),aDirName[0],r);
|
|
361 |
test(0);
|
|
362 |
}
|
|
363 |
}
|
|
364 |
|
|
365 |
GLDEF_C TInt CheckFileExists(const TDesC& aName,TInt aResult,TBool aCompRes/*=ETrue*/)
|
|
366 |
//
|
|
367 |
// Check aName exists
|
|
368 |
//
|
|
369 |
{
|
|
370 |
|
|
371 |
TEntry entry;
|
|
372 |
TInt r=TheFs.Entry(aName,entry);
|
|
373 |
test_Value(r, r == KErrNone || r == aResult);
|
|
374 |
if (aResult!=KErrNone)
|
|
375 |
return(0);
|
|
376 |
TParsePtrC nameParse(aName);
|
|
377 |
TParsePtrC entryParse(entry.iName);
|
|
378 |
TBool nameMatch=(entryParse.Name()==nameParse.Name());
|
|
379 |
TBool extMatch=(entryParse.Ext()==nameParse.Ext()) || (entryParse.Ext().Length()<=1 && nameParse.Ext().Length()<=1);
|
|
380 |
test((nameMatch && extMatch)==aCompRes);
|
|
381 |
return(entry.iSize);
|
|
382 |
}
|
|
383 |
|
|
384 |
GLDEF_C void CheckFileContents(const TDesC& aName,const TDesC8& aContents)
|
|
385 |
//
|
|
386 |
// Check contents of file
|
|
387 |
//
|
|
388 |
{
|
|
389 |
|
|
390 |
RFile f;
|
|
391 |
TInt r=f.Open(TheFs,aName,EFileRead);
|
|
392 |
test_KErrNone(r);
|
|
393 |
HBufC8* testBuf=HBufC8::NewL(aContents.Length());
|
|
394 |
test(testBuf!=NULL);
|
|
395 |
TPtr8 bufPtr(testBuf->Des());
|
|
396 |
r=f.Read(bufPtr);
|
|
397 |
test_KErrNone(r);
|
|
398 |
test(bufPtr==aContents);
|
|
399 |
r=f.Read(bufPtr);
|
|
400 |
test_KErrNone(r);
|
|
401 |
test(bufPtr.Length()==0);
|
|
402 |
f.Close();
|
|
403 |
User::Free(testBuf);
|
|
404 |
}
|
|
405 |
|
|
406 |
GLDEF_C void DeleteTestDirectory()
|
|
407 |
//
|
|
408 |
// Delete the leaf session path directory
|
|
409 |
//
|
|
410 |
{
|
|
411 |
|
|
412 |
TheFs.SetAtt(_L("\\F32-TST\\SCANTEST\\Left\\Dir3\\Dir4\\Hidden"), 0, KEntryAttHidden);
|
|
413 |
TheFs.SetAtt(_L("\\F32-TST\\SCANTEST\\Left\\Dir3\\Dir4\\Hidden\\HiddenFile"), 0, KEntryAttHidden);
|
|
414 |
TheFs.SetAtt(_L("\\F32-TST\\SCANTEST\\Left\\Dir3\\Dir4\\Hidden\\System"), 0, KEntryAttSystem);
|
|
415 |
test.Next(_L("Delete test directory"));
|
|
416 |
CFileMan* fMan=CFileMan::NewL(TheFs);
|
|
417 |
test(fMan!=NULL);
|
|
418 |
TInt r=TheFs.SessionPath(gSessionPath);
|
|
419 |
test_KErrNone(r);
|
|
420 |
r=TheFs.CheckDisk(gSessionPath);
|
|
421 |
if (r!=KErrNone && r!=KErrNotSupported)
|
|
422 |
ReportCheckDiskFailure(r);
|
|
423 |
r=fMan->RmDir(gSessionPath);
|
|
424 |
test_KErrNone(r);
|
|
425 |
delete fMan;
|
|
426 |
}
|
|
427 |
|
|
428 |
GLDEF_C void CreateTestDirectory(const TDesC& aSessionPath)
|
|
429 |
//
|
|
430 |
// Create directory for test
|
|
431 |
//
|
|
432 |
{
|
|
433 |
TParsePtrC path(aSessionPath);
|
|
434 |
test(path.DrivePresent()==EFalse);
|
|
435 |
|
|
436 |
TInt r=TheFs.SetSessionPath(aSessionPath);
|
|
437 |
test_KErrNone(r);
|
|
438 |
r=TheFs.SessionPath(gSessionPath);
|
|
439 |
test_KErrNone(r);
|
|
440 |
r=TheFs.MkDirAll(gSessionPath);
|
|
441 |
test_Value(r, r == KErrNone || r == KErrAlreadyExists);
|
|
442 |
}
|
|
443 |
|
|
444 |
GLDEF_C TInt CurrentDrive()
|
|
445 |
//
|
|
446 |
// Return the current drive number
|
|
447 |
//
|
|
448 |
{
|
|
449 |
|
|
450 |
TInt driveNum;
|
|
451 |
TInt r=TheFs.CharToDrive(gSessionPath[0],driveNum);
|
|
452 |
test_KErrNone(r);
|
|
453 |
return(driveNum);
|
|
454 |
}
|
|
455 |
|
|
456 |
GLDEF_C void Format(TInt aDrive)
|
|
457 |
//
|
|
458 |
// Format current drive
|
|
459 |
//
|
|
460 |
{
|
|
461 |
|
|
462 |
test.Next(_L("Format"));
|
|
463 |
TBuf<4> driveBuf=_L("?:\\");
|
|
464 |
driveBuf[0]=(TText)(aDrive+'A');
|
|
465 |
RFormat format;
|
|
466 |
TInt count;
|
|
467 |
TInt r=format.Open(TheFs,driveBuf,EQuickFormat,count);
|
|
468 |
test_KErrNone(r);
|
|
469 |
while(count)
|
|
470 |
{
|
|
471 |
TInt r=format.Next(count);
|
|
472 |
test_KErrNone(r);
|
|
473 |
}
|
|
474 |
format.Close();
|
|
475 |
}
|
|
476 |
|
|
477 |
LOCAL_C void PushLotsL()
|
|
478 |
//
|
|
479 |
// Expand the cleanup stack
|
|
480 |
//
|
|
481 |
{
|
|
482 |
TInt i;
|
|
483 |
for(i=0;i<1000;i++)
|
|
484 |
CleanupStack::PushL((CBase*)NULL);
|
|
485 |
CleanupStack::Pop(1000);
|
|
486 |
}
|
|
487 |
|
|
488 |
|
|
489 |
LOCAL_C void DoTests(TInt aDrive)
|
|
490 |
//
|
|
491 |
// Do testing on aDrive
|
|
492 |
//
|
|
493 |
{
|
|
494 |
|
|
495 |
gSessionPath=_L("?:\\F32-TST\\");
|
|
496 |
TChar driveLetter;
|
|
497 |
TInt r=TheFs.DriveToChar(aDrive,driveLetter);
|
|
498 |
test_KErrNone(r);
|
|
499 |
gSessionPath[0]=(TText)driveLetter;
|
|
500 |
r=TheFs.SetSessionPath(gSessionPath);
|
|
501 |
test_KErrNone(r);
|
|
502 |
|
|
503 |
// !!! Disable platform security tests until we get the new APIs
|
|
504 |
// if(User::Capability() & KCapabilityRoot)
|
|
505 |
CheckMountLFFS(TheFs,driveLetter);
|
|
506 |
|
|
507 |
User::After(1000000);
|
|
508 |
|
|
509 |
// Format(CurrentDrive());
|
|
510 |
|
|
511 |
test.Printf(_L("Creating session path"));
|
|
512 |
r=TheFs.MkDirAll(gSessionPath);
|
|
513 |
if(r == KErrCorrupt)
|
|
514 |
{
|
|
515 |
test.Printf(_L("Attempting to create directory \'%S\' failed, KErrCorrupt\n"), &gSessionPath);
|
|
516 |
test.Printf(_L("This could be caused by a previous failing test, or a test media defect\n"));
|
|
517 |
test.Printf(_L("Formatting drive, retrying MkDirall\nShould subsequent tests fail with KErrCorrupt (%d) as well, replace test medium !\n"),
|
|
518 |
r);
|
|
519 |
Format(aDrive);
|
|
520 |
r=TheFs.MkDirAll(gSessionPath);
|
|
521 |
test_KErrNone(r);
|
|
522 |
}
|
|
523 |
else if (r == KErrNotReady)
|
|
524 |
{
|
|
525 |
TDriveInfo d;
|
|
526 |
r=TheFs.Drive(d, aDrive);
|
|
527 |
test_KErrNone(r);
|
|
528 |
if (d.iType == EMediaNotPresent)
|
|
529 |
test.Printf(_L("%c: Medium not present - cannot perform test.\n"), (TUint)driveLetter);
|
|
530 |
else
|
|
531 |
test.Printf(_L("medium found (type %d) but drive %c: not ready\nPrevious test may have hung; else, check hardware.\n"), (TInt)d.iType, (TUint)driveLetter);
|
|
532 |
}
|
|
533 |
test_Value(r, r == KErrNone || r == KErrAlreadyExists);
|
|
534 |
TheFs.ResourceCountMarkStart();
|
|
535 |
test.Printf(_L("Calling main test sequence ...\n"));
|
|
536 |
TRAP(r,CallTestsL());
|
|
537 |
test_KErrNone(r);
|
|
538 |
test.Printf(_L("test sequence completed without error\n"));
|
|
539 |
TheFs.ResourceCountMarkEnd();
|
|
540 |
|
|
541 |
CheckDisk();
|
|
542 |
TestingLFFS(EFalse);
|
|
543 |
}
|
|
544 |
|
|
545 |
|
|
546 |
void ParseCommandArguments()
|
|
547 |
//
|
|
548 |
//
|
|
549 |
//
|
|
550 |
{
|
|
551 |
TBuf<0x100> cmd;
|
|
552 |
User::CommandLine(cmd);
|
|
553 |
TLex lex(cmd);
|
|
554 |
TPtrC token=lex.NextToken();
|
|
555 |
TFileName thisfile=RProcess().FileName();
|
|
556 |
if (token.MatchF(thisfile)==0)
|
|
557 |
{
|
|
558 |
token.Set(lex.NextToken());
|
|
559 |
}
|
|
560 |
test.Printf(_L("CLP=%S\n"),&token);
|
|
561 |
|
|
562 |
if(token.Length()!=0)
|
|
563 |
{
|
|
564 |
gDriveToTest=token[0];
|
|
565 |
gDriveToTest.UpperCase();
|
|
566 |
}
|
|
567 |
else
|
|
568 |
gDriveToTest='C';
|
|
569 |
}
|
|
570 |
|
|
571 |
TFullName gExtName;
|
|
572 |
TBool gPrimaryExtensionExists = EFalse;
|
|
573 |
|
|
574 |
GLDEF_C TInt DismountFileSystem(RFs& aFs, const TDesC& aFileSystemName,TInt aDrive)
|
|
575 |
{
|
|
576 |
//Make note of the first extension if it exists, so that we remount
|
|
577 |
//it when the file system is remounted.
|
|
578 |
TInt r = aFs.ExtensionName(gExtName, aDrive, 0);
|
|
579 |
|
|
580 |
if (r == KErrNone)
|
|
581 |
{
|
|
582 |
gPrimaryExtensionExists = ETrue;
|
|
583 |
}
|
|
584 |
return aFs.DismountFileSystem(aFileSystemName, aDrive);
|
|
585 |
}
|
|
586 |
|
|
587 |
GLDEF_C TInt MountFileSystem(RFs& aFs, const TDesC& aFileSystemName,TInt aDrive, TBool aIsSync)
|
|
588 |
{
|
|
589 |
TInt r;
|
|
590 |
if (gPrimaryExtensionExists)
|
|
591 |
{
|
|
592 |
r = aFs.MountFileSystem(aFileSystemName, gExtName, aDrive, aIsSync);
|
|
593 |
}
|
|
594 |
else
|
|
595 |
{
|
|
596 |
r = aFs. MountFileSystem(aFileSystemName, aDrive, aIsSync);
|
|
597 |
}
|
|
598 |
return r;
|
|
599 |
}
|
|
600 |
|
|
601 |
GLDEF_C TInt E32Main()
|
|
602 |
//
|
|
603 |
// Test with drive nearly full
|
|
604 |
//
|
|
605 |
{
|
|
606 |
|
|
607 |
CTrapCleanup* cleanup;
|
|
608 |
cleanup=CTrapCleanup::New();
|
|
609 |
TRAPD(r,PushLotsL());
|
|
610 |
__UHEAP_MARK;
|
|
611 |
|
|
612 |
test.Title();
|
|
613 |
test.Start(_L("Starting tests..."));
|
|
614 |
|
|
615 |
|
|
616 |
ParseCommandArguments(); //need this for drive letter to test
|
|
617 |
|
|
618 |
|
|
619 |
r=TheFs.Connect();
|
|
620 |
test_KErrNone(r);
|
|
621 |
TheFs.SetAllocFailure(gAllocFailOn);
|
|
622 |
TTime timerC;
|
|
623 |
timerC.HomeTime();
|
|
624 |
TFileName sessionp;
|
|
625 |
TheFs.SessionPath(sessionp);
|
|
626 |
|
|
627 |
TBuf<30> privatedir;
|
|
628 |
privatedir = KPrivate;
|
|
629 |
|
|
630 |
TUid thisUID = RProcess().Identity();
|
|
631 |
privatedir.AppendFormat(_L("%08x"),thisUID.iUid);
|
|
632 |
privatedir.Append(_L("\\"));
|
|
633 |
|
|
634 |
test(privatedir == sessionp.Mid(2,sessionp.Length()-2));
|
|
635 |
|
|
636 |
test.Printf(_L("sp=%S\n"),&sessionp);
|
|
637 |
sessionp[0]=(TText)gDriveToTest;
|
|
638 |
test.Printf(_L("sp1=%S\n"),&sessionp);
|
|
639 |
|
|
640 |
TInt theDrive;
|
|
641 |
r=TheFs.CharToDrive(gDriveToTest,theDrive);
|
|
642 |
test_KErrNone(r);
|
|
643 |
|
|
644 |
// Get the TFileCacheFlags for this drive
|
|
645 |
r = TheFs.Volume(gVolInfo, theDrive);
|
|
646 |
if (r == KErrNotReady)
|
|
647 |
{
|
|
648 |
TDriveInfo info;
|
|
649 |
TInt err = TheFs.Drive(info,theDrive);
|
|
650 |
test_KErrNone(err);
|
|
651 |
if (info.iType == EMediaNotPresent)
|
|
652 |
test.Printf(_L("%c: Medium not present - cannot perform test.\n"), (TUint)gDriveToTest);
|
|
653 |
else
|
|
654 |
test.Printf(_L("%c: medium found (type %d) but drive not ready\nPrevious test may have hung; else, check hardware.\n"), (TUint)gDriveToTest, (TInt)info.iType);
|
|
655 |
}
|
|
656 |
else if (r == KErrCorrupt)
|
|
657 |
{
|
|
658 |
test.Printf(_L("%c: Media corruption; previous test may have aborted; else, check hardware\n"), (TUint)gDriveToTest);
|
|
659 |
}
|
|
660 |
test_KErrNone(r);
|
|
661 |
gDriveCacheFlags = gVolInfo.iFileCacheFlags;
|
|
662 |
test.Printf(_L("DriveCacheFlags = %08X\n"), gDriveCacheFlags);
|
|
663 |
|
|
664 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
665 |
TPckgBuf<TIOCacheValues> pkgOrgValues;
|
|
666 |
TIOCacheValues& orgValues=pkgOrgValues();
|
|
667 |
r = controlIo(TheFs,theDrive, KControlIoCacheCount, orgValues);
|
|
668 |
test_KErrNone(r);
|
|
669 |
|
|
670 |
test.Printf(_L("\n"));
|
|
671 |
test.Printf(_L("Requests on close queue at start=%d\n"),orgValues.iCloseCount);
|
|
672 |
test.Printf(_L("Requests on free queue at start=%d\n"),orgValues.iFreeCount);
|
|
673 |
test.Printf(_L("Requests dynamically allocated at start=%d\n"),orgValues.iAllocated);
|
|
674 |
test.Printf(_L("Requests in total at start=%d\n"),orgValues.iTotalCount);
|
|
675 |
|
|
676 |
// File cache
|
|
677 |
|
|
678 |
// flush closed files queue
|
|
679 |
r = TheFs.ControlIo(theDrive, KControlIoFlushClosedFiles);
|
|
680 |
test_KErrNone(r);
|
|
681 |
|
|
682 |
// get number of items on File Cache
|
|
683 |
TFileCacheStats startFileCacheStats;
|
|
684 |
r = controlIo(TheFs,theDrive, KControlIoFileCacheStats, startFileCacheStats);
|
|
685 |
test_Value(r, r == KErrNone || r == KErrNotSupported);
|
|
686 |
test.Printf(_L("File cache: Cachelines (free %d, used %d), Segments(allocated %d locked %d). Closed files(%d)\n"),
|
|
687 |
startFileCacheStats.iFreeCount,
|
|
688 |
startFileCacheStats.iUsedCount,
|
|
689 |
startFileCacheStats.iAllocatedSegmentCount,
|
|
690 |
startFileCacheStats.iLockedSegmentCount,
|
|
691 |
startFileCacheStats.iFilesOnClosedQueue);
|
|
692 |
#endif
|
|
693 |
|
|
694 |
DoTests(theDrive);
|
|
695 |
|
|
696 |
TTime endTimeC;
|
|
697 |
endTimeC.HomeTime();
|
|
698 |
TTimeIntervalSeconds timeTakenC;
|
|
699 |
r=endTimeC.SecondsFrom(timerC,timeTakenC);
|
|
700 |
test_KErrNone(r);
|
|
701 |
test.Printf(_L("Time taken for test = %d seconds\n"),timeTakenC.Int());
|
|
702 |
TheFs.SetAllocFailure(gAllocFailOff);
|
|
703 |
|
|
704 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
705 |
TPckgBuf<TIOCacheValues> pkgValues;
|
|
706 |
TIOCacheValues& values=pkgValues();
|
|
707 |
r = controlIo(TheFs,theDrive, KControlIoCacheCount, values);
|
|
708 |
test_KErrNone(r);
|
|
709 |
|
|
710 |
test.Printf(_L("Requests on close queue at end=%d\n"),values.iCloseCount);
|
|
711 |
test.Printf(_L("Requests on free queue at end=%d\n"),values.iFreeCount);
|
|
712 |
test.Printf(_L("Requests dynamically allocated at end=%d\n"),values.iAllocated);
|
|
713 |
test.Printf(_L("Requests in total at end=%d\n"),values.iTotalCount);
|
|
714 |
|
|
715 |
test(orgValues.iCloseCount==values.iCloseCount);
|
|
716 |
test(orgValues.iAllocated == values.iAllocated);
|
|
717 |
// The free count can increase if the file server runs out of requests in the RequestAllocator
|
|
718 |
// free pool but this should never decrease - this implies a request leak
|
|
719 |
test(orgValues.iFreeCount <= values.iFreeCount);
|
|
720 |
|
|
721 |
// The total number of allocated requests should be equal to :
|
|
722 |
// requests on the close queue + requests on free queue
|
|
723 |
// + 1 (because we used one request to issue KControlIoCacheCount)
|
|
724 |
// If this doesn't equate then this implies a request leak
|
|
725 |
test(values.iTotalCount == values.iCloseCount + values.iFreeCount + 1);
|
|
726 |
|
|
727 |
// File cache
|
|
728 |
TFileCacheStats endFileCacheStats;
|
|
729 |
r = controlIo(TheFs,theDrive, KControlIoFileCacheStats, endFileCacheStats);
|
|
730 |
test_Value(r, r == KErrNone || r == KErrNotSupported);
|
|
731 |
|
|
732 |
test.Printf(_L("File cache: Cachelines (free %d, used %d), Segments(allocated %d locked %d). Closed files(%d)\n"),
|
|
733 |
endFileCacheStats.iFreeCount,
|
|
734 |
endFileCacheStats.iUsedCount,
|
|
735 |
endFileCacheStats.iAllocatedSegmentCount,
|
|
736 |
endFileCacheStats.iLockedSegmentCount,
|
|
737 |
endFileCacheStats.iFilesOnClosedQueue);
|
|
738 |
|
|
739 |
// flush closed files queue
|
|
740 |
test.Printf(_L("Flushing close queue..."));
|
|
741 |
r = TheFs.ControlIo(theDrive, KControlIoFlushClosedFiles);
|
|
742 |
test_KErrNone(r);
|
|
743 |
|
|
744 |
r = controlIo(TheFs,theDrive, KControlIoFileCacheStats, endFileCacheStats);
|
|
745 |
test_Value(r, r == KErrNone || r == KErrNotSupported);
|
|
746 |
test.Printf(_L("File cache: Cachelines (free %d, used %d), Segments(allocated %d locked %d). Closed files(%d)\n"),
|
|
747 |
endFileCacheStats.iFreeCount,
|
|
748 |
endFileCacheStats.iUsedCount,
|
|
749 |
endFileCacheStats.iAllocatedSegmentCount,
|
|
750 |
endFileCacheStats.iLockedSegmentCount,
|
|
751 |
endFileCacheStats.iFilesOnClosedQueue);
|
|
752 |
|
|
753 |
|
|
754 |
if (r == KErrNone)
|
|
755 |
{
|
|
756 |
test(startFileCacheStats.iFreeCount == endFileCacheStats.iFreeCount);
|
|
757 |
test(startFileCacheStats.iUsedCount == endFileCacheStats.iUsedCount);
|
|
758 |
test(startFileCacheStats.iAllocatedSegmentCount == endFileCacheStats.iAllocatedSegmentCount);
|
|
759 |
test(startFileCacheStats.iLockedSegmentCount == endFileCacheStats.iLockedSegmentCount);
|
|
760 |
test(startFileCacheStats.iFileCount == endFileCacheStats.iFileCount);
|
|
761 |
}
|
|
762 |
#endif
|
|
763 |
|
|
764 |
TheFs.Close();
|
|
765 |
test.End();
|
|
766 |
test.Close();
|
|
767 |
__UHEAP_MARKEND;
|
|
768 |
delete cleanup;
|
|
769 |
return(KErrNone);
|
|
770 |
}
|
|
771 |
|
|
772 |
|