os/kernelhwsrv/kerneltest/f32test/bench/t_benchmain.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2006-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\bench\t_benchmain.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <f32file.h>
sl@0
    19
#include <e32test.h>
sl@0
    20
#include <e32hal.h>
sl@0
    21
#include <e32math.h>
sl@0
    22
#include <f32dbg.h>
sl@0
    23
#include "t_benchmain.h"
sl@0
    24
#include "t_chlffs.h"
sl@0
    25
sl@0
    26
RFs         TheFs;
sl@0
    27
TFileName   gSessionPath;
sl@0
    28
TFileName   gExeFileName(RProcess().FileName());
sl@0
    29
TInt        gAllocFailOff=KAllocFailureOff;
sl@0
    30
TInt        gAllocFailOn=KAllocFailureOff;
sl@0
    31
TInt64      gSeed = 51703;
sl@0
    32
TInt        gFilesLimit; 	
sl@0
    33
TInt        gTypes;  		
sl@0
    34
TInt        gMode; 
sl@0
    35
TInt        gFormat = EFalse; 	
sl@0
    36
TInt        gMinutes; 
sl@0
    37
TInt        gFileSize = 0; 			// In Kbytes	
sl@0
    38
sl@0
    39
TInt 		gTestHarness = 0;
sl@0
    40
TInt 		gTestCase = 1;
sl@0
    41
TInt 		gTimeUnit = 1000; // values: 1 - us, 1000 - ms, 1000000 - s
sl@0
    42
sl@0
    43
sl@0
    44
TChar       gDriveToTest = ' ';
sl@0
    45
sl@0
    46
	
sl@0
    47
////////////////////////////////////////////////////////////
sl@0
    48
// Template functions encapsulating ControlIo magic
sl@0
    49
//
sl@0
    50
template <class C>
sl@0
    51
sl@0
    52
TInt controlIo(RFs &fs, TInt drv, TInt fkn, C &c)
sl@0
    53
	{
sl@0
    54
    TPtr8 ptrC((TUint8 *)&c, sizeof(C), sizeof(C));
sl@0
    55
sl@0
    56
    TInt r = fs.ControlIo(drv, fkn, ptrC);
sl@0
    57
sl@0
    58
    return r;
sl@0
    59
	}
sl@0
    60
sl@0
    61
/** Prints headers of FAT32 and File Cache benchmarking
sl@0
    62
sl@0
    63
	@param aType type of test (FAT32 = 1/2 or File Cache = 3/4/5)
sl@0
    64
	@param
sl@0
    65
*/
sl@0
    66
void PrintHeaders(TInt aType, TPtrC16 aTitle ) 
sl@0
    67
	{
sl@0
    68
	TBuf16<250> title = _L("#~TestTitle_%d: ");
sl@0
    69
	
sl@0
    70
	title.Append(aTitle);
sl@0
    71
	title.Append(_L("\n"));
sl@0
    72
	
sl@0
    73
	test.Printf(_L("#~TestId=%d\n"), gTestHarness);	
sl@0
    74
	test.Printf(title, gTestHarness);
sl@0
    75
	test.Printf(_L("#~Report Variant: \n"));	
sl@0
    76
	test.Printf(_L("#~Report Description: \n"));	
sl@0
    77
	
sl@0
    78
	_LIT(KSeconds,"seconds");
sl@0
    79
	_LIT(KMilliSecs,"milliseconds");
sl@0
    80
	_LIT(KMicroSecs,"microseconds");
sl@0
    81
sl@0
    82
	TPtrC16 timeUnit;
sl@0
    83
	if (gTimeUnit == 1) 
sl@0
    84
		timeUnit.Set(KMicroSecs);
sl@0
    85
	else if (gTimeUnit == 1000) 
sl@0
    86
		timeUnit.Set(KMilliSecs);
sl@0
    87
	else if (gTimeUnit == 1000000)
sl@0
    88
		timeUnit.Set(KSeconds);
sl@0
    89
	else
sl@0
    90
		{
sl@0
    91
		test.Printf(_L("Please, check gTimeUnit value\n"));
sl@0
    92
		test(EFalse);	
sl@0
    93
		}
sl@0
    94
sl@0
    95
sl@0
    96
	if(aType == 1) 
sl@0
    97
		{ // All FAT32 tests but t_fsrrepeat
sl@0
    98
		test.Printf(_L("#~TestParam_%d: MaxFiles=%d, type=%d, mode=%d, timeUnit=%S\n"), gTestHarness, gFilesLimit, gTypes, gMode, &timeUnit);
sl@0
    99
		
sl@0
   100
		test.Printf(_L("#~TestRows_%d: 4\n"), gTestHarness);
sl@0
   101
		test.Printf(_L("#~TestColumns_%d: 4, NFiles, 8_3, 20_chars, 50_50\n"), gTestHarness);	
sl@0
   102
		}
sl@0
   103
	else if(aType == 2) 
sl@0
   104
		{ // t_fsrrepeat
sl@0
   105
		test.Printf(_L("#~TestParam_%d: MaxFiles=%d, type=%d, mode=%d, timeUnit=%S\n"), gTestHarness, gFilesLimit, gTypes, gMode, &timeUnit);
sl@0
   106
		
sl@0
   107
		test.Printf(_L("#~TestRows_%d: 12\n"), gTestHarness);
sl@0
   108
		test.Printf(_L("#~TestColumns_%d: 4, DirName, 1st, 2nd, 3rd\n"), gTestHarness);			
sl@0
   109
		} 
sl@0
   110
	else if(aType == 3)
sl@0
   111
		{ // Large sequential reads/writes
sl@0
   112
		test.Printf(_L("#~TestParam_%d: mode=%d, timeUnit=%S\n"), gTestHarness, gMode, &timeUnit);
sl@0
   113
sl@0
   114
		test.Printf(_L("#~TestRows_%d: 8\n"), gTestHarness);
sl@0
   115
		test.Printf(_L("#~TestColumns_%d: 4, bsize, 100KB, 1MB, 10MB\n"), gTestHarness);
sl@0
   116
		}
sl@0
   117
	else if(aType == 4)
sl@0
   118
		{ // Small random reads/writes
sl@0
   119
		test.Printf(_L("#~TestParam_%d: mode=%d, timeUnit=%S\n"), gTestHarness, gMode, &timeUnit);
sl@0
   120
sl@0
   121
		test.Printf(_L("#~TestRows_%d: 11\n"), gTestHarness);
sl@0
   122
		test.Printf(_L("#~TestColumns_%d: 8, bsize, 1KB, 2KB, 4KB, 8KB, 16KB, 32KB, 64KB\n"), gTestHarness);
sl@0
   123
		}
sl@0
   124
	else if(aType == 5)
sl@0
   125
		{ // Streaming
sl@0
   126
		test.Printf(_L("#~TestParam_%d: mode=%d, timeUnit=%S\n"), gTestHarness, gMode, &timeUnit);
sl@0
   127
sl@0
   128
		test.Printf(_L("#~TestRows_%d: 6\n"), gTestHarness);
sl@0
   129
		test.Printf(_L("#~TestColumns_%d: 4, bsize, 5m_w, 15s_w_r, 15s_w_r \n"), gTestHarness);
sl@0
   130
		}
sl@0
   131
	else 
sl@0
   132
		{
sl@0
   133
		test.Printf(_L("Check the function PrintHeaders() in t_benchmain.cpp, which wasn't called with the right parameters\n"));
sl@0
   134
		test(EFalse);	
sl@0
   135
		}
sl@0
   136
	
sl@0
   137
	}
sl@0
   138
sl@0
   139
/** Prints a line of results 
sl@0
   140
sl@0
   141
	@param aPosX  Row of the table
sl@0
   142
	@param aPosY  Column of the table
sl@0
   143
	@param aValue Value figure for that position 
sl@0
   144
*/
sl@0
   145
void PrintResultTime( TInt aPosX, TInt aPosY, TInt aValue) 
sl@0
   146
	{
sl@0
   147
	test.Printf(_L("#~TS_Res_%d,%d,[%d,%d]=%d\n "), gTestHarness, gTestCase, aPosX, aPosY, aValue );
sl@0
   148
	}
sl@0
   149
sl@0
   150
sl@0
   151
/** Prints any other type of data 
sl@0
   152
sl@0
   153
	@param aPosX  Row of the table
sl@0
   154
	@param aPosY  Column of the table
sl@0
   155
	@param aValue Value figure for that position 
sl@0
   156
*/
sl@0
   157
void PrintResult( TInt aPosX, TInt aPosY, TInt aValue) 
sl@0
   158
	{
sl@0
   159
	test.Printf(_L("#~TS_Res_%d,%d,[%d,%d]=%d\n "), gTestHarness, gTestCase, aPosX, aPosY, aValue);
sl@0
   160
	}
sl@0
   161
sl@0
   162
/** Prints string
sl@0
   163
sl@0
   164
	@param aPosX  Row of the table
sl@0
   165
	@param aPosY  Column of the table
sl@0
   166
	@param aValue Value figure for that position 
sl@0
   167
*/
sl@0
   168
void PrintResultS( TInt aPosX, TInt aPosY, TDes16& aValue) 
sl@0
   169
	{
sl@0
   170
	TBuf16<250> buffer = _L("#~TS_Res_%d,%d,[%d,%d]=");
sl@0
   171
	
sl@0
   172
	buffer.Append(aValue);
sl@0
   173
	buffer.Append(_L("\n"));
sl@0
   174
	test.Printf(buffer, gTestHarness, gTestCase, aPosX, aPosY);
sl@0
   175
	}
sl@0
   176
sl@0
   177
/** Call all RFormat methods
sl@0
   178
sl@0
   179
	@param aDrive Drive to be formatted
sl@0
   180
*/
sl@0
   181
void FormatFat(TDriveUnit aDrive)
sl@0
   182
	{
sl@0
   183
	RFormat format;
sl@0
   184
	TPckgBuf<TInt> count;
sl@0
   185
	TInt r = format.Open(TheFs, aDrive.Name(), EQuickFormat, count());
sl@0
   186
	FailIfError(r);
sl@0
   187
	
sl@0
   188
	test(count() == 100);
sl@0
   189
	TRequestStatus status;
sl@0
   190
	while (count())
sl@0
   191
		{
sl@0
   192
		format.Next(count, status);
sl@0
   193
		User::WaitForRequest(status);
sl@0
   194
		test(status == KErrNone || status == KErrNotSupported);
sl@0
   195
		}
sl@0
   196
		
sl@0
   197
	format.Close();
sl@0
   198
	test.Printf(_L("Drive formatted\n"));
sl@0
   199
	}
sl@0
   200
sl@0
   201
/** Validates the drive selection
sl@0
   202
sl@0
   203
	@param aDrive Drive to be validated
sl@0
   204
	@param aTest  Type of test 
sl@0
   205
*/
sl@0
   206
TInt ValidateDriveSelection(TDriveUnit aDrive,TSelectedTest aTest)
sl@0
   207
	{
sl@0
   208
	if ((aDrive == EDriveZ) || ((aDrive == EDriveC) && (aTest == ELocalDriveTest)))
sl@0
   209
		{
sl@0
   210
		test.Printf(_L("Test not available for this drive\n"));
sl@0
   211
		test.Printf(_L("Press any key to continue...\n"));
sl@0
   212
		return (KErrNotSupported);
sl@0
   213
		}
sl@0
   214
	else
sl@0
   215
		return (KErrNone);
sl@0
   216
	}
sl@0
   217
sl@0
   218
/** Validates the selection for this tests and update appropriate variables
sl@0
   219
sl@0
   220
	@param aSelector This object is meant to give information about what needs 
sl@0
   221
					 to be tests in manual mode
sl@0
   222
*/
sl@0
   223
TInt Validate(TAny* aSelector) 
sl@0
   224
	{
sl@0
   225
	if(gMode == 0) 
sl@0
   226
		{
sl@0
   227
		if (((CSelectionBox*)aSelector)->CurrentKeyPress() != EKeyEnter)
sl@0
   228
				return(KErrNone);
sl@0
   229
		
sl@0
   230
		TInt r = ValidateDriveSelection(((CSelectionBox*)aSelector)->CurrentDrive(),EFileSeekTest);
sl@0
   231
		if (r == KErrNotSupported)
sl@0
   232
			return (r);
sl@0
   233
		
sl@0
   234
		TDriveUnit drive = ((CSelectionBox*)aSelector)->CurrentDrive();
sl@0
   235
		gSessionPath[0] = TUint8('A' + drive);
sl@0
   236
		r = TheFs.SetSessionPath(gSessionPath);
sl@0
   237
		FailIfError(r);
sl@0
   238
		}
sl@0
   239
	
sl@0
   240
	return KErrNone;
sl@0
   241
	}
sl@0
   242
sl@0
   243
/** Prints current volume information
sl@0
   244
sl@0
   245
*/
sl@0
   246
void PrintVolInfo()
sl@0
   247
	{
sl@0
   248
    TVolumeInfo volInfo;
sl@0
   249
    TInt r;
sl@0
   250
sl@0
   251
    r = TheFs.Volume(volInfo);
sl@0
   252
    FailIfError(r);
sl@0
   253
sl@0
   254
    test.Printf(_L("DriveAtt:0x%X, MediaAtt:0x%X, Free:%d KBytes\n"), volInfo.iDrive.iDriveAtt, volInfo.iDrive.iMediaAtt, (TUint32)(volInfo.iFree / 1024));
sl@0
   255
	}
sl@0
   256
sl@0
   257
/** Create directory with a number of files, with specified file name type
sl@0
   258
sl@0
   259
    @param  aN      number of files to create
sl@0
   260
    @param  aType   file names type : 1 - 8.3, 2 - 20 characters, 3 - 50/50
sl@0
   261
*/
sl@0
   262
TInt CreateDirWithNFiles(TInt aN, TInt aType)
sl@0
   263
	{
sl@0
   264
	TInt i,r=0;
sl@0
   265
sl@0
   266
	RFile file;
sl@0
   267
	TBuf16<50> directory;
sl@0
   268
	TBuf16<50> dirtemp;
sl@0
   269
	
sl@0
   270
	TBuf16<50> path;
sl@0
   271
	TBuf16<50> buffer(50); 	
sl@0
   272
	
sl@0
   273
	dirtemp.Format(KDirMultipleName,aType, aN);
sl@0
   274
	directory=gSessionPath;
sl@0
   275
	directory.Append(dirtemp);
sl@0
   276
	
sl@0
   277
	r = TheFs.MkDir(directory);
sl@0
   278
	test(r == KErrNone || r == KErrAlreadyExists);
sl@0
   279
sl@0
   280
    const TUint KNumFilesPrintTreshold = 100;
sl@0
   281
    const TInt  KFileSize = gFileSize * 1024;
sl@0
   282
    
sl@0
   283
    PrintVolInfo();
sl@0
   284
	
sl@0
   285
	i = 0; 
sl@0
   286
	while( i < aN )
sl@0
   287
		{        
sl@0
   288
        // generate file name depending on type required
sl@0
   289
        switch(aType)    
sl@0
   290
        	{
sl@0
   291
            case 1: // 8.3 filemnames 
sl@0
   292
                FileNamesGeneration(buffer, 8, i, i%3+1);
sl@0
   293
            break;
sl@0
   294
sl@0
   295
            case 2: // 20 characrer filenames
sl@0
   296
                FileNamesGeneration(buffer, 20, i, i%3+1);
sl@0
   297
            break;
sl@0
   298
sl@0
   299
            case 3: // 50/50 mix
sl@0
   300
                if(i%2) 
sl@0
   301
                	FileNamesGeneration(buffer, 8, i, i%3+1) ;
sl@0
   302
			    else  	
sl@0
   303
			    	FileNamesGeneration(buffer, 20, i, i%3+1) ;
sl@0
   304
            break;
sl@0
   305
            default:
sl@0
   306
                test(0);
sl@0
   307
            break;
sl@0
   308
        	};
sl@0
   309
        path = directory;
sl@0
   310
		path.Append(buffer);
sl@0
   311
        
sl@0
   312
        // create or replace a file
sl@0
   313
        r = file.Replace(TheFs, path, EFileShareAny|EFileWrite);
sl@0
   314
        if(r != KErrNone)
sl@0
   315
        	{
sl@0
   316
            PrintVolInfo();
sl@0
   317
            test.Printf(_L("Error creating file: %S, %d\n"), &path, r);
sl@0
   318
            test(0);
sl@0
   319
        	}
sl@0
   320
sl@0
   321
        // set file size if required, file contents doesn't matter
sl@0
   322
        if(gFileSize > 0)
sl@0
   323
        	{
sl@0
   324
            r = file.SetSize(KFileSize); 
sl@0
   325
            if(r != KErrNone)
sl@0
   326
            	{
sl@0
   327
                PrintVolInfo();
sl@0
   328
                test.Printf(_L("Error setting file size: %S, %d, err:%d\n"), &path, KFileSize, r);
sl@0
   329
                test(0);
sl@0
   330
            	}
sl@0
   331
        	}
sl@0
   332
sl@0
   333
		file.Close();
sl@0
   334
		
sl@0
   335
        if(i > 0 && ((i+1)%KNumFilesPrintTreshold) == 0)
sl@0
   336
        	{
sl@0
   337
            test.Printf(_L("created %d files, type:%d\n"), i + 1, aType);
sl@0
   338
        	}
sl@0
   339
        
sl@0
   340
		i++;
sl@0
   341
    	}//while
sl@0
   342
sl@0
   343
sl@0
   344
    // write "last.txt" file to the end of directory
sl@0
   345
	path = directory;
sl@0
   346
	path.Append(KCommonFile);
sl@0
   347
	r = file.Replace(TheFs,path,EFileShareAny|EFileWrite);
sl@0
   348
    if(r != KErrNone)
sl@0
   349
    	{
sl@0
   350
        PrintVolInfo();
sl@0
   351
        test.Printf(_L("Error creating file: %S, %d\n"), &path, r);
sl@0
   352
        test(0);
sl@0
   353
    	}
sl@0
   354
	
sl@0
   355
	// put random content to the "last.txt" file if specified length of files > 0
sl@0
   356
    if(gFileSize > 0)
sl@0
   357
    	{
sl@0
   358
        r = file.SetSize(gFileSize * 1024); // gFileSize is in KBytes
sl@0
   359
        if(r != KErrNone)
sl@0
   360
        	{
sl@0
   361
            PrintVolInfo();
sl@0
   362
            test.Printf(_L("Error setting file size: %S, %d\n"), &path, r);
sl@0
   363
            test(0);
sl@0
   364
        	}
sl@0
   365
    	}
sl@0
   366
sl@0
   367
	file.Close();
sl@0
   368
	
sl@0
   369
	return(KErrNone);
sl@0
   370
	}
sl@0
   371
sl@0
   372
sl@0
   373
/**
sl@0
   374
 Creates 12 directories with different sort of files and namefiles
sl@0
   375
 100 files with 8.3, 20 chars and 50/50
sl@0
   376
 1000 files with 8.3, 20 chars and 50/50
sl@0
   377
 5000 files with 8.3, 20 chars and 50/50
sl@0
   378
 10000 files with 8.3, 20 chars and 50/50 
sl@0
   379
*/
sl@0
   380
TInt TestFileCreate(TAny* aSelector)
sl@0
   381
	{
sl@0
   382
	TInt i = 100, j = 1;
sl@0
   383
	
sl@0
   384
	Validate(aSelector);
sl@0
   385
	
sl@0
   386
	while(i <= gFilesLimit) 
sl@0
   387
		{
sl@0
   388
		if(i == 100) 
sl@0
   389
			{	
sl@0
   390
			j = 1;
sl@0
   391
			while(j <= gTypes) 
sl@0
   392
				CreateDirWithNFiles(100, j++); 
sl@0
   393
			}
sl@0
   394
		if(i == 1000) 
sl@0
   395
			{	
sl@0
   396
			j=1;
sl@0
   397
			while(j <= gTypes) 
sl@0
   398
				CreateDirWithNFiles(1000, j++); 
sl@0
   399
			}
sl@0
   400
		if(i == 5000) 
sl@0
   401
			{	
sl@0
   402
			j = 1;
sl@0
   403
			while(j <= gTypes) 
sl@0
   404
				CreateDirWithNFiles(5000, j++); 
sl@0
   405
			}
sl@0
   406
		if(i == 10000) 
sl@0
   407
			{	
sl@0
   408
			j = 1;
sl@0
   409
			while(j <= gTypes) 
sl@0
   410
				CreateDirWithNFiles(10000, j++); 
sl@0
   411
			}
sl@0
   412
		i += 100;
sl@0
   413
		}
sl@0
   414
	
sl@0
   415
	return(KErrNone);
sl@0
   416
	}
sl@0
   417
sl@0
   418
/** Generate a filename according to the parameters configuration
sl@0
   419
sl@0
   420
    @param  aBuffer Buffer where the name of the file will be returned
sl@0
   421
    @param  aLong 	Length of the name of the file
sl@0
   422
    @param  aPos 	Number to be attached to the name of the file
sl@0
   423
    @param  ext 	Type of extension (1/2/3) 
sl@0
   424
*/
sl@0
   425
void FileNamesGeneration(TDes16& aBuffer, TInt aLong, TInt aPos,TInt ext) 
sl@0
   426
	{
sl@0
   427
	TInt padding;
sl@0
   428
	TInt i=0;
sl@0
   429
	TBuf16<10> tempbuf;
sl@0
   430
	
sl@0
   431
	_LIT(KNumber,"%d");
sl@0
   432
	tempbuf.Format(KNumber, aPos);
sl@0
   433
	padding = aLong - tempbuf.Size() / 2;
sl@0
   434
	aBuffer = _L("");
sl@0
   435
	while(i < padding)
sl@0
   436
		{
sl@0
   437
		aBuffer.Append('F');
sl@0
   438
		i++;
sl@0
   439
		}
sl@0
   440
	
sl@0
   441
	_LIT(KExtension1, ".TXT");
sl@0
   442
	_LIT(KExtension2, ".HTM");
sl@0
   443
	_LIT(KExtension3, ".LOG");
sl@0
   444
sl@0
   445
	aBuffer.Append(tempbuf);
sl@0
   446
	switch(ext)
sl@0
   447
		{
sl@0
   448
		case 1: aBuffer.Append(KExtension1);break;
sl@0
   449
		case 2: aBuffer.Append(KExtension2);break;
sl@0
   450
		case 3: aBuffer.Append(KExtension3);break;
sl@0
   451
		default: aBuffer.Append(KExtension1);break;
sl@0
   452
		}	
sl@0
   453
	}
sl@0
   454
sl@0
   455
/** Do a checkdisk and report failure
sl@0
   456
sl@0
   457
*/
sl@0
   458
void CheckDisk()
sl@0
   459
	{
sl@0
   460
	test.Next(_L("Check Disk"));
sl@0
   461
	TInt r = TheFs.CheckDisk(gSessionPath);
sl@0
   462
	if (r != KErrNone && r != KErrNotSupported && r != KErrPermissionDenied)
sl@0
   463
		ReportCheckDiskFailure(r);
sl@0
   464
	}
sl@0
   465
sl@0
   466
/** Report a disk failure
sl@0
   467
	
sl@0
   468
	@param aRet The error will be returned in this variable
sl@0
   469
*/
sl@0
   470
void ReportCheckDiskFailure(TInt aRet)
sl@0
   471
	{
sl@0
   472
	test.Printf(_L("CHECKDISK FAILED: "));
sl@0
   473
	switch(aRet)
sl@0
   474
		{
sl@0
   475
		case 1:	test.Printf(_L("File cluster chain contains a bad value (<2 or >maxCluster)\n")); break;
sl@0
   476
		case 2:	test.Printf(_L("Two files are linked to the same cluster\n")); break;
sl@0
   477
		case 3:	test.Printf(_L("Unallocated cluster contains a value != 0\n"));	break;
sl@0
   478
		case 4:	test.Printf(_L("Size of file != number of clusters in chain\n")); break;
sl@0
   479
		default: test.Printf(_L("Undefined Error value %d\n"),aRet);
sl@0
   480
		}
sl@0
   481
	}
sl@0
   482
sl@0
   483
sl@0
   484
/** Expand the cleanup stack
sl@0
   485
sl@0
   486
*/
sl@0
   487
void PushLotsL()
sl@0
   488
	{
sl@0
   489
	TInt i;
sl@0
   490
	
sl@0
   491
	for(i=0;i<1000;i++)
sl@0
   492
		CleanupStack::PushL((CBase*)NULL);
sl@0
   493
	
sl@0
   494
	CleanupStack::Pop(1000);
sl@0
   495
	}
sl@0
   496
sl@0
   497
/** Do testing on aDrive
sl@0
   498
sl@0
   499
	@param aDrive Drive for the testing
sl@0
   500
*/
sl@0
   501
void DoTests(TInt aDrive)
sl@0
   502
	{
sl@0
   503
sl@0
   504
	gSessionPath=_L("?:\\");
sl@0
   505
	TChar driveLetter;
sl@0
   506
	TInt r = TheFs.DriveToChar(aDrive, driveLetter);
sl@0
   507
	FailIfError(r);
sl@0
   508
	gSessionPath[0] = (TText)driveLetter;
sl@0
   509
	r = TheFs.SetSessionPath(gSessionPath);
sl@0
   510
	FailIfError(r);
sl@0
   511
sl@0
   512
    test.Printf(_L("DoTests() Session Path: %S\n"),&gSessionPath);
sl@0
   513
sl@0
   514
	CheckMountLFFS(TheFs,driveLetter);
sl@0
   515
	
sl@0
   516
	User::After(1000000);
sl@0
   517
sl@0
   518
	r = TheFs.MkDirAll(gSessionPath);
sl@0
   519
	if (r != KErrNone && r != KErrAlreadyExists)
sl@0
   520
		{
sl@0
   521
		test.Printf(_L("MkDirAll() r %d\n"),r);
sl@0
   522
		test(EFalse);
sl@0
   523
		}
sl@0
   524
	TheFs.ResourceCountMarkStart();
sl@0
   525
	TRAP(r,CallTestsL());
sl@0
   526
	if (r == KErrNone)
sl@0
   527
		TheFs.ResourceCountMarkEnd();
sl@0
   528
	else
sl@0
   529
		{
sl@0
   530
		test.Printf(_L("Error: Leave %d\n"),r);
sl@0
   531
		test(EFalse);
sl@0
   532
		}
sl@0
   533
		
sl@0
   534
	CheckDisk();
sl@0
   535
	}
sl@0
   536
sl@0
   537
/** Syntax of the test 
sl@0
   538
sl@0
   539
	@param aOption option 1 is related to FAT32 testing/option 2 relates to the file caching
sl@0
   540
*/
sl@0
   541
void syntax (TInt aOption) 
sl@0
   542
	{
sl@0
   543
	_LIT(KBad, "Wrong argument"); 
sl@0
   544
sl@0
   545
	if(aOption == 1) 
sl@0
   546
		{
sl@0
   547
		test.Printf(_L("Usage: \n testname <drive> <100/1000/5000/10000 number of files> <1/2/3 type of files> <mode 0 manual, 1 automatic>\n "));
sl@0
   548
		}
sl@0
   549
	else if (aOption == 2) 
sl@0
   550
		{
sl@0
   551
		test.Printf(_L("Usage: \n t_fcachebm <drive> <mode 0 manual, 1 automatic>\n "));
sl@0
   552
		}
sl@0
   553
	
sl@0
   554
	User::Panic(KBad,KErrArgument);
sl@0
   555
	}
sl@0
   556
sl@0
   557
/**
sl@0
   558
 Parse commands :
sl@0
   559
	 
sl@0
   560
	 1) t_name drive maxfiles filetypes manual/automatic
sl@0
   561
	    maxfiles can be: 100, 1000, 5000 or 10000
sl@0
   562
	    filetypes can be 1 for 8.3, 2 for 20 chars as well and 3 for all
sl@0
   563
	    manual 0 and automatic 1
sl@0
   564
	 2) t_fcachebm drive manua/automatic
sl@0
   565
	 3) t_fsrcreatefiles
sl@0
   566
 */
sl@0
   567
void ParseCommandArguments()
sl@0
   568
	{
sl@0
   569
	TBuf<0x100> cmd;
sl@0
   570
	User::CommandLine(cmd);
sl@0
   571
	
sl@0
   572
    test.Printf(_L("Command line:\n"));
sl@0
   573
    test.Printf(cmd);
sl@0
   574
    test.Printf(_L("\n"));
sl@0
   575
sl@0
   576
    TLex lex(cmd);
sl@0
   577
	lex.SkipSpace();
sl@0
   578
sl@0
   579
    TPtrC token;
sl@0
   580
	TFileName thisfile=RProcess().FileName();
sl@0
   581
	
sl@0
   582
	TInt i = 0;
sl@0
   583
	TInt testcase = 0;
sl@0
   584
	TBool finish = EFalse;
sl@0
   585
	_LIT(KCacheBM, "Z:\\sys\\bin\\t_fcachebm.exe");
sl@0
   586
	_LIT(KCreate, "Z:\\sys\\bin\\t_fsrcreatefiles.exe");
sl@0
   587
	
sl@0
   588
	test.Printf(KCacheBM);
sl@0
   589
	test.Printf(thisfile);
sl@0
   590
	while((!finish) && (i <= 5))
sl@0
   591
		{
sl@0
   592
		switch(i)
sl@0
   593
			{
sl@0
   594
			case 0:
sl@0
   595
				if((thisfile != KCacheBM) && (thisfile != KCreate)) // FAT32 tests
sl@0
   596
					testcase = 1; 
sl@0
   597
				else if(thisfile == KCreate) // FAT32 test files creation
sl@0
   598
					testcase = 3;
sl@0
   599
				else 					 // File Cache (PREQ914) performance tests
sl@0
   600
					testcase = 2;			
sl@0
   601
				break;
sl@0
   602
			case 1:
sl@0
   603
				test.Printf(_L("\nCLP=%S\n"), &token);
sl@0
   604
				if(token.Length() != 0)		
sl@0
   605
					{
sl@0
   606
					gDriveToTest = token[0];
sl@0
   607
					gDriveToTest.UpperCase();
sl@0
   608
					if(gMode==1) 
sl@0
   609
						gSessionPath[0] = (TText)gDriveToTest;
sl@0
   610
					}
sl@0
   611
					else						
sl@0
   612
						{
sl@0
   613
						gDriveToTest = 'C';
sl@0
   614
						}
sl@0
   615
			break;
sl@0
   616
			case 2:
sl@0
   617
				if((testcase == 1) || (testcase == 3)) // testcase == 1 || testcase == 3
sl@0
   618
					{
sl@0
   619
					if(token.Length() != 0) 
sl@0
   620
						{
sl@0
   621
						test.Printf(_L("Number of files=%S\n"),&token);
sl@0
   622
						if(token[0]=='5') 
sl@0
   623
						{
sl@0
   624
							gFilesLimit = 5000;
sl@0
   625
						}
sl@0
   626
						else 
sl@0
   627
							if(token[0] == '1' && token.Length() == 3) gFilesLimit = 100;
sl@0
   628
							else if(token[0] == '1' && token.Length() == 4) gFilesLimit = 1000; 
sl@0
   629
								 else if(token[0] == '1' && token.Length() == 5) gFilesLimit = 10000;
sl@0
   630
								 	  else syntax(testcase);
sl@0
   631
						}
sl@0
   632
					else
sl@0
   633
						gFilesLimit = 10000 ;
sl@0
   634
					
sl@0
   635
					}
sl@0
   636
				else // (testcase == 2)
sl@0
   637
					{
sl@0
   638
					if(token.Length() == 1) 
sl@0
   639
						{
sl@0
   640
						TChar c = token[0];
sl@0
   641
						test.Printf(_L("0 manual/1 automatic ? %S\n"),&token);
sl@0
   642
						if(c.IsDigit() && ((c == '0') || (c == '1'))) 
sl@0
   643
							gMode = c.GetNumericValue();
sl@0
   644
						 	  else syntax(testcase);
sl@0
   645
						}
sl@0
   646
					else 
sl@0
   647
						syntax(testcase);		
sl@0
   648
						}
sl@0
   649
			break;
sl@0
   650
			case 3:
sl@0
   651
				if((testcase == 1) || (testcase == 3)) 
sl@0
   652
					{
sl@0
   653
					if(token.Length() == 1) 
sl@0
   654
						{	
sl@0
   655
						TChar c = token[0];
sl@0
   656
						test.Printf(_L("File type=%S\n"), &token);
sl@0
   657
						if(c.IsDigit() &&((c == '1') || (c == '2') || (c == '3'))) 
sl@0
   658
							gTypes = c.GetNumericValue();
sl@0
   659
						else syntax(testcase);
sl@0
   660
						}
sl@0
   661
					else // Default value
sl@0
   662
						gTypes = 3;
sl@0
   663
					}
sl@0
   664
			break;
sl@0
   665
			case 4: 
sl@0
   666
				if((testcase == 1) || (testcase == 3)) 
sl@0
   667
					{	
sl@0
   668
					TChar c = token[0];
sl@0
   669
					if(token.Length() == 1) 
sl@0
   670
						{	
sl@0
   671
						test.Printf(_L("0 manual/1 automatic ? %S\n"),&token);
sl@0
   672
						if(c.IsDigit() && ((c == '0') || (c == '1'))) 
sl@0
   673
							gMode = c.GetNumericValue();
sl@0
   674
				 	    else syntax(1);
sl@0
   675
						}
sl@0
   676
					else 
sl@0
   677
						gMode = 0;
sl@0
   678
				}
sl@0
   679
			break;
sl@0
   680
			case 5:
sl@0
   681
				if(testcase == 3)
sl@0
   682
					{
sl@0
   683
					TChar c = token[0];
sl@0
   684
					if(c.IsDigit()) 
sl@0
   685
						gFileSize = c.GetNumericValue();
sl@0
   686
					else syntax(1);
sl@0
   687
					}
sl@0
   688
			break;
sl@0
   689
			
sl@0
   690
			default: 
sl@0
   691
			syntax(testcase); 
sl@0
   692
			}
sl@0
   693
		finish = lex.Eos();
sl@0
   694
		token.Set(lex.NextToken());	
sl@0
   695
		i++;
sl@0
   696
		}
sl@0
   697
	}
sl@0
   698
sl@0
   699
/** Main function
sl@0
   700
sl@0
   701
	@return KErrNone if everything was ok, panics otherwise
sl@0
   702
*/
sl@0
   703
TInt E32Main()
sl@0
   704
    {
sl@0
   705
	CTrapCleanup* cleanup;
sl@0
   706
	cleanup = CTrapCleanup::New();
sl@0
   707
	TRAPD(r,PushLotsL());
sl@0
   708
	__UHEAP_MARK;	
sl@0
   709
sl@0
   710
	test.Title();
sl@0
   711
	test.Start(_L("Starting benchmarking tests..."));
sl@0
   712
sl@0
   713
	ParseCommandArguments(); //need this for drive letter to test and all the parameters
sl@0
   714
sl@0
   715
	r = TheFs.Connect();
sl@0
   716
	FailIfError(r);
sl@0
   717
	TheFs.SetAllocFailure(gAllocFailOn);
sl@0
   718
	TTime timerC;
sl@0
   719
	timerC.HomeTime();
sl@0
   720
	TFileName sessionp;
sl@0
   721
	TheFs.SessionPath(sessionp);
sl@0
   722
sl@0
   723
	TInt theDrive;
sl@0
   724
		
sl@0
   725
	r = TheFs.CharToDrive(gDriveToTest,theDrive);
sl@0
   726
	FailIfError(r);
sl@0
   727
	
sl@0
   728
	PrintDrvInfo(TheFs, theDrive); 
sl@0
   729
		
sl@0
   730
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
sl@0
   731
	TPckgBuf<TIOCacheValues> pkgOrgValues;
sl@0
   732
	TIOCacheValues& orgValues=pkgOrgValues();
sl@0
   733
	r = controlIo(TheFs,theDrive, KControlIoCacheCount, orgValues);
sl@0
   734
	FailIfError(r);
sl@0
   735
	
sl@0
   736
	test.Printf(_L("\nNumber of items on close list at beginning=%d\n"), orgValues.iCloseCount);
sl@0
   737
	test.Printf(_L("Number of items on free list at beginning=%d\n"), orgValues.iFreeCount);
sl@0
   738
	test.Printf(_L("Number of items allocated at beginning=%d\n"), orgValues.iAllocated);
sl@0
   739
#endif
sl@0
   740
	
sl@0
   741
	DoTests(theDrive);
sl@0
   742
	
sl@0
   743
	TTime endTimeC;
sl@0
   744
	endTimeC.HomeTime();
sl@0
   745
	TTimeIntervalSeconds timeTakenC;
sl@0
   746
	r = endTimeC.SecondsFrom(timerC,timeTakenC);
sl@0
   747
	FailIfError(r);
sl@0
   748
	
sl@0
   749
	if(gFormat) 
sl@0
   750
		{
sl@0
   751
		FormatFat(gSessionPath[0]-'A');
sl@0
   752
		}
sl@0
   753
	
sl@0
   754
	test.Printf(_L("#~T_Timing_%d: %d S\n"), gTestHarness, timeTakenC.Int());
sl@0
   755
	TheFs.SetAllocFailure(gAllocFailOff);
sl@0
   756
	
sl@0
   757
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
sl@0
   758
	TPckgBuf<TIOCacheValues> pkgValues;
sl@0
   759
	TIOCacheValues& values=pkgValues();
sl@0
   760
	r = controlIo(TheFs,theDrive, KControlIoCacheCount, values);
sl@0
   761
	test(r==KErrNone);
sl@0
   762
	
sl@0
   763
	test.Printf(_L("\nNumber of items on close list at end=%d\n"),values.iCloseCount);
sl@0
   764
	test.Printf(_L("Number of items on free list at end=%d\n"),values.iFreeCount);
sl@0
   765
	test.Printf(_L("Number of items allocated at the end=%d\n"),values.iAllocated);
sl@0
   766
	
sl@0
   767
	test(orgValues.iCloseCount==values.iCloseCount);
sl@0
   768
	test(orgValues.iAllocated == values.iAllocated);
sl@0
   769
#endif
sl@0
   770
sl@0
   771
	TheFs.Close();
sl@0
   772
	test.End();
sl@0
   773
	test.Close();
sl@0
   774
	__UHEAP_MARKEND;
sl@0
   775
	delete cleanup;
sl@0
   776
	return(KErrNone);
sl@0
   777
    }