os/persistentdata/persistentstorage/store/TSTRM/t_storstreamperf.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) 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 "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
//
sl@0
    15
sl@0
    16
#include <e32test.h>
sl@0
    17
#include <s32file.h>
sl@0
    18
#include <s32fileiter.h>
sl@0
    19
#include <s32mem.h>
sl@0
    20
#include <hal.h>
sl@0
    21
sl@0
    22
RTest TheTest(_L("t_storstreamperf"));
sl@0
    23
RFs TheFs;
sl@0
    24
sl@0
    25
TFileName TheTestFile;
sl@0
    26
TFileName TheTestDir;
sl@0
    27
TFileName TheTestDictFile;
sl@0
    28
sl@0
    29
const TUid KDictFileUid = {19445};
sl@0
    30
const TUid KDictStrmUid1 = {19446};
sl@0
    31
const TUid KDictStrmUid2 = {19447};
sl@0
    32
sl@0
    33
const TInt KBufSize = 30000;
sl@0
    34
const TInt KIterCnt = 1000;
sl@0
    35
const TInt KTestDataLen = KBufSize / KIterCnt;
sl@0
    36
const TUint8 KTestData[KTestDataLen] = 
sl@0
    37
	{
sl@0
    38
	'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O',
sl@0
    39
	'P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3'
sl@0
    40
	};
sl@0
    41
const TPtrC8  KTestDes(KTestData, KTestDataLen);
sl@0
    42
sl@0
    43
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    44
sl@0
    45
void DestroyTestEnv()
sl@0
    46
	{
sl@0
    47
	(void)TheFs.Delete(TheTestDictFile);
sl@0
    48
	(void)TheFs.Delete(TheTestFile);
sl@0
    49
	TheFs.Close();
sl@0
    50
	}
sl@0
    51
sl@0
    52
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    53
//Test macros and functions
sl@0
    54
void Check(TInt aValue, TInt aLine)
sl@0
    55
	{
sl@0
    56
	if(!aValue)
sl@0
    57
		{
sl@0
    58
		TheTest.Printf(_L("*** Boolean expression evaluated to false\r\n"));
sl@0
    59
		DestroyTestEnv();
sl@0
    60
		TheTest(EFalse, aLine);
sl@0
    61
		}
sl@0
    62
	}
sl@0
    63
void Check(TInt aValue, TInt aExpected, TInt aLine)
sl@0
    64
	{
sl@0
    65
	if(aValue != aExpected)
sl@0
    66
		{
sl@0
    67
		DestroyTestEnv();
sl@0
    68
		TheTest.Printf(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
sl@0
    69
		TheTest(EFalse, aLine);
sl@0
    70
		}
sl@0
    71
	}
sl@0
    72
#define TEST(arg) ::Check((arg), __LINE__)
sl@0
    73
#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
sl@0
    74
sl@0
    75
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    76
sl@0
    77
void CreateTestEnv()
sl@0
    78
    {
sl@0
    79
	TInt err = TheFs.Connect();
sl@0
    80
	TheTest(err == KErrNone);
sl@0
    81
	
sl@0
    82
	err = TheFs.MkDirAll(TheTestFile);
sl@0
    83
	TEST(err == KErrNone || err == KErrAlreadyExists);
sl@0
    84
	}
sl@0
    85
sl@0
    86
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    87
sl@0
    88
static TInt TheCounterFreq = -10000000;
sl@0
    89
const TInt KMicroSecIn1Sec = 1000000;
sl@0
    90
sl@0
    91
TUint32 CalcTickDiff(TUint32 aStartTicks, TUint32 aEndTicks)
sl@0
    92
	{
sl@0
    93
	TInt64 diffTicks = (TInt64)aEndTicks - (TInt64)aStartTicks;
sl@0
    94
	if(diffTicks < 0)
sl@0
    95
		{
sl@0
    96
		diffTicks = KMaxTUint32 + diffTicks + 1;
sl@0
    97
		}
sl@0
    98
	return (TUint32)diffTicks;
sl@0
    99
	}
sl@0
   100
sl@0
   101
//Prints aFastCount parameter (converted to us)
sl@0
   102
void PrintFcDiffAsUs(const TDesC& aFormatStr, TUint32 aFastCount)
sl@0
   103
	{
sl@0
   104
	double v = ((double)aFastCount * KMicroSecIn1Sec) / (double)TheCounterFreq;
sl@0
   105
	TInt v2 = (TInt)v;
sl@0
   106
	TheTest.Printf(aFormatStr, v2);
sl@0
   107
	}
sl@0
   108
sl@0
   109
///////////////////////////////////////////////////////////////////////////////////////
sl@0
   110
sl@0
   111
//Testing RWriteStream performance.
sl@0
   112
void StreamWriteTestL(RWriteStream& aStream, TUint32& aWriteFc, TUint32& aCommitFc)
sl@0
   113
	{
sl@0
   114
	TUint32 fc = User::FastCounter();
sl@0
   115
	for(TInt i=0;i<KIterCnt;++i)
sl@0
   116
		{
sl@0
   117
		aStream.WriteL(KTestDes);
sl@0
   118
		}
sl@0
   119
	TUint32 fc2 = User::FastCounter();
sl@0
   120
	aStream.CommitL();
sl@0
   121
	TUint32 fc3 = User::FastCounter();
sl@0
   122
	
sl@0
   123
	aWriteFc = CalcTickDiff(fc, fc2);
sl@0
   124
	aCommitFc = CalcTickDiff(fc2, fc3);
sl@0
   125
	}
sl@0
   126
sl@0
   127
void DoStreamWriteTestL(RWriteStream& aStream)
sl@0
   128
	{
sl@0
   129
	TUint32 writeFc = 0, commitFc = 0;
sl@0
   130
	StreamWriteTestL(aStream, writeFc, commitFc);
sl@0
   131
	PrintFcDiffAsUs(_L("###     RWriteStream::WriteL(),  Time=%d us\r\n"), writeFc);
sl@0
   132
	PrintFcDiffAsUs(_L("###     RWriteStream::CommitL(), Time=%d us\r\n"), commitFc);
sl@0
   133
	}
sl@0
   134
sl@0
   135
//Testing RReadStream performance.
sl@0
   136
void StreamReadTestL(RReadStream& aStream, TUint32& aReadFc)
sl@0
   137
	{
sl@0
   138
	TBuf8<KTestDataLen> buf;
sl@0
   139
	TUint32 fc = User::FastCounter();
sl@0
   140
	for(TInt i=0;i<KIterCnt;++i)
sl@0
   141
		{
sl@0
   142
		aStream.ReadL(buf);
sl@0
   143
		}
sl@0
   144
	TUint32 fc2 = User::FastCounter();
sl@0
   145
	TEST(buf == KTestDes);
sl@0
   146
sl@0
   147
	aReadFc = CalcTickDiff(fc, fc2);
sl@0
   148
	}
sl@0
   149
sl@0
   150
void DoStreamReadTestL(RReadStream& aStream)
sl@0
   151
	{
sl@0
   152
	TUint32 readFc = 0;
sl@0
   153
	StreamReadTestL(aStream, readFc);
sl@0
   154
	PrintFcDiffAsUs(_L("###     RReadStream::ReadL(),   Time=%d us\r\n"), readFc);
sl@0
   155
	}
sl@0
   156
sl@0
   157
///////////////////////////////////////////////////////////////////////////////////////
sl@0
   158
sl@0
   159
void GetFastCounterFrequency()
sl@0
   160
	{
sl@0
   161
	TEST2(HAL::Get(HAL::EFastCounterFrequency, TheCounterFreq), KErrNone);
sl@0
   162
	TheTest.Printf(_L("Counter frequency=%d Hz\r\n"), TheCounterFreq);
sl@0
   163
	}
sl@0
   164
sl@0
   165
/**
sl@0
   166
@SYMTestCaseID			PDS-STORE-UT-4053
sl@0
   167
@SYMTestCaseDesc		Test for DEF141471 - STORE, new stream performance tests.
sl@0
   168
						PREQ2505 Insturmentation of PDS.
sl@0
   169
						RDictionaryWriteStream & RDictionaryReadStream performance tests.
sl@0
   170
@SYMTestPriority		High
sl@0
   171
@SYMTestActions			Test for DEF141471 - STORE, new stream performance tests.
sl@0
   172
@SYMTestExpectedResults Test must not fail
sl@0
   173
@SYMDEF					DEF141471
sl@0
   174
*/
sl@0
   175
void DictionaryStreamTestL()
sl@0
   176
	{
sl@0
   177
	(void)TheFs.Delete(TheTestDictFile);
sl@0
   178
	CDictionaryFileStore* store = CDictionaryFileStore::OpenLC(TheFs, TheTestDictFile, KDictFileUid);
sl@0
   179
	
sl@0
   180
	//RDictionaryWriteStream::AssignL()
sl@0
   181
	RDictionaryWriteStream strm1;
sl@0
   182
	CleanupClosePushL(strm1);
sl@0
   183
	TUint32 fc = User::FastCounter();
sl@0
   184
	strm1.AssignL(*store, KDictStrmUid1);
sl@0
   185
	TUint32 assignFc = CalcTickDiff(fc, User::FastCounter());
sl@0
   186
	PrintFcDiffAsUs(_L("###  RDictionaryWriteStream::AssignL(), Time=%d us\r\n"), assignFc);
sl@0
   187
	DoStreamWriteTestL(strm1);
sl@0
   188
	CleanupStack::PopAndDestroy(&strm1);
sl@0
   189
	
sl@0
   190
	//RDictionaryWriteStream::AssignLC()
sl@0
   191
	RDictionaryWriteStream strm2;
sl@0
   192
	fc = User::FastCounter();
sl@0
   193
	strm2.AssignLC(*store, KDictStrmUid2);
sl@0
   194
	assignFc = CalcTickDiff(fc, User::FastCounter());
sl@0
   195
	PrintFcDiffAsUs(_L("###  RDictionaryWriteStream::AssignLC(), Time=%d us\r\n"), assignFc);
sl@0
   196
	DoStreamWriteTestL(strm2);
sl@0
   197
	CleanupStack::PopAndDestroy(&strm2);
sl@0
   198
sl@0
   199
	//RDictionaryReadStream::OpenL()
sl@0
   200
	RDictionaryReadStream strm3;
sl@0
   201
	CleanupClosePushL(strm3);
sl@0
   202
	fc = User::FastCounter();
sl@0
   203
	strm3.OpenL(*store, KDictStrmUid1);
sl@0
   204
	TUint32 openFc = CalcTickDiff(fc, User::FastCounter());
sl@0
   205
	PrintFcDiffAsUs(_L("###  RDictionaryReadStream::OpenL(), Time=%d us\r\n"), openFc);
sl@0
   206
	DoStreamReadTestL(strm3);
sl@0
   207
	CleanupStack::PopAndDestroy(&strm3);
sl@0
   208
sl@0
   209
	//RDictionaryReadStream::OpenLC()
sl@0
   210
	RDictionaryReadStream strm4;
sl@0
   211
	fc = User::FastCounter();
sl@0
   212
	strm4.OpenLC(*store, KDictStrmUid2);
sl@0
   213
	openFc = CalcTickDiff(fc, User::FastCounter());
sl@0
   214
	PrintFcDiffAsUs(_L("###  RDictionaryReadStream::OpenLC(), Time=%d us\r\n"), openFc);
sl@0
   215
	DoStreamReadTestL(strm4);
sl@0
   216
	CleanupStack::PopAndDestroy(&strm4);
sl@0
   217
	
sl@0
   218
	CleanupStack::PopAndDestroy(store);
sl@0
   219
	}
sl@0
   220
sl@0
   221
/**
sl@0
   222
@SYMTestCaseID			PDS-STORE-UT-4054
sl@0
   223
@SYMTestCaseDesc		Test for DEF141471 - STORE, new stream performance tests.
sl@0
   224
						PREQ2505 Insturmentation of PDS.
sl@0
   225
						RFileWriteStream & RFileReadStream performance tests.
sl@0
   226
@SYMTestPriority		High
sl@0
   227
@SYMTestActions			Test for DEF141471 - STORE, new stream performance tests.
sl@0
   228
@SYMTestExpectedResults Test must not fail
sl@0
   229
@SYMDEF					DEF141471
sl@0
   230
*/
sl@0
   231
void FileStreamTestL()
sl@0
   232
	{
sl@0
   233
	(void)TheFs.Delete(TheTestFile);
sl@0
   234
	
sl@0
   235
	//RFileWriteStream::Create()
sl@0
   236
	RFileWriteStream strm1;
sl@0
   237
	TUint32 fc = User::FastCounter();
sl@0
   238
	TInt err = strm1.Create(TheFs, TheTestFile, EFileWrite | EFileRead);
sl@0
   239
	TUint32 createFc = CalcTickDiff(fc, User::FastCounter());
sl@0
   240
	TEST2(err, KErrNone);
sl@0
   241
	PrintFcDiffAsUs(_L("###  RFileWriteStream::Create(), Time=%d us\r\n"), createFc);
sl@0
   242
	strm1.Close();
sl@0
   243
	
sl@0
   244
	//RFileWriteStream::Replace()
sl@0
   245
	RFileWriteStream strm2;
sl@0
   246
	fc = User::FastCounter();
sl@0
   247
	err = strm2.Replace(TheFs, TheTestFile, EFileWrite | EFileRead);
sl@0
   248
	TUint32 replaceFc = CalcTickDiff(fc, User::FastCounter());
sl@0
   249
	TEST2(err, KErrNone);
sl@0
   250
	PrintFcDiffAsUs(_L("###  RFileWriteStream::Replace(), Time=%d us\r\n"), replaceFc);
sl@0
   251
	strm2.Close();
sl@0
   252
	
sl@0
   253
	//RFileWriteStream::Open()
sl@0
   254
	RFileWriteStream strm3;
sl@0
   255
	fc = User::FastCounter();
sl@0
   256
	err = strm3.Open(TheFs, TheTestFile, EFileWrite | EFileRead);
sl@0
   257
	TUint32 openFc = CalcTickDiff(fc, User::FastCounter());
sl@0
   258
	TEST2(err, KErrNone);
sl@0
   259
	PrintFcDiffAsUs(_L("###  RFileWriteStream::Open(), Time=%d us\r\n"), openFc);
sl@0
   260
	strm3.Close();
sl@0
   261
	
sl@0
   262
	//RFileWriteStream::Attach()
sl@0
   263
	RFile file;
sl@0
   264
	err = file.Open(TheFs, TheTestFile, EFileWrite | EFileRead);
sl@0
   265
	TEST2(err, KErrNone);
sl@0
   266
	RFileWriteStream strm4;
sl@0
   267
	CleanupClosePushL(strm4);
sl@0
   268
	fc = User::FastCounter();
sl@0
   269
	strm4.Attach(file);
sl@0
   270
	TUint32 attachFc = CalcTickDiff(fc, User::FastCounter());
sl@0
   271
	PrintFcDiffAsUs(_L("###  RFileWriteStream::Attach(), Time=%d us\r\n"), attachFc);
sl@0
   272
	DoStreamWriteTestL(strm4);
sl@0
   273
	CleanupStack::PopAndDestroy(&strm4);
sl@0
   274
	
sl@0
   275
	//RFileWriteStream::Temp()
sl@0
   276
	RFileWriteStream strm5;
sl@0
   277
	CleanupClosePushL(strm5);
sl@0
   278
	TFileName fname;
sl@0
   279
	fc = User::FastCounter();
sl@0
   280
	err = strm5.Temp(TheFs, TheTestDir, fname, EFileWrite | EFileRead);
sl@0
   281
	TUint32 tempFc = CalcTickDiff(fc, User::FastCounter());
sl@0
   282
	TEST2(err, KErrNone);
sl@0
   283
	PrintFcDiffAsUs(_L("###  RFileWriteStream::Temp(), Time=%d us\r\n"), tempFc);
sl@0
   284
	DoStreamWriteTestL(strm5);
sl@0
   285
	CleanupStack::PopAndDestroy(&strm5);
sl@0
   286
	err = TheFs.Delete(fname);
sl@0
   287
	TEST2(err, KErrNone);
sl@0
   288
	
sl@0
   289
	//RFileReadStream::Open()
sl@0
   290
	RFileReadStream strm6;
sl@0
   291
	fc = User::FastCounter();
sl@0
   292
	err = strm6.Open(TheFs, TheTestFile, EFileRead);
sl@0
   293
	openFc = CalcTickDiff(fc, User::FastCounter());
sl@0
   294
	PrintFcDiffAsUs(_L("###  RFileReadStream::Open(), Time=%d us\r\n"), openFc);
sl@0
   295
	strm6.Close();
sl@0
   296
sl@0
   297
	//RFileReadStream::Attach()
sl@0
   298
	err = file.Open(TheFs, TheTestFile, EFileRead);
sl@0
   299
	TEST2(err, KErrNone);
sl@0
   300
	RFileReadStream strm7;
sl@0
   301
	fc = User::FastCounter();
sl@0
   302
	strm7.Attach(file);
sl@0
   303
	attachFc = CalcTickDiff(fc, User::FastCounter());
sl@0
   304
	PrintFcDiffAsUs(_L("###  RFileReadStream::Attach(), Time=%d us\r\n"), attachFc);
sl@0
   305
	strm7.Close();
sl@0
   306
sl@0
   307
	//RFileReadStream::RFileReadStream(RFile&)
sl@0
   308
	err = file.Open(TheFs, TheTestFile, EFileRead);
sl@0
   309
	TEST2(err, KErrNone);
sl@0
   310
	fc = User::FastCounter();
sl@0
   311
	RFileReadStream strm8(file);
sl@0
   312
	TUint32 constrFc = CalcTickDiff(fc, User::FastCounter());
sl@0
   313
	CleanupClosePushL(strm8);
sl@0
   314
	PrintFcDiffAsUs(_L("###  RFileReadStream::RFileReadStream(RFile&), Time=%d us\r\n"), constrFc);
sl@0
   315
	DoStreamReadTestL(strm8);
sl@0
   316
	CleanupStack::PopAndDestroy(&strm8);
sl@0
   317
	}
sl@0
   318
sl@0
   319
/**
sl@0
   320
@SYMTestCaseID			PDS-STORE-UT-4055
sl@0
   321
@SYMTestCaseDesc		Test for DEF141471 - STORE, new stream performance tests.
sl@0
   322
						PREQ2505 Insturmentation of PDS.
sl@0
   323
						RMemWriteStream & RMemReadStream performance tests.
sl@0
   324
@SYMTestPriority		High
sl@0
   325
@SYMTestActions			Test for DEF141471 - STORE, new stream performance tests.
sl@0
   326
@SYMTestExpectedResults Test must not fail
sl@0
   327
@SYMDEF					DEF141471
sl@0
   328
*/
sl@0
   329
void MemStreamTestL()
sl@0
   330
	{
sl@0
   331
	HBufC8* buf = HBufC8::NewLC(KBufSize);
sl@0
   332
	TPtr8 bufPtr = buf->Des();
sl@0
   333
sl@0
   334
	//RMemWriteStream::Open()	
sl@0
   335
	RMemWriteStream strm1;
sl@0
   336
	TUint32 fc = User::FastCounter();
sl@0
   337
	strm1.Open(const_cast <TUint8*> (bufPtr.Ptr()), KBufSize);
sl@0
   338
	TUint32 openFc = CalcTickDiff(fc, User::FastCounter());
sl@0
   339
	PrintFcDiffAsUs(_L("###  RMemWriteStream::Open(), Time=%d us\r\n"), openFc);
sl@0
   340
	strm1.Close();
sl@0
   341
	
sl@0
   342
	//RMemWriteStream::RMemWriteStream(TAny*,...)	
sl@0
   343
	fc = User::FastCounter();
sl@0
   344
	RMemWriteStream strm2(const_cast <TUint8*> (bufPtr.Ptr()), KBufSize);
sl@0
   345
	TUint32 constrFc = CalcTickDiff(fc, User::FastCounter());
sl@0
   346
	PrintFcDiffAsUs(_L("###  RMemWriteStream::RMemWriteStream(TAny*,...), Time=%d us\r\n"), constrFc);
sl@0
   347
	CleanupClosePushL(strm2);
sl@0
   348
	DoStreamWriteTestL(strm2);
sl@0
   349
	CleanupStack::PopAndDestroy(&strm2);
sl@0
   350
	
sl@0
   351
	//RMemReadStream::Open()
sl@0
   352
	RMemReadStream strm3;
sl@0
   353
	fc = User::FastCounter();
sl@0
   354
	strm3.Open(bufPtr.Ptr(), KBufSize);
sl@0
   355
	openFc = CalcTickDiff(fc, User::FastCounter());
sl@0
   356
	PrintFcDiffAsUs(_L("###  RMemReadStream::Open(), Time=%d us\r\n"), openFc);
sl@0
   357
	strm3.Close();
sl@0
   358
sl@0
   359
	//RMemReadStream::RMemReadStream(TAny*,...)	
sl@0
   360
	fc = User::FastCounter();
sl@0
   361
	RMemReadStream strm4(bufPtr.Ptr(), KBufSize);
sl@0
   362
	constrFc = CalcTickDiff(fc, User::FastCounter());
sl@0
   363
	PrintFcDiffAsUs(_L("###  RMemReadStream::RMemReadStream(TAny*,...), Time=%d us\r\n"), openFc);
sl@0
   364
	CleanupClosePushL(strm4);
sl@0
   365
	DoStreamReadTestL(strm4);
sl@0
   366
	CleanupStack::PopAndDestroy(&strm4);
sl@0
   367
	
sl@0
   368
	CleanupStack::PopAndDestroy(buf);
sl@0
   369
	}
sl@0
   370
sl@0
   371
/**
sl@0
   372
@SYMTestCaseID			PDS-STORE-UT-4056
sl@0
   373
@SYMTestCaseDesc		Test for DEF141471 - STORE, new stream performance tests.
sl@0
   374
						PREQ2505 Insturmentation of PDS.
sl@0
   375
						RBufWriteStream & RBufReadStream performance tests.
sl@0
   376
@SYMTestPriority		High
sl@0
   377
@SYMTestActions			Test for DEF141471 - STORE, new stream performance tests.
sl@0
   378
@SYMTestExpectedResults Test must not fail
sl@0
   379
@SYMDEF					DEF141471
sl@0
   380
*/
sl@0
   381
void BufStreamTestL()
sl@0
   382
	{
sl@0
   383
	CBufFlat* bufFlat = CBufFlat::NewL(KTestDataLen);
sl@0
   384
	CleanupStack::PushL(bufFlat);
sl@0
   385
	
sl@0
   386
	//RBufWriteStream::Open()
sl@0
   387
	RBufWriteStream strm1;
sl@0
   388
	CleanupClosePushL(strm1);
sl@0
   389
	TUint32 fc = User::FastCounter();
sl@0
   390
	strm1.Open(*bufFlat);
sl@0
   391
	TUint32 openFc = CalcTickDiff(fc, User::FastCounter());
sl@0
   392
	PrintFcDiffAsUs(_L("###  RBufWriteStream::Open(), Time=%d us\r\n"), openFc);
sl@0
   393
	DoStreamWriteTestL(strm1);
sl@0
   394
	CleanupStack::PopAndDestroy(&strm1);
sl@0
   395
	TheTest.Printf(_L("       Buffer size=%d\r\n"), bufFlat->Size());
sl@0
   396
sl@0
   397
	//RBufWriteStream::Append()
sl@0
   398
	RBufWriteStream strm2;
sl@0
   399
	CleanupClosePushL(strm2);
sl@0
   400
	fc = User::FastCounter();
sl@0
   401
	strm2.Append(*bufFlat);
sl@0
   402
	TUint32 appendFc = CalcTickDiff(fc, User::FastCounter());
sl@0
   403
	PrintFcDiffAsUs(_L("###  RBufWriteStream::Append(), Time=%d us\r\n"), appendFc);
sl@0
   404
	DoStreamWriteTestL(strm2);
sl@0
   405
	CleanupStack::PopAndDestroy(&strm2);
sl@0
   406
	TheTest.Printf(_L("       Buffer size=%d\r\n"), bufFlat->Size());
sl@0
   407
	
sl@0
   408
	//RBufWriteStream::Insert()
sl@0
   409
	RBufWriteStream strm3;
sl@0
   410
	CleanupClosePushL(strm3);
sl@0
   411
	fc = User::FastCounter();
sl@0
   412
	strm3.Insert(*bufFlat, KBufSize);
sl@0
   413
	TUint32 insertFc = CalcTickDiff(fc, User::FastCounter());
sl@0
   414
	PrintFcDiffAsUs(_L("###  RBufWriteStream::Insert(), Time=%d us\r\n"), insertFc);
sl@0
   415
	DoStreamWriteTestL(strm3);
sl@0
   416
	CleanupStack::PopAndDestroy(&strm3);
sl@0
   417
	TheTest.Printf(_L("       Buffer size=%d\r\n"), bufFlat->Size());
sl@0
   418
	
sl@0
   419
	//RBufWriteStream::Truncate()
sl@0
   420
	RBufWriteStream strm4;
sl@0
   421
	CleanupClosePushL(strm4);
sl@0
   422
	fc = User::FastCounter();
sl@0
   423
	strm4.Truncate(*bufFlat);
sl@0
   424
	TUint32 truncateFc = CalcTickDiff(fc, User::FastCounter());
sl@0
   425
	PrintFcDiffAsUs(_L("###  RBufWriteStream::Truncate(), Time=%d us\r\n"), truncateFc);
sl@0
   426
	DoStreamWriteTestL(strm4);
sl@0
   427
	CleanupStack::PopAndDestroy(&strm4);
sl@0
   428
	TheTest.Printf(_L("       Buffer size=%d\r\n"), bufFlat->Size());
sl@0
   429
	
sl@0
   430
	RBufReadStream strm5;
sl@0
   431
	CleanupClosePushL(strm5);
sl@0
   432
	fc = User::FastCounter();
sl@0
   433
	strm5.Open(*bufFlat);
sl@0
   434
	openFc = CalcTickDiff(fc, User::FastCounter());
sl@0
   435
	PrintFcDiffAsUs(_L("###  RBufReadStream::Open(), Time=%d us\r\n"), openFc);
sl@0
   436
	DoStreamReadTestL(strm5);
sl@0
   437
	CleanupStack::PopAndDestroy(&strm5);
sl@0
   438
	
sl@0
   439
	CleanupStack::PopAndDestroy(bufFlat);
sl@0
   440
	}
sl@0
   441
sl@0
   442
/** 
sl@0
   443
@SYMTestCaseID			PDS-STORE-UT-4057
sl@0
   444
@SYMTestCaseDesc		Test for DEF141471 - STORE, new stream performance tests.
sl@0
   445
						PREQ2505 Insturmentation of PDS.
sl@0
   446
						RPermanentFileStoreIter performance tests.
sl@0
   447
@SYMTestPriority		High
sl@0
   448
@SYMTestActions			Test for DEF141471 - STORE, new stream performance tests.
sl@0
   449
@SYMTestExpectedResults Test must not fail
sl@0
   450
@SYMDEF					DEF141471
sl@0
   451
*/
sl@0
   452
void PermanentFileStoreIterTestL()
sl@0
   453
	{
sl@0
   454
	(void)TheFs.Delete(TheTestFile);
sl@0
   455
sl@0
   456
	CPermanentFileStore* store = CPermanentFileStore::ReplaceLC(TheFs, TheTestFile, EFileWrite | EFileRead);
sl@0
   457
	store->SetTypeL(KPermanentFileStoreLayoutUid);
sl@0
   458
	
sl@0
   459
	//Create streams
sl@0
   460
	const TInt KStreamCnt = 10;
sl@0
   461
	TStreamId streamId[KStreamCnt] = {0}; 	
sl@0
   462
	TheTest.Printf(_L("###  CPermanentFileStore, create %d streams\r\n"), KStreamCnt);
sl@0
   463
	for(TInt i=0;i<KStreamCnt;i++)
sl@0
   464
		{
sl@0
   465
		RStoreWriteStream out;
sl@0
   466
		streamId[i] = out.CreateLC(*store);
sl@0
   467
		TheTest.Printf(_L("###    Stream##%02d, streamId=%08X\r\n"), i + 1, streamId[i].Value());
sl@0
   468
		DoStreamWriteTestL(out);
sl@0
   469
		CleanupStack::PopAndDestroy(&out);
sl@0
   470
		}
sl@0
   471
	TUint32 fc = User::FastCounter();
sl@0
   472
	store->CommitL();
sl@0
   473
	TUint32 commitFc = CalcTickDiff(fc, User::FastCounter());
sl@0
   474
	CleanupStack::PopAndDestroy(store);
sl@0
   475
	PrintFcDiffAsUs(_L("###  RPermanentFileStoreIter::CommitL(), Time=%d us\r\n"), commitFc);
sl@0
   476
	
sl@0
   477
	//RPermanentFileStoreIter::ResetL()
sl@0
   478
	store = CPermanentFileStore::OpenLC(TheFs, TheTestFile, EFileWrite | EFileRead);
sl@0
   479
	RPermanentFileStoreIter it1;
sl@0
   480
	CleanupClosePushL(it1);
sl@0
   481
	fc = User::FastCounter();
sl@0
   482
	it1.ResetL(*store);
sl@0
   483
	TUint32 resetFc = CalcTickDiff(fc, User::FastCounter());
sl@0
   484
	CleanupStack::PopAndDestroy(&it1);
sl@0
   485
	CleanupStack::PopAndDestroy(store);
sl@0
   486
	PrintFcDiffAsUs(_L("###  RPermanentFileStoreIter::ResetL(), Time=%d us\r\n"), resetFc);
sl@0
   487
sl@0
   488
	//RPermanentFileStoreIter::ResetLC()
sl@0
   489
	store = CPermanentFileStore::OpenLC(TheFs, TheTestFile, EFileWrite | EFileRead);
sl@0
   490
	RPermanentFileStoreIter it2;
sl@0
   491
	fc = User::FastCounter();
sl@0
   492
	it2.ResetLC(*store);
sl@0
   493
	resetFc = CalcTickDiff(fc, User::FastCounter());
sl@0
   494
	CleanupStack::PopAndDestroy(&it2);
sl@0
   495
	CleanupStack::PopAndDestroy(store);
sl@0
   496
	PrintFcDiffAsUs(_L("###  RPermanentFileStoreIter::ResetLC(), Time=%d us\r\n"), resetFc);
sl@0
   497
sl@0
   498
	//RPermanentFileStoreIter - construction & destruction
sl@0
   499
	store = CPermanentFileStore::OpenLC(TheFs, TheTestFile, EFileWrite | EFileRead);
sl@0
   500
	fc = User::FastCounter();
sl@0
   501
	RPermanentFileStoreIter it3;
sl@0
   502
	CleanupClosePushL(it3);
sl@0
   503
	it3.ResetL(*store);
sl@0
   504
	CleanupStack::PopAndDestroy(&it3);
sl@0
   505
	TUint32 fc2 = CalcTickDiff(fc, User::FastCounter());
sl@0
   506
	CleanupStack::PopAndDestroy(store);
sl@0
   507
	PrintFcDiffAsUs(_L("###  RPermanentFileStoreIter - construction & destruction, Time=%d us\r\n"), fc2);
sl@0
   508
sl@0
   509
	//RPermanentFileStoreIter::NextL()
sl@0
   510
	store = CPermanentFileStore::OpenLC(TheFs, TheTestFile, EFileWrite | EFileRead);
sl@0
   511
	RPermanentFileStoreIter it4;
sl@0
   512
	it4.ResetLC(*store);
sl@0
   513
	TStreamId id(KNullStreamIdValue);
sl@0
   514
	TInt cnt = 0;
sl@0
   515
	fc = User::FastCounter();
sl@0
   516
	while((id = it4.NextL()) != KNullStreamIdValue)
sl@0
   517
		{
sl@0
   518
		++cnt;
sl@0
   519
		}
sl@0
   520
	TUint32 nextFc = CalcTickDiff(fc, User::FastCounter());
sl@0
   521
	CleanupStack::PopAndDestroy(&it4);
sl@0
   522
	CleanupStack::PopAndDestroy(store);
sl@0
   523
	TEST2(cnt, KStreamCnt);
sl@0
   524
	PrintFcDiffAsUs(_L("###  RPermanentFileStoreIter::NextL(), Time=%d us\r\n"), nextFc);
sl@0
   525
	}
sl@0
   526
sl@0
   527
/**
sl@0
   528
@SYMTestCaseID          SYSLIB-STORE-CT-4007
sl@0
   529
@SYMTestCaseDesc	    CDirectFileStore::ReplaceLC() and SetTypeL() performance test
sl@0
   530
@SYMTestPriority 	    High
sl@0
   531
@SYMTestActions  	    Creates new CDirectFileStore object and measures the time of the operation. 
sl@0
   532
@SYMTestExpectedResults Tests set type time 
sl@0
   533
@SYMCR                  ATHE-7CQP8H
sl@0
   534
*/
sl@0
   535
void CreateDirectFileStoreTestL()
sl@0
   536
	{	
sl@0
   537
	(void)TheFs.Delete(TheTestFile);
sl@0
   538
	    
sl@0
   539
    TUint32 fc = User::FastCounter();
sl@0
   540
	CFileStore* store = CDirectFileStore::ReplaceLC(TheFs, TheTestFile, EFileWrite | EFileRead);
sl@0
   541
	// Must say what kind of file store
sl@0
   542
	// SetTypeL() calls RFileBuf::EndL() which used to call RFile::Size()
sl@0
   543
	store->SetTypeL(KDirectFileStoreLayoutUid);
sl@0
   544
	TUint32 time = CalcTickDiff(fc, User::FastCounter());
sl@0
   545
	CleanupStack::PopAndDestroy(store);
sl@0
   546
	PrintFcDiffAsUs(_L("###  CDirectFileStore::ReplaceLC() & SetTypeL(), Time=%d us\r\n"), time);
sl@0
   547
	}
sl@0
   548
sl@0
   549
/**
sl@0
   550
@SYMTestCaseID          SYSLIB-STORE-CT-4008
sl@0
   551
@SYMTestCaseDesc	    Tests performance when calling CFileStore::Destruct()
sl@0
   552
@SYMTestPriority 	    High
sl@0
   553
@SYMTestActions  	    Creates and deletes a File Store 
sl@0
   554
@SYMTestExpectedResults Tests deletion time 
sl@0
   555
@SYMCR                  ATHE-7CQP8H
sl@0
   556
*/
sl@0
   557
void DirectFileStoreTestL()
sl@0
   558
	{	
sl@0
   559
	(void)TheFs.Delete(TheTestFile);
sl@0
   560
	
sl@0
   561
    TUint32 fc = User::FastCounter();
sl@0
   562
	CFileStore* store = CDirectFileStore::ReplaceLC(TheFs, TheTestFile, EFileWrite | EFileRead);
sl@0
   563
	//then delete it. this calls CFileStore::Destruct(), which used to call Revert()
sl@0
   564
	CleanupStack::PopAndDestroy(store);
sl@0
   565
	TUint32 time = CalcTickDiff(fc, User::FastCounter());
sl@0
   566
	PrintFcDiffAsUs(_L("###  CDirectFileStore construction & destruction, Time=%d us\r\n"), time);
sl@0
   567
	}
sl@0
   568
sl@0
   569
void DoTestsL()
sl@0
   570
	{
sl@0
   571
	TheTest.Start(_L("Get fast counter frequency"));
sl@0
   572
	GetFastCounterFrequency();
sl@0
   573
	
sl@0
   574
	TheTest.Next(_L(" @SYMTestCaseID:PDS-STORE-UT-4053 RDictionaryWriteStream & RDictionaryReadStream - performance test"));
sl@0
   575
	DictionaryStreamTestL();
sl@0
   576
	
sl@0
   577
	TheTest.Next(_L(" @SYMTestCaseID:PDS-STORE-UT-4054 RFileWriteStream & RFileReadStream - performance test"));
sl@0
   578
	FileStreamTestL();
sl@0
   579
sl@0
   580
	TheTest.Next(_L(" @SYMTestCaseID:PDS-STORE-UT-4055 RMemWriteStream & RMemReadStream - performance test"));
sl@0
   581
	MemStreamTestL();
sl@0
   582
sl@0
   583
	TheTest.Next(_L(" @SYMTestCaseID:PDS-STORE-UT-4056 RBufWriteStream & RBufReadStream - performance test"));
sl@0
   584
	BufStreamTestL();
sl@0
   585
sl@0
   586
	TheTest.Next(_L(" @SYMTestCaseID:PDS-STORE-UT-4057 RPermanentFileStoreIter - performance test"));
sl@0
   587
	PermanentFileStoreIterTestL();
sl@0
   588
	
sl@0
   589
	TheTest.Next(_L(" @SYMTestCaseID SYSLIB-STORE-CT-4007 CDirectFileStore::ReplaceLC() & SetTypeL() performance test"));
sl@0
   590
	CreateDirectFileStoreTestL();
sl@0
   591
	
sl@0
   592
	TheTest.Next(_L(" @SYMTestCaseID SYSLIB-STORE-CT-4008 CDirectFileStore construction & destruction performance test"));
sl@0
   593
	DirectFileStoreTestL();
sl@0
   594
	}
sl@0
   595
sl@0
   596
//Usage: "t_streamperf [<drive letter>:]]"
sl@0
   597
TInt E32Main()
sl@0
   598
	{
sl@0
   599
	TheTest.Title();
sl@0
   600
sl@0
   601
	CTrapCleanup* tc = CTrapCleanup::New();
sl@0
   602
	TheTest(tc != NULL);
sl@0
   603
		
sl@0
   604
	TBuf<256> cmdline;
sl@0
   605
	User::CommandLine(cmdline);
sl@0
   606
sl@0
   607
	TParse parse;
sl@0
   608
sl@0
   609
	_LIT(KTestFile, "c:\\stor-tst\\t_streamperf.dat");
sl@0
   610
	parse.Set(cmdline, &KTestFile, 0);
sl@0
   611
	TheTestFile.Copy(parse.FullName());
sl@0
   612
sl@0
   613
	_LIT(KTestPath, "c:\\stor-tst\\");
sl@0
   614
	parse.Set(cmdline, &KTestPath, 0);
sl@0
   615
	TheTestDir.Copy(parse.FullName());
sl@0
   616
	
sl@0
   617
	_LIT(KDictFile, "c:\\stor-tst\\dicfile.ini");
sl@0
   618
	parse.Set(cmdline, &KDictFile, 0);
sl@0
   619
	TheTestDictFile.Copy(parse.FullName());
sl@0
   620
sl@0
   621
	__UHEAP_MARK;
sl@0
   622
sl@0
   623
	CreateTestEnv();
sl@0
   624
	TRAPD(err, DoTestsL());
sl@0
   625
	TEST2(err, KErrNone);
sl@0
   626
	DestroyTestEnv();
sl@0
   627
sl@0
   628
	__UHEAP_MARKEND;
sl@0
   629
sl@0
   630
	TheTest.End();
sl@0
   631
	TheTest.Close();
sl@0
   632
sl@0
   633
	delete tc;
sl@0
   634
sl@0
   635
	User::Heap().Check();
sl@0
   636
	return KErrNone;
sl@0
   637
	}