|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <d32dbms.h> |
|
17 #include <s32file.h> |
|
18 #include <e32test.h> |
|
19 #include <e32math.h> |
|
20 #include <s32mem.h> |
|
21 #include <hal.h> |
|
22 |
|
23 static RTest TheTest(_L("t_dbperf2")); |
|
24 static CTrapCleanup* TheTrapCleanup; |
|
25 static RFs TheFs; |
|
26 static RDbs TheDbs; |
|
27 static RDbNamedDatabase TheDatabase; |
|
28 static RDbRowSet TheRowSet; |
|
29 static RFile TheTestFile; |
|
30 static TFileName TheDatabaseFileName; |
|
31 static TFileName TheLogFileName; |
|
32 static TFileName TheTestFileName; |
|
33 static TParse TheParse; |
|
34 |
|
35 #define COUNT_OF(array) (sizeof(array)/sizeof(array[0])) |
|
36 |
|
37 const TInt KTestRecordCount = 400; |
|
38 |
|
39 const TInt KTextColSize = 200;//Change KCreateTestTableSql string too! |
|
40 |
|
41 _LIT(KCreateTestTableSql, "CREATE TABLE A(I1 INTEGER, I2 DOUBLE, I3 VARCHAR(200))"); |
|
42 _LIT(KCreateIndexSql, "CREATE UNIQUE INDEX IDX ON A(I1)"); |
|
43 |
|
44 const TInt KColSize2 = 500; |
|
45 _LIT(KCreateTestTableSql2, "CREATE TABLE A(I1 INTEGER, I2 LONG VARCHAR, I3 LONG VARBINARY)"); |
|
46 |
|
47 const TChar KBufChar('O'); |
|
48 TBuf8<KColSize2> TheBinRndData; |
|
49 TBuf16<KColSize2> TheTextRndData; |
|
50 |
|
51 ////////////////////////////////////////////////////// |
|
52 |
|
53 static TInt TheCounterFreq = -10000000; |
|
54 const TInt KMicroSecIn1Sec = 1000000; |
|
55 |
|
56 TUint32 CalcTickDiff(TUint32 aStartTicks, TUint32 aEndTicks) |
|
57 { |
|
58 TInt64 diffTicks = (TInt64)aEndTicks - (TInt64)aStartTicks; |
|
59 if(diffTicks < 0) |
|
60 { |
|
61 diffTicks = KMaxTUint32 + diffTicks + 1; |
|
62 } |
|
63 return (TUint32)diffTicks; |
|
64 } |
|
65 |
|
66 //Prints aFastCount parameter (converted to us) |
|
67 void PrintFcDiffAsUs(const TDesC& aFormatStr, TUint32 aFastCount) |
|
68 { |
|
69 double v = ((double)aFastCount * KMicroSecIn1Sec) / (double)TheCounterFreq; |
|
70 TInt v2 = (TInt)v; |
|
71 TheTest.Printf(aFormatStr, v2); |
|
72 } |
|
73 |
|
74 //Prints aFastCount parameter (converted to us) and the records count |
|
75 void PrintFcDiffAsUs2(const TDesC& aFormatStr, TInt aRecCnt, TUint32 aFastCount) |
|
76 { |
|
77 double v = ((double)aFastCount * KMicroSecIn1Sec) / (double)TheCounterFreq; |
|
78 TInt v2 = (TInt)v; |
|
79 TheTest.Printf(aFormatStr, aRecCnt, v2); |
|
80 } |
|
81 |
|
82 ////////////////////////////////////////////////////// |
|
83 |
|
84 enum TRowSetType {EViewRowSet, ETableRowSet}; |
|
85 const TRowSetType KRowSetTypes[] = {EViewRowSet/*, ETableRowSet*/}; //Excluding ETableRowSet means that the test requires less time. |
|
86 const TPtrC KRowSetTypeStr[] = {_L("RDbView.")/*, _L("RDbTable.")*/};//The coverage is not affected that much. |
|
87 |
|
88 ////////////////////////////////////////////////////// |
|
89 |
|
90 const RDbRowSet::TAccess KAccessModes[] = {RDbRowSet::EInsertOnly, RDbRowSet::EUpdatable}; |
|
91 const TPtrC KAccessModeStr[] = {_L("Insert only."), _L("Updatable.")}; |
|
92 |
|
93 ////////////////////////////////////////////////////// |
|
94 |
|
95 enum TUpdDirection {EUpdBackward, EUpdForward}; |
|
96 const TUpdDirection KUpdDirectionTypes[] = {EUpdBackward, EUpdForward}; |
|
97 const TPtrC KUpdDirectionTypeStr[] = {_L("Backward."), _L("Forward.")}; |
|
98 |
|
99 ////////////////////////////////////////////////////// |
|
100 |
|
101 enum TCommitRecCnt {ECommit_1_Rec = 1, ECommit_Cnt_Rec = 20, ECommit_All_Rec = KTestRecordCount}; |
|
102 const TCommitRecCnt KCommitTypes[] = {ECommit_1_Rec, ECommit_Cnt_Rec, ECommit_All_Rec}; |
|
103 const TPtrC KCommitTypeStr[] = {_L("Commit after 1 op."), _L("Commit after 20 ops."), _L("Commit at end.")}; |
|
104 |
|
105 /////////////////////////////////////////////////////////////////////////////////////// |
|
106 |
|
107 //Delete "aFullName" file. |
|
108 static void DeleteFile(const TDesC& aFullName) |
|
109 { |
|
110 RFs fsSession; |
|
111 TInt err = fsSession.Connect(); |
|
112 if(err == KErrNone) |
|
113 { |
|
114 TEntry entry; |
|
115 if(fsSession.Entry(aFullName, entry) == KErrNone) |
|
116 { |
|
117 err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly); |
|
118 if(err != KErrNone) |
|
119 { |
|
120 TheTest.Printf(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName); |
|
121 } |
|
122 err = fsSession.Delete(aFullName); |
|
123 if(err != KErrNone) |
|
124 { |
|
125 TheTest.Printf(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName); |
|
126 } |
|
127 } |
|
128 fsSession.Close(); |
|
129 } |
|
130 else |
|
131 { |
|
132 TheTest.Printf(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName); |
|
133 } |
|
134 } |
|
135 |
|
136 /////////////////////////////////////////////////////////////////////////////////////// |
|
137 |
|
138 static void CloseAll() |
|
139 { |
|
140 TheRowSet.Close(); |
|
141 TheDatabase.Close(); |
|
142 TheDbs.Close(); |
|
143 TheTestFile.Close(); |
|
144 TheFs.Close(); |
|
145 } |
|
146 |
|
147 /////////////////////////////////////////////////////////////////////////////////////// |
|
148 /////////////////////////////////////////////////////////////////////////////////////// |
|
149 //Tests macros and functions. |
|
150 //If (!aValue) then the test will be panicked, the test data files will be deleted. |
|
151 static void Check(TInt aValue, TInt aLine) |
|
152 { |
|
153 if(!aValue) |
|
154 { |
|
155 CloseAll(); |
|
156 DeleteFile(TheDatabaseFileName); |
|
157 DeleteFile(TheTestFileName); |
|
158 TheTest(EFalse, aLine); |
|
159 } |
|
160 } |
|
161 //If (aValue != aExpected) then the test will be panicked, the test data files will be deleted. |
|
162 static void Check(TInt aValue, TInt aExpected, TInt aLine) |
|
163 { |
|
164 if(aValue != aExpected) |
|
165 { |
|
166 TheTest.Printf(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); |
|
167 CloseAll(); |
|
168 DeleteFile(TheDatabaseFileName); |
|
169 DeleteFile(TheTestFileName); |
|
170 TheTest(EFalse, aLine); |
|
171 } |
|
172 } |
|
173 //Use these to test conditions. |
|
174 #define TEST(arg) ::Check((arg), __LINE__) |
|
175 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) |
|
176 |
|
177 /////////////////////////////////////////////////////////////////////////////////////// |
|
178 |
|
179 void PrintFileSize() |
|
180 { |
|
181 RDbDatabase::TSize s = TheDatabase.Size(); |
|
182 TheTest.Printf(_L("####FileSize: %d\r\n"), s.iSize); |
|
183 } |
|
184 |
|
185 /////////////////////////////////////////////////////////////////////////////////////// |
|
186 |
|
187 void DbRowSetInsertTestL(TRowSetType aRowSetType, RDbRowSet::TAccess aAccessMode, TCommitRecCnt aCommitRecCnt) |
|
188 { |
|
189 TBuf<KTextColSize> textColVal; |
|
190 for(TInt ii=23000;ii<(23000+KTextColSize);++ii) |
|
191 { |
|
192 textColVal.Append(TChar(ii)); |
|
193 } |
|
194 for(TInt compaction=0;compaction<2;++compaction) |
|
195 { |
|
196 TheTest.Printf(compaction ? _L("Compaction:Yes.\r\n") : _L("Compaction:No.\r\n")); |
|
197 TheRowSet.Close(); |
|
198 TInt err; |
|
199 err = TheDatabase.Execute(_L("DELETE FROM A")); |
|
200 TEST(err >= 0); |
|
201 TUint32 fc = User::FastCounter(); |
|
202 if(aRowSetType == EViewRowSet) |
|
203 { |
|
204 RDbView view; |
|
205 err = view.Prepare(TheDatabase, _L("SELECT * FROM A"), aAccessMode); |
|
206 TEST2(err, KErrNone); |
|
207 err = view.EvaluateAll(); |
|
208 TEST2(err, KErrNone); |
|
209 TheRowSet = view; |
|
210 } |
|
211 else |
|
212 { |
|
213 RDbTable tbl; |
|
214 err = tbl.Open(TheDatabase, _L("A"), aAccessMode); |
|
215 TEST2(err, KErrNone); |
|
216 TheRowSet = tbl; |
|
217 } |
|
218 TUint32 prepFc = CalcTickDiff(fc, User::FastCounter()); |
|
219 TUint32 insFc = 0; |
|
220 TUint32 setcolFc = 0; |
|
221 TUint32 putFc = 0; |
|
222 TUint32 commitFc = 0; |
|
223 TUint32 totalFc = 0; |
|
224 fc = User::FastCounter(); |
|
225 for(TInt i=0,count=0;i<KTestRecordCount;++i) |
|
226 { |
|
227 TUint32 tmpFc; |
|
228 if(aCommitRecCnt != ECommit_1_Rec && count == 0) |
|
229 { |
|
230 tmpFc = User::FastCounter(); |
|
231 err = TheDatabase.Begin(); |
|
232 TEST2(err, KErrNone); |
|
233 commitFc += CalcTickDiff(tmpFc, User::FastCounter()); |
|
234 } |
|
235 tmpFc = User::FastCounter(); |
|
236 TheRowSet.InsertL(); |
|
237 insFc += CalcTickDiff(tmpFc, User::FastCounter()); |
|
238 tmpFc = User::FastCounter(); |
|
239 TheRowSet.SetColL(1, i); |
|
240 TheRowSet.SetColL(2, i * 10.1234); |
|
241 TheRowSet.SetColL(3, textColVal); |
|
242 setcolFc += CalcTickDiff(tmpFc, User::FastCounter()); |
|
243 tmpFc = User::FastCounter(); |
|
244 TheRowSet.PutL(); |
|
245 putFc += CalcTickDiff(tmpFc, User::FastCounter()); |
|
246 if(aCommitRecCnt != ECommit_1_Rec && ++count == aCommitRecCnt) |
|
247 { |
|
248 tmpFc = User::FastCounter(); |
|
249 count = 0; |
|
250 err = TheDatabase.Commit(); |
|
251 TEST2(err, KErrNone); |
|
252 commitFc += CalcTickDiff(tmpFc, User::FastCounter()); |
|
253 if(compaction) |
|
254 { |
|
255 err = TheDatabase.Compact(); |
|
256 TEST2(err, KErrNone); |
|
257 } |
|
258 } |
|
259 } |
|
260 totalFc = CalcTickDiff(fc, User::FastCounter()); |
|
261 PrintFcDiffAsUs(_L("###Prepare,time=%d us\r\n"), prepFc); |
|
262 PrintFcDiffAsUs(_L("###InsertL,time=%d us\r\n"), insFc); |
|
263 PrintFcDiffAsUs(_L("###SetColL,time=%d us\r\n"), setcolFc); |
|
264 PrintFcDiffAsUs(_L("###PutL, time=%d us\r\n"), putFc); |
|
265 PrintFcDiffAsUs(_L("###Commit, time=%d us\r\n"), commitFc); |
|
266 PrintFcDiffAsUs(_L("###Total, time=%d us\r\n"), totalFc); |
|
267 TheRowSet.Close(); |
|
268 PrintFileSize(); |
|
269 //Check |
|
270 if(aAccessMode != RDbRowSet::EInsertOnly) |
|
271 { |
|
272 RDbView view; |
|
273 err = view.Prepare(TheDatabase, _L("SELECT * FROM A"), aAccessMode); |
|
274 TEST2(err, KErrNone); |
|
275 err = view.EvaluateAll(); |
|
276 TEST2(err, KErrNone); |
|
277 TInt count = view.CountL(); |
|
278 view.Close(); |
|
279 TEST2(count, KTestRecordCount); |
|
280 } |
|
281 }//end of - for(TInt compaction=0;compaction<2;++compaction) |
|
282 } |
|
283 |
|
284 void FirstRecL(TUpdDirection aUpdDirection) |
|
285 { |
|
286 TBool rc = EFalse; |
|
287 switch(aUpdDirection) |
|
288 { |
|
289 case EUpdBackward: |
|
290 rc = TheRowSet.LastL(); |
|
291 break; |
|
292 case EUpdForward: |
|
293 default: |
|
294 rc = TheRowSet.FirstL(); |
|
295 break; |
|
296 } |
|
297 TEST(rc); |
|
298 } |
|
299 |
|
300 void NextRecL(TUpdDirection aUpdDirection) |
|
301 { |
|
302 TBool rc = EFalse; |
|
303 switch(aUpdDirection) |
|
304 { |
|
305 case EUpdBackward: |
|
306 rc = TheRowSet.PreviousL(); |
|
307 break; |
|
308 case EUpdForward: |
|
309 default: |
|
310 rc = TheRowSet.NextL(); |
|
311 break; |
|
312 } |
|
313 TEST(rc); |
|
314 } |
|
315 |
|
316 void DbRowSetUpdateTestL(TRowSetType aRowSetType, TUpdDirection aUpdDirection, TCommitRecCnt aCommitRecCnt) |
|
317 { |
|
318 TBuf<KTextColSize> textColVal; |
|
319 for(TInt ii=33000;ii<(33000+KTextColSize);++ii) |
|
320 { |
|
321 textColVal.Append(TChar(ii)); |
|
322 } |
|
323 |
|
324 for(TInt compaction=0;compaction<2;++compaction) |
|
325 { |
|
326 TheTest.Printf(compaction ? _L("Compaction:Yes.\r\n") : _L("Compaction:No.\r\n")); |
|
327 TheRowSet.Close(); |
|
328 TInt err; |
|
329 TUint32 fc = User::FastCounter(); |
|
330 if(aRowSetType == EViewRowSet) |
|
331 { |
|
332 RDbView view; |
|
333 err = view.Prepare(TheDatabase, _L("SELECT * FROM A WHERE I1 >= 0 AND I1 <= 1000000"), RDbRowSet::EUpdatable); |
|
334 TEST2(err, KErrNone); |
|
335 err = view.EvaluateAll(); |
|
336 TEST2(err, KErrNone); |
|
337 TheRowSet = view; |
|
338 } |
|
339 else |
|
340 { |
|
341 RDbTable tbl; |
|
342 err = tbl.Open(TheDatabase, _L("A"), RDbRowSet::EUpdatable); |
|
343 TEST2(err, KErrNone); |
|
344 TheRowSet = tbl; |
|
345 } |
|
346 TInt cnt = TheRowSet.CountL(); |
|
347 TEST2(cnt, KTestRecordCount); |
|
348 TUint32 prepFc = CalcTickDiff(fc, User::FastCounter()); |
|
349 TUint32 insFc = 0; |
|
350 TUint32 setcolFc = 0; |
|
351 TUint32 putFc = 0; |
|
352 TUint32 commitFc = 0; |
|
353 TUint32 totalFc = 0; |
|
354 fc = User::FastCounter(); |
|
355 for(TInt i=0,count=0;i<KTestRecordCount;++i) |
|
356 { |
|
357 TRAP(err, (i == 0 ? FirstRecL(aUpdDirection) : NextRecL(aUpdDirection))); |
|
358 TEST2(err, KErrNone); |
|
359 TUint32 tmpFc; |
|
360 if(aCommitRecCnt != ECommit_1_Rec && count == 0) |
|
361 { |
|
362 tmpFc = User::FastCounter(); |
|
363 err = TheDatabase.Begin(); |
|
364 TEST2(err, KErrNone); |
|
365 commitFc += CalcTickDiff(tmpFc, User::FastCounter()); |
|
366 } |
|
367 tmpFc = User::FastCounter(); |
|
368 TheRowSet.UpdateL(); |
|
369 insFc += CalcTickDiff(tmpFc, User::FastCounter()); |
|
370 tmpFc = User::FastCounter(); |
|
371 TheRowSet.SetColL(2, i * 20.0); |
|
372 TheRowSet.SetColL(3, textColVal); |
|
373 setcolFc += CalcTickDiff(tmpFc, User::FastCounter()); |
|
374 tmpFc = User::FastCounter(); |
|
375 TheRowSet.PutL(); |
|
376 putFc += CalcTickDiff(tmpFc, User::FastCounter()); |
|
377 if(aCommitRecCnt != ECommit_1_Rec && ++count == aCommitRecCnt) |
|
378 { |
|
379 tmpFc = User::FastCounter(); |
|
380 count = 0; |
|
381 err = TheDatabase.Commit(); |
|
382 TEST2(err, KErrNone); |
|
383 commitFc += CalcTickDiff(tmpFc, User::FastCounter()); |
|
384 if(compaction) |
|
385 { |
|
386 err = TheDatabase.Compact(); |
|
387 TEST2(err, KErrNone); |
|
388 } |
|
389 } |
|
390 } |
|
391 totalFc = CalcTickDiff(fc, User::FastCounter()); |
|
392 PrintFcDiffAsUs(_L("###Prepare,time=%d us\r\n"), prepFc); |
|
393 PrintFcDiffAsUs(_L("###UpdateL,time=%d us\r\n"), insFc); |
|
394 PrintFcDiffAsUs(_L("###SetColL,time=%d us\r\n"), setcolFc); |
|
395 PrintFcDiffAsUs(_L("###PutL, time=%d us\r\n"), putFc); |
|
396 PrintFcDiffAsUs(_L("###Commit, time=%d us\r\n"), commitFc); |
|
397 PrintFcDiffAsUs(_L("###Total, time=%d us\r\n"), totalFc); |
|
398 TheRowSet.Close(); |
|
399 PrintFileSize(); |
|
400 }//end of - for(TInt compaction=0;compaction<2;++compaction) |
|
401 } |
|
402 |
|
403 /////////////////////////////////////////////////////////////////////////////////////// |
|
404 |
|
405 void CreateDatabase() |
|
406 { |
|
407 TInt err = TheDatabase.Replace(TheFs, TheDatabaseFileName); |
|
408 TEST2(err, KErrNone); |
|
409 TheDatabase.Close(); |
|
410 err = TheDbs.Connect(); |
|
411 TEST2(err, KErrNone); |
|
412 err = TheDatabase.Open(TheDbs, TheDatabaseFileName); |
|
413 TEST2(err, KErrNone); |
|
414 err = TheDatabase.Execute(KCreateTestTableSql); |
|
415 TEST2(err, KErrNone); |
|
416 err = TheDatabase.Execute(KCreateIndexSql); |
|
417 TEST2(err, KErrNone); |
|
418 } |
|
419 |
|
420 void CreateAndFillDatabase() |
|
421 { |
|
422 TInt err = TheDatabase.Replace(TheFs, TheDatabaseFileName); |
|
423 TEST2(err, KErrNone); |
|
424 TheDatabase.Close(); |
|
425 err = TheDbs.Connect(); |
|
426 TEST2(err, KErrNone); |
|
427 err = TheDatabase.Open(TheDbs, TheDatabaseFileName); |
|
428 TEST2(err, KErrNone); |
|
429 err = TheDatabase.Execute(KCreateTestTableSql); |
|
430 TEST2(err, KErrNone); |
|
431 err = TheDatabase.Execute(KCreateIndexSql); |
|
432 TEST2(err, KErrNone); |
|
433 // |
|
434 TBuf<KTextColSize> textColVal; |
|
435 for(TInt ii=23000;ii<(23000+KTextColSize);++ii) |
|
436 { |
|
437 textColVal.Append(TChar(ii)); |
|
438 } |
|
439 err = TheDatabase.Begin(); |
|
440 TEST2(err, KErrNone); |
|
441 for(TInt i=0;i<KTestRecordCount;++i) |
|
442 { |
|
443 TBuf<KTextColSize + 100> sql; |
|
444 sql.Format(_L("INSERT INTO A(I1,I2,I3) VALUES(%d,%d,'%S')"), i, i + 100000, &textColVal); |
|
445 err = TheDatabase.Execute(sql); |
|
446 TEST2(err, 1); |
|
447 } |
|
448 err = TheDatabase.Commit(); |
|
449 TEST2(err, KErrNone); |
|
450 } |
|
451 |
|
452 void DestroyDatabase() |
|
453 { |
|
454 TheRowSet.Close(); |
|
455 TheDatabase.Close(); |
|
456 TheDbs.Close(); |
|
457 TInt err = TheFs.Delete(TheDatabaseFileName); |
|
458 TEST2(err, KErrNone); |
|
459 } |
|
460 |
|
461 void GetFastCounterFrequency() |
|
462 { |
|
463 TheTest.Start(_L("Get fast counter frequency")); |
|
464 TEST2(HAL::Get(HAL::EFastCounterFrequency, TheCounterFreq), KErrNone); |
|
465 TheTest.Printf(_L("Counter frequency=%d\r\n"), TheCounterFreq); |
|
466 } |
|
467 |
|
468 void FileBlockSizeTestsL() |
|
469 { |
|
470 TheTest.Next(_L("File Block Size test")); |
|
471 |
|
472 const TInt KBlockSizeLow = 64, KBlockSizeHigh = 1024 * 64; |
|
473 for(TInt blockSize=KBlockSizeLow;blockSize<=KBlockSizeHigh;blockSize*=2) |
|
474 { |
|
475 for(TInt addSize=-4;addSize<=4;addSize+=4) |
|
476 { |
|
477 TInt currBlockSize = blockSize + addSize; |
|
478 TBuf<100> title; |
|
479 title.Copy(_L("File block size ")); |
|
480 title.AppendNum((TInt64)currBlockSize); |
|
481 title.Append(_L(" bytes")); |
|
482 TheTest.Printf(title); |
|
483 |
|
484 HBufC8* data = HBufC8::New(currBlockSize); |
|
485 TEST(data != NULL); |
|
486 TPtr8 dataPtr = data->Des(); |
|
487 dataPtr.SetLength(currBlockSize); |
|
488 |
|
489 TInt err = TheTestFile.Replace(TheFs, TheTestFileName, EFileRead | EFileWrite); |
|
490 TEST2(err, KErrNone); |
|
491 err = TheTestFile.Write(dataPtr); |
|
492 TEST2(err, KErrNone); |
|
493 err = TheTestFile.Flush(); |
|
494 TEST2(err, KErrNone); |
|
495 TUint32 fc = User::FastCounter(); |
|
496 err = TheTestFile.Write(0, dataPtr); |
|
497 fc = CalcTickDiff(fc, User::FastCounter()); |
|
498 PrintFcDiffAsUs(_L("###Time=%d us\r\n"), fc); |
|
499 TEST2(err, KErrNone); |
|
500 TheTestFile.Close(); |
|
501 |
|
502 delete data; |
|
503 } |
|
504 } |
|
505 DeleteFile(TheTestFileName); |
|
506 } |
|
507 |
|
508 /** |
|
509 @SYMTestCaseID SYSLIB-DBMS-UT-3310 |
|
510 @SYMTestCaseDesc DBMS, RDbView performance tests. |
|
511 @SYMTestPriority High |
|
512 @SYMTestActions The test creates and fills a test table with integer, real and text column. Then |
|
513 executes 3 test subcases: |
|
514 - updates the integer column only in all records, using "SELECT I1,I2,I3" cursor; |
|
515 - updates the text column only in all records, using "SELECT I1,I2,I3" cursor; |
|
516 - updates all columns in all records, using "SELECT I1,I2,I3" cursor; |
|
517 The execution times are printed out. |
|
518 @SYMTestExpectedResults Test must not fail |
|
519 @SYMREQ REQ7141 |
|
520 */ |
|
521 void RecordLenTestL() |
|
522 { |
|
523 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-3310 Record length test - create database")); |
|
524 CreateAndFillDatabase(); |
|
525 //////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
526 TheTest.Printf(_L("Record length test - update the integer column only")); |
|
527 TUint32 fc = User::FastCounter(); |
|
528 RDbView view; |
|
529 TInt err = view.Prepare(TheDatabase, _L("SELECT * FROM A")); |
|
530 TEST2(err, KErrNone); |
|
531 err = view.EvaluateAll(); |
|
532 TEST2(err, KErrNone); |
|
533 TheRowSet = view; |
|
534 err = TheDatabase.Begin(); |
|
535 TEST2(err, KErrNone); |
|
536 TInt recCnt = 0; |
|
537 TheRowSet.FirstL(); |
|
538 do |
|
539 { |
|
540 TheRowSet.UpdateL(); |
|
541 TheRowSet.SetColL(1, 60000 + recCnt); |
|
542 TheRowSet.PutL(); |
|
543 ++recCnt; |
|
544 } |
|
545 while(TheRowSet.NextL()); |
|
546 TEST2(recCnt, KTestRecordCount); |
|
547 err = TheDatabase.Commit(); |
|
548 TEST2(err, KErrNone); |
|
549 PrintFcDiffAsUs(_L("###Time=%d us\r\n"), CalcTickDiff(fc, User::FastCounter())); |
|
550 TheRowSet.Close(); |
|
551 //////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
552 TheTest.Printf(_L("Record length test - update the text column only")); |
|
553 fc = User::FastCounter(); |
|
554 err = view.Prepare(TheDatabase, _L("SELECT * FROM A")); |
|
555 TEST2(err, KErrNone); |
|
556 err = view.EvaluateAll(); |
|
557 TEST2(err, KErrNone); |
|
558 TheRowSet = view; |
|
559 err = TheDatabase.Begin(); |
|
560 TEST2(err, KErrNone); |
|
561 recCnt = 0; |
|
562 TheRowSet.FirstL(); |
|
563 do |
|
564 { |
|
565 TheRowSet.UpdateL(); |
|
566 TheRowSet.SetColL(3, _L("0123456789")); |
|
567 TheRowSet.PutL(); |
|
568 ++recCnt; |
|
569 } |
|
570 while(TheRowSet.NextL()); |
|
571 TEST2(recCnt, KTestRecordCount); |
|
572 err = TheDatabase.Commit(); |
|
573 TEST2(err, KErrNone); |
|
574 PrintFcDiffAsUs(_L("###Time=%d us\r\n"), CalcTickDiff(fc, User::FastCounter())); |
|
575 TheRowSet.Close(); |
|
576 //////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
577 TheTest.Printf(_L("Record length test - update all columns")); |
|
578 fc = User::FastCounter(); |
|
579 err = view.Prepare(TheDatabase, _L("SELECT * FROM A")); |
|
580 TEST2(err, KErrNone); |
|
581 err = view.EvaluateAll(); |
|
582 TEST2(err, KErrNone); |
|
583 TheRowSet = view; |
|
584 err = TheDatabase.Begin(); |
|
585 TEST2(err, KErrNone); |
|
586 recCnt = 0; |
|
587 TheRowSet.FirstL(); |
|
588 do |
|
589 { |
|
590 TheRowSet.UpdateL(); |
|
591 TheRowSet.SetColL(1, 34567 - recCnt); |
|
592 TheRowSet.SetColL(2, 888.111); |
|
593 TheRowSet.SetColL(3, _L("QWETYUIOPASDF")); |
|
594 TheRowSet.PutL(); |
|
595 ++recCnt; |
|
596 } |
|
597 while(TheRowSet.NextL()); |
|
598 TEST2(recCnt, KTestRecordCount); |
|
599 err = TheDatabase.Commit(); |
|
600 TEST2(err, KErrNone); |
|
601 PrintFcDiffAsUs(_L("###Time=%d ms\r\n"), CalcTickDiff(fc, User::FastCounter())); |
|
602 //////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
603 DestroyDatabase();//This will destroy TheRowSet object too. |
|
604 } |
|
605 |
|
606 /** |
|
607 @SYMTestCaseID SYSLIB-DBMS-UT-3311 |
|
608 @SYMTestCaseDesc DBMS, RDbView performance tests. |
|
609 @SYMTestPriority High |
|
610 @SYMTestActions The test measures the time used by insert-only or updatable cursor to: |
|
611 - insert certain amount of records, comitting after each insert; |
|
612 - insert certain amount of records, comitting after 20 inserts; |
|
613 - insert certain amount of records, comitting at the end; |
|
614 All cases repeated with and without compaction (except the first one). |
|
615 The execution times are printed out. |
|
616 @SYMTestExpectedResults Test must not fail |
|
617 @SYMREQ REQ7141 |
|
618 */ |
|
619 void InsertTestsL() |
|
620 { |
|
621 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-3311 RDbView \"insert\" performance tests")); |
|
622 for(TInt i1=0;i1<COUNT_OF(KRowSetTypes);++i1) |
|
623 { |
|
624 for(TInt i2=0;i2<COUNT_OF(KAccessModes);++i2) |
|
625 { |
|
626 for(TInt i3=0;i3<COUNT_OF(KCommitTypes);++i3) |
|
627 { |
|
628 CreateDatabase(); |
|
629 TBuf<200> title; |
|
630 title.Copy(_L("Insert.")); |
|
631 title.Append(KRowSetTypeStr[i1]); |
|
632 title.Append(KAccessModeStr[i2]); |
|
633 title.Append(KCommitTypeStr[i3]); |
|
634 TheTest.Printf(title); |
|
635 DbRowSetInsertTestL(KRowSetTypes[i1], KAccessModes[i2], KCommitTypes[i3]); |
|
636 DestroyDatabase(); |
|
637 } |
|
638 } |
|
639 } |
|
640 } |
|
641 |
|
642 /** |
|
643 @SYMTestCaseID SYSLIB-DBMS-UT-3312 |
|
644 @SYMTestCaseDesc DBMS, RDbView performance tests. |
|
645 @SYMTestPriority High |
|
646 @SYMTestActions The test measures the time used by updatable cursor to: |
|
647 - update (moving forward/backward) certain amount of records, comitting after each update; |
|
648 - update (moving forward/backward) certain amount of records, comitting after 20 update; |
|
649 - update (moving forward/backward) certain amount of records, comitting at the end; |
|
650 All cases repeated with and without compaction (except the first one). |
|
651 The execution times are printed out. |
|
652 @SYMTestExpectedResults Test must not fail |
|
653 @SYMREQ REQ7141 |
|
654 */ |
|
655 void UpdateTestsL() |
|
656 { |
|
657 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-3312 RDbView \"update\" performance tests")); |
|
658 for(TInt i1=0;i1<COUNT_OF(KRowSetTypes);++i1) |
|
659 { |
|
660 for(TInt i2=0;i2<COUNT_OF(KUpdDirectionTypes);++i2) |
|
661 { |
|
662 for(TInt i3=0;i3<COUNT_OF(KCommitTypes);++i3) |
|
663 { |
|
664 CreateAndFillDatabase(); |
|
665 TBuf<200> title; |
|
666 title.Copy(_L("Update.")); |
|
667 title.Append(KRowSetTypeStr[i1]); |
|
668 title.Append(KUpdDirectionTypeStr[i2]); |
|
669 title.Append(KCommitTypeStr[i3]); |
|
670 TheTest.Printf(title); |
|
671 DbRowSetUpdateTestL(KRowSetTypes[i1], KUpdDirectionTypes[i2], KCommitTypes[i3]); |
|
672 DestroyDatabase(); |
|
673 } |
|
674 } |
|
675 } |
|
676 } |
|
677 |
|
678 /** |
|
679 @SYMTestCaseID SYSLIB-DBMS-UT-3313 |
|
680 @SYMTestCaseDesc DBMS, RDbDatabase::Execute() performance tests. |
|
681 @SYMTestPriority High |
|
682 @SYMTestActions The test measures the time used by RDbDatabase::Execute() to: |
|
683 - insert certain amount of records, comitting after each insert; |
|
684 - insert certain amount of records, comitting after 20 inserts; |
|
685 - insert certain amount of records, comitting at the end; |
|
686 All cases repeated with and without compaction (except the first one). |
|
687 The execution times are printed out. |
|
688 @SYMTestExpectedResults Test must not fail |
|
689 @SYMREQ REQ7141 |
|
690 */ |
|
691 void DbInsertTestsL() |
|
692 { |
|
693 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-3313 RDbDatabase::Execute() \"insert\" performance tests")); |
|
694 TBuf<KTextColSize> textColVal; |
|
695 for(TInt ii=23000;ii<(23000+KTextColSize);++ii) |
|
696 { |
|
697 textColVal.Append(TChar(ii)); |
|
698 } |
|
699 for(TInt compaction=0;compaction<2;++compaction) |
|
700 { |
|
701 for(TInt i3=0;i3<COUNT_OF(KCommitTypes);++i3) |
|
702 { |
|
703 CreateDatabase(); |
|
704 TBuf<200> title; |
|
705 title.Copy(_L("RDbDatabase::Execute().Insert.")); |
|
706 title.Append(KCommitTypeStr[i3]); |
|
707 title.Append(compaction ? _L("Compaction:Yes.") : _L("Compaction:No.")); |
|
708 TheTest.Printf(title); |
|
709 TInt count = 0, err = KErrNone; |
|
710 TUint32 fc = User::FastCounter(); |
|
711 for(TInt i=0;i<KTestRecordCount;++i) |
|
712 { |
|
713 if(KCommitTypes[i3] != ECommit_1_Rec && count == 0) |
|
714 { |
|
715 err = TheDatabase.Begin(); |
|
716 TEST2(err, KErrNone); |
|
717 } |
|
718 TBuf<KTextColSize + 100> sql; |
|
719 sql.Format(_L("INSERT INTO A(I1,I2,I3) VALUES(%d,%d,'%S')"), i, i + 100000, &textColVal); |
|
720 err = TheDatabase.Execute(sql); |
|
721 TEST2(err, 1); |
|
722 if(KCommitTypes[i3] != ECommit_1_Rec && ++count == KCommitTypes[i3]) |
|
723 { |
|
724 count = 0; |
|
725 err = TheDatabase.Commit(); |
|
726 TEST2(err, KErrNone); |
|
727 if(compaction) |
|
728 { |
|
729 err = TheDatabase.Compact(); |
|
730 TEST2(err, KErrNone); |
|
731 } |
|
732 } |
|
733 } |
|
734 PrintFcDiffAsUs(_L("###RDbDatabase::Execute(), Time=%d us\r\n"), CalcTickDiff(fc, User::FastCounter())); |
|
735 PrintFileSize(); |
|
736 DestroyDatabase(); |
|
737 } |
|
738 } |
|
739 } |
|
740 |
|
741 /** |
|
742 @SYMTestCaseID SYSLIB-DBMS-UT-3314 |
|
743 @SYMTestCaseDesc DBMS, RDbDatabase::Execute() performance tests. |
|
744 @SYMTestPriority High |
|
745 @SYMTestActions The test measures the time used by RDbDatabase::Execute() to: |
|
746 - update certain amount of records, comitting after each update; |
|
747 - update certain amount of records, comitting after 20 updates; |
|
748 - update certain amount of records, comitting at the end; |
|
749 All cases repeated with and without compaction (except the first one). |
|
750 The execution times are printed out. |
|
751 @SYMTestExpectedResults Test must not fail |
|
752 @SYMREQ REQ7141 |
|
753 */ |
|
754 void DbUpdateTestsL() |
|
755 { |
|
756 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-3314 RDbDatabase::Execute() \"update\" performance tests")); |
|
757 TBuf<KTextColSize> textColVal; |
|
758 for(TInt ii=43000;ii<(43000+KTextColSize);++ii) |
|
759 { |
|
760 textColVal.Append(TChar(ii)); |
|
761 } |
|
762 for(TInt compaction=0;compaction<2;++compaction) |
|
763 { |
|
764 for(TInt i3=0;i3<COUNT_OF(KCommitTypes);++i3) |
|
765 { |
|
766 CreateAndFillDatabase(); |
|
767 TBuf<200> title; |
|
768 title.Copy(_L("RDbDatabase::Execute().Update.")); |
|
769 title.Append(KCommitTypeStr[i3]); |
|
770 title.Append(compaction ? _L("Compaction:Yes.") : _L("Compaction:No.")); |
|
771 TheTest.Printf(title); |
|
772 TInt count = 0, err = KErrNone; |
|
773 TUint32 fc = User::FastCounter(); |
|
774 for(TInt i=0;i<KTestRecordCount;++i) |
|
775 { |
|
776 if(KCommitTypes[i3] != ECommit_1_Rec && count == 0) |
|
777 { |
|
778 err = TheDatabase.Begin(); |
|
779 TEST2(err, KErrNone); |
|
780 } |
|
781 TBuf<KTextColSize + 100> sql; |
|
782 sql.Format(_L("UPDATE A SET I2=%d,I3='%S' WHERE I1=%d"), i + 556622, &textColVal, i); |
|
783 err = TheDatabase.Execute(sql); |
|
784 TEST2(err, 1); |
|
785 if(KCommitTypes[i3] != ECommit_1_Rec && ++count == KCommitTypes[i3]) |
|
786 { |
|
787 count = 0; |
|
788 err = TheDatabase.Commit(); |
|
789 TEST2(err, KErrNone); |
|
790 if(compaction) |
|
791 { |
|
792 err = TheDatabase.Compact(); |
|
793 TEST2(err, KErrNone); |
|
794 } |
|
795 } |
|
796 } |
|
797 PrintFcDiffAsUs(_L("###RDbDatabase::Execute(), Time=%d us\r\n"), CalcTickDiff(fc, User::FastCounter())); |
|
798 PrintFileSize(); |
|
799 DestroyDatabase(); |
|
800 } |
|
801 } |
|
802 } |
|
803 |
|
804 /** |
|
805 @SYMTestCaseID PDS-DBMS-UT-4010 |
|
806 @SYMTestCaseDesc Test for DEF141419 - DBMS, new performance tests - RDbUpdate, RDbStoreDatabase. |
|
807 Tests the performance of RDbColWriteStream::OpenLC() and RDbColWriteStream::OpenL(). |
|
808 @SYMTestPriority High |
|
809 @SYMTestActions Test for DEF141419 - DBMS, new performance tests - RDbUpdate, RDbStoreDatabase |
|
810 @SYMTestExpectedResults Test must not fail |
|
811 @SYMDEF DEF141419 |
|
812 */ |
|
813 void DbColWriteStreamTestsL() |
|
814 { |
|
815 TheTest.Next(_L(" @SYMTestCaseID:PDS-DBMS-UT-4010 RDbColWriteStream performance test")); |
|
816 |
|
817 TInt err = TheDatabase.Replace(TheFs, TheDatabaseFileName); |
|
818 TEST2(err, KErrNone); |
|
819 err = TheDatabase.Execute(KCreateTestTableSql2); |
|
820 TEST(err >= 0); |
|
821 |
|
822 RDbView view; |
|
823 err = view.Prepare(TheDatabase, _L("select * from A"), view.EInsertOnly); |
|
824 TEST2(err, KErrNone); |
|
825 TheRowSet = view; |
|
826 |
|
827 CDbColSet* colSet = TheRowSet.ColSetL(); |
|
828 const TDbColNo KIdx1 = colSet->ColNo(_L("I1")); |
|
829 const TDbColNo KIdx2 = colSet->ColNo(_L("I2")); |
|
830 const TDbColNo KIdx3 = colSet->ColNo(_L("I3")); |
|
831 delete colSet; |
|
832 |
|
833 TheTextRndData.SetLength(KColSize2); |
|
834 TheTextRndData.Fill(KBufChar); |
|
835 TheBinRndData.SetLength(KColSize2); |
|
836 TheBinRndData.Fill(KBufChar); |
|
837 |
|
838 err = TheDatabase.Begin(); |
|
839 TEST2(err, KErrNone); |
|
840 |
|
841 TUint32 openLcFc = 0; |
|
842 TUint32 openLFc = 0; |
|
843 TUint32 fc = User::FastCounter(); |
|
844 |
|
845 for(TInt i=0;i<KTestRecordCount;++i) |
|
846 { |
|
847 TheRowSet.InsertL(); |
|
848 TheRowSet.SetColL(KIdx1, i + 1); |
|
849 |
|
850 RDbColWriteStream strm1; |
|
851 TUint32 tmp = User::FastCounter(); |
|
852 strm1.OpenLC(TheRowSet, KIdx2); |
|
853 openLcFc += CalcTickDiff(tmp, User::FastCounter()); |
|
854 strm1.WriteL(TheTextRndData, KColSize2); |
|
855 strm1.CommitL(); |
|
856 CleanupStack::PopAndDestroy(&strm1); |
|
857 |
|
858 RDbColWriteStream strm2; |
|
859 CleanupClosePushL(strm2); |
|
860 tmp = User::FastCounter(); |
|
861 strm2.OpenL(TheRowSet, KIdx3); |
|
862 openLFc += CalcTickDiff(tmp, User::FastCounter()); |
|
863 strm2.WriteL(TheBinRndData, KColSize2); |
|
864 strm2.CommitL(); |
|
865 CleanupStack::PopAndDestroy(&strm2); |
|
866 |
|
867 TheRowSet.PutL(); |
|
868 } |
|
869 |
|
870 PrintFcDiffAsUs2(_L("###RDbColWriteStream, write %3d records, Time=%d us\r\n"), |
|
871 KTestRecordCount, CalcTickDiff(fc, User::FastCounter())); |
|
872 PrintFcDiffAsUs (_L("###OpenLC() , Time=%d us\r\n"), openLcFc); |
|
873 PrintFcDiffAsUs (_L("###OpenL() , Time=%d us\r\n"), openLFc); |
|
874 |
|
875 TheRowSet.Close(); |
|
876 |
|
877 err = TheDatabase.Commit(); |
|
878 TEST2(err, KErrNone); |
|
879 |
|
880 TheDatabase.Close(); |
|
881 } |
|
882 |
|
883 /** |
|
884 @SYMTestCaseID PDS-DBMS-UT-4011 |
|
885 @SYMTestCaseDesc Test for DEF141419 - DBMS, new performance tests - RDbUpdate, RDbStoreDatabase. |
|
886 Tests the performance of RDbColReadStream::OpenLC() and RDbColReadStream::OpenL(). |
|
887 @SYMTestPriority High |
|
888 @SYMTestActions Test for DEF141419 - DBMS, new performance tests - RDbUpdate, RDbStoreDatabase. |
|
889 @SYMTestExpectedResults Test must not fail |
|
890 @SYMDEF DEF141419 |
|
891 */ |
|
892 void DbColReadStreamTestsL() |
|
893 { |
|
894 TheTest.Next(_L(" @SYMTestCaseID:PDS-DBMS-UT-4011 RDbColReadStream performance test")); |
|
895 |
|
896 TInt err = TheDatabase.Open(TheFs, TheDatabaseFileName); |
|
897 TEST2(err, KErrNone); |
|
898 |
|
899 RDbView view; |
|
900 err = view.Prepare(TheDatabase, _L("select * from A"), view.EReadOnly); |
|
901 TEST2(err, KErrNone); |
|
902 TheRowSet = view; |
|
903 |
|
904 err = view.EvaluateAll(); |
|
905 TEST2(err, KErrNone); |
|
906 |
|
907 CDbColSet* colSet = TheRowSet.ColSetL(); |
|
908 const TDbColNo KIdx1 = colSet->ColNo(_L("I1")); |
|
909 const TDbColNo KIdx2 = colSet->ColNo(_L("I2")); |
|
910 const TDbColNo KIdx3 = colSet->ColNo(_L("I3")); |
|
911 delete colSet; |
|
912 |
|
913 TBuf8<KColSize2> binData; |
|
914 TBuf16<KColSize2> textData; |
|
915 |
|
916 TInt recCnt = 0; |
|
917 TUint32 openLcFc = 0; |
|
918 TUint32 openLFc = 0; |
|
919 TUint32 fc = User::FastCounter(); |
|
920 |
|
921 if(TheRowSet.FirstL()) |
|
922 { |
|
923 do |
|
924 { |
|
925 TheRowSet.GetL(); |
|
926 ++recCnt; |
|
927 |
|
928 TInt i1 = TheRowSet.ColInt(KIdx1); |
|
929 TEST2(recCnt, i1); |
|
930 |
|
931 RDbColReadStream strm1; |
|
932 TUint32 tmp = User::FastCounter(); |
|
933 strm1.OpenLC(TheRowSet, KIdx2); |
|
934 openLcFc += CalcTickDiff(tmp, User::FastCounter()); |
|
935 strm1.ReadL(textData, KColSize2); |
|
936 CleanupStack::PopAndDestroy(&strm1); |
|
937 TEST(textData == TheTextRndData); |
|
938 |
|
939 RDbColReadStream strm2; |
|
940 CleanupClosePushL(strm2); |
|
941 tmp = User::FastCounter(); |
|
942 strm2.OpenL(TheRowSet, KIdx3); |
|
943 openLFc += CalcTickDiff(tmp, User::FastCounter()); |
|
944 strm2.ReadL(binData, KColSize2); |
|
945 CleanupStack::PopAndDestroy(&strm2); |
|
946 TEST(binData == TheBinRndData); |
|
947 } while(TheRowSet.NextL()); |
|
948 } |
|
949 TEST2(recCnt, KTestRecordCount); |
|
950 |
|
951 PrintFcDiffAsUs2(_L("###RDbColReadStream, read %3d records, Time=%d us\r\n"), |
|
952 recCnt, CalcTickDiff(fc, User::FastCounter())); |
|
953 PrintFcDiffAsUs (_L("###OpenLC() , Time=%d us\r\n"), openLcFc); |
|
954 PrintFcDiffAsUs (_L("###OpenL() , Time=%d us\r\n"), openLFc); |
|
955 |
|
956 TheRowSet.Close(); |
|
957 |
|
958 TheDatabase.Close(); |
|
959 } |
|
960 |
|
961 /** |
|
962 @SYMTestCaseID PDS-DBMS-UT-4012 |
|
963 @SYMTestCaseDesc Test for DEF141419 - DBMS, new performance tests - RDbUpdate, RDbStoreDatabase. |
|
964 RDbUpdate performance tests. |
|
965 @SYMTestPriority High |
|
966 @SYMTestActions Test for DEF141419 - DBMS, new performance tests - RDbUpdate, RDbStoreDatabase |
|
967 @SYMTestExpectedResults Test must not fail |
|
968 @SYMDEF DEF141419 |
|
969 */ |
|
970 void DbUpdateTestL() |
|
971 { |
|
972 TheTest.Next(_L(" @SYMTestCaseID:PDS-DBMS-UT-4012 RDbUpdate performance test")); |
|
973 |
|
974 TInt err = TheDbs.Connect(); |
|
975 TEST2(err, KErrNone); |
|
976 |
|
977 err = TheDatabase.Open(TheDbs, TheDatabaseFileName); |
|
978 TEST2(err, KErrNone); |
|
979 |
|
980 TUint32 execFc = 0; |
|
981 TUint32 nextFc = 0; |
|
982 TUint32 rowCntFc = 0; |
|
983 |
|
984 //Synchronous update |
|
985 TInt recCnt = 0; |
|
986 RDbUpdate upd1; |
|
987 TUint32 fc = User::FastCounter(); |
|
988 err = upd1.Execute(TheDatabase, _L("UPDATE A SET I1=1000, I2='8888888888888888'")); |
|
989 execFc = CalcTickDiff(fc, User::FastCounter()); |
|
990 TEST2(err, KErrNone); |
|
991 TUint32 tmp = User::FastCounter(); |
|
992 while((err = upd1.Next()) > 0) |
|
993 { |
|
994 } |
|
995 nextFc = CalcTickDiff(tmp, User::FastCounter()); |
|
996 tmp = User::FastCounter(); |
|
997 recCnt = upd1.RowCount(); |
|
998 rowCntFc = CalcTickDiff(tmp, User::FastCounter()); |
|
999 upd1.Close(); |
|
1000 fc = CalcTickDiff(fc, User::FastCounter()); |
|
1001 TEST2(err, 0); |
|
1002 TEST2(recCnt, KTestRecordCount); |
|
1003 |
|
1004 TheDatabase.Close(); |
|
1005 |
|
1006 PrintFcDiffAsUs2(_L("###Sync RDbUpdate, %3d records, Time=%d us\r\n"), recCnt, fc); |
|
1007 PrintFcDiffAsUs (_L("###Execute() , Time=%d us\r\n"), execFc); |
|
1008 PrintFcDiffAsUs (_L("###Next() , Time=%d us\r\n"), nextFc); |
|
1009 PrintFcDiffAsUs (_L("###RowCount() , Time=%d us\r\n"), rowCntFc); |
|
1010 |
|
1011 //Asynchronous update |
|
1012 err = TheDatabase.Open(TheDbs, TheDatabaseFileName); |
|
1013 TEST2(err, KErrNone); |
|
1014 |
|
1015 execFc = 0; |
|
1016 nextFc = 0; |
|
1017 rowCntFc = 0; |
|
1018 recCnt = 0; |
|
1019 |
|
1020 RDbUpdate upd2; |
|
1021 fc = User::FastCounter(); |
|
1022 err = upd2.Execute(TheDatabase, _L("UPDATE A SET I1=5678, I2='9w27u22272252542r2242242424221'")); |
|
1023 execFc = CalcTickDiff(fc, User::FastCounter()); |
|
1024 TEST2(err, KErrNone); |
|
1025 TRequestStatus stat; |
|
1026 tmp = User::FastCounter(); |
|
1027 do |
|
1028 { |
|
1029 upd2.Next(stat); |
|
1030 User::WaitForRequest(stat); |
|
1031 } while(stat.Int() > 0); |
|
1032 nextFc = CalcTickDiff(tmp, User::FastCounter()); |
|
1033 tmp = User::FastCounter(); |
|
1034 recCnt = upd2.RowCount(); |
|
1035 rowCntFc = CalcTickDiff(tmp, User::FastCounter()); |
|
1036 upd2.Close(); |
|
1037 fc = CalcTickDiff(fc, User::FastCounter()); |
|
1038 TEST2(stat.Int(), 0); |
|
1039 TEST2(recCnt, KTestRecordCount); |
|
1040 |
|
1041 TheDatabase.Close(); |
|
1042 |
|
1043 PrintFcDiffAsUs2(_L("###Async RDbUpdate, %3d records, Time=%d us\r\n"), recCnt, fc); |
|
1044 PrintFcDiffAsUs (_L("###Execute() , Time=%d us\r\n"), execFc); |
|
1045 PrintFcDiffAsUs (_L("###Next() , Time=%d us\r\n"), nextFc); |
|
1046 PrintFcDiffAsUs (_L("###RowCount() , Time=%d us\r\n"), rowCntFc); |
|
1047 |
|
1048 TheDbs.Close(); |
|
1049 err = TheFs.Delete(TheDatabaseFileName); |
|
1050 TEST2(err, KErrNone); |
|
1051 } |
|
1052 |
|
1053 /** |
|
1054 @SYMTestCaseID PDS-DBMS-UT-4013 |
|
1055 @SYMTestCaseDesc Test for DEF141419 - DBMS, new performance tests - RDbUpdate, RDbStoreDatabase. |
|
1056 RDbStoreDatabase performance tests. |
|
1057 @SYMTestPriority High |
|
1058 @SYMTestActions Test for DEF141419 - DBMS, new performance tests - RDbUpdate, RDbStoreDatabase. |
|
1059 @SYMTestExpectedResults Test must not fail |
|
1060 @SYMDEF DEF141419 |
|
1061 */ |
|
1062 void DbStoreDatabaseTestL() |
|
1063 { |
|
1064 TheTest.Next(_L(" @SYMTestCaseID:PDS-DBMS-UT-4013 RDbStoreDatabase performance test")); |
|
1065 |
|
1066 CFileStore* fstore = CPermanentFileStore::ReplaceLC(TheFs, TheDatabaseFileName, EFileRead | EFileWrite); |
|
1067 fstore->SetTypeL(fstore->Layout()); |
|
1068 |
|
1069 //Create the database, insert records, compress the store. |
|
1070 |
|
1071 RDbStoreDatabase db1; |
|
1072 CleanupClosePushL(db1); |
|
1073 TUint32 fc = User::FastCounter(); |
|
1074 TStreamId strmId = db1.CreateL(fstore); |
|
1075 TUint32 createFc = CalcTickDiff(fc, User::FastCounter()); |
|
1076 |
|
1077 TInt err = db1.Execute(KCreateTestTableSql2); |
|
1078 TEST(err >= 0); |
|
1079 err = db1.Begin(); |
|
1080 TEST2(err, 0); |
|
1081 for(TInt i=0;i<KTestRecordCount;++i) |
|
1082 { |
|
1083 err = db1.Execute(_L("INSERT INTO A(I1, I2) VALUES(1, 'ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZAAAAAAAAAAAAAAAAAAAAAAAAAAAA')")); |
|
1084 TEST2(err, 1); |
|
1085 } |
|
1086 err = db1.Commit(); |
|
1087 TEST2(err, 0); |
|
1088 |
|
1089 CleanupStack::PopAndDestroy(&db1); |
|
1090 TUint32 writeFc = CalcTickDiff(fc, User::FastCounter()); |
|
1091 |
|
1092 TInt fsize1 = 0; |
|
1093 err = fstore->File().Size(fsize1); |
|
1094 TEST2(err, KErrNone); |
|
1095 |
|
1096 fc = User::FastCounter(); |
|
1097 RDbStoreDatabase::CompressL(*fstore, strmId); |
|
1098 TUint32 compressFc = CalcTickDiff(fc, User::FastCounter()); |
|
1099 |
|
1100 TInt fsize2 = 0; |
|
1101 err = fstore->File().Size(fsize2); |
|
1102 TEST2(err, KErrNone); |
|
1103 |
|
1104 CleanupStack::PopAndDestroy(fstore); |
|
1105 |
|
1106 PrintFcDiffAsUs2(_L("###RDbStoreDatabase, write %3d records, Time=%d us\r\n"), KTestRecordCount, writeFc); |
|
1107 PrintFcDiffAsUs (_L("###CreateL() , Time=%d us\r\n"), createFc); |
|
1108 PrintFcDiffAsUs (_L("###CompressL() , Time=%d us\r\n"), compressFc); |
|
1109 |
|
1110 //Decompress the store, open the database, read the records |
|
1111 |
|
1112 fstore = CPermanentFileStore::OpenLC(TheFs, TheDatabaseFileName, EFileRead | EFileWrite); |
|
1113 fstore->SetTypeL(fstore->Layout()); |
|
1114 |
|
1115 fc = User::FastCounter(); |
|
1116 RDbStoreDatabase::DecompressL(*fstore, strmId); |
|
1117 TUint32 decompressFc = CalcTickDiff(fc, User::FastCounter()); |
|
1118 |
|
1119 TInt fsize3 = 0; |
|
1120 err = fstore->File().Size(fsize3); |
|
1121 TEST2(err, KErrNone); |
|
1122 |
|
1123 RDbStoreDatabase db2; |
|
1124 CleanupClosePushL(db2); |
|
1125 fc = User::FastCounter(); |
|
1126 db2.OpenL(fstore, strmId); |
|
1127 TUint32 openFc = CalcTickDiff(fc, User::FastCounter()); |
|
1128 |
|
1129 RDbView view; |
|
1130 err = view.Prepare(db2, _L("SELECT * FROM A")); |
|
1131 TEST2(err, KErrNone); |
|
1132 err = view.EvaluateAll(); |
|
1133 TEST2(err, KErrNone); |
|
1134 TheRowSet = view; |
|
1135 |
|
1136 CDbColSet* colSet = TheRowSet.ColSetL(); |
|
1137 const TDbColNo KIdx1 = colSet->ColNo(_L("I1")); |
|
1138 const TDbColNo KIdx2 = colSet->ColNo(_L("I2")); |
|
1139 const TDbColNo KIdx3 = colSet->ColNo(_L("I3")); |
|
1140 delete colSet; |
|
1141 |
|
1142 TInt recCnt = 0; |
|
1143 if(TheRowSet.FirstL()) |
|
1144 { |
|
1145 do |
|
1146 { |
|
1147 TheRowSet.GetL(); |
|
1148 ++recCnt; |
|
1149 |
|
1150 RDbColReadStream strm1; |
|
1151 strm1.OpenLC(TheRowSet, KIdx2); |
|
1152 TBuf<KColSize2> buf; |
|
1153 _LIT(KText, "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZAAAAAAAAAAAAAAAAAAAAAAAAAAAA");//the same as the used in the INSERT statement above |
|
1154 strm1.ReadL(buf, KText().Length()); |
|
1155 CleanupStack::PopAndDestroy(&strm1); |
|
1156 TEST(KText() == buf); |
|
1157 } while(TheRowSet.NextL()); |
|
1158 } |
|
1159 TEST2(recCnt, KTestRecordCount); |
|
1160 |
|
1161 TheRowSet.Close(); |
|
1162 TUint32 readFc = CalcTickDiff(fc, User::FastCounter()); |
|
1163 |
|
1164 CleanupStack::PopAndDestroy(&db2); |
|
1165 CleanupStack::PopAndDestroy(fstore); |
|
1166 |
|
1167 PrintFcDiffAsUs2(_L("###RDbStoreDatabase, read %3d records , Time=%d us\r\n"), recCnt, readFc); |
|
1168 PrintFcDiffAsUs (_L("###OpenL() , Time=%d us\r\n"), openFc); |
|
1169 PrintFcDiffAsUs (_L("###DecompressL() , Time=%d us\r\n"), decompressFc); |
|
1170 TheTest.Printf(_L("###File size. After write: %d. After Compress(): %d. After Decompress(): %d\r\n"), fsize1, fsize2, fsize3); |
|
1171 |
|
1172 err = TheFs.Delete(TheDatabaseFileName); |
|
1173 TEST2(err, KErrNone); |
|
1174 } |
|
1175 |
|
1176 /** |
|
1177 @SYMTestCaseID PDS-DBMS-UT-4014 |
|
1178 @SYMTestCaseDesc Test for DEF141419 - DBMS, new performance tests - RDbUpdate, RDbStoreDatabase. |
|
1179 RDbDatabase performance tests. |
|
1180 @SYMTestPriority High |
|
1181 @SYMTestActions Test for DEF141419 - DBMS, new performance tests - RDbUpdate, RDbStoreDatabase. |
|
1182 @SYMTestExpectedResults Test must not fail |
|
1183 @SYMDEF DEF141419 |
|
1184 */ |
|
1185 void DbDatabaseTestL() |
|
1186 { |
|
1187 TheTest.Next(_L(" @SYMTestCaseID:PDS-DBMS-UT-4014 RDbDatabase performance test")); |
|
1188 |
|
1189 TInt err = TheDatabase.Replace(TheFs, TheDatabaseFileName); |
|
1190 TEST2(err, KErrNone); |
|
1191 |
|
1192 //CDbColSet |
|
1193 _LIT(KColName1, "Col1"); |
|
1194 _LIT(KColName2, "Col2"); |
|
1195 _LIT(KColName3, "Col3"); |
|
1196 TUint32 fc = User::FastCounter(); |
|
1197 CDbColSet* colset = CDbColSet::NewLC(); |
|
1198 TDbCol col1(KColName1, EDbColInt32); |
|
1199 colset->AddL(col1); |
|
1200 TDbCol col2(KColName2, EDbColText16, 100); |
|
1201 colset->AddL(col2); |
|
1202 TDbCol col3(KColName3, EDbColBinary, 100); |
|
1203 colset->AddL(col3); |
|
1204 TUint32 colSetFc = CalcTickDiff(fc, User::FastCounter()); |
|
1205 PrintFcDiffAsUs(_L("###CDbColSet::NewLC() & CDbColSet::AddL(), Time=%d us\r\n"), colSetFc); |
|
1206 |
|
1207 //RDbDatabase::CreateTable() |
|
1208 _LIT(KTblName, "ATbl"); |
|
1209 fc = User::FastCounter(); |
|
1210 err = TheDatabase.CreateTable(KTblName, *colset); |
|
1211 TUint32 createTblFc = CalcTickDiff(fc, User::FastCounter()); |
|
1212 TEST2(err, KErrNone); |
|
1213 PrintFcDiffAsUs(_L("###RDbDatabase::CreateTable(), Time=%d us\r\n"), createTblFc); |
|
1214 |
|
1215 //RDbDatabase::AlterTable() |
|
1216 _LIT(KColName4, "Col4"); |
|
1217 TDbCol col4(KColName4, EDbColReal64); |
|
1218 colset->AddL(col4); |
|
1219 fc = User::FastCounter(); |
|
1220 err = TheDatabase.AlterTable(KTblName, *colset); |
|
1221 TUint32 alterTblFc = CalcTickDiff(fc, User::FastCounter()); |
|
1222 TEST2(err, KErrNone); |
|
1223 PrintFcDiffAsUs(_L("###RDbDatabase::AlterTable(), Time=%d us\r\n"), alterTblFc); |
|
1224 |
|
1225 //CDbKey |
|
1226 fc = User::FastCounter(); |
|
1227 CDbKey* dbKey = CDbKey::NewLC(); |
|
1228 TDbKeyCol keyCol1(KColName1, TDbKeyCol::EAsc); |
|
1229 dbKey->AddL(keyCol1); |
|
1230 TDbKeyCol keyCol2(KColName4, TDbKeyCol::EDesc); |
|
1231 dbKey->AddL(keyCol2); |
|
1232 TUint32 dbKeyFc = CalcTickDiff(fc, User::FastCounter()); |
|
1233 PrintFcDiffAsUs(_L("###CDbKey::NewLC() & CDbKey::AddL(), Time=%d us\r\n"), dbKeyFc); |
|
1234 |
|
1235 //RDbDatabase::CreateIndex() |
|
1236 _LIT(KKeyName, "AKey"); |
|
1237 fc = User::FastCounter(); |
|
1238 err = TheDatabase.CreateIndex(KKeyName, KTblName, *dbKey); |
|
1239 TUint32 createIndexFc = CalcTickDiff(fc, User::FastCounter()); |
|
1240 TEST2(err, KErrNone); |
|
1241 PrintFcDiffAsUs(_L("###RDbDatabase::CreateIndex(), Time=%d us\r\n"), createIndexFc); |
|
1242 |
|
1243 CleanupStack::PopAndDestroy(dbKey); |
|
1244 CleanupStack::PopAndDestroy(colset); |
|
1245 |
|
1246 //RDbDatabase::TableNamesL() |
|
1247 fc = User::FastCounter(); |
|
1248 CDbTableNames* tblNames = TheDatabase.TableNamesL(); |
|
1249 TUint32 tblNamesFc = CalcTickDiff(fc, User::FastCounter()); |
|
1250 delete tblNames; |
|
1251 PrintFcDiffAsUs(_L("###RDbDatabase::TableNamesL(), Time=%d us\r\n"), tblNamesFc); |
|
1252 |
|
1253 //RDbDatabase::IndexNamesL() |
|
1254 fc = User::FastCounter(); |
|
1255 CDbIndexNames* idxNames = TheDatabase.IndexNamesL(KTblName); |
|
1256 TUint32 idxNamesFc = CalcTickDiff(fc, User::FastCounter()); |
|
1257 delete idxNames; |
|
1258 PrintFcDiffAsUs(_L("###RDbDatabase::IndexNamesL(), Time=%d us\r\n"), idxNamesFc); |
|
1259 |
|
1260 //RDbDatabase::ColSetL() |
|
1261 fc = User::FastCounter(); |
|
1262 colset = TheDatabase.ColSetL(KTblName); |
|
1263 colSetFc = CalcTickDiff(fc, User::FastCounter()); |
|
1264 delete colset; |
|
1265 PrintFcDiffAsUs(_L("###RDbDatabase::ColSetL(), Time=%d us\r\n"), colSetFc); |
|
1266 |
|
1267 //RDbDatabase::KeyL() |
|
1268 fc = User::FastCounter(); |
|
1269 dbKey = TheDatabase.KeyL(KKeyName, KTblName); |
|
1270 dbKeyFc = CalcTickDiff(fc, User::FastCounter()); |
|
1271 delete dbKey; |
|
1272 PrintFcDiffAsUs(_L("###RDbDatabase::KeyL(), Time=%d us\r\n"), dbKeyFc); |
|
1273 |
|
1274 //RDbDatabase::DropIndex() |
|
1275 fc = User::FastCounter(); |
|
1276 err = TheDatabase.DropIndex(KKeyName, KTblName); |
|
1277 TUint32 dropIdxFc = CalcTickDiff(fc, User::FastCounter()); |
|
1278 TEST2(err, KErrNone); |
|
1279 PrintFcDiffAsUs(_L("###RDbDatabase::DropIndex(), Time=%d us\r\n"), dropIdxFc); |
|
1280 |
|
1281 //RDbDatabase::DropTable() |
|
1282 fc = User::FastCounter(); |
|
1283 err = TheDatabase.DropTable(KTblName); |
|
1284 TUint32 dropTblFc = CalcTickDiff(fc, User::FastCounter()); |
|
1285 TEST2(err, KErrNone); |
|
1286 PrintFcDiffAsUs(_L("###RDbDatabase::DropTable(), Time=%d us\r\n"), dropTblFc); |
|
1287 |
|
1288 TheDatabase.Close(); |
|
1289 } |
|
1290 |
|
1291 void PrintDiskUsage(const TDesC& aPath, TInt aOffset = 0) |
|
1292 { |
|
1293 _LIT(KSpace, " "); |
|
1294 TheTest.Printf(_L("%*.*S%S\r\n"), aOffset, aOffset, &KSpace, &aPath); |
|
1295 TFindFile findFile(TheFs); |
|
1296 CDir* fileNameCol = NULL; |
|
1297 TBuf<8> fileNameMask; |
|
1298 fileNameMask.Copy(_L("*.*")); |
|
1299 TInt err = findFile.FindWildByDir(fileNameMask, aPath, fileNameCol); |
|
1300 if(err == KErrNone) |
|
1301 { |
|
1302 do |
|
1303 { |
|
1304 const TDesC& file = findFile.File();//"file" variable contains the drive and the path. the file name in "file" is invalid in this case. |
|
1305 (void)TheParse.Set(file, NULL, NULL); |
|
1306 TPtrC driveName = TheParse.Drive(); |
|
1307 if(aPath.FindF(driveName) < 0) |
|
1308 { |
|
1309 goto cont; |
|
1310 } |
|
1311 |
|
1312 TInt cnt = fileNameCol->Count(); |
|
1313 for(TInt i=0;i<cnt;++i) |
|
1314 { |
|
1315 const ::TEntry& entry = (*fileNameCol)[i]; |
|
1316 if(!entry.IsDir()) |
|
1317 { |
|
1318 TheTest.Printf(_L("%*.*S %S, size=%d\r\n"), aOffset, aOffset, &KSpace, &entry.iName, entry.iSize); |
|
1319 } |
|
1320 else |
|
1321 { |
|
1322 TBuf<100> path; |
|
1323 path.Copy(aPath); |
|
1324 path.Append(entry.iName); |
|
1325 path.Append(_L("\\")); |
|
1326 PrintDiskUsage(path, aOffset + 4); |
|
1327 } |
|
1328 } |
|
1329 cont: |
|
1330 delete fileNameCol; |
|
1331 fileNameCol = NULL; |
|
1332 } while((err = findFile.FindWild(fileNameCol)) == KErrNone);//Get the next set of files |
|
1333 } |
|
1334 else |
|
1335 { |
|
1336 TheTest.Printf(_L(" FindWildByDir() failed with err=%d\r\n"), err); |
|
1337 } |
|
1338 } |
|
1339 |
|
1340 void DoTestL() |
|
1341 { |
|
1342 GetFastCounterFrequency(); |
|
1343 |
|
1344 FileBlockSizeTestsL(); |
|
1345 |
|
1346 RecordLenTestL(); |
|
1347 |
|
1348 InsertTestsL(); |
|
1349 |
|
1350 UpdateTestsL(); |
|
1351 |
|
1352 DbInsertTestsL(); |
|
1353 |
|
1354 DbUpdateTestsL(); |
|
1355 |
|
1356 DbColWriteStreamTestsL(); |
|
1357 |
|
1358 DbColReadStreamTestsL(); |
|
1359 |
|
1360 DbUpdateTestL(); |
|
1361 |
|
1362 DbStoreDatabaseTestL(); |
|
1363 |
|
1364 DbDatabaseTestL(); |
|
1365 } |
|
1366 |
|
1367 //Usage: "t_dbperf2 [<drive letter>:]" |
|
1368 TInt E32Main() |
|
1369 { |
|
1370 TheTest.Title(); |
|
1371 |
|
1372 TheTrapCleanup = CTrapCleanup::New(); |
|
1373 TEST(TheTrapCleanup != NULL); |
|
1374 |
|
1375 //Construct test database file name |
|
1376 _LIT(KTestDatabase, "c:\\dbms-tst\\t_dbperf2.db"); |
|
1377 TFileName fname; |
|
1378 User::CommandLine(fname); |
|
1379 TParse parse; |
|
1380 parse.Set(fname, &KTestDatabase, 0); |
|
1381 const TDesC& dbFilePath = parse.FullName(); |
|
1382 TheDatabaseFileName.Copy(dbFilePath); |
|
1383 TheTest.Printf(_L("Test database: %S\r\n"), &TheDatabaseFileName); |
|
1384 //Construct test file name |
|
1385 _LIT(KTestFile, "c:\\dbms-tst\\t_dbperf2.dat"); |
|
1386 parse.Set(fname, &KTestFile, 0); |
|
1387 const TDesC& testFilePath = parse.FullName(); |
|
1388 TheTestFileName.Copy(testFilePath); |
|
1389 |
|
1390 __UHEAP_MARK; |
|
1391 |
|
1392 TInt err = TheFs.Connect(); |
|
1393 TEST2(err, KErrNone); |
|
1394 err = TheFs.MkDir(TheDatabaseFileName); |
|
1395 TheTest.Printf(_L("MkDir(): err=%d\r\n"), err); |
|
1396 TEST(err == KErrNone || err == KErrAlreadyExists); |
|
1397 |
|
1398 DeleteFile(TheDatabaseFileName); |
|
1399 TRAP(err, DoTestL()); |
|
1400 DeleteFile(TheDatabaseFileName); |
|
1401 DeleteFile(TheTestFileName); |
|
1402 TEST2(err, KErrNone); |
|
1403 |
|
1404 TheTest.Printf(_L("====================================================\r\n")); |
|
1405 PrintDiskUsage(_L("c:\\")); |
|
1406 TheTest.Printf(_L("====================================================\r\n")); |
|
1407 |
|
1408 CloseAll(); |
|
1409 |
|
1410 __UHEAP_MARKEND; |
|
1411 |
|
1412 TheTest.End(); |
|
1413 TheTest.Close(); |
|
1414 |
|
1415 delete TheTrapCleanup; |
|
1416 return KErrNone; |
|
1417 } |