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