sl@0: // Copyright (c) 2008-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: #include "sqliteTestUtl.h" sl@0: #include "t_sqliteperf.h" sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: const char* const KTestName = "t_sqliteperf test"; sl@0: sl@0: _LIT(KTestDir, "c:\\test\\"); sl@0: _LIT(KTestDbName, "c:\\test\\t_sqliteperf.db"); sl@0: _LIT8(KTestDbName8, "c:\\test\\t_sqliteperf.db\x0"); sl@0: sl@0: _LIT(KSqlSrvName, "sqlsrv.exe"); sl@0: sl@0: static RSqlDatabase TheDb; sl@0: sl@0: const TInt KInsertRecCnt = 1000; sl@0: const TInt KUpdateRecCnt = KInsertRecCnt / 10; sl@0: const TInt KDeleteRecCnt = KInsertRecCnt / 10; sl@0: const TInt KSelectRecCnt = KInsertRecCnt / 10; sl@0: sl@0: static TInt TheUpdateRecIds[KUpdateRecCnt] = {0}; sl@0: static TInt TheDeleteRecIds[KDeleteRecCnt] = {0}; sl@0: static TInt TheSelectRecIds[KSelectRecCnt] = {0}; sl@0: sl@0: static TInt TheInsertRecId = 0; sl@0: static TInt TheUpdateRecId = 0; sl@0: static TInt TheDeleteRecId = 0; sl@0: static TInt TheSelectRecId = 0; sl@0: sl@0: const char KMultiInsertSql[] = "INSERT INTO Tbl VALUES(:Id, 9234567890, 99.998, 'TEXT VALUE', x'AABBCCDDEEFF')"; sl@0: const char KMultiUpdateSql[] = "UPDATE Tbl SET D=11.113 WHERE I IN"; sl@0: const char KMultiDeleteSql[] = "DELETE FROM Tbl WHERE I IN"; sl@0: const char KMultiSelectSql[] = "SELECT I64,D,T,B FROM Tbl WHERE I IN"; sl@0: sl@0: const char KSingleInsertSql[] = "INSERT INTO Tbl VALUES(%d, 9234567890, 99.998, 'TEXT VALUE', x'AABBCCDDEEFF')"; sl@0: const char KSingleUpdateSql[] = "UPDATE Tbl SET D=11.113 WHERE I="; sl@0: const char KSingleDeleteSql[] = "DELETE FROM Tbl WHERE I="; sl@0: const char KSingleSelectSql[] = "SELECT I64,D,T,B FROM Tbl WHERE I="; sl@0: sl@0: //This buffer is used for SQL statement formatting. 2000 bytes should be enough as a buffer max length. sl@0: static TBuf8<2000> TheSqlBuf; sl@0: //This buffer is used for printf related formatting. 500 characters should be enough. sl@0: static TBuf<500> ThePrintBuf; sl@0: sl@0: #define UNUSED_VAR(a) (a) = (a) sl@0: #define UNUSED_PTR(a) a.Set(a) sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: extern "C" const char* TestDbName(void) sl@0: { sl@0: return (const char*)KTestDbName8().Ptr(); sl@0: } sl@0: sl@0: static void DeleteTestFiles() sl@0: { sl@0: TheDb.Close(); sl@0: (void)RSqlDatabase::Delete(KTestDbName); sl@0: } sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: //Test macros and functions sl@0: static void Check(TInt aValue, TInt aLine) sl@0: { sl@0: if(!aValue) sl@0: { sl@0: DeleteTestFiles(); sl@0: TestTestLine(EFalse, aLine); sl@0: } sl@0: } sl@0: static void Check(TInt aValue, TInt aExpected, TInt aLine) sl@0: { sl@0: if(aValue != aExpected) sl@0: { sl@0: DeleteTestFiles(); sl@0: RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); sl@0: TestTestLine(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: static TInt KillProcess(const TDesC& aProcessName) sl@0: { sl@0: TFullName name; sl@0: //RDebug::Print(_L("Find and kill \"%S\" process.\n"), &aProcessName); sl@0: TBuf<64> pattern(aProcessName); sl@0: TInt length = pattern.Length(); sl@0: pattern += _L("*"); sl@0: TFindProcess procFinder(pattern); sl@0: sl@0: while (procFinder.Next(name) == KErrNone) sl@0: { sl@0: if (name.Length() > length) sl@0: {//If found name is a string containing aProcessName string. sl@0: TChar c(name[length]); sl@0: if (c.IsAlphaDigit() || sl@0: c == TChar('_') || sl@0: c == TChar('-')) sl@0: { sl@0: // If the found name is other valid application name sl@0: // starting with aProcessName string. sl@0: //RDebug::Print(_L(":: Process name: \"%S\".\n"), &name); sl@0: continue; sl@0: } sl@0: } sl@0: RProcess proc; sl@0: if (proc.Open(name) == KErrNone) sl@0: { sl@0: proc.Kill(0); sl@0: //RDebug::Print(_L("\"%S\" process killed.\n"), &name); sl@0: } sl@0: proc.Close(); sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: static TInt TheCounterFreq = -10000000; sl@0: const TInt KMicroSecIn1Sec = 1000000; sl@0: sl@0: //Prints aFastCount parameter (converted to us) sl@0: static TInt FcDiff2Us(TUint32 aFastCount) sl@0: { sl@0: double v = ((double)aFastCount * KMicroSecIn1Sec) / (double)TheCounterFreq; sl@0: TInt v2 = (TInt)v; sl@0: return v2; sl@0: } sl@0: sl@0: static void GetFastCounterFrequency() sl@0: { sl@0: TEST2(HAL::Get(HAL::EFastCounterFrequency, TheCounterFreq), KErrNone); sl@0: TBuf8<32> printString; sl@0: printString.Format(_L8("Counter frequency=%d\r\n"), TheCounterFreq); sl@0: TestPrintf((const char*)printString.PtrZ()); sl@0: } sl@0: sl@0: extern "C" unsigned int FastCounterValue(void) sl@0: { sl@0: return User::FastCounter(); sl@0: } sl@0: sl@0: //The performance test case results are stored in the ThePerfTestResult array. sl@0: static TUint32 ThePerfTestResult[EPerfTestModeCnt][EPerfTestTypeCnt]; sl@0: sl@0: extern "C" void StorePerfTestResult(TPerfTestMode aMode, TPerfTestType aType, unsigned int aResult) sl@0: { sl@0: ThePerfTestResult[aMode][aType] = aResult; sl@0: } sl@0: sl@0: static void PrintPerfTestResults() sl@0: { sl@0: TBuf8<256> printString; sl@0: TInt r1 = FcDiff2Us(ThePerfTestResult[EPerfTestSqlMode] [EPerfTestMultiInsert]); sl@0: TInt r2 = FcDiff2Us(ThePerfTestResult[EPerfTestSqliteSqlMode] [EPerfTestMultiInsert]); sl@0: TInt r3 = FcDiff2Us(ThePerfTestResult[EPerfTestSqliteDefaultMode][EPerfTestMultiInsert]); sl@0: TInt r4 = (TInt)((Abs(r2 - r1) * 100.0) / r1); sl@0: TInt r5 = (TInt)((Abs(r3 - r1) * 100.0) / r1); sl@0: TestPrintf("### SQL SQLITE-SQL SQLITE-DEFAULT\r\n"); sl@0: printString.Format(_L8("###Multi Insert: %8dus %8dus %8dus %8d%%%% %8d%%%%\r\n"), r1, r2, r3, r2 > r1 ? -r4 : +r4, r3 > r1 ? -r5 : +r5); sl@0: TestPrintf((const char*)printString.PtrZ()); sl@0: sl@0: r1 = FcDiff2Us(ThePerfTestResult[EPerfTestSqlMode] [EPerfTestMultiUpdate]); sl@0: r2 = FcDiff2Us(ThePerfTestResult[EPerfTestSqliteSqlMode] [EPerfTestMultiUpdate]); sl@0: r3 = FcDiff2Us(ThePerfTestResult[EPerfTestSqliteDefaultMode][EPerfTestMultiUpdate]); sl@0: r4 = (TInt)((Abs(r2 - r1) * 100.0) / r1); sl@0: r5 = (TInt)((Abs(r3 - r1) * 100.0) / r1); sl@0: printString.Format(_L8("###Multi Update: %8dus %8dus %8dus %8d%%%% %8d%%%%\r\n"), r1, r2, r3, r2 > r1 ? -r4 : +r4, r3 > r1 ? -r5 : +r5); sl@0: TestPrintf((const char*)printString.PtrZ()); sl@0: sl@0: r1 = FcDiff2Us(ThePerfTestResult[EPerfTestSqlMode] [EPerfTestMultiDelete]); sl@0: r2 = FcDiff2Us(ThePerfTestResult[EPerfTestSqliteSqlMode] [EPerfTestMultiDelete]); sl@0: r3 = FcDiff2Us(ThePerfTestResult[EPerfTestSqliteDefaultMode][EPerfTestMultiDelete]); sl@0: r4 = (TInt)((Abs(r2 - r1) * 100.0) / r1); sl@0: r5 = (TInt)((Abs(r3 - r1) * 100.0) / r1); sl@0: printString.Format(_L8("###Multi Delete: %8dus %8dus %8dus %8d%%%% %8d%%%%\r\n"), r1, r2, r3, r2 > r1 ? -r4 : +r4, r3 > r1 ? -r5 : +r5); sl@0: TestPrintf((const char*)printString.PtrZ()); sl@0: sl@0: r1 = FcDiff2Us(ThePerfTestResult[EPerfTestSqlMode] [EPerfTestMultiSelect]); sl@0: r2 = FcDiff2Us(ThePerfTestResult[EPerfTestSqliteSqlMode] [EPerfTestMultiSelect]); sl@0: r3 = FcDiff2Us(ThePerfTestResult[EPerfTestSqliteDefaultMode][EPerfTestMultiSelect]); sl@0: r4 = (TInt)((Abs(r2 - r1) * 100.0) / r1); sl@0: r5 = (TInt)((Abs(r3 - r1) * 100.0) / r1); sl@0: printString.Format(_L8("###Multi Select: %8dus %8dus %8dus %8d%%%% %8d%%%%\r\n"), r1, r2, r3, r2 > r1 ? -r4 : +r4, r3 > r1 ? -r5 : +r5); sl@0: TestPrintf((const char*)printString.PtrZ()); sl@0: sl@0: r1 = FcDiff2Us(ThePerfTestResult[EPerfTestSqlMode] [EPerfTestSingleInsert]); sl@0: r2 = FcDiff2Us(ThePerfTestResult[EPerfTestSqliteSqlMode] [EPerfTestSingleInsert]); sl@0: r3 = FcDiff2Us(ThePerfTestResult[EPerfTestSqliteDefaultMode][EPerfTestSingleInsert]); sl@0: r4 = (TInt)((Abs(r2 - r1) * 100.0) / r1); sl@0: r5 = (TInt)((Abs(r3 - r1) * 100.0) / r1); sl@0: printString.Format(_L8("##Single Insert: %8dus %8dus %8dus %8d%%%% %8d%%%%\r\n"), r1, r2, r3, r2 > r1 ? -r4 : +r4, r3 > r1 ? -r5 : +r5); sl@0: TestPrintf((const char*)printString.PtrZ()); sl@0: sl@0: r1 = FcDiff2Us(ThePerfTestResult[EPerfTestSqlMode] [EPerfTestSingleUpdate]); sl@0: r2 = FcDiff2Us(ThePerfTestResult[EPerfTestSqliteSqlMode] [EPerfTestSingleUpdate]); sl@0: r3 = FcDiff2Us(ThePerfTestResult[EPerfTestSqliteDefaultMode][EPerfTestSingleUpdate]); sl@0: r4 = (TInt)((Abs(r2 - r1) * 100.0) / r1); sl@0: r5 = (TInt)((Abs(r3 - r1) * 100.0) / r1); sl@0: printString.Format(_L8("##Single Update: %8dus %8dus %8dus %8d%%%% %8d%%%%\r\n"), r1, r2, r3, r2 > r1 ? -r4 : +r4, r3 > r1 ? -r5 : +r5); sl@0: TestPrintf((const char*)printString.PtrZ()); sl@0: sl@0: r1 = FcDiff2Us(ThePerfTestResult[EPerfTestSqlMode] [EPerfTestSingleDelete]); sl@0: r2 = FcDiff2Us(ThePerfTestResult[EPerfTestSqliteSqlMode] [EPerfTestSingleDelete]); sl@0: r3 = FcDiff2Us(ThePerfTestResult[EPerfTestSqliteDefaultMode][EPerfTestSingleDelete]); sl@0: r4 = (TInt)((Abs(r2 - r1) * 100.0) / r1); sl@0: r5 = (TInt)((Abs(r3 - r1) * 100.0) / r1); sl@0: printString.Format(_L8("##Single Delete: %8dus %8dus %8dus %8d%%%% %8d%%%%\r\n"), r1, r2, r3, r2 > r1 ? -r4 : +r4, r3 > r1 ? -r5 : +r5); sl@0: TestPrintf((const char*)printString.PtrZ()); sl@0: sl@0: r1 = FcDiff2Us(ThePerfTestResult[EPerfTestSqlMode] [EPerfTestSingleSelect]); sl@0: r2 = FcDiff2Us(ThePerfTestResult[EPerfTestSqliteSqlMode] [EPerfTestSingleSelect]); sl@0: r3 = FcDiff2Us(ThePerfTestResult[EPerfTestSqliteDefaultMode][EPerfTestSingleSelect]); sl@0: r4 = (TInt)((Abs(r2 - r1) * 100.0) / r1); sl@0: r5 = (TInt)((Abs(r3 - r1) * 100.0) / r1); sl@0: printString.Format(_L8("##Single Select: %8dus %8dus %8dus %8d%%%% %8d%%%%\r\n"), r1, r2, r3, r2 > r1 ? -r4 : +r4, r3 > r1 ? -r5 : +r5); sl@0: TestPrintf((const char*)printString.PtrZ()); sl@0: } sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: static void CreateTestDir() sl@0: { sl@0: RFs fs; sl@0: TInt err = fs.Connect(); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = fs.MkDir(KTestDir); sl@0: TEST(err == KErrNone || err == KErrAlreadyExists); sl@0: sl@0: err = fs.CreatePrivatePath(EDriveC); sl@0: TEST(err == KErrNone || err == KErrAlreadyExists); sl@0: sl@0: fs.Close(); sl@0: } sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: static void CreateTestDatabase() sl@0: { sl@0: RSqlDatabase::Delete(KTestDbName); sl@0: sl@0: _LIT8(KConfigStr, "encoding=\"UTF-8\""); sl@0: TInt err = TheDb.Create(KTestDbName, &KConfigStr); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = TheDb.Exec(_L8("CREATE TABLE Tbl(I INTEGER PRIMARY KEY, I64 BIGINT, D DOUBLE, T TEXT, B BINARY)")); sl@0: TEST2(err, 1); sl@0: sl@0: TheDb.Close(); sl@0: } sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: //////////////////// SQL server tests /////////////////////////// sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SQLITE3-UT-4010 sl@0: @SYMTestCaseDesc SQL server multi-insert performance test. sl@0: The test inserts 1000 records in a single transaction and stores sl@0: the execution time for later use (comparison and printing). sl@0: @SYMTestPriority High sl@0: @SYMTestActions SQL server multi-insert performance test. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ8782 sl@0: */ sl@0: static void SqlServerMultiInsertTest(const char aInsertSql[], TInt aInsertRecCnt) sl@0: { sl@0: TestNext(" @SYMTestCaseID:SYSLIB-SQLITE3-UT-4010 "); sl@0: (void)KillProcess(KSqlSrvName); sl@0: sl@0: TInt err = TheDb.Open(KTestDbName); sl@0: TEST2(err, KErrNone); sl@0: sl@0: RSqlStatement stmt; sl@0: err = stmt.Prepare(TheDb, TPtrC8((const TUint8*)aInsertSql)); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TUint32 fc = FastCounterValue(); sl@0: err = TheDb.Exec(_L8("BEGIN")); sl@0: TEST(err >= 0); sl@0: sl@0: for(TInt i=0;i= 0); sl@0: StorePerfTestResult(EPerfTestSqlMode, EPerfTestMultiInsert, FastCounterValue() - fc); sl@0: sl@0: stmt.Close(); sl@0: TheDb.Close(); sl@0: } sl@0: sl@0: static void FormatSqlStmt(TDes8& aSqlBuf, const char aSql[], TInt aRecIds[], TInt aRecCnt) sl@0: { sl@0: aSqlBuf.Copy(TPtrC8((const TUint8*)aSql)); sl@0: aSqlBuf.Append(_L8("(")); sl@0: for(TInt i=0;i msgbuf; sl@0: sl@0: msgbuf.Format(_L8("SQL: insert %d records in a single transaction"), KInsertRecCnt); sl@0: TestNext((const char*)msgbuf.PtrZ()); sl@0: SqlServerMultiInsertTest(KMultiInsertSql, KInsertRecCnt); sl@0: sl@0: msgbuf.Format(_L8("SQL: update %d records in a single transaction"), KUpdateRecCnt); sl@0: TestNext((const char*)msgbuf.PtrZ()); sl@0: SqlServerMultiUpdateTest(KMultiUpdateSql, TheUpdateRecIds, KUpdateRecCnt); sl@0: sl@0: msgbuf.Format(_L8("SQL: delete %d records in a single transaction"), KDeleteRecCnt); sl@0: TestNext((const char*)msgbuf.PtrZ()); sl@0: SqlServerMultiDeleteTest(KMultiDeleteSql, TheDeleteRecIds, KDeleteRecCnt); sl@0: sl@0: msgbuf.Format(_L8("SQL: select %d records"), KSelectRecCnt); sl@0: msgbuf.Copy(msgbuf); sl@0: TestNext((const char*)msgbuf.PtrZ()); sl@0: SqlServerMultiSelectTest(KMultiSelectSql, TheSelectRecIds, KSelectRecCnt); sl@0: sl@0: TestNext("SQL: insert a single record"); sl@0: SqlServerSingleInsertTest(KSingleInsertSql, TheInsertRecId); sl@0: sl@0: TestNext("SQL: update a single record"); sl@0: SqlServerSingleUpdateTest(KSingleUpdateSql, TheUpdateRecId); sl@0: sl@0: TestNext("SQL: delete a single record"); sl@0: SqlServerSingleDeleteTest(KSingleDeleteSql, TheDeleteRecId); sl@0: sl@0: TestNext("SQL: select a single record"); sl@0: SqlServerSingleSelectTest(KSingleSelectSql, TheSelectRecId); sl@0: sl@0: (void)RSqlDatabase::Delete(KTestDbName); sl@0: } sl@0: sl@0: static void DoSqliteLibraryTests(TPerfTestMode aPerfTestMode) sl@0: { sl@0: TEST(aPerfTestMode > EPerfTestSqlMode && aPerfTestMode < EPerfTestModeCnt); sl@0: sl@0: SqliteInitialize(aPerfTestMode); sl@0: sl@0: TestNext("SQLite: Create the test database"); sl@0: CreateTestDatabase(); sl@0: sl@0: TBuf8<200> msgbuf; sl@0: _LIT8(KSqliteConfigSql, "\"SQL\""); sl@0: _LIT8(KSqliteConfigDefault, "\"Default\""); sl@0: sl@0: msgbuf.Format(_L8("@SYMTestCaseID:SYSLIB-SQLITE3-UT-4018: SQLite, configuration: %S: insert %d records in a single transaction"), sl@0: aPerfTestMode == EPerfTestSqliteSqlMode ? &KSqliteConfigSql : &KSqliteConfigDefault, KInsertRecCnt); sl@0: TestNext((const char*)msgbuf.PtrZ()); sl@0: SqliteMultiInsertTest(aPerfTestMode, KMultiInsertSql, KInsertRecCnt); sl@0: sl@0: msgbuf.Format(_L8("@SYMTestCaseID:SYSLIB-SQLITE3-UT-4019: SQLite, configuration: %S: update %d records in a single transaction"), sl@0: aPerfTestMode == EPerfTestSqliteSqlMode ? &KSqliteConfigSql : &KSqliteConfigDefault, KUpdateRecCnt); sl@0: TestNext((const char*)msgbuf.PtrZ()); sl@0: SqliteMultiUpdateTest(aPerfTestMode, KMultiUpdateSql, TheUpdateRecIds, KUpdateRecCnt); sl@0: sl@0: msgbuf.Format(_L8("@SYMTestCaseID:SYSLIB-SQLITE3-UT-4020: SQLite, configuration: %S: delete %d records in a single transaction"), sl@0: aPerfTestMode == EPerfTestSqliteSqlMode ? &KSqliteConfigSql : &KSqliteConfigDefault, KDeleteRecCnt); sl@0: TestNext((const char*)msgbuf.PtrZ()); sl@0: SqliteMultiDeleteTest(aPerfTestMode, KMultiDeleteSql, TheDeleteRecIds, KDeleteRecCnt); sl@0: sl@0: msgbuf.Format(_L8("@SYMTestCaseID:SYSLIB-SQLITE3-UT-4021: SQLite, configuration: %S: select %d records"), sl@0: aPerfTestMode == EPerfTestSqliteSqlMode ? &KSqliteConfigSql : &KSqliteConfigDefault, KSelectRecCnt); sl@0: TestNext((const char*)msgbuf.PtrZ()); sl@0: SqliteMultiSelectTest(aPerfTestMode, KMultiSelectSql, TheSelectRecIds, KSelectRecCnt); sl@0: sl@0: msgbuf.Format(_L8("@SYMTestCaseID:SYSLIB-SQLITE3-UT-4022: SQLite, configuration: %S: insert a single record"), sl@0: aPerfTestMode == EPerfTestSqliteSqlMode ? &KSqliteConfigSql : &KSqliteConfigDefault); sl@0: TestNext((const char*)msgbuf.PtrZ()); sl@0: SqliteSingleInsertTest(aPerfTestMode, KSingleInsertSql, TheInsertRecId); sl@0: sl@0: msgbuf.Format(_L8("@SYMTestCaseID:SYSLIB-SQLITE3-UT-4023: SQLite, configuration: %S: update a single record"), sl@0: aPerfTestMode == EPerfTestSqliteSqlMode ? &KSqliteConfigSql : &KSqliteConfigDefault); sl@0: TestNext((const char*)msgbuf.PtrZ()); sl@0: SqliteSingleUpdateTest(aPerfTestMode, KSingleUpdateSql, TheUpdateRecId); sl@0: sl@0: msgbuf.Format(_L8("@SYMTestCaseID:SYSLIB-SQLITE3-UT-4024: SQLite, configuration: %S: delete a single record"), sl@0: aPerfTestMode == EPerfTestSqliteSqlMode ? &KSqliteConfigSql : &KSqliteConfigDefault); sl@0: TestNext((const char*)msgbuf.PtrZ()); sl@0: SqliteSingleDeleteTest(aPerfTestMode, KSingleDeleteSql, TheDeleteRecId); sl@0: sl@0: msgbuf.Format(_L8("@SYMTestCaseID:SYSLIB-SQLITE3-UT-4025: SQLite, configuration: %S: select a single record"), sl@0: aPerfTestMode == EPerfTestSqliteSqlMode ? &KSqliteConfigSql : &KSqliteConfigDefault); sl@0: TestNext((const char*)msgbuf.PtrZ()); sl@0: SqliteSingleSelectTest(aPerfTestMode, KSingleSelectSql, TheSelectRecId); sl@0: sl@0: (void)RSqlDatabase::Delete(KTestDbName); sl@0: sl@0: SqliteFinalize(aPerfTestMode); sl@0: } sl@0: sl@0: static TBool IdIn(TInt aId, const TInt aData[], TInt aDataSize) sl@0: { sl@0: TEST(aId > 0); sl@0: TEST(aDataSize >= 0); sl@0: for(TInt i=0;i 0); sl@0: if(aData[i] == aId) sl@0: { sl@0: return ETrue; sl@0: } sl@0: } sl@0: return EFalse; sl@0: } sl@0: sl@0: static void VerifyGeneratedRecIds() sl@0: { sl@0: TInt i; sl@0: sl@0: for(i=0;i 0 && TheUpdateRecIds[i] <= KInsertRecCnt); sl@0: TEST(!IdIn(TheUpdateRecIds[i], TheUpdateRecIds, i)); sl@0: TEST(!IdIn(TheUpdateRecIds[i], TheDeleteRecIds, KDeleteRecCnt)); sl@0: TEST(!IdIn(TheUpdateRecIds[i], TheSelectRecIds, KSelectRecCnt)); sl@0: } sl@0: sl@0: for(i=0;i 0 && TheDeleteRecIds[i] <= KInsertRecCnt); sl@0: TEST(!IdIn(TheDeleteRecIds[i], TheDeleteRecIds, i)); sl@0: TEST(!IdIn(TheDeleteRecIds[i], TheUpdateRecIds, KUpdateRecCnt)); sl@0: TEST(!IdIn(TheDeleteRecIds[i], TheSelectRecIds, KSelectRecCnt)); sl@0: } sl@0: sl@0: for(i=0;i 0 && TheSelectRecIds[i] <= KInsertRecCnt); sl@0: TEST(!IdIn(TheSelectRecIds[i], TheSelectRecIds, i)); sl@0: TEST(!IdIn(TheSelectRecIds[i], TheUpdateRecIds, KUpdateRecCnt)); sl@0: TEST(!IdIn(TheSelectRecIds[i], TheDeleteRecIds, KDeleteRecCnt)); sl@0: } sl@0: sl@0: TEST(TheInsertRecId > 0); sl@0: sl@0: TEST(TheUpdateRecId > 0 && TheUpdateRecId <= KInsertRecCnt); sl@0: TEST(!IdIn(TheUpdateRecId, TheUpdateRecIds, KUpdateRecCnt)); sl@0: TEST(!IdIn(TheUpdateRecId, TheDeleteRecIds, KDeleteRecCnt)); sl@0: TEST(!IdIn(TheUpdateRecId, TheSelectRecIds, KSelectRecCnt)); sl@0: sl@0: TEST(TheDeleteRecId > 0 && TheDeleteRecId <= KInsertRecCnt); sl@0: TEST(!IdIn(TheDeleteRecId, TheUpdateRecIds, KUpdateRecCnt)); sl@0: TEST(!IdIn(TheDeleteRecId, TheDeleteRecIds, KDeleteRecCnt)); sl@0: TEST(!IdIn(TheDeleteRecId, TheSelectRecIds, KSelectRecCnt)); sl@0: sl@0: TEST(TheSelectRecId > 0 && TheSelectRecId <= KInsertRecCnt); sl@0: TEST(!IdIn(TheSelectRecId, TheUpdateRecIds, KUpdateRecCnt)); sl@0: TEST(!IdIn(TheSelectRecId, TheDeleteRecIds, KDeleteRecCnt)); sl@0: TEST(!IdIn(TheSelectRecId, TheSelectRecIds, KSelectRecCnt)); sl@0: } sl@0: sl@0: static void GenerateTestRecIds() sl@0: { sl@0: TTime now; sl@0: now.UniversalTime(); sl@0: TInt64 seed = now.Int64(); sl@0: TInt i; sl@0: sl@0: //Update multi sl@0: for(i=0;i 0 && !IdIn(id, TheUpdateRecIds, i)) sl@0: { sl@0: TheUpdateRecIds[i++] = id; sl@0: } sl@0: } sl@0: //Delete multi sl@0: for(i=0;i 0 && !IdIn(id, TheDeleteRecIds, i) && !IdIn(id, TheUpdateRecIds, KUpdateRecCnt)) sl@0: { sl@0: TheDeleteRecIds[i++] = id; sl@0: } sl@0: } sl@0: //Select multi sl@0: for(i=0;i 0 && !IdIn(id, TheSelectRecIds, i) && !IdIn(id, TheUpdateRecIds, KUpdateRecCnt) && sl@0: !IdIn(id, TheDeleteRecIds, KDeleteRecCnt)) sl@0: { sl@0: TheSelectRecIds[i++] = id; sl@0: } sl@0: } sl@0: //Insert one sl@0: TheInsertRecId = KInsertRecCnt + 1; sl@0: //Update one sl@0: for(;;) sl@0: { sl@0: TInt id = Math::Rand(seed) % KInsertRecCnt; sl@0: if(id > 0 && !IdIn(id, TheUpdateRecIds, KUpdateRecCnt) && !IdIn(id, TheDeleteRecIds, KDeleteRecCnt) && sl@0: !IdIn(id, TheSelectRecIds, KSelectRecCnt)) sl@0: { sl@0: TheUpdateRecId = id; sl@0: break; sl@0: } sl@0: } sl@0: //Delete one sl@0: for(;;) sl@0: { sl@0: TInt id = Math::Rand(seed) % KInsertRecCnt; sl@0: if(id > 0 && id != TheUpdateRecId && !IdIn(id, TheUpdateRecIds, KUpdateRecCnt) && sl@0: !IdIn(id, TheDeleteRecIds, KDeleteRecCnt) && !IdIn(id, TheSelectRecIds, KSelectRecCnt)) sl@0: { sl@0: TheDeleteRecId = id; sl@0: break; sl@0: } sl@0: } sl@0: //Select one sl@0: for(;;) sl@0: { sl@0: TInt id = Math::Rand(seed) % KInsertRecCnt; sl@0: if(id > 0 && id != TheUpdateRecId && id != TheDeleteRecId && !IdIn(id, TheUpdateRecIds, KUpdateRecCnt) && sl@0: !IdIn(id, TheDeleteRecIds, KDeleteRecCnt) && sl@0: !IdIn(id, TheSelectRecIds, KSelectRecCnt)) sl@0: { sl@0: TheSelectRecId = id; sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: sl@0: static void DoTests() sl@0: { sl@0: TestStart("Get fast counter frequency"); sl@0: GetFastCounterFrequency(); sl@0: sl@0: TestNext("Generate test record ids"); sl@0: GenerateTestRecIds(); sl@0: sl@0: TestNext("Verify generated test record ids"); sl@0: VerifyGeneratedRecIds(); sl@0: sl@0: DoSqlServerTests(); sl@0: (void)KillProcess(KSqlSrvName); sl@0: sl@0: DoSqliteLibraryTests(EPerfTestSqliteDefaultMode); sl@0: sl@0: DoSqliteLibraryTests(EPerfTestSqliteSqlMode); sl@0: sl@0: PrintPerfTestResults(); sl@0: } sl@0: sl@0: TInt E32Main() sl@0: { sl@0: TestOpen(KTestName); sl@0: TestTitle(); sl@0: sl@0: CTrapCleanup* tc = CTrapCleanup::New(); sl@0: sl@0: __UHEAP_MARK; sl@0: sl@0: CreateTestDir(); sl@0: DeleteTestFiles(); sl@0: DoTests(); sl@0: DeleteTestFiles(); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: TestEnd(); sl@0: TestClose(); sl@0: sl@0: delete tc; sl@0: sl@0: User::Heap().Check(); sl@0: return KErrNone; sl@0: }