sl@0: // Copyright (c) 2010 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: MDS harvesting performance test sl@0: // sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "t_sqlcmdlineutil.h" sl@0: sl@0: RTest TheTest(_L("t_sqlperformance5 test")); sl@0: RSqlDatabase TheDb; sl@0: sl@0: _LIT(KDbName, "c:\\test\\t_sqlperformance5.db"); sl@0: sl@0: TFileName TheDbFileName; sl@0: TBuf<200> TheTestTitle; sl@0: TCmdLineParams TheCmdLineParams(TCmdLineParams::EDbUtf16, 16384, 32); sl@0: TBuf8<200> TheSqlConfigString; sl@0: sl@0: _LIT(KUtf8, "UTF8 "); sl@0: _LIT(KUtf16, "UTF16"); sl@0: sl@0: const TInt KThumbnailCount = 60; sl@0: const TInt KMaxThumbnailSize = 40 * 1024; sl@0: sl@0: const TInt KThumbnailSizes[KThumbnailCount] = sl@0: { sl@0: //1 2 3 4 5 6 7 8 9 10 sl@0: 22054, 24076, 33281, 24733, 33094, 31443, 29264, 28725, 31798, 29322, //1 sl@0: 25002, 26926, 31097, 21988, 33659, 29081, 33050, 36857, 37686, 24034, //2 sl@0: 21093, 28314, 20186, 27222, 28600, 32735, 27279, 31898, 31380, 36316, //3 sl@0: 34295, 31642, 21829, 32912, 31584, 32557, 36601, 22744, 32808, 26130, //4 sl@0: 31222, 21545, 35899, 22257, 25856, 31169, 34893, 23496, 23034, 30381, //5 sl@0: 25810, 27123, 33442, 22275, 30260, 31028, 32415, 27345, 26614, 33704 //6 sl@0: }; sl@0: sl@0: TInt TheFastCounterFreq = 0; sl@0: sl@0: TInt TheCreateDbTime = 0; sl@0: TInt TheCreateTablesTime = 0; sl@0: TInt TheBindParamsTime = 0; sl@0: TInt TheStmtExecTime = 0; sl@0: TInt TheStmtResetTime = 0; sl@0: TInt ThePopulateTempTableTime = 0; sl@0: TInt TheFlushTime = 0; sl@0: sl@0: //////////////////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: void TestEnvDestroy() sl@0: { sl@0: TheDb.Close(); sl@0: (void)RSqlDatabase::Delete(TheDbFileName); sl@0: ResetSoftHeapLimit(); sl@0: } sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: //Test macros and functions sl@0: void Check1(TInt aValue, TInt aLine) sl@0: { sl@0: if(!aValue) sl@0: { sl@0: TestEnvDestroy(); sl@0: TheTest.Printf(_L("*** Line %d\r\n"), aLine); sl@0: TheTest(EFalse, aLine); sl@0: } sl@0: } sl@0: void Check2(TInt aValue, TInt aExpected, TInt aLine) sl@0: { sl@0: if(aValue != aExpected) sl@0: { sl@0: TSqlRetCodeClass cl = SqlRetCodeClass(aValue); sl@0: if(cl == ESqlDbError) sl@0: { sl@0: TPtrC errmsg = TheDb.LastErrorMessage(); sl@0: TheTest.Printf(_L("*** SQLite err=\"%S\"\r\n"), &errmsg); sl@0: } sl@0: TestEnvDestroy(); sl@0: TheTest.Printf(_L("*** Line %d, Expected error: %d, got: %d\r\n"), aLine, aExpected, aValue); sl@0: TheTest(EFalse, aLine); sl@0: } sl@0: } sl@0: #define TEST(arg) ::Check1((arg), __LINE__) sl@0: #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__) sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: void TestEnvInit() sl@0: { sl@0: RFs fs; sl@0: TInt err = fs.Connect(); sl@0: TEST2(err, KErrNone); sl@0: err = fs.MkDirAll(TheDbFileName); sl@0: TEST(err == KErrNone || err == KErrAlreadyExists); sl@0: fs.Close(); sl@0: } sl@0: sl@0: TInt TimeDiffUs(TUint32 aStartTicks, TUint32 aEndTicks) sl@0: { sl@0: if(TheFastCounterFreq == 0) sl@0: { sl@0: TEST2(HAL::Get(HAL::EFastCounterFrequency, TheFastCounterFreq), KErrNone); sl@0: TheTest.Printf(_L("==Fast counter frequency: %d Hz\r\n"), TheFastCounterFreq); 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: const TInt KMicroSecIn1Sec = 1000000; sl@0: TInt us = (diffTicks * KMicroSecIn1Sec) / TheFastCounterFreq; sl@0: return us; sl@0: } sl@0: sl@0: void PrintTime(const TDesC& aFmt, TUint32 aStartTicks, TUint32 aEndTicks) sl@0: { sl@0: TInt us = TimeDiffUs(aStartTicks, aEndTicks); sl@0: TheTest.Printf(aFmt, us); sl@0: } sl@0: sl@0: //============================================================================= sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-SQL-CT-4205 sl@0: @SYMTestCaseDesc Thumbnail database performance test. sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions The test executes statements to create the thumbnail database. sl@0: @SYMTestExpectedResults The test must not fail sl@0: @SYMDEF ou1cimx1#362240 sl@0: */ sl@0: void CreateDb() sl@0: { sl@0: (void)RSqlDatabase::Delete(TheDbFileName); sl@0: sl@0: TUint32 fc1 = User::FastCounter(); sl@0: sl@0: TInt err = TheDb.Create(TheDbFileName, &TheSqlConfigString); sl@0: sl@0: TUint32 fc2 = User::FastCounter(); sl@0: TheCreateDbTime = TimeDiffUs(fc1, fc2); sl@0: sl@0: TEST2(err, KErrNone); sl@0: sl@0: fc1 = User::FastCounter(); sl@0: sl@0: err = TheDb.Exec(_L("CREATE TABLE ThumbnailInfo (Path TEXT COLLATE NOCASE,TNId INTEGER,Size INTEGER,Format INTEGER,TNPath TEXT COLLATE NOCASE,Width INTEGER,Height INTEGER,OrigWidth INTEGER,OrigHeight INTEGER,Flags INTEGER,VideoPosition INTEGER,Orientation INTEGER,humbFromPath INTEGER,Modified LARGEINT);")); sl@0: TEST(err >= 0); sl@0: sl@0: err = TheDb.Exec(_L("CREATE TABLE ThumbnailInfoData(Data BLOB);")); sl@0: TEST(err >= 0); sl@0: sl@0: err = TheDb.Exec(_L("CREATE TABLE ThumbnailDeleted(Path TEXT UNIQUE COLLATE NOCASE);")); sl@0: TEST(err >= 0); sl@0: sl@0: err = TheDb.Exec(_L("CREATE INDEX idx1 ON ThumbnailInfo(Path, Size);")); sl@0: TEST(err >= 0); sl@0: sl@0: err = TheDb.Exec(_L("CREATE INDEX idx4 ON ThumbnailDeleted(Path);")); sl@0: TEST(err >= 0); sl@0: sl@0: err = TheDb.Exec(_L("CREATE TABLE ThumbnailVersion (Major INTEGER,Minor INTEGER,IMEI TEXT COLLATE NOCASE);")); sl@0: TEST(err >= 0); sl@0: sl@0: fc2 = User::FastCounter(); sl@0: TheCreateTablesTime = TimeDiffUs(fc1, fc2); sl@0: sl@0: TheDb.Close(); sl@0: } sl@0: sl@0: void PoulateTempTables(RSqlStatement& aStmt1, RSqlStatement& aStmt2) sl@0: { sl@0: HBufC8* thumbnailBuf = HBufC8::New(KMaxThumbnailSize); sl@0: TEST(thumbnailBuf != NULL); sl@0: TPtr8 thumbnailData = thumbnailBuf->Des(); sl@0: thumbnailData.SetLength(KMaxThumbnailSize); sl@0: thumbnailData.Fill(TChar('A')); sl@0: sl@0: TUint32 fc3 = User::FastCounter(); sl@0: sl@0: for(TInt i=0;i= 0); sl@0: TInt err = aStmt1.BindText(paramIndex, _L("c:\\test\\abcdefgh123456789.jpg")); sl@0: TEST2(err, KErrNone); sl@0: sl@0: paramIndex = aStmt1.ParameterIndex(_L(":Width")); sl@0: TEST(paramIndex >= 0); sl@0: err = aStmt1.BindInt(paramIndex, 50); sl@0: TEST2(err, KErrNone); sl@0: sl@0: paramIndex = aStmt1.ParameterIndex(_L(":Height")); sl@0: TEST(paramIndex >= 0); sl@0: err = aStmt1.BindInt(paramIndex, 40); sl@0: TEST2(err, KErrNone); sl@0: sl@0: paramIndex = aStmt1.ParameterIndex(_L(":OrigWidth")); sl@0: TEST(paramIndex >= 0); sl@0: err = aStmt1.BindInt(paramIndex, 1000); sl@0: TEST2(err, KErrNone); sl@0: sl@0: paramIndex = aStmt1.ParameterIndex(_L(":OrigHeight")); sl@0: TEST(paramIndex >= 0); sl@0: err = aStmt1.BindInt(paramIndex, 2000); sl@0: TEST2(err, KErrNone); sl@0: sl@0: paramIndex = aStmt1.ParameterIndex(_L(":Format")); sl@0: TEST(paramIndex >= 0); sl@0: err = aStmt1.BindInt(paramIndex, 10); sl@0: TEST2(err, KErrNone); sl@0: sl@0: paramIndex = aStmt1.ParameterIndex(_L(":Flags")); sl@0: TEST(paramIndex >= 0); sl@0: err = aStmt1.BindInt(paramIndex, 0x1E); sl@0: TEST2(err, KErrNone); sl@0: sl@0: paramIndex = aStmt1.ParameterIndex(_L(":Size")); sl@0: TEST(paramIndex >= 0); sl@0: err = aStmt1.BindInt(paramIndex, 1200); sl@0: TEST2(err, KErrNone); sl@0: sl@0: paramIndex = aStmt1.ParameterIndex(_L(":Orient")); sl@0: TEST(paramIndex >= 0); sl@0: err = aStmt1.BindInt(paramIndex, 2); sl@0: TEST2(err, KErrNone); sl@0: sl@0: paramIndex = aStmt1.ParameterIndex(_L(":ThumbFromPath")); sl@0: TEST(paramIndex >= 0); sl@0: err = aStmt1.BindInt(paramIndex, 1); sl@0: TEST2(err, KErrNone); sl@0: sl@0: paramIndex = aStmt1.ParameterIndex(_L(":Modified")); sl@0: TEST(paramIndex >= 0); sl@0: err = aStmt1.BindInt64(paramIndex, 3212398543392LL); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TUint32 fc2 = User::FastCounter(); sl@0: TheBindParamsTime += TimeDiffUs(fc1, fc2); sl@0: sl@0: fc1 = User::FastCounter(); sl@0: err = aStmt1.Exec(); sl@0: fc2 = User::FastCounter(); sl@0: TheStmtExecTime += TimeDiffUs(fc1, fc2); sl@0: sl@0: TEST2(err, 1); sl@0: sl@0: fc1 = User::FastCounter(); sl@0: err = aStmt1.Reset(); sl@0: fc2 = User::FastCounter(); sl@0: TheStmtResetTime += TimeDiffUs(fc1, fc2); sl@0: sl@0: TEST2(err, KErrNone); sl@0: sl@0: thumbnailData.SetLength(KThumbnailSizes[i]); sl@0: sl@0: fc1 = User::FastCounter(); sl@0: paramIndex = aStmt2.ParameterIndex(_L(":Data")); sl@0: TEST(paramIndex >= 0); sl@0: err = aStmt2.BindBinary(paramIndex, thumbnailData); sl@0: TEST2(err, KErrNone); sl@0: fc2 = User::FastCounter(); sl@0: TheBindParamsTime += TimeDiffUs(fc1, fc2); sl@0: sl@0: fc1 = User::FastCounter(); sl@0: err = aStmt2.Exec(); sl@0: fc2 = User::FastCounter(); sl@0: TheStmtExecTime += TimeDiffUs(fc1, fc2); sl@0: sl@0: TEST2(err, 1); sl@0: sl@0: fc1 = User::FastCounter(); sl@0: err = aStmt2.Reset(); sl@0: fc2 = User::FastCounter(); sl@0: TheStmtResetTime += TimeDiffUs(fc1, fc2); sl@0: sl@0: TEST2(err, KErrNone); sl@0: } sl@0: sl@0: TUint32 fc4 = User::FastCounter(); sl@0: ThePopulateTempTableTime += TimeDiffUs(fc3, fc4); sl@0: sl@0: delete thumbnailBuf; sl@0: } sl@0: sl@0: void FlushTempTables() sl@0: { sl@0: TUint32 fc1 = User::FastCounter(); sl@0: sl@0: TInt err = TheDb.Exec(_L("BEGIN TRANSACTION")); sl@0: TEST(err >= 0); sl@0: sl@0: err = TheDb.Exec(_L("INSERT INTO ThumbnailInfo SELECT * FROM TempThumbnailInfo;")); sl@0: TEST2(err, KThumbnailCount); sl@0: sl@0: err = TheDb.Exec(_L("INSERT INTO ThumbnailInfoData SELECT * FROM TempThumbnailInfoData;")); sl@0: TEST2(err, KThumbnailCount); sl@0: sl@0: err = TheDb.Exec(_L("DELETE FROM TempThumbnailInfo;")); sl@0: TEST(err >= 0); sl@0: sl@0: err = TheDb.Exec(_L("DELETE FROM TempThumbnailInfoData;")); sl@0: TEST(err >= 0); sl@0: sl@0: err = TheDb.Exec(_L("COMMIT;")); sl@0: TEST(err >= 0); sl@0: sl@0: TUint32 fc2 = User::FastCounter(); sl@0: TheFlushTime += TimeDiffUs(fc1, fc2); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-SQL-CT-4206 sl@0: @SYMTestCaseDesc Thumbnail database performance test. sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions The test inserts 60 thumbnails with summary size of 1.7Mb into the thumbnail database. sl@0: @SYMTestExpectedResults The test must not fail sl@0: @SYMDEF ou1cimx1#362240 sl@0: */ sl@0: void PopulateDb() sl@0: { sl@0: TInt dataToCommit = 0; sl@0: for(TInt i=0;i= 0); sl@0: sl@0: err = TheDb.Exec(_L("CREATE TEMP TABLE TempThumbnailInfoData (Data BLOB);")); sl@0: TEST(err >= 0); sl@0: sl@0: RSqlStatement stmt1; sl@0: err = stmt1.Prepare(TheDb, _L("INSERT INTO TempThumbnailInfo(Path,Size,Format,Width,Height,OrigWidth,OrigHeight,Flags,Orientation,ThumbFromPath,Modified) VALUES (:Path,:Size,:Format,:Width,:Height,:OrigWidth,:OrigHeight,:Flags,:Orient,:ThumbFromPath,:Modified);")); sl@0: TEST2(err, KErrNone); sl@0: sl@0: RSqlStatement stmt2; sl@0: err = stmt2.Prepare(TheDb, _L("INSERT INTO TempThumbnailInfoData (Data) VALUES (:Data);")); sl@0: TEST2(err, KErrNone); sl@0: sl@0: PoulateTempTables(stmt1, stmt2); sl@0: FlushTempTables(); sl@0: sl@0: stmt2.Close(); sl@0: stmt1.Close(); sl@0: TheDb.Close(); sl@0: sl@0: TheTest.Printf(_L("==Create database, time=%d microseconds\r\n"), TheCreateDbTime); sl@0: TheTest.Printf(_L("==Create tables, time=%d microseconds\r\n"), TheCreateTablesTime); sl@0: TheTest.Printf(_L("==Bind parameters time, time=%d microseconds\r\n"), TheBindParamsTime); sl@0: TheTest.Printf(_L("==Temp tables, statement exec, time=%d microseconds\r\n"), TheStmtExecTime); sl@0: TheTest.Printf(_L("==Temp tables, statement reset, time=%d microseconds\r\n"), TheStmtResetTime); sl@0: TheTest.Printf(_L("==Populate temp tables, time=%d microseconds\r\n"), ThePopulateTempTableTime); sl@0: TheTest.Printf(_L("==Copy temp tables to main tables, time=%d microseconds\r\n"), TheFlushTime); sl@0: } sl@0: sl@0: void DoTestsL() sl@0: { sl@0: TheTestTitle.Format(_L("@SYMTestCaseID:PDS-SQL-CT-4205 Create database, encoding: \"%S\", page size: %d\r\n"), sl@0: TheCmdLineParams.iDbEncoding == TCmdLineParams::EDbUtf16 ? &KUtf16 : &KUtf8, TheCmdLineParams.iPageSize); sl@0: TheTest.Start(TheTestTitle); sl@0: CreateDb(); sl@0: sl@0: TheTestTitle.Format(_L("@SYMTestCaseID:PDS-SQL-CT-4206 Populate database, encoding: \"%S\", page size: %d\r\n"), sl@0: TheCmdLineParams.iDbEncoding == TCmdLineParams::EDbUtf16 ? &KUtf16 : &KUtf8, TheCmdLineParams.iPageSize); sl@0: TheTest.Next(TheTestTitle); sl@0: PopulateDb(); sl@0: sl@0: (void)RSqlDatabase::Delete(TheDbFileName); sl@0: } sl@0: 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: __UHEAP_MARK; sl@0: sl@0: GetCmdLineParamsAndSqlConfigString(TheTest, _L("t_sqlperformance5"), TheCmdLineParams, TheSqlConfigString); sl@0: PrepareDbName(KDbName, TheCmdLineParams.iDriveName, TheDbFileName); sl@0: SetSoftHeapLimit(TheCmdLineParams.iSoftHeapLimitKb); sl@0: sl@0: TheTest.Printf(_L("==Databases: %S\r\n"), &TheDbFileName); sl@0: sl@0: TestEnvDestroy(); sl@0: TestEnvInit(); sl@0: TRAPD(err, DoTestsL()); sl@0: TestEnvDestroy(); sl@0: TEST2(err, KErrNone); 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: }