persistentstorage/sql/TEST/t_sqlperformance2.cpp
changeset 29 cce6680bbf1c
parent 0 08ec8eefde2f
child 55 44f437012c90
equal deleted inserted replaced
28:7a522c0700d3 29:cce6680bbf1c
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    14 //
    14 //
    15 
    15 
    16 #include <e32test.h>
    16 #include <e32test.h>
    17 #include <bautils.h>
    17 #include <bautils.h>
    18 #include <sqldb.h>
    18 #include <sqldb.h>
       
    19 #include "t_sqlcmdlineutil.h"
    19 
    20 
    20 ///////////////////////////////////////////////////////////////////////////////////////
    21 ///////////////////////////////////////////////////////////////////////////////////////
    21 
    22 
    22 RTest			TheTest(_L("t_sqlperformance2 test"));
    23 RTest			TheTest(_L("t_sqlperformance2 test"));
    23 RSqlDatabase 	TheDb;
    24 RSqlDatabase 	TheDb;
    24 TFileName		TheDbFileName;
    25 TFileName		TheDbFileName;
    25 RFs				TheFs;
    26 RFs				TheFs;
    26 
    27 
       
    28 TBuf<200> 		TheTestTitle;
       
    29 TCmdLineParams 	TheCmdLineParams;
       
    30 TBuf8<200> 		TheSqlConfigString;
       
    31 
       
    32 _LIT(KUtf8,  "UTF8 ");
       
    33 _LIT(KUtf16, "UTF16");
       
    34 
    27 TInt TheBlobSize = 1024 * 256;
    35 TInt TheBlobSize = 1024 * 256;
    28 
       
    29 TBuf<256>  TheCmd;
       
    30 TDriveName TheDriveName;
       
    31 TParse     TheParse;
       
    32 
    36 
    33 ///////////////////////////////////////////////////////////////////////////////////////
    37 ///////////////////////////////////////////////////////////////////////////////////////
    34 
    38 
    35 void TestEnvDestroy()
    39 void TestEnvDestroy()
    36 	{
    40 	{
    67 
    71 
    68 void TestEnvInit()
    72 void TestEnvInit()
    69     {
    73     {
    70     TInt err = TheFs.Connect();
    74     TInt err = TheFs.Connect();
    71     TEST2(err, KErrNone);
    75     TEST2(err, KErrNone);
    72     //Get the drive number from the database file name
    76     //
    73 	err = TheParse.Set(TheDbFileName, NULL, NULL);
    77     TInt driveNumber = -1;
    74 	TEST2(err, KErrNone);
    78 	err = RFs::CharToDrive(TheCmdLineParams.iDriveName[0], driveNumber);
    75 	TPtrC driveName = TheParse.Drive();
       
    76 	TEST(driveName.Length() > 0);
       
    77 	TInt driveNumber = -1;
       
    78 	err = RFs::CharToDrive(driveName[0], driveNumber);
       
    79 	TEST2(err, KErrNone);
    79 	TEST2(err, KErrNone);
    80 	TDriveNumber driveNo = static_cast <TDriveNumber> (driveNumber);
    80 	TDriveNumber driveNo = static_cast <TDriveNumber> (driveNumber);
    81 	TDriveInfo driveInfo;
    81 	TDriveInfo driveInfo;
    82 	err = TheFs.Drive(driveInfo, driveNo);
    82 	err = TheFs.Drive(driveInfo, driveNo);
    83 	TEST2(err, KErrNone);
    83 	TEST2(err, KErrNone);
    84     //Create the test directory
    84     //Create the test directory
    85 	err = TheFs.MkDir(TheParse.DriveAndPath());
    85 	err = TheFs.MkDirAll(TheDbFileName);
    86 	TEST(err == KErrNone || err == KErrAlreadyExists);
    86 	TEST(err == KErrNone || err == KErrAlreadyExists);
    87     //Print drive info and the database name 
    87     //Print drive info and the database name 
    88 	_LIT(KType1, "Not present");
    88 	_LIT(KType1, "Not present");
    89 	_LIT(KType2, "Unknown");
    89 	_LIT(KType2, "Unknown");
    90 	_LIT(KType3, "Floppy");
    90 	_LIT(KType3, "Floppy");
   128 ///////////////////////////////////////////////////////////////////////////////////////
   128 ///////////////////////////////////////////////////////////////////////////////////////
   129 	
   129 	
   130 void CreateTestDb()
   130 void CreateTestDb()
   131 	{
   131 	{
   132 	(void)RSqlDatabase::Delete(TheDbFileName);
   132 	(void)RSqlDatabase::Delete(TheDbFileName);
   133 	TInt err = TheDb.Create(TheDbFileName);
   133 	TInt err = TheDb.Create(TheDbFileName, &TheSqlConfigString);
   134 	TEST2(err, KErrNone);
   134 	TEST2(err, KErrNone);
   135 	err = TheDb.Exec(_L8("CREATE TABLE A(B BLOB)"));
   135 	err = TheDb.Exec(_L8("CREATE TABLE A(B BLOB)"));
   136 	TEST2(err, 1);
   136 	TEST2(err, 1);
   137 	}
   137 	}
   138 
   138 
   529 	PrintFileSize(TheDb);
   529 	PrintFileSize(TheDb);
   530 	TheDb.Close();
   530 	TheDb.Close();
   531 	(void)RSqlDatabase::Delete(TheDbFileName);	
   531 	(void)RSqlDatabase::Delete(TheDbFileName);	
   532 	}
   532 	}
   533 
   533 
   534 void DoReadBlobIncrL(TDes8& aDes)
   534 void DoReadBlobIncrL(TDes8& aDes, TInt aMaxLength)
   535 	{
   535 	{
   536 	TTime t1, t2, t3, t4;
   536 	TTime t1, t2, t3, t4;
   537 	
   537 	
   538 	TTimeIntervalMicroSeconds openTime, readTime; 
   538 	TTimeIntervalMicroSeconds openTime, readTime; 
   539 	
   539 	
   545 	t2.HomeTime();
   545 	t2.HomeTime();
   546 	
   546 	
   547 	openTime = t2.MicroSecondsFrom(t1);
   547 	openTime = t2.MicroSecondsFrom(t1);
   548 		
   548 		
   549 	t3.HomeTime();
   549 	t3.HomeTime();
   550 	strm.ReadL(aDes);
   550 	strm.ReadL(aDes, aMaxLength);
   551 	t4.HomeTime();
   551 	t4.HomeTime();
   552 
   552 
   553 	readTime = t4.MicroSecondsFrom(t3);
   553 	readTime = t4.MicroSecondsFrom(t3);
   554 	
   554 	
   555 	PrintReadTime(openTime, readTime);
   555 	PrintReadTime(openTime, readTime);
   561 	{
   561 	{
   562 	HBufC8* data = HBufC8::New(TheBlobSize);
   562 	HBufC8* data = HBufC8::New(TheBlobSize);
   563 	TEST(data != NULL);
   563 	TEST(data != NULL);
   564 	TPtr8 dataptr = data->Des();
   564 	TPtr8 dataptr = data->Des();
   565 	
   565 	
   566 	TRAPD(err, DoReadBlobIncrL(dataptr));
   566 	TRAPD(err, DoReadBlobIncrL(dataptr, TheBlobSize));
   567 	TEST2(err, KErrNone);
   567 	TEST2(err, KErrNone);
   568 	TEST2(dataptr.Length(), TheBlobSize);
   568 	TEST2(dataptr.Length(), TheBlobSize);
   569 	
   569 	
   570 	delete data;
   570 	delete data;
   571 	}
   571 	}
   659 
   659 
   660 	RSqlColumnReadStream strm;
   660 	RSqlColumnReadStream strm;
   661 	t5.HomeTime();
   661 	t5.HomeTime();
   662 	err = strm.ColumnBinary(stmt, 0);
   662 	err = strm.ColumnBinary(stmt, 0);
   663 	TEST2(err, KErrNone);
   663 	TEST2(err, KErrNone);
   664 	TRAP(err, strm.ReadL(dataptr));
   664 	TRAP(err, strm.ReadL(dataptr, TheBlobSize));
   665 	t6.HomeTime();
   665 	t6.HomeTime();
   666 	TEST2(err, KErrNone);
   666 	TEST2(err, KErrNone);
   667 	TEST2(dataptr.Length(), TheBlobSize);
   667 	TEST2(dataptr.Length(), TheBlobSize);
   668 	readTime = t6.MicroSecondsFrom(t5);
   668 	readTime = t6.MicroSecondsFrom(t5);
   669 
   669 
   744 void SequentialWriteTestL()
   744 void SequentialWriteTestL()
   745 	{
   745 	{
   746 	const TInt KBufLen = 32768; // 32Kb
   746 	const TInt KBufLen = 32768; // 32Kb
   747 	HBufC8* buf = HBufC8::NewL(KBufLen);
   747 	HBufC8* buf = HBufC8::NewL(KBufLen);
   748 	TPtr8 dataPtr =	buf->Des();
   748 	TPtr8 dataPtr =	buf->Des();
       
   749 	dataPtr.SetLength(KBufLen);
   749 	dataPtr.Fill('A', KBufLen);	
   750 	dataPtr.Fill('A', KBufLen);	
   750 	
   751 	
   751 	CreateTestDb();
   752 	CreateTestDb();
   752 	InsertZeroBlob(); // insert zeroblob of "TheBlobSize" size
   753 	InsertZeroBlob(); // insert zeroblob of "TheBlobSize" size
   753 		
   754 		
   810 void TransSequentialWriteTestL()
   811 void TransSequentialWriteTestL()
   811 	{
   812 	{
   812 	const TInt KBufLen = 32768; // 32Kb
   813 	const TInt KBufLen = 32768; // 32Kb
   813 	HBufC8* buf = HBufC8::NewL(KBufLen);
   814 	HBufC8* buf = HBufC8::NewL(KBufLen);
   814 	TPtr8 dataPtr =	buf->Des();
   815 	TPtr8 dataPtr =	buf->Des();
       
   816 	dataPtr.SetLength(KBufLen);
   815 	dataPtr.Fill('A', KBufLen);	
   817 	dataPtr.Fill('A', KBufLen);	
   816 	
   818 	
   817 	CreateTestDb();
   819 	CreateTestDb();
   818 	InsertZeroBlob(); // insert zeroblob of "TheBlobSize" size
   820 	InsertZeroBlob(); // insert zeroblob of "TheBlobSize" size
   819 		
   821 		
   887 void WholeWriteTestL()
   889 void WholeWriteTestL()
   888 	{
   890 	{
   889 	TInt bufLen = TheBlobSize; 
   891 	TInt bufLen = TheBlobSize; 
   890 	HBufC8* buf = HBufC8::NewL(bufLen);
   892 	HBufC8* buf = HBufC8::NewL(bufLen);
   891 	TPtr8 dataPtr =	buf->Des();
   893 	TPtr8 dataPtr =	buf->Des();
       
   894 	dataPtr.SetLength(bufLen);
   892 	dataPtr.Fill('Z', bufLen);	
   895 	dataPtr.Fill('Z', bufLen);	
   893 	
   896 	
   894 	CreateTestDb();
   897 	CreateTestDb();
   895 	InsertRealBlob(); // insert blob of "TheBlobSize" size
   898 	InsertRealBlob(); // insert blob of "TheBlobSize" size
   896 			
   899 			
   951 void TransWholeWriteTestL()
   954 void TransWholeWriteTestL()
   952 	{
   955 	{
   953 	TInt bufLen = TheBlobSize;
   956 	TInt bufLen = TheBlobSize;
   954 	HBufC8* buf = HBufC8::NewL(bufLen);
   957 	HBufC8* buf = HBufC8::NewL(bufLen);
   955 	TPtr8 dataPtr =	buf->Des();
   958 	TPtr8 dataPtr =	buf->Des();
       
   959 	dataPtr.SetLength(bufLen);
   956 	dataPtr.Fill('Z', bufLen);	
   960 	dataPtr.Fill('Z', bufLen);	
   957 	
   961 	
   958 	CreateTestDb();
   962 	CreateTestDb();
   959 	InsertRealBlob(); // insert blob of "TheBlobSize" size
   963 	InsertRealBlob(); // insert blob of "TheBlobSize" size
   960 	
   964 	
  1022 void WholeReadTestL()
  1026 void WholeReadTestL()
  1023 	{
  1027 	{
  1024 	TInt bufLen = TheBlobSize; 
  1028 	TInt bufLen = TheBlobSize; 
  1025 	HBufC8* buf = HBufC8::NewL(bufLen);
  1029 	HBufC8* buf = HBufC8::NewL(bufLen);
  1026 	TPtr8 dataPtr =	buf->Des();
  1030 	TPtr8 dataPtr =	buf->Des();
       
  1031 	dataPtr.SetLength(bufLen);
  1027 	dataPtr.Fill('A', bufLen);	
  1032 	dataPtr.Fill('A', bufLen);	
  1028 	
  1033 	
  1029 	CreateTestDb();
  1034 	CreateTestDb();
  1030 	InsertRealBlob(); // insert blob of "TheBlobSize" size
  1035 	InsertRealBlob(); // insert blob of "TheBlobSize" size
  1031 	
  1036 	
  1102 ///////////////////////////////////////////////////////////////////////////////////
  1107 ///////////////////////////////////////////////////////////////////////////////////
  1103 ///////////////////////////////////////////////////////////////////////////////////
  1108 ///////////////////////////////////////////////////////////////////////////////////
  1104 
  1109 
  1105 void DoTests()
  1110 void DoTests()
  1106 	{
  1111 	{
  1107 	TheTest.Start(_L("@SYMTestCaseID:SYSLIB-SQL-UT-4084 SQL, BLOB write, performance tests\r\n"));
  1112 	TheTestTitle.Format(_L("@SYMTestCaseID:SYSLIB-SQL-UT-4084 SQL, BLOB write, performance tests, encoding: \"%S\", page size: %d\r\n"), 
       
  1113 			TheCmdLineParams.iDbEncoding == TCmdLineParams::EDbUtf16 ? &KUtf16 : &KUtf8, TheCmdLineParams.iPageSize);
       
  1114 	TheTest.Start(TheTestTitle);
  1108 	BlobWriteTest();
  1115 	BlobWriteTest();
  1109 	
  1116 	
  1110 	TheTest.Next(_L("@SYMTestCaseID:SYSLIB-SQL-UT-4085 SQL, BLOB read, performance tests\r\n"));
  1117 	TheTestTitle.Format(_L("@SYMTestCaseID:SYSLIB-SQL-UT-4085 SQL, BLOB read, performance tests, encoding: \"%S\", page size: %d\r\n"), 
       
  1118 			TheCmdLineParams.iDbEncoding == TCmdLineParams::EDbUtf16 ? &KUtf16 : &KUtf8, TheCmdLineParams.iPageSize);
       
  1119 	TheTest.Next(TheTestTitle);
  1111 	BlobReadTest();
  1120 	BlobReadTest();
  1112 
  1121 
  1113 	TheTest.Printf(_L("==================================================================\r\n"));
  1122 	TheTest.Printf(_L("==================================================================\r\n"));
  1114 	
  1123 	
  1115 	// Bigger blob tests - only on hardware, release mode
  1124 	// Bigger blob tests - only on hardware, release mode
  1116 #if !defined __WINS__ && !defined __WINSCW__ && !defined _DEBUG
  1125 #if !defined __WINS__ && !defined __WINSCW__ && !defined _DEBUG
  1117 	
  1126 	
  1118 	TheBlobSize = 1024 * 1024 + 128 * 1024;//1.125Mb 
  1127 	TheBlobSize = 1024 * 1024 + 128 * 1024;//1.125Mb 
  1119 
  1128 
  1120 	TheTest.Next(_L("@SYMTestCaseID:SYSLIB-SQL-UT-4115 SQL, sequential BLOB writes, performance tests\r\n"));
  1129 	TheTestTitle.Format(_L("@SYMTestCaseID:SYSLIB-SQL-UT-4115 SQL, sequential BLOB writes, performance tests, encoding: \"%S\", page size: %d\r\n"), 
       
  1130 			TheCmdLineParams.iDbEncoding == TCmdLineParams::EDbUtf16 ? &KUtf16 : &KUtf8, TheCmdLineParams.iPageSize);
       
  1131 	TheTest.Next(TheTestTitle);
  1121 	TRAPD(err, SequentialWriteTestL());
  1132 	TRAPD(err, SequentialWriteTestL());
  1122 	TEST2(err, KErrNone);
  1133 	TEST2(err, KErrNone);
  1123 	
  1134 	
  1124 	TheTest.Next(_L("@SYMTestCaseID:SYSLIB-SQL-UT-4116 SQL, transaction sequential BLOB writes, performance tests\r\n"));
  1135 	TheTestTitle.Format(_L("@SYMTestCaseID:SYSLIB-SQL-UT-4116 SQL, transaction sequential BLOB writes, performance tests, encoding: \"%S\", page size: %d\r\n"), 
       
  1136 			TheCmdLineParams.iDbEncoding == TCmdLineParams::EDbUtf16 ? &KUtf16 : &KUtf8, TheCmdLineParams.iPageSize);
       
  1137 	TheTest.Next(TheTestTitle);
  1125 	TRAP(err, TransSequentialWriteTestL());
  1138 	TRAP(err, TransSequentialWriteTestL());
  1126 	TEST2(err, KErrNone);
  1139 	TEST2(err, KErrNone);
  1127 		
  1140 		
  1128 	TheBlobSize = 256 * 1024 ; // 256Kb
  1141 	TheBlobSize = 256 * 1024 ; // 256Kb
  1129 		
  1142 		
  1130 	TheTest.Next(_L("@SYMTestCaseID:SYSLIB-SQL-UT-4117 SQL, whole BLOB write, performance tests\r\n"));
  1143 	TheTestTitle.Format(_L("@SYMTestCaseID:SYSLIB-SQL-UT-4117 SQL, whole BLOB write, performance tests, encoding: \"%S\", page size: %d\r\n"), 
       
  1144 			TheCmdLineParams.iDbEncoding == TCmdLineParams::EDbUtf16 ? &KUtf16 : &KUtf8, TheCmdLineParams.iPageSize);
       
  1145 	TheTest.Next(TheTestTitle);
  1131 	TRAP(err, WholeWriteTestL());
  1146 	TRAP(err, WholeWriteTestL());
  1132 	TEST2(err, KErrNone);
  1147 	TEST2(err, KErrNone);
  1133 	
  1148 	
  1134 	TheTest.Next(_L("@SYMTestCaseID:SYSLIB-SQL-UT-4118 SQL, transaction whole BLOB write, performance tests\r\n"));
  1149 	TheTestTitle.Format(_L("@SYMTestCaseID:SYSLIB-SQL-UT-4118 SQL, transaction whole BLOB write, performance tests, encoding: \"%S\", page size: %d\r\n"), 
       
  1150 			TheCmdLineParams.iDbEncoding == TCmdLineParams::EDbUtf16 ? &KUtf16 : &KUtf8, TheCmdLineParams.iPageSize);
       
  1151 	TheTest.Next(TheTestTitle);
  1135 	TRAP(err, TransWholeWriteTestL());
  1152 	TRAP(err, TransWholeWriteTestL());
  1136 	TEST2(err, KErrNone);
  1153 	TEST2(err, KErrNone);
  1137 	
  1154 	
  1138 	TheTest.Next(_L("@SYMTestCaseID:SYSLIB-SQL-UT-4119 SQL, whole BLOB read, performance tests\r\n"));
  1155 	TheTestTitle.Format(_L("@SYMTestCaseID:SYSLIB-SQL-UT-4119 SQL, whole BLOB read, performance tests, encoding: \"%S\", page size: %d\r\n"), 
       
  1156 			TheCmdLineParams.iDbEncoding == TCmdLineParams::EDbUtf16 ? &KUtf16 : &KUtf8, TheCmdLineParams.iPageSize);
       
  1157 	TheTest.Next(TheTestTitle);
  1139 	TRAP(err, WholeReadTestL());
  1158 	TRAP(err, WholeReadTestL());
  1140 	TEST2(err, KErrNone);
  1159 	TEST2(err, KErrNone);
  1141 	
  1160 	
  1142 #endif//!defined __WINS__ && !defined __WINSCW__ && !defined _DEBUG
  1161 #endif//!defined __WINS__ && !defined __WINSCW__ && !defined _DEBUG
  1143 	}
  1162 	}
  1144 
       
  1145 //Usage: "t_sqlperformance2 [<drive letter>:]"
       
  1146 
  1163 
  1147 TInt E32Main()
  1164 TInt E32Main()
  1148 	{
  1165 	{
  1149 	TheTest.Title();
  1166 	TheTest.Title();
  1150 
  1167 
  1151 	CTrapCleanup* tc = CTrapCleanup::New();
  1168 	CTrapCleanup* tc = CTrapCleanup::New();
  1152 	TheTest(tc != NULL);
  1169 	TheTest(tc != NULL);
  1153 
  1170 
  1154 	__UHEAP_MARK;
  1171 	__UHEAP_MARK;
  1155 
  1172 
  1156 	User::CommandLine(TheCmd);
  1173 	GetCmdLineParamsAndSqlConfigString(TheTest, _L("t_sqlperformance2"), TheCmdLineParams, TheSqlConfigString);
  1157 	TheCmd.TrimAll();
       
  1158 	if(TheCmd.Length() > 0)
       
  1159 		{
       
  1160 		TheDriveName.Copy(TheCmd);
       
  1161 		}
       
  1162 
       
  1163 	_LIT(KDbName, "c:\\test\\t_sqlperformance2.db");
  1174 	_LIT(KDbName, "c:\\test\\t_sqlperformance2.db");
  1164 	TheParse.Set(TheDriveName, &KDbName, 0);
  1175 	PrepareDbName(KDbName, TheCmdLineParams.iDriveName, TheDbFileName);
  1165 	const TDesC& dbFilePath = TheParse.FullName();
  1176 
  1166 	TheDbFileName.Copy(dbFilePath);
  1177 	TheTest.Printf(_L("==Databases: %S\r\n"), &TheDbFileName); 
  1167 	
  1178 	
  1168 	TestEnvInit();
  1179 	TestEnvInit();
  1169 	DoTests();
  1180 	DoTests();
  1170 	TestEnvDestroy();
  1181 	TestEnvDestroy();
  1171 
  1182