os/kernelhwsrv/kerneltest/f32test/bench/t_fsrrepeat.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) 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_fsrrepeat.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 "t_select.h"
sl@0
    21
#include "t_benchmain.h"
sl@0
    22
sl@0
    23
sl@0
    24
GLDEF_D RTest test(_L("FS Benchmarks, Open and read 4 KB"));
sl@0
    25
sl@0
    26
//----------------------------------------------------------------------------------------------
sl@0
    27
//! @SYMTestCaseID      PBASE-T_FSRREPEAT-0276
sl@0
    28
//! @SYMTestType        CIT
sl@0
    29
//! @SYMPREQ            PREQ000
sl@0
    30
//! @SYMTestCaseDesc    This test case is measuring performance of the FAT implementation
sl@0
    31
//! @SYMTestActions     0.  Expects the files to exist in order to successful execution
sl@0
    32
//!						1.	Time the opening and read 3 times 4 Kb of last.txt file in each directory 
sl@0
    33
//!						2.	Time the opening and read 3 times 4 Kb of last.txt file in each directory 
sl@0
    34
//!							with two  clients accessing the directory 
sl@0
    35
//!						3.	Time the opening and read 3 times of 4 Kb of last.txt file in each directory 
sl@0
    36
//!							with two clients accessing different directories
sl@0
    37
//!
sl@0
    38
//! @SYMTestExpectedResults Finishes if the system behaves as expected, panics otherwise
sl@0
    39
//! @SYMTestPriority        High
sl@0
    40
//! @SYMTestStatus          Implemented
sl@0
    41
//----------------------------------------------------------------------------------------------
sl@0
    42
sl@0
    43
sl@0
    44
LOCAL_D RSemaphore client,write_screen;
sl@0
    45
LOCAL_D const TInt KHeapSize=0x4000;
sl@0
    46
sl@0
    47
LOCAL_D TDriveList gDriveList;
sl@0
    48
sl@0
    49
LOCAL_D TFileName gDelEntryDir;
sl@0
    50
LOCAL_D TFileName gDelEntryDir2;
sl@0
    51
sl@0
    52
// Concurrent threads
sl@0
    53
RThread gSpeedy;
sl@0
    54
RThread gSpeedyII;
sl@0
    55
TInt gT1;
sl@0
    56
TInt gT2;
sl@0
    57
TBool gKillMe = EFalse; 
sl@0
    58
sl@0
    59
LOCAL_D TInt ThreadCount = 0;
sl@0
    60
LOCAL_D TBuf8<4096> buf;
sl@0
    61
sl@0
    62
_LIT(KDirMultipleName2, "dir%d_%d\\");
sl@0
    63
sl@0
    64
_LIT(KDeleteMe,"DELETE%d.ME");
sl@0
    65
_LIT(KDeleteMe2,"BLABLA%d.RHD");
sl@0
    66
sl@0
    67
sl@0
    68
/** Delete entry in directory
sl@0
    69
sl@0
    70
*/
sl@0
    71
LOCAL_C TInt DeleteEntryAccess2(TAny* )
sl@0
    72
	{
sl@0
    73
	RFs fs;
sl@0
    74
	TInt r = fs.Connect();
sl@0
    75
	TBuf<100> dirfile;
sl@0
    76
	TBuf<50> filename;
sl@0
    77
	RFile file;
sl@0
    78
sl@0
    79
	fs.SetSessionPath(gSessionPath);
sl@0
    80
	filename.Format(KDeleteMe2, gT2);
sl@0
    81
	
sl@0
    82
	dirfile = gDelEntryDir2;
sl@0
    83
	dirfile.Append(filename);
sl@0
    84
	
sl@0
    85
	client.Signal();
sl@0
    86
	
sl@0
    87
	FOREVER
sl@0
    88
		{
sl@0
    89
		if(!gKillMe)
sl@0
    90
			{
sl@0
    91
			r = file.Create(fs, dirfile, EFileShareAny|EFileWrite);
sl@0
    92
			if(r == KErrAlreadyExists) 
sl@0
    93
				r = file.Open(fs, dirfile, EFileShareAny|EFileWrite);
sl@0
    94
			file.Close();
sl@0
    95
			FailIfError(r);
sl@0
    96
			
sl@0
    97
			r = fs.Delete(dirfile);
sl@0
    98
			if((r != KErrNone) && (r != KErrInUse)) 
sl@0
    99
				{
sl@0
   100
				test.Printf(_L("error = %d\n"), r);
sl@0
   101
				}				
sl@0
   102
			test((r == KErrNone) || (r == KErrInUse));
sl@0
   103
			}
sl@0
   104
		}
sl@0
   105
	}
sl@0
   106
sl@0
   107
/** Delete entry in directory
sl@0
   108
sl@0
   109
*/
sl@0
   110
LOCAL_C TInt DeleteEntryAccess(TAny*)
sl@0
   111
	{
sl@0
   112
	RFs fs2;
sl@0
   113
	TInt r = fs2.Connect();
sl@0
   114
	TBuf<100> dirfile;
sl@0
   115
	TBuf<50> filename;
sl@0
   116
	RFile file2;
sl@0
   117
	RTest test(_L("test 2")); 
sl@0
   118
	
sl@0
   119
	fs2.SetSessionPath(gSessionPath);
sl@0
   120
	filename.Format(KDeleteMe,gT1);
sl@0
   121
	
sl@0
   122
	dirfile = gDelEntryDir;
sl@0
   123
	dirfile.Append(filename);
sl@0
   124
	
sl@0
   125
	client.Signal();
sl@0
   126
	
sl@0
   127
	FOREVER
sl@0
   128
		{
sl@0
   129
		if(!gKillMe)
sl@0
   130
			{
sl@0
   131
			r = file2.Create(fs2, dirfile, EFileShareAny|EFileWrite);
sl@0
   132
			if(r == KErrAlreadyExists) 
sl@0
   133
				r = file2.Open(fs2, dirfile, EFileShareAny|EFileWrite);
sl@0
   134
			file2.Close();
sl@0
   135
			FailIfError(r);
sl@0
   136
			
sl@0
   137
			r = fs2.Delete(dirfile);
sl@0
   138
			if((r != KErrNone) && (r != KErrInUse)) 
sl@0
   139
				{
sl@0
   140
				test.Printf(_L("error = %d\n"), r);
sl@0
   141
				}
sl@0
   142
			test((r == KErrNone) || (r == KErrInUse));			 
sl@0
   143
			}
sl@0
   144
		}
sl@0
   145
	}
sl@0
   146
sl@0
   147
/** Starts two concurrent client sessions in different directories
sl@0
   148
sl@0
   149
*/
sl@0
   150
LOCAL_C void DoTest2(TThreadFunction aFunction)
sl@0
   151
	{
sl@0
   152
	gKillMe = EFalse;
sl@0
   153
sl@0
   154
	TBuf<20> buf = _L("Speedy");
sl@0
   155
	buf.AppendNum(ThreadCount++);
sl@0
   156
	gT1 = ThreadCount;
sl@0
   157
	TInt r = gSpeedy.Create(buf, aFunction, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
sl@0
   158
	FailIfError(r);
sl@0
   159
sl@0
   160
	buf = _L("Speedy");
sl@0
   161
	buf.AppendNum(ThreadCount++);
sl@0
   162
	gT2 = ThreadCount;
sl@0
   163
	r = gSpeedyII.Create(buf, DeleteEntryAccess2, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
sl@0
   164
	FailIfError(r);
sl@0
   165
sl@0
   166
 	gSpeedy.SetPriority(EPriorityLess);
sl@0
   167
    gSpeedyII.SetPriority(EPriorityLess);
sl@0
   168
    
sl@0
   169
	gSpeedy.Resume();
sl@0
   170
	gSpeedyII.Resume();
sl@0
   171
	
sl@0
   172
	client.Wait();
sl@0
   173
	client.Wait();
sl@0
   174
	}
sl@0
   175
	
sl@0
   176
/** Kills the concurrent session
sl@0
   177
sl@0
   178
*/
sl@0
   179
LOCAL_C void DoTestKill()
sl@0
   180
	{
sl@0
   181
	gKillMe = ETrue;
sl@0
   182
	User::After(10000000);
sl@0
   183
	
sl@0
   184
	gSpeedy.Kill(KErrNone);
sl@0
   185
	gSpeedy.Close();	
sl@0
   186
	
sl@0
   187
	gSpeedyII.Kill(KErrNone);
sl@0
   188
	gSpeedyII.Close();	
sl@0
   189
	}
sl@0
   190
sl@0
   191
/** Open last.txt with RFs and without any other process
sl@0
   192
sl@0
   193
	@param aN 		Number of files in the directory
sl@0
   194
	@param aType	Type of files 
sl@0
   195
	@param aStep 	Test step
sl@0
   196
*/
sl@0
   197
LOCAL_C void OpenFile(TInt aN, TInt aType, TInt aStep) 
sl@0
   198
	{
sl@0
   199
	TBuf16<100> file;
sl@0
   200
    TBuf16<100> dir;
sl@0
   201
	
sl@0
   202
	TInt r = 0;
sl@0
   203
	TTime startTime;
sl@0
   204
	TTime endTime;
sl@0
   205
	TTimeIntervalMicroSeconds timeTaken(0);
sl@0
   206
	TInt timeTakenArray[3] = {-1, -1, -1};
sl@0
   207
	TInt i;
sl@0
   208
	RFile f;
sl@0
   209
	
sl@0
   210
	if(aN <= gFilesLimit) 
sl@0
   211
		{
sl@0
   212
		if(aType <= gTypes)
sl@0
   213
			{
sl@0
   214
			file = gSessionPath;
sl@0
   215
			
sl@0
   216
			dir.Format(KDirMultipleName2, aType, aN);
sl@0
   217
			file.Append(dir);
sl@0
   218
sl@0
   219
			file.Append(KCommonFile);
sl@0
   220
				
sl@0
   221
			i = 0;
sl@0
   222
			while(i < 3) 
sl@0
   223
				{	
sl@0
   224
				startTime.HomeTime();
sl@0
   225
				
sl@0
   226
				r = f.Open(TheFs, file, EFileShareAny|EFileRead);
sl@0
   227
				FailIfError(r);
sl@0
   228
				r = f.Read(buf);
sl@0
   229
				FailIfError(r);
sl@0
   230
				
sl@0
   231
				f.Close();
sl@0
   232
				
sl@0
   233
				endTime.HomeTime();
sl@0
   234
sl@0
   235
				timeTaken = endTime.MicroSecondsFrom(startTime);
sl@0
   236
				timeTakenArray[i++] = I64LOW(timeTaken.Int64() / gTimeUnit);
sl@0
   237
				}
sl@0
   238
			}
sl@0
   239
		}
sl@0
   240
	
sl@0
   241
	dir.Format(KDirMultipleName,aType,aN);
sl@0
   242
	
sl@0
   243
	PrintResultS(aStep, 1, dir);
sl@0
   244
	PrintResultTime(aStep, 2, timeTakenArray[0]);
sl@0
   245
	PrintResultTime(aStep, 3, timeTakenArray[1]);
sl@0
   246
	PrintResultTime(aStep, 4, timeTakenArray[2]);
sl@0
   247
	}
sl@0
   248
sl@0
   249
/** Times the opening of a file and read operation
sl@0
   250
	Precondition: This test expects the drive already filled with the right files
sl@0
   251
	
sl@0
   252
	@param aSelector Configuration in case of manual execution
sl@0
   253
*/
sl@0
   254
LOCAL_C TInt TestOpen(TAny* aSelector)
sl@0
   255
	{
sl@0
   256
	TInt i = 100, j;
sl@0
   257
	TInt testStep;
sl@0
   258
sl@0
   259
	Validate(aSelector);
sl@0
   260
sl@0
   261
	test.Printf(_L("#~TS_Title_%d,%d: Open last.txt and read 4 K repeatedly, RFs::Open\n"), gTestHarness, gTestCase);
sl@0
   262
	
sl@0
   263
	i = 100;
sl@0
   264
	testStep = 1;
sl@0
   265
	while(i <= KMaxFiles)
sl@0
   266
		{	
sl@0
   267
		if(i == 100 || i == 1000 || i == 5000 || i == 10000)
sl@0
   268
			{
sl@0
   269
			j = 1;
sl@0
   270
			while(j <= KMaxTypes) 
sl@0
   271
				{
sl@0
   272
				OpenFile(i, j, testStep++);
sl@0
   273
				j++;
sl@0
   274
				}
sl@0
   275
			}
sl@0
   276
		i += 100;
sl@0
   277
		}
sl@0
   278
	
sl@0
   279
	gTestCase++;
sl@0
   280
	return(KErrNone);
sl@0
   281
	}
sl@0
   282
sl@0
   283
/** Times the opening of a file and read operation with two threads accessing 
sl@0
   284
	different directories
sl@0
   285
sl@0
   286
	@param aSelector Configuration in case of manual execution
sl@0
   287
*/
sl@0
   288
LOCAL_C TInt TestOpenMultSame(TAny* aSelector)
sl@0
   289
	{
sl@0
   290
	TInt i = 100,j;
sl@0
   291
	TBuf16<50> directory;
sl@0
   292
	TBuf16<50> dirtemp;
sl@0
   293
	TInt testStep;	
sl@0
   294
	
sl@0
   295
	Validate(aSelector);
sl@0
   296
sl@0
   297
	test.Printf(_L("#~TS_Title_%d,%d: Open last.txt and read 4 K repeatedly with mult clients accessing, RFs::Open\n"), gTestHarness, gTestCase);
sl@0
   298
		
sl@0
   299
	i = 100;
sl@0
   300
	testStep = 1;
sl@0
   301
	while(i <= KMaxFiles)
sl@0
   302
		{	
sl@0
   303
		if(i == 100 || i == 1000 || i == 5000 || i == 10000)
sl@0
   304
			{
sl@0
   305
			j = 1;
sl@0
   306
			while(j <= KMaxTypes) 
sl@0
   307
				{
sl@0
   308
				directory = gSessionPath;
sl@0
   309
				dirtemp.Format(KDirMultipleName2, j, i);
sl@0
   310
				directory.Append(dirtemp);
sl@0
   311
				gDelEntryDir = directory;
sl@0
   312
				gDelEntryDir2 = directory;
sl@0
   313
sl@0
   314
				DoTest2(DeleteEntryAccess);
sl@0
   315
sl@0
   316
				OpenFile(i, j, testStep++);
sl@0
   317
sl@0
   318
				DoTestKill();
sl@0
   319
sl@0
   320
				j++;
sl@0
   321
				}
sl@0
   322
			}
sl@0
   323
		i += 100;
sl@0
   324
		}
sl@0
   325
sl@0
   326
	gTestCase++;
sl@0
   327
	return(KErrNone);
sl@0
   328
	}
sl@0
   329
sl@0
   330
/** Times the opening of a file and read operation with two threads accessing 
sl@0
   331
	different directories
sl@0
   332
sl@0
   333
	@param aSelector Configuration in case of manual execution
sl@0
   334
*/
sl@0
   335
LOCAL_C TInt TestOpenMultDif(TAny* aSelector)
sl@0
   336
	{
sl@0
   337
	TInt i = 100,j;
sl@0
   338
	TBuf16<50> directory;
sl@0
   339
	TBuf16<50> dirtemp;
sl@0
   340
	TInt testStep;
sl@0
   341
		
sl@0
   342
	Validate(aSelector);
sl@0
   343
sl@0
   344
	CreateDirWithNFiles(300,3);				
sl@0
   345
	
sl@0
   346
	directory = gSessionPath;
sl@0
   347
	dirtemp.Format(KDirMultipleName2, 3, 300);
sl@0
   348
	directory.Append(dirtemp);
sl@0
   349
	
sl@0
   350
	gDelEntryDir2 = directory;
sl@0
   351
sl@0
   352
	test.Printf(_L("#~TS_Title_%d,%d: Open last.txt and read 4 K repeatedly mult clients accessing dif dirs, RFs::Open\n"), gTestHarness, gTestCase);
sl@0
   353
	
sl@0
   354
	i = 100;
sl@0
   355
	testStep = 1;
sl@0
   356
	while(i <= KMaxFiles)
sl@0
   357
		{	
sl@0
   358
		if(i == 100 || i == 1000 || i == 5000 || i == 10000)
sl@0
   359
			{
sl@0
   360
			j = 1;
sl@0
   361
			while(j <= KMaxTypes) 
sl@0
   362
				{
sl@0
   363
				directory = gSessionPath;
sl@0
   364
				dirtemp.Format(KDirMultipleName2, j, i);
sl@0
   365
				directory.Append(dirtemp);
sl@0
   366
				gDelEntryDir = directory;
sl@0
   367
sl@0
   368
				DoTest2(DeleteEntryAccess);
sl@0
   369
sl@0
   370
				OpenFile(i, j, testStep++);
sl@0
   371
sl@0
   372
				DoTestKill();
sl@0
   373
				
sl@0
   374
				j++;
sl@0
   375
				}
sl@0
   376
			}
sl@0
   377
		i += 100;
sl@0
   378
		}
sl@0
   379
sl@0
   380
	gTestCase++;
sl@0
   381
	return(KErrNone);
sl@0
   382
	}
sl@0
   383
sl@0
   384
/** It goes automatically through all the options
sl@0
   385
sl@0
   386
	@param aSelector Configuration in case of manual execution
sl@0
   387
*/
sl@0
   388
LOCAL_C TInt TestAll(TAny* aSelector)
sl@0
   389
	{
sl@0
   390
	
sl@0
   391
 	TestOpen(aSelector);
sl@0
   392
 	TestOpenMultSame(aSelector);
sl@0
   393
 	TestOpenMultDif(aSelector);
sl@0
   394
sl@0
   395
	return(KErrNone);
sl@0
   396
	}
sl@0
   397
sl@0
   398
/** Call all tests
sl@0
   399
sl@0
   400
*/
sl@0
   401
GLDEF_C void CallTestsL()
sl@0
   402
	{
sl@0
   403
sl@0
   404
	TInt r=client.CreateLocal(0);
sl@0
   405
	FailIfError(r);
sl@0
   406
	
sl@0
   407
	gFileSize = 8;
sl@0
   408
sl@0
   409
	// Each test case of the suite has an identifyer for parsing purposes of the results
sl@0
   410
	gTestHarness = 5; 	
sl@0
   411
	gTestCase = 1;
sl@0
   412
		
sl@0
   413
	PrintHeaders(2, _L("t_fsrrepeat. Repeat reading"));
sl@0
   414
sl@0
   415
	CSelectionBox* TheSelector = CSelectionBox::NewL(test.Console());
sl@0
   416
	
sl@0
   417
	
sl@0
   418
	if(gMode == 0) 
sl@0
   419
		{ // Manual
sl@0
   420
		gSessionPath = _L("?:\\");
sl@0
   421
		TCallBack createFiles(TestFileCreate,TheSelector);
sl@0
   422
		TCallBack openF(TestOpen,TheSelector);
sl@0
   423
		TCallBack openMultSame(TestOpenMultSame,TheSelector);
sl@0
   424
		TCallBack openMultDif(TestOpenMultDif,TheSelector);
sl@0
   425
		TCallBack openAll(TestAll,TheSelector);
sl@0
   426
		TheSelector->AddDriveSelectorL(TheFs);
sl@0
   427
		TheSelector->AddLineL(_L("Create all files"),createFiles);
sl@0
   428
		TheSelector->AddLineL(_L("Open and read repeatedly"),openF);
sl@0
   429
		TheSelector->AddLineL(_L("Same mult clients same dir "),openMultSame);
sl@0
   430
		TheSelector->AddLineL(_L("Same mult clients dif dir"),openMultDif);
sl@0
   431
		TheSelector->AddLineL(_L("Execute all options"),openAll);
sl@0
   432
		TheSelector->Run();
sl@0
   433
		}
sl@0
   434
	else 
sl@0
   435
		{ // Automatic
sl@0
   436
		TestAll(TheSelector);
sl@0
   437
		}
sl@0
   438
		
sl@0
   439
	client.Close();
sl@0
   440
	test.Printf(_L("#~TestEnd_%d\n"), gTestHarness);
sl@0
   441
	delete TheSelector;
sl@0
   442
	}