sl@0: // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: RTest TheTest(_L("t_storstreamperf")); sl@0: RFs TheFs; sl@0: sl@0: TFileName TheTestFile; sl@0: TFileName TheTestDir; sl@0: TFileName TheTestDictFile; sl@0: sl@0: const TUid KDictFileUid = {19445}; sl@0: const TUid KDictStrmUid1 = {19446}; sl@0: const TUid KDictStrmUid2 = {19447}; sl@0: sl@0: const TInt KBufSize = 30000; sl@0: const TInt KIterCnt = 1000; sl@0: const TInt KTestDataLen = KBufSize / KIterCnt; sl@0: const TUint8 KTestData[KTestDataLen] = sl@0: { sl@0: 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O', sl@0: 'P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3' sl@0: }; sl@0: const TPtrC8 KTestDes(KTestData, KTestDataLen); sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: void DestroyTestEnv() sl@0: { sl@0: (void)TheFs.Delete(TheTestDictFile); sl@0: (void)TheFs.Delete(TheTestFile); sl@0: TheFs.Close(); sl@0: } sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: //Test macros and functions sl@0: void Check(TInt aValue, TInt aLine) sl@0: { sl@0: if(!aValue) sl@0: { sl@0: TheTest.Printf(_L("*** Boolean expression evaluated to false\r\n")); sl@0: DestroyTestEnv(); sl@0: TheTest(EFalse, aLine); sl@0: } sl@0: } sl@0: void Check(TInt aValue, TInt aExpected, TInt aLine) sl@0: { sl@0: if(aValue != aExpected) sl@0: { sl@0: DestroyTestEnv(); sl@0: TheTest.Printf(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); sl@0: TheTest(EFalse, aLine); sl@0: } sl@0: } sl@0: #define TEST(arg) ::Check((arg), __LINE__) sl@0: #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: void CreateTestEnv() sl@0: { sl@0: TInt err = TheFs.Connect(); sl@0: TheTest(err == KErrNone); sl@0: sl@0: err = TheFs.MkDirAll(TheTestFile); sl@0: TEST(err == KErrNone || err == KErrAlreadyExists); sl@0: } sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: static TInt TheCounterFreq = -10000000; sl@0: const TInt KMicroSecIn1Sec = 1000000; sl@0: sl@0: TUint32 CalcTickDiff(TUint32 aStartTicks, TUint32 aEndTicks) sl@0: { sl@0: TInt64 diffTicks = (TInt64)aEndTicks - (TInt64)aStartTicks; sl@0: if(diffTicks < 0) sl@0: { sl@0: diffTicks = KMaxTUint32 + diffTicks + 1; sl@0: } sl@0: return (TUint32)diffTicks; sl@0: } sl@0: sl@0: //Prints aFastCount parameter (converted to us) sl@0: void PrintFcDiffAsUs(const TDesC& aFormatStr, TUint32 aFastCount) sl@0: { sl@0: double v = ((double)aFastCount * KMicroSecIn1Sec) / (double)TheCounterFreq; sl@0: TInt v2 = (TInt)v; sl@0: TheTest.Printf(aFormatStr, v2); sl@0: } sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: //Testing RWriteStream performance. sl@0: void StreamWriteTestL(RWriteStream& aStream, TUint32& aWriteFc, TUint32& aCommitFc) sl@0: { sl@0: TUint32 fc = User::FastCounter(); sl@0: for(TInt i=0;i buf; sl@0: TUint32 fc = User::FastCounter(); sl@0: for(TInt i=0;iDes(); sl@0: sl@0: //RMemWriteStream::Open() sl@0: RMemWriteStream strm1; sl@0: TUint32 fc = User::FastCounter(); sl@0: strm1.Open(const_cast (bufPtr.Ptr()), KBufSize); sl@0: TUint32 openFc = CalcTickDiff(fc, User::FastCounter()); sl@0: PrintFcDiffAsUs(_L("### RMemWriteStream::Open(), Time=%d us\r\n"), openFc); sl@0: strm1.Close(); sl@0: sl@0: //RMemWriteStream::RMemWriteStream(TAny*,...) sl@0: fc = User::FastCounter(); sl@0: RMemWriteStream strm2(const_cast (bufPtr.Ptr()), KBufSize); sl@0: TUint32 constrFc = CalcTickDiff(fc, User::FastCounter()); sl@0: PrintFcDiffAsUs(_L("### RMemWriteStream::RMemWriteStream(TAny*,...), Time=%d us\r\n"), constrFc); sl@0: CleanupClosePushL(strm2); sl@0: DoStreamWriteTestL(strm2); sl@0: CleanupStack::PopAndDestroy(&strm2); sl@0: sl@0: //RMemReadStream::Open() sl@0: RMemReadStream strm3; sl@0: fc = User::FastCounter(); sl@0: strm3.Open(bufPtr.Ptr(), KBufSize); sl@0: openFc = CalcTickDiff(fc, User::FastCounter()); sl@0: PrintFcDiffAsUs(_L("### RMemReadStream::Open(), Time=%d us\r\n"), openFc); sl@0: strm3.Close(); sl@0: sl@0: //RMemReadStream::RMemReadStream(TAny*,...) sl@0: fc = User::FastCounter(); sl@0: RMemReadStream strm4(bufPtr.Ptr(), KBufSize); sl@0: constrFc = CalcTickDiff(fc, User::FastCounter()); sl@0: PrintFcDiffAsUs(_L("### RMemReadStream::RMemReadStream(TAny*,...), Time=%d us\r\n"), openFc); sl@0: CleanupClosePushL(strm4); sl@0: DoStreamReadTestL(strm4); sl@0: CleanupStack::PopAndDestroy(&strm4); sl@0: sl@0: CleanupStack::PopAndDestroy(buf); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-STORE-UT-4056 sl@0: @SYMTestCaseDesc Test for DEF141471 - STORE, new stream performance tests. sl@0: PREQ2505 Insturmentation of PDS. sl@0: RBufWriteStream & RBufReadStream performance tests. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Test for DEF141471 - STORE, new stream performance tests. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF DEF141471 sl@0: */ sl@0: void BufStreamTestL() sl@0: { sl@0: CBufFlat* bufFlat = CBufFlat::NewL(KTestDataLen); sl@0: CleanupStack::PushL(bufFlat); sl@0: sl@0: //RBufWriteStream::Open() sl@0: RBufWriteStream strm1; sl@0: CleanupClosePushL(strm1); sl@0: TUint32 fc = User::FastCounter(); sl@0: strm1.Open(*bufFlat); sl@0: TUint32 openFc = CalcTickDiff(fc, User::FastCounter()); sl@0: PrintFcDiffAsUs(_L("### RBufWriteStream::Open(), Time=%d us\r\n"), openFc); sl@0: DoStreamWriteTestL(strm1); sl@0: CleanupStack::PopAndDestroy(&strm1); sl@0: TheTest.Printf(_L(" Buffer size=%d\r\n"), bufFlat->Size()); sl@0: sl@0: //RBufWriteStream::Append() sl@0: RBufWriteStream strm2; sl@0: CleanupClosePushL(strm2); sl@0: fc = User::FastCounter(); sl@0: strm2.Append(*bufFlat); sl@0: TUint32 appendFc = CalcTickDiff(fc, User::FastCounter()); sl@0: PrintFcDiffAsUs(_L("### RBufWriteStream::Append(), Time=%d us\r\n"), appendFc); sl@0: DoStreamWriteTestL(strm2); sl@0: CleanupStack::PopAndDestroy(&strm2); sl@0: TheTest.Printf(_L(" Buffer size=%d\r\n"), bufFlat->Size()); sl@0: sl@0: //RBufWriteStream::Insert() sl@0: RBufWriteStream strm3; sl@0: CleanupClosePushL(strm3); sl@0: fc = User::FastCounter(); sl@0: strm3.Insert(*bufFlat, KBufSize); sl@0: TUint32 insertFc = CalcTickDiff(fc, User::FastCounter()); sl@0: PrintFcDiffAsUs(_L("### RBufWriteStream::Insert(), Time=%d us\r\n"), insertFc); sl@0: DoStreamWriteTestL(strm3); sl@0: CleanupStack::PopAndDestroy(&strm3); sl@0: TheTest.Printf(_L(" Buffer size=%d\r\n"), bufFlat->Size()); sl@0: sl@0: //RBufWriteStream::Truncate() sl@0: RBufWriteStream strm4; sl@0: CleanupClosePushL(strm4); sl@0: fc = User::FastCounter(); sl@0: strm4.Truncate(*bufFlat); sl@0: TUint32 truncateFc = CalcTickDiff(fc, User::FastCounter()); sl@0: PrintFcDiffAsUs(_L("### RBufWriteStream::Truncate(), Time=%d us\r\n"), truncateFc); sl@0: DoStreamWriteTestL(strm4); sl@0: CleanupStack::PopAndDestroy(&strm4); sl@0: TheTest.Printf(_L(" Buffer size=%d\r\n"), bufFlat->Size()); sl@0: sl@0: RBufReadStream strm5; sl@0: CleanupClosePushL(strm5); sl@0: fc = User::FastCounter(); sl@0: strm5.Open(*bufFlat); sl@0: openFc = CalcTickDiff(fc, User::FastCounter()); sl@0: PrintFcDiffAsUs(_L("### RBufReadStream::Open(), Time=%d us\r\n"), openFc); sl@0: DoStreamReadTestL(strm5); sl@0: CleanupStack::PopAndDestroy(&strm5); sl@0: sl@0: CleanupStack::PopAndDestroy(bufFlat); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-STORE-UT-4057 sl@0: @SYMTestCaseDesc Test for DEF141471 - STORE, new stream performance tests. sl@0: PREQ2505 Insturmentation of PDS. sl@0: RPermanentFileStoreIter performance tests. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Test for DEF141471 - STORE, new stream performance tests. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF DEF141471 sl@0: */ sl@0: void PermanentFileStoreIterTestL() sl@0: { sl@0: (void)TheFs.Delete(TheTestFile); sl@0: sl@0: CPermanentFileStore* store = CPermanentFileStore::ReplaceLC(TheFs, TheTestFile, EFileWrite | EFileRead); sl@0: store->SetTypeL(KPermanentFileStoreLayoutUid); sl@0: sl@0: //Create streams sl@0: const TInt KStreamCnt = 10; sl@0: TStreamId streamId[KStreamCnt] = {0}; sl@0: TheTest.Printf(_L("### CPermanentFileStore, create %d streams\r\n"), KStreamCnt); sl@0: for(TInt i=0;iCommitL(); sl@0: TUint32 commitFc = CalcTickDiff(fc, User::FastCounter()); sl@0: CleanupStack::PopAndDestroy(store); sl@0: PrintFcDiffAsUs(_L("### RPermanentFileStoreIter::CommitL(), Time=%d us\r\n"), commitFc); sl@0: sl@0: //RPermanentFileStoreIter::ResetL() sl@0: store = CPermanentFileStore::OpenLC(TheFs, TheTestFile, EFileWrite | EFileRead); sl@0: RPermanentFileStoreIter it1; sl@0: CleanupClosePushL(it1); sl@0: fc = User::FastCounter(); sl@0: it1.ResetL(*store); sl@0: TUint32 resetFc = CalcTickDiff(fc, User::FastCounter()); sl@0: CleanupStack::PopAndDestroy(&it1); sl@0: CleanupStack::PopAndDestroy(store); sl@0: PrintFcDiffAsUs(_L("### RPermanentFileStoreIter::ResetL(), Time=%d us\r\n"), resetFc); sl@0: sl@0: //RPermanentFileStoreIter::ResetLC() sl@0: store = CPermanentFileStore::OpenLC(TheFs, TheTestFile, EFileWrite | EFileRead); sl@0: RPermanentFileStoreIter it2; sl@0: fc = User::FastCounter(); sl@0: it2.ResetLC(*store); sl@0: resetFc = CalcTickDiff(fc, User::FastCounter()); sl@0: CleanupStack::PopAndDestroy(&it2); sl@0: CleanupStack::PopAndDestroy(store); sl@0: PrintFcDiffAsUs(_L("### RPermanentFileStoreIter::ResetLC(), Time=%d us\r\n"), resetFc); sl@0: sl@0: //RPermanentFileStoreIter - construction & destruction sl@0: store = CPermanentFileStore::OpenLC(TheFs, TheTestFile, EFileWrite | EFileRead); sl@0: fc = User::FastCounter(); sl@0: RPermanentFileStoreIter it3; sl@0: CleanupClosePushL(it3); sl@0: it3.ResetL(*store); sl@0: CleanupStack::PopAndDestroy(&it3); sl@0: TUint32 fc2 = CalcTickDiff(fc, User::FastCounter()); sl@0: CleanupStack::PopAndDestroy(store); sl@0: PrintFcDiffAsUs(_L("### RPermanentFileStoreIter - construction & destruction, Time=%d us\r\n"), fc2); sl@0: sl@0: //RPermanentFileStoreIter::NextL() sl@0: store = CPermanentFileStore::OpenLC(TheFs, TheTestFile, EFileWrite | EFileRead); sl@0: RPermanentFileStoreIter it4; sl@0: it4.ResetLC(*store); sl@0: TStreamId id(KNullStreamIdValue); sl@0: TInt cnt = 0; sl@0: fc = User::FastCounter(); sl@0: while((id = it4.NextL()) != KNullStreamIdValue) sl@0: { sl@0: ++cnt; sl@0: } sl@0: TUint32 nextFc = CalcTickDiff(fc, User::FastCounter()); sl@0: CleanupStack::PopAndDestroy(&it4); sl@0: CleanupStack::PopAndDestroy(store); sl@0: TEST2(cnt, KStreamCnt); sl@0: PrintFcDiffAsUs(_L("### RPermanentFileStoreIter::NextL(), Time=%d us\r\n"), nextFc); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-STORE-CT-4007 sl@0: @SYMTestCaseDesc CDirectFileStore::ReplaceLC() and SetTypeL() performance test sl@0: @SYMTestPriority High sl@0: @SYMTestActions Creates new CDirectFileStore object and measures the time of the operation. sl@0: @SYMTestExpectedResults Tests set type time sl@0: @SYMCR ATHE-7CQP8H sl@0: */ sl@0: void CreateDirectFileStoreTestL() sl@0: { sl@0: (void)TheFs.Delete(TheTestFile); sl@0: sl@0: TUint32 fc = User::FastCounter(); sl@0: CFileStore* store = CDirectFileStore::ReplaceLC(TheFs, TheTestFile, EFileWrite | EFileRead); sl@0: // Must say what kind of file store sl@0: // SetTypeL() calls RFileBuf::EndL() which used to call RFile::Size() sl@0: store->SetTypeL(KDirectFileStoreLayoutUid); sl@0: TUint32 time = CalcTickDiff(fc, User::FastCounter()); sl@0: CleanupStack::PopAndDestroy(store); sl@0: PrintFcDiffAsUs(_L("### CDirectFileStore::ReplaceLC() & SetTypeL(), Time=%d us\r\n"), time); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-STORE-CT-4008 sl@0: @SYMTestCaseDesc Tests performance when calling CFileStore::Destruct() sl@0: @SYMTestPriority High sl@0: @SYMTestActions Creates and deletes a File Store sl@0: @SYMTestExpectedResults Tests deletion time sl@0: @SYMCR ATHE-7CQP8H sl@0: */ sl@0: void DirectFileStoreTestL() sl@0: { sl@0: (void)TheFs.Delete(TheTestFile); sl@0: sl@0: TUint32 fc = User::FastCounter(); sl@0: CFileStore* store = CDirectFileStore::ReplaceLC(TheFs, TheTestFile, EFileWrite | EFileRead); sl@0: //then delete it. this calls CFileStore::Destruct(), which used to call Revert() sl@0: CleanupStack::PopAndDestroy(store); sl@0: TUint32 time = CalcTickDiff(fc, User::FastCounter()); sl@0: PrintFcDiffAsUs(_L("### CDirectFileStore construction & destruction, Time=%d us\r\n"), time); sl@0: } sl@0: sl@0: void DoTestsL() sl@0: { sl@0: TheTest.Start(_L("Get fast counter frequency")); sl@0: GetFastCounterFrequency(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:PDS-STORE-UT-4053 RDictionaryWriteStream & RDictionaryReadStream - performance test")); sl@0: DictionaryStreamTestL(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:PDS-STORE-UT-4054 RFileWriteStream & RFileReadStream - performance test")); sl@0: FileStreamTestL(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:PDS-STORE-UT-4055 RMemWriteStream & RMemReadStream - performance test")); sl@0: MemStreamTestL(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:PDS-STORE-UT-4056 RBufWriteStream & RBufReadStream - performance test")); sl@0: BufStreamTestL(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:PDS-STORE-UT-4057 RPermanentFileStoreIter - performance test")); sl@0: PermanentFileStoreIterTestL(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID SYSLIB-STORE-CT-4007 CDirectFileStore::ReplaceLC() & SetTypeL() performance test")); sl@0: CreateDirectFileStoreTestL(); sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID SYSLIB-STORE-CT-4008 CDirectFileStore construction & destruction performance test")); sl@0: DirectFileStoreTestL(); sl@0: } sl@0: sl@0: //Usage: "t_streamperf [:]]" sl@0: TInt E32Main() sl@0: { sl@0: TheTest.Title(); sl@0: sl@0: CTrapCleanup* tc = CTrapCleanup::New(); sl@0: TheTest(tc != NULL); sl@0: sl@0: TBuf<256> cmdline; sl@0: User::CommandLine(cmdline); sl@0: sl@0: TParse parse; sl@0: sl@0: _LIT(KTestFile, "c:\\stor-tst\\t_streamperf.dat"); sl@0: parse.Set(cmdline, &KTestFile, 0); sl@0: TheTestFile.Copy(parse.FullName()); sl@0: sl@0: _LIT(KTestPath, "c:\\stor-tst\\"); sl@0: parse.Set(cmdline, &KTestPath, 0); sl@0: TheTestDir.Copy(parse.FullName()); sl@0: sl@0: _LIT(KDictFile, "c:\\stor-tst\\dicfile.ini"); sl@0: parse.Set(cmdline, &KDictFile, 0); sl@0: TheTestDictFile.Copy(parse.FullName()); sl@0: sl@0: __UHEAP_MARK; sl@0: sl@0: CreateTestEnv(); sl@0: TRAPD(err, DoTestsL()); sl@0: TEST2(err, KErrNone); sl@0: DestroyTestEnv(); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: TheTest.End(); sl@0: TheTest.Close(); sl@0: sl@0: delete tc; sl@0: sl@0: User::Heap().Check(); sl@0: return KErrNone; sl@0: }