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