1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/dbms/tdbms/t_dbperf2.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,1421 @@
1.4 +// Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <d32dbms.h>
1.20 +#include <s32file.h>
1.21 +#include <e32test.h>
1.22 +#include <e32math.h>
1.23 +#include <s32mem.h>
1.24 +#include <hal.h>
1.25 +
1.26 +static RTest TheTest(_L("t_dbperf2"));
1.27 +static CTrapCleanup* TheTrapCleanup;
1.28 +static RFs TheFs;
1.29 +static RDbs TheDbs;
1.30 +static RDbNamedDatabase TheDatabase;
1.31 +static RDbRowSet TheRowSet;
1.32 +static RFile TheTestFile;
1.33 +static TFileName TheDatabaseFileName;
1.34 +static TFileName TheLogFileName;
1.35 +static TFileName TheTestFileName;
1.36 +static TParse TheParse;
1.37 +
1.38 +#define COUNT_OF(array) (sizeof(array)/sizeof(array[0]))
1.39 +
1.40 +const TInt KTestRecordCount = 400;
1.41 +
1.42 +const TInt KTextColSize = 200;//Change KCreateTestTableSql string too!
1.43 +
1.44 +_LIT(KCreateTestTableSql, "CREATE TABLE A(I1 INTEGER, I2 DOUBLE, I3 VARCHAR(200))");
1.45 +_LIT(KCreateIndexSql, "CREATE UNIQUE INDEX IDX ON A(I1)");
1.46 +
1.47 +const TInt KColSize2 = 500;
1.48 +_LIT(KCreateTestTableSql2, "CREATE TABLE A(I1 INTEGER, I2 LONG VARCHAR, I3 LONG VARBINARY)");
1.49 +
1.50 +const TChar KBufChar('O');
1.51 +TBuf8<KColSize2> TheBinRndData;
1.52 +TBuf16<KColSize2> TheTextRndData;
1.53 +
1.54 +//////////////////////////////////////////////////////
1.55 +
1.56 +static TInt TheCounterFreq = -10000000;
1.57 +const TInt KMicroSecIn1Sec = 1000000;
1.58 +
1.59 +TUint32 CalcTickDiff(TUint32 aStartTicks, TUint32 aEndTicks)
1.60 + {
1.61 + TInt64 diffTicks = (TInt64)aEndTicks - (TInt64)aStartTicks;
1.62 + if(diffTicks < 0)
1.63 + {
1.64 + diffTicks = KMaxTUint32 + diffTicks + 1;
1.65 + }
1.66 + return (TUint32)diffTicks;
1.67 + }
1.68 +
1.69 +//Prints aFastCount parameter (converted to us)
1.70 +void PrintFcDiffAsUs(const TDesC& aFormatStr, TUint32 aFastCount)
1.71 + {
1.72 + double v = ((double)aFastCount * KMicroSecIn1Sec) / (double)TheCounterFreq;
1.73 + TInt v2 = (TInt)v;
1.74 + TheTest.Printf(aFormatStr, v2);
1.75 + }
1.76 +
1.77 +//Prints aFastCount parameter (converted to us) and the records count
1.78 +void PrintFcDiffAsUs2(const TDesC& aFormatStr, TInt aRecCnt, TUint32 aFastCount)
1.79 + {
1.80 + double v = ((double)aFastCount * KMicroSecIn1Sec) / (double)TheCounterFreq;
1.81 + TInt v2 = (TInt)v;
1.82 + TheTest.Printf(aFormatStr, aRecCnt, v2);
1.83 + }
1.84 +
1.85 +//////////////////////////////////////////////////////
1.86 +
1.87 +enum TRowSetType {EViewRowSet, ETableRowSet};
1.88 +const TRowSetType KRowSetTypes[] = {EViewRowSet/*, ETableRowSet*/}; //Excluding ETableRowSet means that the test requires less time.
1.89 +const TPtrC KRowSetTypeStr[] = {_L("RDbView.")/*, _L("RDbTable.")*/};//The coverage is not affected that much.
1.90 +
1.91 +//////////////////////////////////////////////////////
1.92 +
1.93 +const RDbRowSet::TAccess KAccessModes[] = {RDbRowSet::EInsertOnly, RDbRowSet::EUpdatable};
1.94 +const TPtrC KAccessModeStr[] = {_L("Insert only."), _L("Updatable.")};
1.95 +
1.96 +//////////////////////////////////////////////////////
1.97 +
1.98 +enum TUpdDirection {EUpdBackward, EUpdForward};
1.99 +const TUpdDirection KUpdDirectionTypes[] = {EUpdBackward, EUpdForward};
1.100 +const TPtrC KUpdDirectionTypeStr[] = {_L("Backward."), _L("Forward.")};
1.101 +
1.102 +//////////////////////////////////////////////////////
1.103 +
1.104 +enum TCommitRecCnt {ECommit_1_Rec = 1, ECommit_Cnt_Rec = 20, ECommit_All_Rec = KTestRecordCount};
1.105 +const TCommitRecCnt KCommitTypes[] = {ECommit_1_Rec, ECommit_Cnt_Rec, ECommit_All_Rec};
1.106 +const TPtrC KCommitTypeStr[] = {_L("Commit after 1 op."), _L("Commit after 20 ops."), _L("Commit at end.")};
1.107 +
1.108 +///////////////////////////////////////////////////////////////////////////////////////
1.109 +
1.110 +//Delete "aFullName" file.
1.111 +static void DeleteFile(const TDesC& aFullName)
1.112 + {
1.113 + RFs fsSession;
1.114 + TInt err = fsSession.Connect();
1.115 + if(err == KErrNone)
1.116 + {
1.117 + TEntry entry;
1.118 + if(fsSession.Entry(aFullName, entry) == KErrNone)
1.119 + {
1.120 + err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
1.121 + if(err != KErrNone)
1.122 + {
1.123 + TheTest.Printf(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
1.124 + }
1.125 + err = fsSession.Delete(aFullName);
1.126 + if(err != KErrNone)
1.127 + {
1.128 + TheTest.Printf(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
1.129 + }
1.130 + }
1.131 + fsSession.Close();
1.132 + }
1.133 + else
1.134 + {
1.135 + TheTest.Printf(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
1.136 + }
1.137 + }
1.138 +
1.139 +///////////////////////////////////////////////////////////////////////////////////////
1.140 +
1.141 +static void CloseAll()
1.142 + {
1.143 + TheRowSet.Close();
1.144 + TheDatabase.Close();
1.145 + TheDbs.Close();
1.146 + TheTestFile.Close();
1.147 + TheFs.Close();
1.148 + }
1.149 +
1.150 +///////////////////////////////////////////////////////////////////////////////////////
1.151 +///////////////////////////////////////////////////////////////////////////////////////
1.152 +//Tests macros and functions.
1.153 +//If (!aValue) then the test will be panicked, the test data files will be deleted.
1.154 +static void Check(TInt aValue, TInt aLine)
1.155 + {
1.156 + if(!aValue)
1.157 + {
1.158 + CloseAll();
1.159 + DeleteFile(TheDatabaseFileName);
1.160 + DeleteFile(TheTestFileName);
1.161 + TheTest(EFalse, aLine);
1.162 + }
1.163 + }
1.164 +//If (aValue != aExpected) then the test will be panicked, the test data files will be deleted.
1.165 +static void Check(TInt aValue, TInt aExpected, TInt aLine)
1.166 + {
1.167 + if(aValue != aExpected)
1.168 + {
1.169 + TheTest.Printf(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
1.170 + CloseAll();
1.171 + DeleteFile(TheDatabaseFileName);
1.172 + DeleteFile(TheTestFileName);
1.173 + TheTest(EFalse, aLine);
1.174 + }
1.175 + }
1.176 +//Use these to test conditions.
1.177 +#define TEST(arg) ::Check((arg), __LINE__)
1.178 +#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
1.179 +
1.180 +///////////////////////////////////////////////////////////////////////////////////////
1.181 +
1.182 +void PrintFileSize()
1.183 + {
1.184 + RDbDatabase::TSize s = TheDatabase.Size();
1.185 + TheTest.Printf(_L("####FileSize: %d\r\n"), s.iSize);
1.186 + }
1.187 +
1.188 +///////////////////////////////////////////////////////////////////////////////////////
1.189 +
1.190 +void DbRowSetInsertTestL(TRowSetType aRowSetType, RDbRowSet::TAccess aAccessMode, TCommitRecCnt aCommitRecCnt)
1.191 + {
1.192 + TBuf<KTextColSize> textColVal;
1.193 + for(TInt ii=23000;ii<(23000+KTextColSize);++ii)
1.194 + {
1.195 + textColVal.Append(TChar(ii));
1.196 + }
1.197 + for(TInt compaction=0;compaction<2;++compaction)
1.198 + {
1.199 + TheTest.Printf(compaction ? _L("Compaction:Yes.\r\n") : _L("Compaction:No.\r\n"));
1.200 + TheRowSet.Close();
1.201 + TInt err;
1.202 + err = TheDatabase.Execute(_L("DELETE FROM A"));
1.203 + TEST(err >= 0);
1.204 + TUint32 fc = User::FastCounter();
1.205 + if(aRowSetType == EViewRowSet)
1.206 + {
1.207 + RDbView view;
1.208 + err = view.Prepare(TheDatabase, _L("SELECT * FROM A"), aAccessMode);
1.209 + TEST2(err, KErrNone);
1.210 + err = view.EvaluateAll();
1.211 + TEST2(err, KErrNone);
1.212 + TheRowSet = view;
1.213 + }
1.214 + else
1.215 + {
1.216 + RDbTable tbl;
1.217 + err = tbl.Open(TheDatabase, _L("A"), aAccessMode);
1.218 + TEST2(err, KErrNone);
1.219 + TheRowSet = tbl;
1.220 + }
1.221 + TUint32 prepFc = CalcTickDiff(fc, User::FastCounter());
1.222 + TUint32 insFc = 0;
1.223 + TUint32 setcolFc = 0;
1.224 + TUint32 putFc = 0;
1.225 + TUint32 commitFc = 0;
1.226 + TUint32 totalFc = 0;
1.227 + fc = User::FastCounter();
1.228 + for(TInt i=0,count=0;i<KTestRecordCount;++i)
1.229 + {
1.230 + TUint32 tmpFc;
1.231 + if(aCommitRecCnt != ECommit_1_Rec && count == 0)
1.232 + {
1.233 + tmpFc = User::FastCounter();
1.234 + err = TheDatabase.Begin();
1.235 + TEST2(err, KErrNone);
1.236 + commitFc += CalcTickDiff(tmpFc, User::FastCounter());
1.237 + }
1.238 + tmpFc = User::FastCounter();
1.239 + TheRowSet.InsertL();
1.240 + insFc += CalcTickDiff(tmpFc, User::FastCounter());
1.241 + tmpFc = User::FastCounter();
1.242 + TheRowSet.SetColL(1, i);
1.243 + TheRowSet.SetColL(2, i * 10.1234);
1.244 + TheRowSet.SetColL(3, textColVal);
1.245 + setcolFc += CalcTickDiff(tmpFc, User::FastCounter());
1.246 + tmpFc = User::FastCounter();
1.247 + TheRowSet.PutL();
1.248 + putFc += CalcTickDiff(tmpFc, User::FastCounter());
1.249 + if(aCommitRecCnt != ECommit_1_Rec && ++count == aCommitRecCnt)
1.250 + {
1.251 + tmpFc = User::FastCounter();
1.252 + count = 0;
1.253 + err = TheDatabase.Commit();
1.254 + TEST2(err, KErrNone);
1.255 + commitFc += CalcTickDiff(tmpFc, User::FastCounter());
1.256 + if(compaction)
1.257 + {
1.258 + err = TheDatabase.Compact();
1.259 + TEST2(err, KErrNone);
1.260 + }
1.261 + }
1.262 + }
1.263 + totalFc = CalcTickDiff(fc, User::FastCounter());
1.264 + PrintFcDiffAsUs(_L("###Prepare,time=%d us\r\n"), prepFc);
1.265 + PrintFcDiffAsUs(_L("###InsertL,time=%d us\r\n"), insFc);
1.266 + PrintFcDiffAsUs(_L("###SetColL,time=%d us\r\n"), setcolFc);
1.267 + PrintFcDiffAsUs(_L("###PutL, time=%d us\r\n"), putFc);
1.268 + PrintFcDiffAsUs(_L("###Commit, time=%d us\r\n"), commitFc);
1.269 + PrintFcDiffAsUs(_L("###Total, time=%d us\r\n"), totalFc);
1.270 + TheRowSet.Close();
1.271 + PrintFileSize();
1.272 + //Check
1.273 + if(aAccessMode != RDbRowSet::EInsertOnly)
1.274 + {
1.275 + RDbView view;
1.276 + err = view.Prepare(TheDatabase, _L("SELECT * FROM A"), aAccessMode);
1.277 + TEST2(err, KErrNone);
1.278 + err = view.EvaluateAll();
1.279 + TEST2(err, KErrNone);
1.280 + TInt count = view.CountL();
1.281 + view.Close();
1.282 + TEST2(count, KTestRecordCount);
1.283 + }
1.284 + }//end of - for(TInt compaction=0;compaction<2;++compaction)
1.285 + }
1.286 +
1.287 +void FirstRecL(TUpdDirection aUpdDirection)
1.288 + {
1.289 + TBool rc = EFalse;
1.290 + switch(aUpdDirection)
1.291 + {
1.292 + case EUpdBackward:
1.293 + rc = TheRowSet.LastL();
1.294 + break;
1.295 + case EUpdForward:
1.296 + default:
1.297 + rc = TheRowSet.FirstL();
1.298 + break;
1.299 + }
1.300 + TEST(rc);
1.301 + }
1.302 +
1.303 +void NextRecL(TUpdDirection aUpdDirection)
1.304 + {
1.305 + TBool rc = EFalse;
1.306 + switch(aUpdDirection)
1.307 + {
1.308 + case EUpdBackward:
1.309 + rc = TheRowSet.PreviousL();
1.310 + break;
1.311 + case EUpdForward:
1.312 + default:
1.313 + rc = TheRowSet.NextL();
1.314 + break;
1.315 + }
1.316 + TEST(rc);
1.317 + }
1.318 +
1.319 +void DbRowSetUpdateTestL(TRowSetType aRowSetType, TUpdDirection aUpdDirection, TCommitRecCnt aCommitRecCnt)
1.320 + {
1.321 + TBuf<KTextColSize> textColVal;
1.322 + for(TInt ii=33000;ii<(33000+KTextColSize);++ii)
1.323 + {
1.324 + textColVal.Append(TChar(ii));
1.325 + }
1.326 +
1.327 + for(TInt compaction=0;compaction<2;++compaction)
1.328 + {
1.329 + TheTest.Printf(compaction ? _L("Compaction:Yes.\r\n") : _L("Compaction:No.\r\n"));
1.330 + TheRowSet.Close();
1.331 + TInt err;
1.332 + TUint32 fc = User::FastCounter();
1.333 + if(aRowSetType == EViewRowSet)
1.334 + {
1.335 + RDbView view;
1.336 + err = view.Prepare(TheDatabase, _L("SELECT * FROM A WHERE I1 >= 0 AND I1 <= 1000000"), RDbRowSet::EUpdatable);
1.337 + TEST2(err, KErrNone);
1.338 + err = view.EvaluateAll();
1.339 + TEST2(err, KErrNone);
1.340 + TheRowSet = view;
1.341 + }
1.342 + else
1.343 + {
1.344 + RDbTable tbl;
1.345 + err = tbl.Open(TheDatabase, _L("A"), RDbRowSet::EUpdatable);
1.346 + TEST2(err, KErrNone);
1.347 + TheRowSet = tbl;
1.348 + }
1.349 + TInt cnt = TheRowSet.CountL();
1.350 + TEST2(cnt, KTestRecordCount);
1.351 + TUint32 prepFc = CalcTickDiff(fc, User::FastCounter());
1.352 + TUint32 insFc = 0;
1.353 + TUint32 setcolFc = 0;
1.354 + TUint32 putFc = 0;
1.355 + TUint32 commitFc = 0;
1.356 + TUint32 totalFc = 0;
1.357 + fc = User::FastCounter();
1.358 + for(TInt i=0,count=0;i<KTestRecordCount;++i)
1.359 + {
1.360 + TRAP(err, (i == 0 ? FirstRecL(aUpdDirection) : NextRecL(aUpdDirection)));
1.361 + TEST2(err, KErrNone);
1.362 + TUint32 tmpFc;
1.363 + if(aCommitRecCnt != ECommit_1_Rec && count == 0)
1.364 + {
1.365 + tmpFc = User::FastCounter();
1.366 + err = TheDatabase.Begin();
1.367 + TEST2(err, KErrNone);
1.368 + commitFc += CalcTickDiff(tmpFc, User::FastCounter());
1.369 + }
1.370 + tmpFc = User::FastCounter();
1.371 + TheRowSet.UpdateL();
1.372 + insFc += CalcTickDiff(tmpFc, User::FastCounter());
1.373 + tmpFc = User::FastCounter();
1.374 + TheRowSet.SetColL(2, i * 20.0);
1.375 + TheRowSet.SetColL(3, textColVal);
1.376 + setcolFc += CalcTickDiff(tmpFc, User::FastCounter());
1.377 + tmpFc = User::FastCounter();
1.378 + TheRowSet.PutL();
1.379 + putFc += CalcTickDiff(tmpFc, User::FastCounter());
1.380 + if(aCommitRecCnt != ECommit_1_Rec && ++count == aCommitRecCnt)
1.381 + {
1.382 + tmpFc = User::FastCounter();
1.383 + count = 0;
1.384 + err = TheDatabase.Commit();
1.385 + TEST2(err, KErrNone);
1.386 + commitFc += CalcTickDiff(tmpFc, User::FastCounter());
1.387 + if(compaction)
1.388 + {
1.389 + err = TheDatabase.Compact();
1.390 + TEST2(err, KErrNone);
1.391 + }
1.392 + }
1.393 + }
1.394 + totalFc = CalcTickDiff(fc, User::FastCounter());
1.395 + PrintFcDiffAsUs(_L("###Prepare,time=%d us\r\n"), prepFc);
1.396 + PrintFcDiffAsUs(_L("###UpdateL,time=%d us\r\n"), insFc);
1.397 + PrintFcDiffAsUs(_L("###SetColL,time=%d us\r\n"), setcolFc);
1.398 + PrintFcDiffAsUs(_L("###PutL, time=%d us\r\n"), putFc);
1.399 + PrintFcDiffAsUs(_L("###Commit, time=%d us\r\n"), commitFc);
1.400 + PrintFcDiffAsUs(_L("###Total, time=%d us\r\n"), totalFc);
1.401 + TheRowSet.Close();
1.402 + PrintFileSize();
1.403 + }//end of - for(TInt compaction=0;compaction<2;++compaction)
1.404 + }
1.405 +
1.406 +///////////////////////////////////////////////////////////////////////////////////////
1.407 +
1.408 +void CreateDatabase()
1.409 + {
1.410 + TInt err = TheDatabase.Replace(TheFs, TheDatabaseFileName);
1.411 + TEST2(err, KErrNone);
1.412 + TheDatabase.Close();
1.413 + err = TheDbs.Connect();
1.414 + TEST2(err, KErrNone);
1.415 + err = TheDatabase.Open(TheDbs, TheDatabaseFileName);
1.416 + TEST2(err, KErrNone);
1.417 + err = TheDatabase.Execute(KCreateTestTableSql);
1.418 + TEST2(err, KErrNone);
1.419 + err = TheDatabase.Execute(KCreateIndexSql);
1.420 + TEST2(err, KErrNone);
1.421 + }
1.422 +
1.423 +void CreateAndFillDatabase()
1.424 + {
1.425 + TInt err = TheDatabase.Replace(TheFs, TheDatabaseFileName);
1.426 + TEST2(err, KErrNone);
1.427 + TheDatabase.Close();
1.428 + err = TheDbs.Connect();
1.429 + TEST2(err, KErrNone);
1.430 + err = TheDatabase.Open(TheDbs, TheDatabaseFileName);
1.431 + TEST2(err, KErrNone);
1.432 + err = TheDatabase.Execute(KCreateTestTableSql);
1.433 + TEST2(err, KErrNone);
1.434 + err = TheDatabase.Execute(KCreateIndexSql);
1.435 + TEST2(err, KErrNone);
1.436 + //
1.437 + TBuf<KTextColSize> textColVal;
1.438 + for(TInt ii=23000;ii<(23000+KTextColSize);++ii)
1.439 + {
1.440 + textColVal.Append(TChar(ii));
1.441 + }
1.442 + err = TheDatabase.Begin();
1.443 + TEST2(err, KErrNone);
1.444 + for(TInt i=0;i<KTestRecordCount;++i)
1.445 + {
1.446 + TBuf<KTextColSize + 100> sql;
1.447 + sql.Format(_L("INSERT INTO A(I1,I2,I3) VALUES(%d,%d,'%S')"), i, i + 100000, &textColVal);
1.448 + err = TheDatabase.Execute(sql);
1.449 + TEST2(err, 1);
1.450 + }
1.451 + err = TheDatabase.Commit();
1.452 + TEST2(err, KErrNone);
1.453 + }
1.454 +
1.455 +void DestroyDatabase()
1.456 + {
1.457 + TheRowSet.Close();
1.458 + TheDatabase.Close();
1.459 + TheDbs.Close();
1.460 + TInt err = TheFs.Delete(TheDatabaseFileName);
1.461 + TEST2(err, KErrNone);
1.462 + }
1.463 +
1.464 +void GetFastCounterFrequency()
1.465 + {
1.466 + TheTest.Start(_L("Get fast counter frequency"));
1.467 + TEST2(HAL::Get(HAL::EFastCounterFrequency, TheCounterFreq), KErrNone);
1.468 + TheTest.Printf(_L("Counter frequency=%d\r\n"), TheCounterFreq);
1.469 + }
1.470 +
1.471 +void FileBlockSizeTestsL()
1.472 + {
1.473 + TheTest.Next(_L("File Block Size test"));
1.474 +
1.475 + const TInt KBlockSizeLow = 64, KBlockSizeHigh = 1024 * 64;
1.476 + for(TInt blockSize=KBlockSizeLow;blockSize<=KBlockSizeHigh;blockSize*=2)
1.477 + {
1.478 + for(TInt addSize=-4;addSize<=4;addSize+=4)
1.479 + {
1.480 + TInt currBlockSize = blockSize + addSize;
1.481 + TBuf<100> title;
1.482 + title.Copy(_L("File block size "));
1.483 + title.AppendNum((TInt64)currBlockSize);
1.484 + title.Append(_L(" bytes"));
1.485 + TheTest.Printf(title);
1.486 +
1.487 + HBufC8* data = HBufC8::New(currBlockSize);
1.488 + TEST(data != NULL);
1.489 + TPtr8 dataPtr = data->Des();
1.490 + dataPtr.SetLength(currBlockSize);
1.491 +
1.492 + TInt err = TheTestFile.Replace(TheFs, TheTestFileName, EFileRead | EFileWrite);
1.493 + TEST2(err, KErrNone);
1.494 + err = TheTestFile.Write(dataPtr);
1.495 + TEST2(err, KErrNone);
1.496 + err = TheTestFile.Flush();
1.497 + TEST2(err, KErrNone);
1.498 + TUint32 fc = User::FastCounter();
1.499 + err = TheTestFile.Write(0, dataPtr);
1.500 + fc = CalcTickDiff(fc, User::FastCounter());
1.501 + PrintFcDiffAsUs(_L("###Time=%d us\r\n"), fc);
1.502 + TEST2(err, KErrNone);
1.503 + TheTestFile.Close();
1.504 +
1.505 + delete data;
1.506 + }
1.507 + }
1.508 + DeleteFile(TheTestFileName);
1.509 + }
1.510 +
1.511 +/**
1.512 +@SYMTestCaseID SYSLIB-DBMS-UT-3310
1.513 +@SYMTestCaseDesc DBMS, RDbView performance tests.
1.514 +@SYMTestPriority High
1.515 +@SYMTestActions The test creates and fills a test table with integer, real and text column. Then
1.516 + executes 3 test subcases:
1.517 + - updates the integer column only in all records, using "SELECT I1,I2,I3" cursor;
1.518 + - updates the text column only in all records, using "SELECT I1,I2,I3" cursor;
1.519 + - updates all columns in all records, using "SELECT I1,I2,I3" cursor;
1.520 + The execution times are printed out.
1.521 +@SYMTestExpectedResults Test must not fail
1.522 +@SYMREQ REQ7141
1.523 +*/
1.524 +void RecordLenTestL()
1.525 + {
1.526 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-3310 Record length test - create database"));
1.527 + CreateAndFillDatabase();
1.528 + ////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.529 + TheTest.Printf(_L("Record length test - update the integer column only"));
1.530 + TUint32 fc = User::FastCounter();
1.531 + RDbView view;
1.532 + TInt err = view.Prepare(TheDatabase, _L("SELECT * FROM A"));
1.533 + TEST2(err, KErrNone);
1.534 + err = view.EvaluateAll();
1.535 + TEST2(err, KErrNone);
1.536 + TheRowSet = view;
1.537 + err = TheDatabase.Begin();
1.538 + TEST2(err, KErrNone);
1.539 + TInt recCnt = 0;
1.540 + TheRowSet.FirstL();
1.541 + do
1.542 + {
1.543 + TheRowSet.UpdateL();
1.544 + TheRowSet.SetColL(1, 60000 + recCnt);
1.545 + TheRowSet.PutL();
1.546 + ++recCnt;
1.547 + }
1.548 + while(TheRowSet.NextL());
1.549 + TEST2(recCnt, KTestRecordCount);
1.550 + err = TheDatabase.Commit();
1.551 + TEST2(err, KErrNone);
1.552 + PrintFcDiffAsUs(_L("###Time=%d us\r\n"), CalcTickDiff(fc, User::FastCounter()));
1.553 + TheRowSet.Close();
1.554 + ////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.555 + TheTest.Printf(_L("Record length test - update the text column only"));
1.556 + fc = User::FastCounter();
1.557 + err = view.Prepare(TheDatabase, _L("SELECT * FROM A"));
1.558 + TEST2(err, KErrNone);
1.559 + err = view.EvaluateAll();
1.560 + TEST2(err, KErrNone);
1.561 + TheRowSet = view;
1.562 + err = TheDatabase.Begin();
1.563 + TEST2(err, KErrNone);
1.564 + recCnt = 0;
1.565 + TheRowSet.FirstL();
1.566 + do
1.567 + {
1.568 + TheRowSet.UpdateL();
1.569 + TheRowSet.SetColL(3, _L("0123456789"));
1.570 + TheRowSet.PutL();
1.571 + ++recCnt;
1.572 + }
1.573 + while(TheRowSet.NextL());
1.574 + TEST2(recCnt, KTestRecordCount);
1.575 + err = TheDatabase.Commit();
1.576 + TEST2(err, KErrNone);
1.577 + PrintFcDiffAsUs(_L("###Time=%d us\r\n"), CalcTickDiff(fc, User::FastCounter()));
1.578 + TheRowSet.Close();
1.579 + ////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.580 + TheTest.Printf(_L("Record length test - update all columns"));
1.581 + fc = User::FastCounter();
1.582 + err = view.Prepare(TheDatabase, _L("SELECT * FROM A"));
1.583 + TEST2(err, KErrNone);
1.584 + err = view.EvaluateAll();
1.585 + TEST2(err, KErrNone);
1.586 + TheRowSet = view;
1.587 + err = TheDatabase.Begin();
1.588 + TEST2(err, KErrNone);
1.589 + recCnt = 0;
1.590 + TheRowSet.FirstL();
1.591 + do
1.592 + {
1.593 + TheRowSet.UpdateL();
1.594 + TheRowSet.SetColL(1, 34567 - recCnt);
1.595 + TheRowSet.SetColL(2, 888.111);
1.596 + TheRowSet.SetColL(3, _L("QWETYUIOPASDF"));
1.597 + TheRowSet.PutL();
1.598 + ++recCnt;
1.599 + }
1.600 + while(TheRowSet.NextL());
1.601 + TEST2(recCnt, KTestRecordCount);
1.602 + err = TheDatabase.Commit();
1.603 + TEST2(err, KErrNone);
1.604 + PrintFcDiffAsUs(_L("###Time=%d ms\r\n"), CalcTickDiff(fc, User::FastCounter()));
1.605 + ////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.606 + DestroyDatabase();//This will destroy TheRowSet object too.
1.607 + }
1.608 +
1.609 +/**
1.610 +@SYMTestCaseID SYSLIB-DBMS-UT-3311
1.611 +@SYMTestCaseDesc DBMS, RDbView performance tests.
1.612 +@SYMTestPriority High
1.613 +@SYMTestActions The test measures the time used by insert-only or updatable cursor to:
1.614 + - insert certain amount of records, comitting after each insert;
1.615 + - insert certain amount of records, comitting after 20 inserts;
1.616 + - insert certain amount of records, comitting at the end;
1.617 + All cases repeated with and without compaction (except the first one).
1.618 + The execution times are printed out.
1.619 +@SYMTestExpectedResults Test must not fail
1.620 +@SYMREQ REQ7141
1.621 +*/
1.622 +void InsertTestsL()
1.623 + {
1.624 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-3311 RDbView \"insert\" performance tests"));
1.625 + for(TInt i1=0;i1<COUNT_OF(KRowSetTypes);++i1)
1.626 + {
1.627 + for(TInt i2=0;i2<COUNT_OF(KAccessModes);++i2)
1.628 + {
1.629 + for(TInt i3=0;i3<COUNT_OF(KCommitTypes);++i3)
1.630 + {
1.631 + CreateDatabase();
1.632 + TBuf<200> title;
1.633 + title.Copy(_L("Insert."));
1.634 + title.Append(KRowSetTypeStr[i1]);
1.635 + title.Append(KAccessModeStr[i2]);
1.636 + title.Append(KCommitTypeStr[i3]);
1.637 + TheTest.Printf(title);
1.638 + DbRowSetInsertTestL(KRowSetTypes[i1], KAccessModes[i2], KCommitTypes[i3]);
1.639 + DestroyDatabase();
1.640 + }
1.641 + }
1.642 + }
1.643 + }
1.644 +
1.645 +/**
1.646 +@SYMTestCaseID SYSLIB-DBMS-UT-3312
1.647 +@SYMTestCaseDesc DBMS, RDbView performance tests.
1.648 +@SYMTestPriority High
1.649 +@SYMTestActions The test measures the time used by updatable cursor to:
1.650 + - update (moving forward/backward) certain amount of records, comitting after each update;
1.651 + - update (moving forward/backward) certain amount of records, comitting after 20 update;
1.652 + - update (moving forward/backward) certain amount of records, comitting at the end;
1.653 + All cases repeated with and without compaction (except the first one).
1.654 + The execution times are printed out.
1.655 +@SYMTestExpectedResults Test must not fail
1.656 +@SYMREQ REQ7141
1.657 +*/
1.658 +void UpdateTestsL()
1.659 + {
1.660 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-3312 RDbView \"update\" performance tests"));
1.661 + for(TInt i1=0;i1<COUNT_OF(KRowSetTypes);++i1)
1.662 + {
1.663 + for(TInt i2=0;i2<COUNT_OF(KUpdDirectionTypes);++i2)
1.664 + {
1.665 + for(TInt i3=0;i3<COUNT_OF(KCommitTypes);++i3)
1.666 + {
1.667 + CreateAndFillDatabase();
1.668 + TBuf<200> title;
1.669 + title.Copy(_L("Update."));
1.670 + title.Append(KRowSetTypeStr[i1]);
1.671 + title.Append(KUpdDirectionTypeStr[i2]);
1.672 + title.Append(KCommitTypeStr[i3]);
1.673 + TheTest.Printf(title);
1.674 + DbRowSetUpdateTestL(KRowSetTypes[i1], KUpdDirectionTypes[i2], KCommitTypes[i3]);
1.675 + DestroyDatabase();
1.676 + }
1.677 + }
1.678 + }
1.679 + }
1.680 +
1.681 +/**
1.682 +@SYMTestCaseID SYSLIB-DBMS-UT-3313
1.683 +@SYMTestCaseDesc DBMS, RDbDatabase::Execute() performance tests.
1.684 +@SYMTestPriority High
1.685 +@SYMTestActions The test measures the time used by RDbDatabase::Execute() to:
1.686 + - insert certain amount of records, comitting after each insert;
1.687 + - insert certain amount of records, comitting after 20 inserts;
1.688 + - insert certain amount of records, comitting at the end;
1.689 + All cases repeated with and without compaction (except the first one).
1.690 + The execution times are printed out.
1.691 +@SYMTestExpectedResults Test must not fail
1.692 +@SYMREQ REQ7141
1.693 +*/
1.694 +void DbInsertTestsL()
1.695 + {
1.696 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-3313 RDbDatabase::Execute() \"insert\" performance tests"));
1.697 + TBuf<KTextColSize> textColVal;
1.698 + for(TInt ii=23000;ii<(23000+KTextColSize);++ii)
1.699 + {
1.700 + textColVal.Append(TChar(ii));
1.701 + }
1.702 + for(TInt compaction=0;compaction<2;++compaction)
1.703 + {
1.704 + for(TInt i3=0;i3<COUNT_OF(KCommitTypes);++i3)
1.705 + {
1.706 + CreateDatabase();
1.707 + TBuf<200> title;
1.708 + title.Copy(_L("RDbDatabase::Execute().Insert."));
1.709 + title.Append(KCommitTypeStr[i3]);
1.710 + title.Append(compaction ? _L("Compaction:Yes.") : _L("Compaction:No."));
1.711 + TheTest.Printf(title);
1.712 + TInt count = 0, err = KErrNone;
1.713 + TUint32 fc = User::FastCounter();
1.714 + for(TInt i=0;i<KTestRecordCount;++i)
1.715 + {
1.716 + if(KCommitTypes[i3] != ECommit_1_Rec && count == 0)
1.717 + {
1.718 + err = TheDatabase.Begin();
1.719 + TEST2(err, KErrNone);
1.720 + }
1.721 + TBuf<KTextColSize + 100> sql;
1.722 + sql.Format(_L("INSERT INTO A(I1,I2,I3) VALUES(%d,%d,'%S')"), i, i + 100000, &textColVal);
1.723 + err = TheDatabase.Execute(sql);
1.724 + TEST2(err, 1);
1.725 + if(KCommitTypes[i3] != ECommit_1_Rec && ++count == KCommitTypes[i3])
1.726 + {
1.727 + count = 0;
1.728 + err = TheDatabase.Commit();
1.729 + TEST2(err, KErrNone);
1.730 + if(compaction)
1.731 + {
1.732 + err = TheDatabase.Compact();
1.733 + TEST2(err, KErrNone);
1.734 + }
1.735 + }
1.736 + }
1.737 + PrintFcDiffAsUs(_L("###RDbDatabase::Execute(), Time=%d us\r\n"), CalcTickDiff(fc, User::FastCounter()));
1.738 + PrintFileSize();
1.739 + DestroyDatabase();
1.740 + }
1.741 + }
1.742 + }
1.743 +
1.744 +/**
1.745 +@SYMTestCaseID SYSLIB-DBMS-UT-3314
1.746 +@SYMTestCaseDesc DBMS, RDbDatabase::Execute() performance tests.
1.747 +@SYMTestPriority High
1.748 +@SYMTestActions The test measures the time used by RDbDatabase::Execute() to:
1.749 + - update certain amount of records, comitting after each update;
1.750 + - update certain amount of records, comitting after 20 updates;
1.751 + - update certain amount of records, comitting at the end;
1.752 + All cases repeated with and without compaction (except the first one).
1.753 + The execution times are printed out.
1.754 +@SYMTestExpectedResults Test must not fail
1.755 +@SYMREQ REQ7141
1.756 +*/
1.757 +void DbUpdateTestsL()
1.758 + {
1.759 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-3314 RDbDatabase::Execute() \"update\" performance tests"));
1.760 + TBuf<KTextColSize> textColVal;
1.761 + for(TInt ii=43000;ii<(43000+KTextColSize);++ii)
1.762 + {
1.763 + textColVal.Append(TChar(ii));
1.764 + }
1.765 + for(TInt compaction=0;compaction<2;++compaction)
1.766 + {
1.767 + for(TInt i3=0;i3<COUNT_OF(KCommitTypes);++i3)
1.768 + {
1.769 + CreateAndFillDatabase();
1.770 + TBuf<200> title;
1.771 + title.Copy(_L("RDbDatabase::Execute().Update."));
1.772 + title.Append(KCommitTypeStr[i3]);
1.773 + title.Append(compaction ? _L("Compaction:Yes.") : _L("Compaction:No."));
1.774 + TheTest.Printf(title);
1.775 + TInt count = 0, err = KErrNone;
1.776 + TUint32 fc = User::FastCounter();
1.777 + for(TInt i=0;i<KTestRecordCount;++i)
1.778 + {
1.779 + if(KCommitTypes[i3] != ECommit_1_Rec && count == 0)
1.780 + {
1.781 + err = TheDatabase.Begin();
1.782 + TEST2(err, KErrNone);
1.783 + }
1.784 + TBuf<KTextColSize + 100> sql;
1.785 + sql.Format(_L("UPDATE A SET I2=%d,I3='%S' WHERE I1=%d"), i + 556622, &textColVal, i);
1.786 + err = TheDatabase.Execute(sql);
1.787 + TEST2(err, 1);
1.788 + if(KCommitTypes[i3] != ECommit_1_Rec && ++count == KCommitTypes[i3])
1.789 + {
1.790 + count = 0;
1.791 + err = TheDatabase.Commit();
1.792 + TEST2(err, KErrNone);
1.793 + if(compaction)
1.794 + {
1.795 + err = TheDatabase.Compact();
1.796 + TEST2(err, KErrNone);
1.797 + }
1.798 + }
1.799 + }
1.800 + PrintFcDiffAsUs(_L("###RDbDatabase::Execute(), Time=%d us\r\n"), CalcTickDiff(fc, User::FastCounter()));
1.801 + PrintFileSize();
1.802 + DestroyDatabase();
1.803 + }
1.804 + }
1.805 + }
1.806 +
1.807 +/**
1.808 +@SYMTestCaseID PDS-DBMS-UT-4010
1.809 +@SYMTestCaseDesc Test for DEF141419 - DBMS, new performance tests - RDbUpdate, RDbStoreDatabase.
1.810 + Tests the performance of RDbColWriteStream::OpenLC() and RDbColWriteStream::OpenL().
1.811 +@SYMTestPriority High
1.812 +@SYMTestActions Test for DEF141419 - DBMS, new performance tests - RDbUpdate, RDbStoreDatabase
1.813 +@SYMTestExpectedResults Test must not fail
1.814 +@SYMDEF DEF141419
1.815 +*/
1.816 +void DbColWriteStreamTestsL()
1.817 + {
1.818 + TheTest.Next(_L(" @SYMTestCaseID:PDS-DBMS-UT-4010 RDbColWriteStream performance test"));
1.819 +
1.820 + TInt err = TheDatabase.Replace(TheFs, TheDatabaseFileName);
1.821 + TEST2(err, KErrNone);
1.822 + err = TheDatabase.Execute(KCreateTestTableSql2);
1.823 + TEST(err >= 0);
1.824 +
1.825 + RDbView view;
1.826 + err = view.Prepare(TheDatabase, _L("select * from A"), view.EInsertOnly);
1.827 + TEST2(err, KErrNone);
1.828 + TheRowSet = view;
1.829 +
1.830 + CDbColSet* colSet = TheRowSet.ColSetL();
1.831 + const TDbColNo KIdx1 = colSet->ColNo(_L("I1"));
1.832 + const TDbColNo KIdx2 = colSet->ColNo(_L("I2"));
1.833 + const TDbColNo KIdx3 = colSet->ColNo(_L("I3"));
1.834 + delete colSet;
1.835 +
1.836 + TheTextRndData.SetLength(KColSize2);
1.837 + TheTextRndData.Fill(KBufChar);
1.838 + TheBinRndData.SetLength(KColSize2);
1.839 + TheBinRndData.Fill(KBufChar);
1.840 +
1.841 + err = TheDatabase.Begin();
1.842 + TEST2(err, KErrNone);
1.843 +
1.844 + TUint32 openLcFc = 0;
1.845 + TUint32 openLFc = 0;
1.846 + TUint32 fc = User::FastCounter();
1.847 +
1.848 + for(TInt i=0;i<KTestRecordCount;++i)
1.849 + {
1.850 + TheRowSet.InsertL();
1.851 + TheRowSet.SetColL(KIdx1, i + 1);
1.852 +
1.853 + RDbColWriteStream strm1;
1.854 + TUint32 tmp = User::FastCounter();
1.855 + strm1.OpenLC(TheRowSet, KIdx2);
1.856 + openLcFc += CalcTickDiff(tmp, User::FastCounter());
1.857 + strm1.WriteL(TheTextRndData, KColSize2);
1.858 + strm1.CommitL();
1.859 + CleanupStack::PopAndDestroy(&strm1);
1.860 +
1.861 + RDbColWriteStream strm2;
1.862 + CleanupClosePushL(strm2);
1.863 + tmp = User::FastCounter();
1.864 + strm2.OpenL(TheRowSet, KIdx3);
1.865 + openLFc += CalcTickDiff(tmp, User::FastCounter());
1.866 + strm2.WriteL(TheBinRndData, KColSize2);
1.867 + strm2.CommitL();
1.868 + CleanupStack::PopAndDestroy(&strm2);
1.869 +
1.870 + TheRowSet.PutL();
1.871 + }
1.872 +
1.873 + PrintFcDiffAsUs2(_L("###RDbColWriteStream, write %3d records, Time=%d us\r\n"),
1.874 + KTestRecordCount, CalcTickDiff(fc, User::FastCounter()));
1.875 + PrintFcDiffAsUs (_L("###OpenLC() , Time=%d us\r\n"), openLcFc);
1.876 + PrintFcDiffAsUs (_L("###OpenL() , Time=%d us\r\n"), openLFc);
1.877 +
1.878 + TheRowSet.Close();
1.879 +
1.880 + err = TheDatabase.Commit();
1.881 + TEST2(err, KErrNone);
1.882 +
1.883 + TheDatabase.Close();
1.884 + }
1.885 +
1.886 +/**
1.887 +@SYMTestCaseID PDS-DBMS-UT-4011
1.888 +@SYMTestCaseDesc Test for DEF141419 - DBMS, new performance tests - RDbUpdate, RDbStoreDatabase.
1.889 + Tests the performance of RDbColReadStream::OpenLC() and RDbColReadStream::OpenL().
1.890 +@SYMTestPriority High
1.891 +@SYMTestActions Test for DEF141419 - DBMS, new performance tests - RDbUpdate, RDbStoreDatabase.
1.892 +@SYMTestExpectedResults Test must not fail
1.893 +@SYMDEF DEF141419
1.894 +*/
1.895 +void DbColReadStreamTestsL()
1.896 + {
1.897 + TheTest.Next(_L(" @SYMTestCaseID:PDS-DBMS-UT-4011 RDbColReadStream performance test"));
1.898 +
1.899 + TInt err = TheDatabase.Open(TheFs, TheDatabaseFileName);
1.900 + TEST2(err, KErrNone);
1.901 +
1.902 + RDbView view;
1.903 + err = view.Prepare(TheDatabase, _L("select * from A"), view.EReadOnly);
1.904 + TEST2(err, KErrNone);
1.905 + TheRowSet = view;
1.906 +
1.907 + err = view.EvaluateAll();
1.908 + TEST2(err, KErrNone);
1.909 +
1.910 + CDbColSet* colSet = TheRowSet.ColSetL();
1.911 + const TDbColNo KIdx1 = colSet->ColNo(_L("I1"));
1.912 + const TDbColNo KIdx2 = colSet->ColNo(_L("I2"));
1.913 + const TDbColNo KIdx3 = colSet->ColNo(_L("I3"));
1.914 + delete colSet;
1.915 +
1.916 + TBuf8<KColSize2> binData;
1.917 + TBuf16<KColSize2> textData;
1.918 +
1.919 + TInt recCnt = 0;
1.920 + TUint32 openLcFc = 0;
1.921 + TUint32 openLFc = 0;
1.922 + TUint32 fc = User::FastCounter();
1.923 +
1.924 + if(TheRowSet.FirstL())
1.925 + {
1.926 + do
1.927 + {
1.928 + TheRowSet.GetL();
1.929 + ++recCnt;
1.930 +
1.931 + TInt i1 = TheRowSet.ColInt(KIdx1);
1.932 + TEST2(recCnt, i1);
1.933 +
1.934 + RDbColReadStream strm1;
1.935 + TUint32 tmp = User::FastCounter();
1.936 + strm1.OpenLC(TheRowSet, KIdx2);
1.937 + openLcFc += CalcTickDiff(tmp, User::FastCounter());
1.938 + strm1.ReadL(textData, KColSize2);
1.939 + CleanupStack::PopAndDestroy(&strm1);
1.940 + TEST(textData == TheTextRndData);
1.941 +
1.942 + RDbColReadStream strm2;
1.943 + CleanupClosePushL(strm2);
1.944 + tmp = User::FastCounter();
1.945 + strm2.OpenL(TheRowSet, KIdx3);
1.946 + openLFc += CalcTickDiff(tmp, User::FastCounter());
1.947 + strm2.ReadL(binData, KColSize2);
1.948 + CleanupStack::PopAndDestroy(&strm2);
1.949 + TEST(binData == TheBinRndData);
1.950 + } while(TheRowSet.NextL());
1.951 + }
1.952 + TEST2(recCnt, KTestRecordCount);
1.953 +
1.954 + PrintFcDiffAsUs2(_L("###RDbColReadStream, read %3d records, Time=%d us\r\n"),
1.955 + recCnt, CalcTickDiff(fc, User::FastCounter()));
1.956 + PrintFcDiffAsUs (_L("###OpenLC() , Time=%d us\r\n"), openLcFc);
1.957 + PrintFcDiffAsUs (_L("###OpenL() , Time=%d us\r\n"), openLFc);
1.958 +
1.959 + TheRowSet.Close();
1.960 +
1.961 + TheDatabase.Close();
1.962 + }
1.963 +
1.964 +/**
1.965 +@SYMTestCaseID PDS-DBMS-UT-4012
1.966 +@SYMTestCaseDesc Test for DEF141419 - DBMS, new performance tests - RDbUpdate, RDbStoreDatabase.
1.967 + RDbUpdate performance tests.
1.968 +@SYMTestPriority High
1.969 +@SYMTestActions Test for DEF141419 - DBMS, new performance tests - RDbUpdate, RDbStoreDatabase
1.970 +@SYMTestExpectedResults Test must not fail
1.971 +@SYMDEF DEF141419
1.972 +*/
1.973 +void DbUpdateTestL()
1.974 + {
1.975 + TheTest.Next(_L(" @SYMTestCaseID:PDS-DBMS-UT-4012 RDbUpdate performance test"));
1.976 +
1.977 + TInt err = TheDbs.Connect();
1.978 + TEST2(err, KErrNone);
1.979 +
1.980 + err = TheDatabase.Open(TheDbs, TheDatabaseFileName);
1.981 + TEST2(err, KErrNone);
1.982 +
1.983 + TUint32 execFc = 0;
1.984 + TUint32 nextFc = 0;
1.985 + TUint32 rowCntFc = 0;
1.986 +
1.987 + //Synchronous update
1.988 + TInt recCnt = 0;
1.989 + RDbUpdate upd1;
1.990 + TUint32 fc = User::FastCounter();
1.991 + err = upd1.Execute(TheDatabase, _L("UPDATE A SET I1=1000, I2='8888888888888888'"));
1.992 + execFc = CalcTickDiff(fc, User::FastCounter());
1.993 + TEST2(err, KErrNone);
1.994 + TUint32 tmp = User::FastCounter();
1.995 + while((err = upd1.Next()) > 0)
1.996 + {
1.997 + }
1.998 + nextFc = CalcTickDiff(tmp, User::FastCounter());
1.999 + tmp = User::FastCounter();
1.1000 + recCnt = upd1.RowCount();
1.1001 + rowCntFc = CalcTickDiff(tmp, User::FastCounter());
1.1002 + upd1.Close();
1.1003 + fc = CalcTickDiff(fc, User::FastCounter());
1.1004 + TEST2(err, 0);
1.1005 + TEST2(recCnt, KTestRecordCount);
1.1006 +
1.1007 + TheDatabase.Close();
1.1008 +
1.1009 + PrintFcDiffAsUs2(_L("###Sync RDbUpdate, %3d records, Time=%d us\r\n"), recCnt, fc);
1.1010 + PrintFcDiffAsUs (_L("###Execute() , Time=%d us\r\n"), execFc);
1.1011 + PrintFcDiffAsUs (_L("###Next() , Time=%d us\r\n"), nextFc);
1.1012 + PrintFcDiffAsUs (_L("###RowCount() , Time=%d us\r\n"), rowCntFc);
1.1013 +
1.1014 + //Asynchronous update
1.1015 + err = TheDatabase.Open(TheDbs, TheDatabaseFileName);
1.1016 + TEST2(err, KErrNone);
1.1017 +
1.1018 + execFc = 0;
1.1019 + nextFc = 0;
1.1020 + rowCntFc = 0;
1.1021 + recCnt = 0;
1.1022 +
1.1023 + RDbUpdate upd2;
1.1024 + fc = User::FastCounter();
1.1025 + err = upd2.Execute(TheDatabase, _L("UPDATE A SET I1=5678, I2='9w27u22272252542r2242242424221'"));
1.1026 + execFc = CalcTickDiff(fc, User::FastCounter());
1.1027 + TEST2(err, KErrNone);
1.1028 + TRequestStatus stat;
1.1029 + tmp = User::FastCounter();
1.1030 + do
1.1031 + {
1.1032 + upd2.Next(stat);
1.1033 + User::WaitForRequest(stat);
1.1034 + } while(stat.Int() > 0);
1.1035 + nextFc = CalcTickDiff(tmp, User::FastCounter());
1.1036 + tmp = User::FastCounter();
1.1037 + recCnt = upd2.RowCount();
1.1038 + rowCntFc = CalcTickDiff(tmp, User::FastCounter());
1.1039 + upd2.Close();
1.1040 + fc = CalcTickDiff(fc, User::FastCounter());
1.1041 + TEST2(stat.Int(), 0);
1.1042 + TEST2(recCnt, KTestRecordCount);
1.1043 +
1.1044 + TheDatabase.Close();
1.1045 +
1.1046 + PrintFcDiffAsUs2(_L("###Async RDbUpdate, %3d records, Time=%d us\r\n"), recCnt, fc);
1.1047 + PrintFcDiffAsUs (_L("###Execute() , Time=%d us\r\n"), execFc);
1.1048 + PrintFcDiffAsUs (_L("###Next() , Time=%d us\r\n"), nextFc);
1.1049 + PrintFcDiffAsUs (_L("###RowCount() , Time=%d us\r\n"), rowCntFc);
1.1050 +
1.1051 + TheDbs.Close();
1.1052 + err = TheFs.Delete(TheDatabaseFileName);
1.1053 + TEST2(err, KErrNone);
1.1054 + }
1.1055 +
1.1056 +/**
1.1057 +@SYMTestCaseID PDS-DBMS-UT-4013
1.1058 +@SYMTestCaseDesc Test for DEF141419 - DBMS, new performance tests - RDbUpdate, RDbStoreDatabase.
1.1059 + RDbStoreDatabase performance tests.
1.1060 +@SYMTestPriority High
1.1061 +@SYMTestActions Test for DEF141419 - DBMS, new performance tests - RDbUpdate, RDbStoreDatabase.
1.1062 +@SYMTestExpectedResults Test must not fail
1.1063 +@SYMDEF DEF141419
1.1064 +*/
1.1065 +void DbStoreDatabaseTestL()
1.1066 + {
1.1067 + TheTest.Next(_L(" @SYMTestCaseID:PDS-DBMS-UT-4013 RDbStoreDatabase performance test"));
1.1068 +
1.1069 + CFileStore* fstore = CPermanentFileStore::ReplaceLC(TheFs, TheDatabaseFileName, EFileRead | EFileWrite);
1.1070 + fstore->SetTypeL(fstore->Layout());
1.1071 +
1.1072 + //Create the database, insert records, compress the store.
1.1073 +
1.1074 + RDbStoreDatabase db1;
1.1075 + CleanupClosePushL(db1);
1.1076 + TUint32 fc = User::FastCounter();
1.1077 + TStreamId strmId = db1.CreateL(fstore);
1.1078 + TUint32 createFc = CalcTickDiff(fc, User::FastCounter());
1.1079 +
1.1080 + TInt err = db1.Execute(KCreateTestTableSql2);
1.1081 + TEST(err >= 0);
1.1082 + err = db1.Begin();
1.1083 + TEST2(err, 0);
1.1084 + for(TInt i=0;i<KTestRecordCount;++i)
1.1085 + {
1.1086 + err = db1.Execute(_L("INSERT INTO A(I1, I2) VALUES(1, 'ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZAAAAAAAAAAAAAAAAAAAAAAAAAAAA')"));
1.1087 + TEST2(err, 1);
1.1088 + }
1.1089 + err = db1.Commit();
1.1090 + TEST2(err, 0);
1.1091 +
1.1092 + CleanupStack::PopAndDestroy(&db1);
1.1093 + TUint32 writeFc = CalcTickDiff(fc, User::FastCounter());
1.1094 +
1.1095 + TInt fsize1 = 0;
1.1096 + err = fstore->File().Size(fsize1);
1.1097 + TEST2(err, KErrNone);
1.1098 +
1.1099 + fc = User::FastCounter();
1.1100 + RDbStoreDatabase::CompressL(*fstore, strmId);
1.1101 + TUint32 compressFc = CalcTickDiff(fc, User::FastCounter());
1.1102 +
1.1103 + TInt fsize2 = 0;
1.1104 + err = fstore->File().Size(fsize2);
1.1105 + TEST2(err, KErrNone);
1.1106 +
1.1107 + CleanupStack::PopAndDestroy(fstore);
1.1108 +
1.1109 + PrintFcDiffAsUs2(_L("###RDbStoreDatabase, write %3d records, Time=%d us\r\n"), KTestRecordCount, writeFc);
1.1110 + PrintFcDiffAsUs (_L("###CreateL() , Time=%d us\r\n"), createFc);
1.1111 + PrintFcDiffAsUs (_L("###CompressL() , Time=%d us\r\n"), compressFc);
1.1112 +
1.1113 + //Decompress the store, open the database, read the records
1.1114 +
1.1115 + fstore = CPermanentFileStore::OpenLC(TheFs, TheDatabaseFileName, EFileRead | EFileWrite);
1.1116 + fstore->SetTypeL(fstore->Layout());
1.1117 +
1.1118 + fc = User::FastCounter();
1.1119 + RDbStoreDatabase::DecompressL(*fstore, strmId);
1.1120 + TUint32 decompressFc = CalcTickDiff(fc, User::FastCounter());
1.1121 +
1.1122 + TInt fsize3 = 0;
1.1123 + err = fstore->File().Size(fsize3);
1.1124 + TEST2(err, KErrNone);
1.1125 +
1.1126 + RDbStoreDatabase db2;
1.1127 + CleanupClosePushL(db2);
1.1128 + fc = User::FastCounter();
1.1129 + db2.OpenL(fstore, strmId);
1.1130 + TUint32 openFc = CalcTickDiff(fc, User::FastCounter());
1.1131 +
1.1132 + RDbView view;
1.1133 + err = view.Prepare(db2, _L("SELECT * FROM A"));
1.1134 + TEST2(err, KErrNone);
1.1135 + err = view.EvaluateAll();
1.1136 + TEST2(err, KErrNone);
1.1137 + TheRowSet = view;
1.1138 +
1.1139 + CDbColSet* colSet = TheRowSet.ColSetL();
1.1140 + const TDbColNo KIdx1 = colSet->ColNo(_L("I1"));
1.1141 + const TDbColNo KIdx2 = colSet->ColNo(_L("I2"));
1.1142 + const TDbColNo KIdx3 = colSet->ColNo(_L("I3"));
1.1143 + delete colSet;
1.1144 +
1.1145 + TInt recCnt = 0;
1.1146 + if(TheRowSet.FirstL())
1.1147 + {
1.1148 + do
1.1149 + {
1.1150 + TheRowSet.GetL();
1.1151 + ++recCnt;
1.1152 +
1.1153 + RDbColReadStream strm1;
1.1154 + strm1.OpenLC(TheRowSet, KIdx2);
1.1155 + TBuf<KColSize2> buf;
1.1156 + _LIT(KText, "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZAAAAAAAAAAAAAAAAAAAAAAAAAAAA");//the same as the used in the INSERT statement above
1.1157 + strm1.ReadL(buf, KText().Length());
1.1158 + CleanupStack::PopAndDestroy(&strm1);
1.1159 + TEST(KText() == buf);
1.1160 + } while(TheRowSet.NextL());
1.1161 + }
1.1162 + TEST2(recCnt, KTestRecordCount);
1.1163 +
1.1164 + TheRowSet.Close();
1.1165 + TUint32 readFc = CalcTickDiff(fc, User::FastCounter());
1.1166 +
1.1167 + CleanupStack::PopAndDestroy(&db2);
1.1168 + CleanupStack::PopAndDestroy(fstore);
1.1169 +
1.1170 + PrintFcDiffAsUs2(_L("###RDbStoreDatabase, read %3d records , Time=%d us\r\n"), recCnt, readFc);
1.1171 + PrintFcDiffAsUs (_L("###OpenL() , Time=%d us\r\n"), openFc);
1.1172 + PrintFcDiffAsUs (_L("###DecompressL() , Time=%d us\r\n"), decompressFc);
1.1173 + TheTest.Printf(_L("###File size. After write: %d. After Compress(): %d. After Decompress(): %d\r\n"), fsize1, fsize2, fsize3);
1.1174 +
1.1175 + err = TheFs.Delete(TheDatabaseFileName);
1.1176 + TEST2(err, KErrNone);
1.1177 + }
1.1178 +
1.1179 +/**
1.1180 +@SYMTestCaseID PDS-DBMS-UT-4014
1.1181 +@SYMTestCaseDesc Test for DEF141419 - DBMS, new performance tests - RDbUpdate, RDbStoreDatabase.
1.1182 + RDbDatabase performance tests.
1.1183 +@SYMTestPriority High
1.1184 +@SYMTestActions Test for DEF141419 - DBMS, new performance tests - RDbUpdate, RDbStoreDatabase.
1.1185 +@SYMTestExpectedResults Test must not fail
1.1186 +@SYMDEF DEF141419
1.1187 +*/
1.1188 +void DbDatabaseTestL()
1.1189 + {
1.1190 + TheTest.Next(_L(" @SYMTestCaseID:PDS-DBMS-UT-4014 RDbDatabase performance test"));
1.1191 +
1.1192 + TInt err = TheDatabase.Replace(TheFs, TheDatabaseFileName);
1.1193 + TEST2(err, KErrNone);
1.1194 +
1.1195 + //CDbColSet
1.1196 + _LIT(KColName1, "Col1");
1.1197 + _LIT(KColName2, "Col2");
1.1198 + _LIT(KColName3, "Col3");
1.1199 + TUint32 fc = User::FastCounter();
1.1200 + CDbColSet* colset = CDbColSet::NewLC();
1.1201 + TDbCol col1(KColName1, EDbColInt32);
1.1202 + colset->AddL(col1);
1.1203 + TDbCol col2(KColName2, EDbColText16, 100);
1.1204 + colset->AddL(col2);
1.1205 + TDbCol col3(KColName3, EDbColBinary, 100);
1.1206 + colset->AddL(col3);
1.1207 + TUint32 colSetFc = CalcTickDiff(fc, User::FastCounter());
1.1208 + PrintFcDiffAsUs(_L("###CDbColSet::NewLC() & CDbColSet::AddL(), Time=%d us\r\n"), colSetFc);
1.1209 +
1.1210 + //RDbDatabase::CreateTable()
1.1211 + _LIT(KTblName, "ATbl");
1.1212 + fc = User::FastCounter();
1.1213 + err = TheDatabase.CreateTable(KTblName, *colset);
1.1214 + TUint32 createTblFc = CalcTickDiff(fc, User::FastCounter());
1.1215 + TEST2(err, KErrNone);
1.1216 + PrintFcDiffAsUs(_L("###RDbDatabase::CreateTable(), Time=%d us\r\n"), createTblFc);
1.1217 +
1.1218 + //RDbDatabase::AlterTable()
1.1219 + _LIT(KColName4, "Col4");
1.1220 + TDbCol col4(KColName4, EDbColReal64);
1.1221 + colset->AddL(col4);
1.1222 + fc = User::FastCounter();
1.1223 + err = TheDatabase.AlterTable(KTblName, *colset);
1.1224 + TUint32 alterTblFc = CalcTickDiff(fc, User::FastCounter());
1.1225 + TEST2(err, KErrNone);
1.1226 + PrintFcDiffAsUs(_L("###RDbDatabase::AlterTable(), Time=%d us\r\n"), alterTblFc);
1.1227 +
1.1228 + //CDbKey
1.1229 + fc = User::FastCounter();
1.1230 + CDbKey* dbKey = CDbKey::NewLC();
1.1231 + TDbKeyCol keyCol1(KColName1, TDbKeyCol::EAsc);
1.1232 + dbKey->AddL(keyCol1);
1.1233 + TDbKeyCol keyCol2(KColName4, TDbKeyCol::EDesc);
1.1234 + dbKey->AddL(keyCol2);
1.1235 + TUint32 dbKeyFc = CalcTickDiff(fc, User::FastCounter());
1.1236 + PrintFcDiffAsUs(_L("###CDbKey::NewLC() & CDbKey::AddL(), Time=%d us\r\n"), dbKeyFc);
1.1237 +
1.1238 + //RDbDatabase::CreateIndex()
1.1239 + _LIT(KKeyName, "AKey");
1.1240 + fc = User::FastCounter();
1.1241 + err = TheDatabase.CreateIndex(KKeyName, KTblName, *dbKey);
1.1242 + TUint32 createIndexFc = CalcTickDiff(fc, User::FastCounter());
1.1243 + TEST2(err, KErrNone);
1.1244 + PrintFcDiffAsUs(_L("###RDbDatabase::CreateIndex(), Time=%d us\r\n"), createIndexFc);
1.1245 +
1.1246 + CleanupStack::PopAndDestroy(dbKey);
1.1247 + CleanupStack::PopAndDestroy(colset);
1.1248 +
1.1249 + //RDbDatabase::TableNamesL()
1.1250 + fc = User::FastCounter();
1.1251 + CDbTableNames* tblNames = TheDatabase.TableNamesL();
1.1252 + TUint32 tblNamesFc = CalcTickDiff(fc, User::FastCounter());
1.1253 + delete tblNames;
1.1254 + PrintFcDiffAsUs(_L("###RDbDatabase::TableNamesL(), Time=%d us\r\n"), tblNamesFc);
1.1255 +
1.1256 + //RDbDatabase::IndexNamesL()
1.1257 + fc = User::FastCounter();
1.1258 + CDbIndexNames* idxNames = TheDatabase.IndexNamesL(KTblName);
1.1259 + TUint32 idxNamesFc = CalcTickDiff(fc, User::FastCounter());
1.1260 + delete idxNames;
1.1261 + PrintFcDiffAsUs(_L("###RDbDatabase::IndexNamesL(), Time=%d us\r\n"), idxNamesFc);
1.1262 +
1.1263 + //RDbDatabase::ColSetL()
1.1264 + fc = User::FastCounter();
1.1265 + colset = TheDatabase.ColSetL(KTblName);
1.1266 + colSetFc = CalcTickDiff(fc, User::FastCounter());
1.1267 + delete colset;
1.1268 + PrintFcDiffAsUs(_L("###RDbDatabase::ColSetL(), Time=%d us\r\n"), colSetFc);
1.1269 +
1.1270 + //RDbDatabase::KeyL()
1.1271 + fc = User::FastCounter();
1.1272 + dbKey = TheDatabase.KeyL(KKeyName, KTblName);
1.1273 + dbKeyFc = CalcTickDiff(fc, User::FastCounter());
1.1274 + delete dbKey;
1.1275 + PrintFcDiffAsUs(_L("###RDbDatabase::KeyL(), Time=%d us\r\n"), dbKeyFc);
1.1276 +
1.1277 + //RDbDatabase::DropIndex()
1.1278 + fc = User::FastCounter();
1.1279 + err = TheDatabase.DropIndex(KKeyName, KTblName);
1.1280 + TUint32 dropIdxFc = CalcTickDiff(fc, User::FastCounter());
1.1281 + TEST2(err, KErrNone);
1.1282 + PrintFcDiffAsUs(_L("###RDbDatabase::DropIndex(), Time=%d us\r\n"), dropIdxFc);
1.1283 +
1.1284 + //RDbDatabase::DropTable()
1.1285 + fc = User::FastCounter();
1.1286 + err = TheDatabase.DropTable(KTblName);
1.1287 + TUint32 dropTblFc = CalcTickDiff(fc, User::FastCounter());
1.1288 + TEST2(err, KErrNone);
1.1289 + PrintFcDiffAsUs(_L("###RDbDatabase::DropTable(), Time=%d us\r\n"), dropTblFc);
1.1290 +
1.1291 + TheDatabase.Close();
1.1292 + }
1.1293 +
1.1294 +void PrintDiskUsage(const TDesC& aPath, TInt aOffset = 0)
1.1295 + {
1.1296 + _LIT(KSpace, " ");
1.1297 + TheTest.Printf(_L("%*.*S%S\r\n"), aOffset, aOffset, &KSpace, &aPath);
1.1298 + TFindFile* findFile = new TFindFile(TheFs);//TFindFile has TParse data member.
1.1299 + //Since this function is called recoursively, on some platforms
1.1300 + //the test might crash - "stack overflow" problem.
1.1301 + TEST(findFile != NULL);
1.1302 + CDir* fileNameCol = NULL;
1.1303 + TBuf<8> fileNameMask;
1.1304 + fileNameMask.Copy(_L("*.*"));
1.1305 + TInt err = findFile->FindWildByDir(fileNameMask, aPath, fileNameCol);
1.1306 + if(err == KErrNone)
1.1307 + {
1.1308 + do
1.1309 + {
1.1310 + const TDesC& file = findFile->File();//"file" variable contains the drive and the path. the file name in "file" is invalid in this case.
1.1311 + (void)TheParse.Set(file, NULL, NULL);
1.1312 + TPtrC driveName = TheParse.Drive();
1.1313 + if(aPath.FindF(driveName) >= 0)
1.1314 + {
1.1315 + TInt cnt = fileNameCol->Count();
1.1316 + for(TInt i=0;i<cnt;++i)
1.1317 + {
1.1318 + const ::TEntry& entry = (*fileNameCol)[i];
1.1319 + if(!entry.IsDir())
1.1320 + {
1.1321 + TheTest.Printf(_L("%*.*S %S, size=%d\r\n"), aOffset, aOffset, &KSpace, &entry.iName, entry.iSize);
1.1322 + }
1.1323 + else
1.1324 + {
1.1325 + TFileName* path = new TFileName;//allocated in heap to prevent "stack overflow" prolem
1.1326 + TEST(path != NULL);
1.1327 + path->Copy(aPath);
1.1328 + path->Append(entry.iName);
1.1329 + path->Append(_L("\\"));
1.1330 + PrintDiskUsage(*path, aOffset + 4);
1.1331 + delete path;
1.1332 + }
1.1333 + }
1.1334 + } // if(aPath.FindF(driveName) >= 0)
1.1335 +
1.1336 + delete fileNameCol;
1.1337 + fileNameCol = NULL;
1.1338 + } while((err = findFile->FindWild(fileNameCol)) == KErrNone);//Get the next set of files
1.1339 + }
1.1340 + else
1.1341 + {
1.1342 + TheTest.Printf(_L(" FindWildByDir() failed with err=%d\r\n"), err);
1.1343 + }
1.1344 + delete findFile;
1.1345 + }
1.1346 +
1.1347 +void DoTestL()
1.1348 + {
1.1349 + GetFastCounterFrequency();
1.1350 +
1.1351 + FileBlockSizeTestsL();
1.1352 +
1.1353 + RecordLenTestL();
1.1354 +
1.1355 + InsertTestsL();
1.1356 +
1.1357 + UpdateTestsL();
1.1358 +
1.1359 + DbInsertTestsL();
1.1360 +
1.1361 + DbUpdateTestsL();
1.1362 +
1.1363 + DbColWriteStreamTestsL();
1.1364 +
1.1365 + DbColReadStreamTestsL();
1.1366 +
1.1367 + DbUpdateTestL();
1.1368 +
1.1369 + DbStoreDatabaseTestL();
1.1370 +
1.1371 + DbDatabaseTestL();
1.1372 + }
1.1373 +
1.1374 +//Usage: "t_dbperf2 [<drive letter>:]"
1.1375 +TInt E32Main()
1.1376 + {
1.1377 + TheTest.Title();
1.1378 +
1.1379 + TheTrapCleanup = CTrapCleanup::New();
1.1380 + TEST(TheTrapCleanup != NULL);
1.1381 +
1.1382 + //Construct test database file name
1.1383 + _LIT(KTestDatabase, "c:\\dbms-tst\\t_dbperf2.db");
1.1384 + TFileName fname;
1.1385 + User::CommandLine(fname);
1.1386 + TParse parse;
1.1387 + parse.Set(fname, &KTestDatabase, 0);
1.1388 + const TDesC& dbFilePath = parse.FullName();
1.1389 + TheDatabaseFileName.Copy(dbFilePath);
1.1390 + TheTest.Printf(_L("Test database: %S\r\n"), &TheDatabaseFileName);
1.1391 + //Construct test file name
1.1392 + _LIT(KTestFile, "c:\\dbms-tst\\t_dbperf2.dat");
1.1393 + parse.Set(fname, &KTestFile, 0);
1.1394 + const TDesC& testFilePath = parse.FullName();
1.1395 + TheTestFileName.Copy(testFilePath);
1.1396 +
1.1397 + __UHEAP_MARK;
1.1398 +
1.1399 + TInt err = TheFs.Connect();
1.1400 + TEST2(err, KErrNone);
1.1401 + err = TheFs.MkDir(TheDatabaseFileName);
1.1402 + TheTest.Printf(_L("MkDir(): err=%d\r\n"), err);
1.1403 + TEST(err == KErrNone || err == KErrAlreadyExists);
1.1404 +
1.1405 + DeleteFile(TheDatabaseFileName);
1.1406 + TRAP(err, DoTestL());
1.1407 + DeleteFile(TheDatabaseFileName);
1.1408 + DeleteFile(TheTestFileName);
1.1409 + TEST2(err, KErrNone);
1.1410 +
1.1411 + TheTest.Printf(_L("====================== Disk usage ==================\r\n"));
1.1412 + PrintDiskUsage(_L("c:\\"));
1.1413 + TheTest.Printf(_L("====================================================\r\n"));
1.1414 +
1.1415 + CloseAll();
1.1416 +
1.1417 + __UHEAP_MARKEND;
1.1418 +
1.1419 + TheTest.End();
1.1420 + TheTest.Close();
1.1421 +
1.1422 + delete TheTrapCleanup;
1.1423 + return KErrNone;
1.1424 + }