os/kernelhwsrv/kerneltest/f32test/filesystem/fat/t_main.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/filesystem/fat/t_main.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,638 @@
     1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// f32test\server\t_main.cpp
    1.18 +//
    1.19 +//
    1.20 +
    1.21 +#define __E32TEST_EXTENSION__
    1.22 +
    1.23 +#include <f32file.h>
    1.24 +#include <e32test.h>
    1.25 +#include <e32math.h>
    1.26 +#include <f32dbg.h>
    1.27 +#include "t_server.h"
    1.28 +
    1.29 +GLDEF_D	RFs TheFs;
    1.30 +GLDEF_D TFileName gSessionPath;
    1.31 +GLDEF_D TInt gAllocFailOff=KAllocFailureOff;
    1.32 +GLDEF_D TInt gAllocFailOn=KAllocFailureOff;
    1.33 +GLDEF_D TInt64 gSeed=51703;
    1.34 +
    1.35 +GLDEF_D TChar gDriveToTest;
    1.36 +GLDEF_D TVolumeInfo gVolInfo;	// volume info for current drive
    1.37 +GLDEF_D TFileCacheFlags gDriveCacheFlags;
    1.38 +
    1.39 +_LIT(KPrivate, "\\Private\\");
    1.40 +
    1.41 +
    1.42 +////////////////////////////////////////////////////////////
    1.43 +// Template functions encapsulating ControlIo magic
    1.44 +//
    1.45 +GLDEF_D template <class C>
    1.46 +GLDEF_C TInt controlIo(RFs &fs, TInt drv, TInt fkn, C &c)
    1.47 +{
    1.48 +    TPtr8 ptrC((TUint8 *)&c, sizeof(C), sizeof(C));
    1.49 +
    1.50 +    TInt r = fs.ControlIo(drv, fkn, ptrC);
    1.51 +
    1.52 +    return r;
    1.53 +}
    1.54 +
    1.55 +
    1.56 +GLDEF_C void CreateShortName(TDes& aFileName,TInt64& aSeed)
    1.57 +//
    1.58 +// Create a random, dos legal 8.3 char name
    1.59 +//
    1.60 +	{
    1.61 +
    1.62 +	TInt length=Math::Rand(aSeed)%11;
    1.63 +	if (length==0)
    1.64 +		length=1;
    1.65 +	else if (length==3)	// don't create three letter names like 'AUX' or 'PRN'
    1.66 +		length++;
    1.67 +	else if (length>8)	// end in '.' if no extension
    1.68 +		length++;
    1.69 +
    1.70 +	aFileName.SetLength(length);
    1.71 +	for(TInt i=0;i<length;i++)
    1.72 +		{
    1.73 +		if (i==9)
    1.74 +			{
    1.75 +			aFileName[i]='.';
    1.76 +			continue;
    1.77 +			}
    1.78 +		TInt letter=Math::Rand(aSeed)%26;
    1.79 +		aFileName[i]=(TText)('A'+letter);
    1.80 +		}
    1.81 +	}
    1.82 +
    1.83 +
    1.84 +GLDEF_C void CreateLongName(TDes& aFileName,TInt64& aSeed,TInt aLength)
    1.85 +//
    1.86 +// Create a random, dos legal 8.3 char name
    1.87 +//
    1.88 +	{
    1.89 +
    1.90 +	TInt length;
    1.91 +	if (aLength>0)
    1.92 +		length=aLength;
    1.93 +	else
    1.94 +		{
    1.95 +		length=Math::Rand(aSeed)%128;
    1.96 +		length+=Math::Rand(aSeed)%128;
    1.97 +		length+=Math::Rand(aSeed)%128;
    1.98 +		length+=Math::Rand(aSeed)%128;
    1.99 +		length-=256;
   1.100 +			length=Abs(length);
   1.101 +		if (length==0)
   1.102 +			length=1;
   1.103 +		if (length>220)
   1.104 +			length=31;
   1.105 +		}
   1.106 +	if (length==3)	// don't create three letter names like 'AUX' or 'PRN'
   1.107 +		length++;
   1.108 +
   1.109 +	aFileName.SetLength(length);
   1.110 +	TInt spaceChar=-1;
   1.111 +	TInt i;
   1.112 +	for(i=0;i<length;i++)
   1.113 +		{
   1.114 +StartAgain:
   1.115 +		TChar letter=0;
   1.116 +		TBool illegalChar=ETrue;
   1.117 +
   1.118 +		while(illegalChar)
   1.119 +			{
   1.120 +#if defined(__WINS__)
   1.121 +			if (gSessionPath[0]=='C')
   1.122 +				letter=(TChar)('A'+Math::Rand(aSeed)%26);
   1.123 +			else
   1.124 +				letter=(TChar)Math::Rand(aSeed)%256;
   1.125 +#else
   1.126 +			letter=(TChar)Math::Rand(aSeed)%256;
   1.127 +#endif
   1.128 +			TBool space=letter.IsSpace();
   1.129 +			if (space && spaceChar==-1)
   1.130 +				spaceChar=i;
   1.131 +			else if (!space && spaceChar!=-1)
   1.132 +				spaceChar=-1;
   1.133 +
   1.134 +			switch(letter)
   1.135 +				{
   1.136 +			case '<':
   1.137 +			case '>':
   1.138 +			case ':':
   1.139 +			case '"':
   1.140 +			case '/':
   1.141 +			case '|':
   1.142 +			case '*':
   1.143 +			case '?':
   1.144 +			case '\\':
   1.145 +			case '\0':
   1.146 +				break;
   1.147 +			default:
   1.148 +				illegalChar=EFalse;
   1.149 +				};
   1.150 +			}
   1.151 +		aFileName[i]=(TText)letter;
   1.152 +		}
   1.153 +
   1.154 +	if (spaceChar!=-1)
   1.155 +		{
   1.156 +		i=spaceChar;
   1.157 +		goto StartAgain;
   1.158 +		}
   1.159 +	}
   1.160 +
   1.161 +
   1.162 +GLDEF_C void CheckDisk()
   1.163 +//
   1.164 +// Do a checkdisk and report failure
   1.165 +//
   1.166 +	{
   1.167 +	test.Next(_L("Check Disk"));
   1.168 +	TInt r=TheFs.CheckDisk(gSessionPath);
   1.169 +	if (r!=KErrNone && r!=KErrNotSupported && r!=KErrPermissionDenied)
   1.170 +		ReportCheckDiskFailure(r);
   1.171 +	}
   1.172 +
   1.173 +GLDEF_C void ReportCheckDiskFailure(TInt aRet)
   1.174 +//
   1.175 +// Report the failure of checkdisk
   1.176 +//
   1.177 +	{
   1.178 +
   1.179 +	test.Printf(_L("CHECKDISK FAILED: "));
   1.180 +	switch(aRet)
   1.181 +		{
   1.182 +	case 1:	test.Printf(_L("File cluster chain contains a bad value (<2 or >maxCluster)\n")); break;
   1.183 +	case 2:	test.Printf(_L("Two files are linked to the same cluster\n")); break;
   1.184 +	case 3:	test.Printf(_L("Unallocated cluster contains a value != 0\n"));	break;
   1.185 +	case 4:	test.Printf(_L("Size of file != number of clusters in chain\n")); break;
   1.186 +	default: test.Printf(_L("Undefined Error value %d\n"),aRet);
   1.187 +		}
   1.188 +	test(EFalse);
   1.189 +	}
   1.190 +
   1.191 +
   1.192 +GLDEF_C void MakeFile(const TDesC& aFileName,const TUidType& aUidType,const TDesC8& aFileContents)
   1.193 +//
   1.194 +// Make a file and write uid and data
   1.195 +//
   1.196 +	{
   1.197 +
   1.198 +	RFile file;
   1.199 +	TInt r=file.Replace(TheFs,aFileName,0);
   1.200 +	if (r==KErrPathNotFound)
   1.201 +		{
   1.202 +		r=TheFs.MkDirAll(aFileName);
   1.203 +		test_KErrNone(r);
   1.204 +		r=file.Replace(TheFs,aFileName,0);
   1.205 +		}
   1.206 +	test_KErrNone(r);
   1.207 +	TCheckedUid checkedUid(aUidType);
   1.208 +	TPtrC8 uidData((TUint8*)&checkedUid,sizeof(TCheckedUid));
   1.209 +	r=file.Write(uidData);
   1.210 +	test_KErrNone(r);
   1.211 +	r=file.Write(aFileContents);
   1.212 +	test_KErrNone(r);
   1.213 +	file.Close();
   1.214 +	}
   1.215 +
   1.216 +GLDEF_C void MakeFile(const TDesC& aFileName,const TDesC8& aFileContents)
   1.217 +//
   1.218 +// Make a file and write something in it
   1.219 +//
   1.220 +	{
   1.221 +
   1.222 +	RFile file;
   1.223 +	TInt r=file.Replace(TheFs,aFileName,0);
   1.224 +	if (r==KErrPathNotFound)
   1.225 +		{
   1.226 +		r=TheFs.MkDirAll(aFileName);
   1.227 +		test_KErrNone(r);
   1.228 +		r=file.Replace(TheFs,aFileName,0);
   1.229 +		}
   1.230 +	test_KErrNone(r);
   1.231 +	r=file.Write(aFileContents);
   1.232 +	test_KErrNone(r);
   1.233 +	file.Close();
   1.234 +	}
   1.235 +
   1.236 +GLDEF_C void MakeFile(const TDesC& aFileName,TInt anAttributes)
   1.237 +//
   1.238 +// Make a file and write something in it
   1.239 +//
   1.240 +	{
   1.241 +
   1.242 +	RFile file;
   1.243 +	TInt r=file.Replace(TheFs,aFileName,0);
   1.244 +	if (r==KErrPathNotFound)
   1.245 +		{
   1.246 +		r=TheFs.MkDirAll(aFileName);
   1.247 +		test_KErrNone(r);
   1.248 +		r=file.Replace(TheFs,aFileName,0);
   1.249 +		}
   1.250 +	test_KErrNone(r);
   1.251 +	file.Close();
   1.252 +	r=TheFs.SetAtt(aFileName,anAttributes,0);
   1.253 +	test_KErrNone(r);
   1.254 +	}
   1.255 +
   1.256 +GLDEF_C void MakeFile(const TDesC& aFileName)
   1.257 +//
   1.258 +// Make a file
   1.259 +//
   1.260 +	{
   1.261 +
   1.262 +	MakeFile(aFileName,_L8(""));
   1.263 +	}
   1.264 +
   1.265 +GLDEF_C void MakeDir(const TDesC& aDirName)
   1.266 +//
   1.267 +// Make a directory
   1.268 +//
   1.269 +	{
   1.270 +
   1.271 +	TInt r=TheFs.MkDirAll(aDirName);
   1.272 +	if (r!=KErrNone && r!=KErrAlreadyExists)
   1.273 +		{
   1.274 +		test.Printf(_L("%c: MakeDir Error %d\n"),aDirName[0],r);
   1.275 +		test(0);
   1.276 +		}
   1.277 +	}
   1.278 +
   1.279 +
   1.280 +GLDEF_C void DeleteTestDirectory()
   1.281 +//
   1.282 +// Delete the leaf session path directory
   1.283 +//
   1.284 +	{
   1.285 +
   1.286 +	TheFs.SetAtt(_L("\\F32-TST\\SCANTEST\\Left\\Dir3\\Dir4\\Hidden"), 0, KEntryAttHidden);
   1.287 +	TheFs.SetAtt(_L("\\F32-TST\\SCANTEST\\Left\\Dir3\\Dir4\\Hidden\\HiddenFile"), 0, KEntryAttHidden);
   1.288 +	TheFs.SetAtt(_L("\\F32-TST\\SCANTEST\\Left\\Dir3\\Dir4\\Hidden\\System"), 0, KEntryAttSystem);
   1.289 +	test.Next(_L("Delete test directory"));
   1.290 +	CFileMan* fMan=CFileMan::NewL(TheFs);
   1.291 +	test(fMan!=NULL);
   1.292 +	TInt r=TheFs.SessionPath(gSessionPath);
   1.293 +	test_KErrNone(r);
   1.294 +	r=TheFs.CheckDisk(gSessionPath);
   1.295 +	if (r!=KErrNone && r!=KErrNotSupported)
   1.296 +		ReportCheckDiskFailure(r);
   1.297 +	r=fMan->RmDir(gSessionPath);
   1.298 +	test_KErrNone(r);
   1.299 +	delete fMan;
   1.300 +	}
   1.301 +
   1.302 +GLDEF_C void CreateTestDirectory(const TDesC& aSessionPath)
   1.303 +//
   1.304 +// Create directory for test
   1.305 +//
   1.306 +	{
   1.307 +	TParsePtrC path(aSessionPath);
   1.308 +	test(path.DrivePresent()==EFalse);
   1.309 +
   1.310 +	TInt r=TheFs.SetSessionPath(aSessionPath);
   1.311 +	test_KErrNone(r);
   1.312 +	r=TheFs.SessionPath(gSessionPath);
   1.313 +	test_KErrNone(r);
   1.314 +	r=TheFs.MkDirAll(gSessionPath);
   1.315 +	test_Value(r, r == KErrNone || r == KErrAlreadyExists);
   1.316 +	}
   1.317 +
   1.318 +GLDEF_C TInt CurrentDrive()
   1.319 +//
   1.320 +// Return the current drive number
   1.321 +//
   1.322 +	{
   1.323 +
   1.324 +	TInt driveNum;
   1.325 +	TInt r=TheFs.CharToDrive(gSessionPath[0],driveNum);
   1.326 +	test_KErrNone(r);
   1.327 +	return(driveNum);
   1.328 +	}
   1.329 +
   1.330 +GLDEF_C void Format(TInt aDrive)
   1.331 +//
   1.332 +// Format current drive
   1.333 +//
   1.334 +	{
   1.335 +
   1.336 +	test.Next(_L("Format"));
   1.337 +	TBuf<4> driveBuf=_L("?:\\");
   1.338 +	driveBuf[0]=(TText)(aDrive+'A');
   1.339 +	RFormat format;
   1.340 +	TInt count;
   1.341 +	TInt r=format.Open(TheFs,driveBuf,EQuickFormat,count);
   1.342 +	test_KErrNone(r);
   1.343 +	while(count)
   1.344 +		{
   1.345 +		TInt r=format.Next(count);
   1.346 +		test_KErrNone(r);
   1.347 +		}
   1.348 +	format.Close();
   1.349 +	}
   1.350 +
   1.351 +LOCAL_C void PushLotsL()
   1.352 +//
   1.353 +// Expand the cleanup stack
   1.354 +//
   1.355 +	{
   1.356 +	TInt i;
   1.357 +	for(i=0;i<1000;i++)
   1.358 +		CleanupStack::PushL((CBase*)NULL);
   1.359 +	CleanupStack::Pop(1000);
   1.360 +	}
   1.361 +
   1.362 +
   1.363 +LOCAL_C void DoTests(TInt aDrive)
   1.364 +//
   1.365 +// Do testing on aDrive
   1.366 +//
   1.367 +	{
   1.368 +
   1.369 +	gSessionPath=_L("?:\\F32-TST\\");
   1.370 +	TChar driveLetter;
   1.371 +	TInt r=TheFs.DriveToChar(aDrive,driveLetter);
   1.372 +	test_KErrNone(r);
   1.373 +	gSessionPath[0]=(TText)driveLetter;
   1.374 +	r=TheFs.SetSessionPath(gSessionPath);
   1.375 +	test_KErrNone(r);
   1.376 +
   1.377 +	User::After(1000000);
   1.378 +
   1.379 +//	Format(CurrentDrive());
   1.380 +
   1.381 +	test.Printf(_L("Creating session path"));
   1.382 +	r=TheFs.MkDirAll(gSessionPath);
   1.383 +	if(r == KErrCorrupt)
   1.384 +		{
   1.385 +		test.Printf(_L("Attempting to create directory \'%S\' failed, KErrCorrupt\n"), &gSessionPath);
   1.386 +		test.Printf(_L("This could be caused by a previous failing test, or a test media defect\n"));
   1.387 +		test.Printf(_L("Formatting drive, retrying MkDirall\nShould subsequent tests fail with KErrCorrupt (%d) as well, replace test medium !\n"),
   1.388 +			r);
   1.389 +		Format(aDrive);
   1.390 +		r=TheFs.MkDirAll(gSessionPath);
   1.391 +		test_KErrNone(r);
   1.392 +		}
   1.393 +	else if (r == KErrNotReady)
   1.394 +		{
   1.395 +		TDriveInfo d;
   1.396 +		r=TheFs.Drive(d, aDrive);
   1.397 +		test_KErrNone(r);
   1.398 +		if (d.iType == EMediaNotPresent)
   1.399 +			test.Printf(_L("%c: Medium not present - cannot perform test.\n"), (TUint)driveLetter);
   1.400 +		else
   1.401 +			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);
   1.402 +		}
   1.403 +	test_Value(r, r == KErrNone || r == KErrAlreadyExists);
   1.404 +	TheFs.ResourceCountMarkStart();
   1.405 +	test.Printf(_L("Calling main test sequence ...\n"));
   1.406 +	TRAP(r,CallTestsL());
   1.407 +	test_KErrNone(r);
   1.408 +	test.Printf(_L("test sequence completed without error\n"));
   1.409 +	TheFs.ResourceCountMarkEnd();
   1.410 +
   1.411 +	CheckDisk();
   1.412 +	}
   1.413 +
   1.414 +
   1.415 +void ParseCommandArguments()
   1.416 +//
   1.417 +//
   1.418 +//
   1.419 +	{
   1.420 +	TBuf<0x100> cmd;
   1.421 +	User::CommandLine(cmd);
   1.422 +	TLex lex(cmd);
   1.423 +	TPtrC token=lex.NextToken();
   1.424 +	TFileName thisfile=RProcess().FileName();
   1.425 +	if (token.MatchF(thisfile)==0)
   1.426 +		{
   1.427 +		token.Set(lex.NextToken());
   1.428 +		}
   1.429 +	test.Printf(_L("CLP=%S\n"),&token);
   1.430 +
   1.431 +	if(token.Length()!=0)
   1.432 +		{
   1.433 +		gDriveToTest=token[0];
   1.434 +		gDriveToTest.UpperCase();
   1.435 +		}
   1.436 +	else
   1.437 +		gDriveToTest='C';
   1.438 +	}
   1.439 +
   1.440 +TFullName gExtName;
   1.441 +TBool gPrimaryExtensionExists = EFalse;
   1.442 +
   1.443 +GLDEF_C TInt DismountFileSystem(RFs& aFs, const TDesC& aFileSystemName,TInt aDrive)
   1.444 +	{
   1.445 +	//Make note of the first extension if it exists, so that we remount
   1.446 +	//it when the file system is remounted.
   1.447 +	TInt r = aFs.ExtensionName(gExtName, aDrive, 0);
   1.448 +
   1.449 +	if (r == KErrNone)
   1.450 +		{
   1.451 +		gPrimaryExtensionExists = ETrue;
   1.452 +		}
   1.453 +	return aFs.DismountFileSystem(aFileSystemName, aDrive);
   1.454 +	}
   1.455 +
   1.456 +GLDEF_C TInt MountFileSystem(RFs& aFs, const TDesC& aFileSystemName,TInt aDrive, TBool aIsSync)
   1.457 +	{
   1.458 +	TInt r;
   1.459 +	if (gPrimaryExtensionExists)
   1.460 +		{
   1.461 +		r = aFs.MountFileSystem(aFileSystemName, gExtName, aDrive, aIsSync);
   1.462 +		}
   1.463 +	else
   1.464 +		{
   1.465 +		r = aFs. MountFileSystem(aFileSystemName, aDrive, aIsSync);
   1.466 +		}
   1.467 +	return r;
   1.468 +	}
   1.469 +
   1.470 +GLDEF_C TInt E32Main()
   1.471 +//
   1.472 +// Test with drive nearly full
   1.473 +//
   1.474 +    {
   1.475 +
   1.476 +	CTrapCleanup* cleanup;
   1.477 +	cleanup=CTrapCleanup::New();
   1.478 +	TRAPD(r,PushLotsL());
   1.479 +	__UHEAP_MARK;
   1.480 +
   1.481 +	test.Title();
   1.482 +	test.Start(_L("Starting tests..."));
   1.483 +
   1.484 +
   1.485 +	ParseCommandArguments(); //need this for drive letter to test
   1.486 +
   1.487 +
   1.488 +	r=TheFs.Connect();
   1.489 +	test_KErrNone(r);
   1.490 +	TheFs.SetAllocFailure(gAllocFailOn);
   1.491 +	TTime timerC;
   1.492 +	timerC.HomeTime();
   1.493 +	TFileName sessionp;
   1.494 +	TheFs.SessionPath(sessionp);
   1.495 +
   1.496 +	TBuf<30> privatedir;
   1.497 +	privatedir = KPrivate;
   1.498 +
   1.499 +	TUid thisUID = RProcess().Identity();
   1.500 +	privatedir.AppendFormat(_L("%08x"),thisUID.iUid);
   1.501 +	privatedir.Append(_L("\\"));
   1.502 +
   1.503 +	test(privatedir == sessionp.Mid(2,sessionp.Length()-2));
   1.504 +
   1.505 +	test.Printf(_L("sp=%S\n"),&sessionp);
   1.506 +	sessionp[0]=(TText)gDriveToTest;
   1.507 +	test.Printf(_L("sp1=%S\n"),&sessionp);
   1.508 +
   1.509 +	TInt theDrive;
   1.510 +	r=TheFs.CharToDrive(gDriveToTest,theDrive);
   1.511 +	test_KErrNone(r);
   1.512 +
   1.513 +	// Get the TFileCacheFlags for this drive
   1.514 +	r = TheFs.Volume(gVolInfo, theDrive);
   1.515 +	if (r == KErrNotReady)
   1.516 +		{
   1.517 +		TDriveInfo info;
   1.518 +		TInt err = TheFs.Drive(info,theDrive);
   1.519 +		test_KErrNone(err);
   1.520 +		if (info.iType == EMediaNotPresent)
   1.521 +			test.Printf(_L("%c: Medium not present - cannot perform test.\n"), (TUint)gDriveToTest);
   1.522 +		else
   1.523 +			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);
   1.524 +		}
   1.525 +	else if (r == KErrCorrupt)
   1.526 +		{
   1.527 +		test.Printf(_L("%c: Media corruption; previous test may have aborted; else, check hardware\n"), (TUint)gDriveToTest);
   1.528 +		}
   1.529 +	test_KErrNone(r);
   1.530 +	gDriveCacheFlags = gVolInfo.iFileCacheFlags;
   1.531 +	test.Printf(_L("DriveCacheFlags = %08X\n"), gDriveCacheFlags);
   1.532 +
   1.533 +#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
   1.534 +	TPckgBuf<TIOCacheValues> pkgOrgValues;
   1.535 +	TIOCacheValues& orgValues=pkgOrgValues();
   1.536 +	r = controlIo(TheFs,theDrive, KControlIoCacheCount, orgValues);
   1.537 +	test_KErrNone(r);
   1.538 +
   1.539 +	test.Printf(_L("\n"));
   1.540 +	test.Printf(_L("Requests on close queue at start=%d\n"),orgValues.iCloseCount);
   1.541 +	test.Printf(_L("Requests on free queue at start=%d\n"),orgValues.iFreeCount);
   1.542 +	test.Printf(_L("Requests dynamically allocated at start=%d\n"),orgValues.iAllocated);
   1.543 +	test.Printf(_L("Requests in total at start=%d\n"),orgValues.iTotalCount);
   1.544 +
   1.545 +	// File cache
   1.546 +
   1.547 +	// flush closed files queue
   1.548 +	r = TheFs.ControlIo(theDrive, KControlIoFlushClosedFiles);
   1.549 +	test_KErrNone(r);
   1.550 +
   1.551 +	// get number of items on File Cache
   1.552 +	TFileCacheStats startFileCacheStats;
   1.553 +	r = controlIo(TheFs,theDrive, KControlIoFileCacheStats, startFileCacheStats);
   1.554 +	test_Value(r, r == KErrNone || r == KErrNotSupported);
   1.555 +	test.Printf(_L("File cache: Cachelines (free %d, used %d), Segments(allocated %d locked %d). Closed files(%d)\n"),
   1.556 +		startFileCacheStats.iFreeCount,
   1.557 +		startFileCacheStats.iUsedCount,
   1.558 +		startFileCacheStats.iAllocatedSegmentCount,
   1.559 +		startFileCacheStats.iLockedSegmentCount,
   1.560 +		startFileCacheStats.iFilesOnClosedQueue);
   1.561 +#endif
   1.562 +
   1.563 +	DoTests(theDrive);
   1.564 +
   1.565 +	TTime endTimeC;
   1.566 +	endTimeC.HomeTime();
   1.567 +	TTimeIntervalSeconds timeTakenC;
   1.568 +	r=endTimeC.SecondsFrom(timerC,timeTakenC);
   1.569 +	test_KErrNone(r);
   1.570 +	test.Printf(_L("Time taken for test = %d seconds\n"),timeTakenC.Int());
   1.571 +	TheFs.SetAllocFailure(gAllocFailOff);
   1.572 +
   1.573 +#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
   1.574 +	TPckgBuf<TIOCacheValues> pkgValues;
   1.575 +	TIOCacheValues& values=pkgValues();
   1.576 +	r = controlIo(TheFs,theDrive, KControlIoCacheCount, values);
   1.577 +	test_KErrNone(r);
   1.578 +
   1.579 +	test.Printf(_L("Requests on close queue at end=%d\n"),values.iCloseCount);
   1.580 +	test.Printf(_L("Requests on free queue at end=%d\n"),values.iFreeCount);
   1.581 +	test.Printf(_L("Requests dynamically allocated at end=%d\n"),values.iAllocated);
   1.582 +	test.Printf(_L("Requests in total at end=%d\n"),values.iTotalCount);
   1.583 +
   1.584 +	test(orgValues.iCloseCount==values.iCloseCount);
   1.585 +	test(orgValues.iAllocated == values.iAllocated);
   1.586 +	// The free count can increase if the file server runs out of requests in the RequestAllocator
   1.587 +	// free pool but this should never decrease - this implies a request leak
   1.588 +	test(orgValues.iFreeCount <= values.iFreeCount);
   1.589 +
   1.590 +	// The total number of allocated requests should be equal to :
   1.591 +	// requests on the close queue + requests on free queue
   1.592 +	// + 1 (because we used one request to issue KControlIoCacheCount)
   1.593 +	// If this doesn't equate then this implies a request leak
   1.594 +	test(values.iTotalCount == values.iCloseCount + values.iFreeCount + 1);
   1.595 +
   1.596 +	// File cache
   1.597 +	TFileCacheStats endFileCacheStats;
   1.598 +	r = controlIo(TheFs,theDrive, KControlIoFileCacheStats, endFileCacheStats);
   1.599 +	test_Value(r, r == KErrNone || r == KErrNotSupported);
   1.600 +
   1.601 +	test.Printf(_L("File cache: Cachelines (free %d, used %d), Segments(allocated %d locked %d). Closed files(%d)\n"),
   1.602 +		endFileCacheStats.iFreeCount,
   1.603 +		endFileCacheStats.iUsedCount,
   1.604 +		endFileCacheStats.iAllocatedSegmentCount,
   1.605 +		endFileCacheStats.iLockedSegmentCount,
   1.606 +		endFileCacheStats.iFilesOnClosedQueue);
   1.607 +
   1.608 +	// flush closed files queue
   1.609 +	test.Printf(_L("Flushing close queue..."));
   1.610 +	r = TheFs.ControlIo(theDrive, KControlIoFlushClosedFiles);
   1.611 +	test_KErrNone(r);
   1.612 +
   1.613 +	r = controlIo(TheFs,theDrive, KControlIoFileCacheStats, endFileCacheStats);
   1.614 +	test_Value(r, r == KErrNone || r == KErrNotSupported);
   1.615 +	test.Printf(_L("File cache: Cachelines (free %d, used %d), Segments(allocated %d locked %d). Closed files(%d)\n"),
   1.616 +		endFileCacheStats.iFreeCount,
   1.617 +		endFileCacheStats.iUsedCount,
   1.618 +		endFileCacheStats.iAllocatedSegmentCount,
   1.619 +		endFileCacheStats.iLockedSegmentCount,
   1.620 +		endFileCacheStats.iFilesOnClosedQueue);
   1.621 +
   1.622 +
   1.623 +	if (r == KErrNone)
   1.624 +		{
   1.625 +		test(startFileCacheStats.iFreeCount == endFileCacheStats.iFreeCount);
   1.626 +		test(startFileCacheStats.iUsedCount == endFileCacheStats.iUsedCount);
   1.627 +		test(startFileCacheStats.iAllocatedSegmentCount == endFileCacheStats.iAllocatedSegmentCount);
   1.628 +		test(startFileCacheStats.iLockedSegmentCount == endFileCacheStats.iLockedSegmentCount);
   1.629 +		test(startFileCacheStats.iFileCount == endFileCacheStats.iFileCount);
   1.630 +		}
   1.631 +#endif
   1.632 +
   1.633 +	TheFs.Close();
   1.634 +	test.End();
   1.635 +	test.Close();
   1.636 +	__UHEAP_MARKEND;
   1.637 +	delete cleanup;
   1.638 +	return(KErrNone);
   1.639 +    }
   1.640 +
   1.641 +