|
1 // Copyright (c) 2010 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: MDS harvesting performance test |
|
14 // |
|
15 #include <e32test.h> |
|
16 #include <e32math.h> |
|
17 #include <bautils.h> |
|
18 #include <hal.h> |
|
19 #include <sqldb.h> |
|
20 #include "t_sqlcmdlineutil.h" |
|
21 |
|
22 RTest TheTest(_L("t_sqlperformance5 test")); |
|
23 RSqlDatabase TheDb; |
|
24 |
|
25 _LIT(KDbName, "c:\\test\\t_sqlperformance5.db"); |
|
26 |
|
27 TFileName TheDbFileName; |
|
28 TBuf<200> TheTestTitle; |
|
29 TCmdLineParams TheCmdLineParams(TCmdLineParams::EDbUtf16, 16384, 32); |
|
30 TBuf8<200> TheSqlConfigString; |
|
31 |
|
32 _LIT(KUtf8, "UTF8 "); |
|
33 _LIT(KUtf16, "UTF16"); |
|
34 |
|
35 const TInt KThumbnailCount = 60; |
|
36 const TInt KMaxThumbnailSize = 40 * 1024; |
|
37 |
|
38 const TInt KThumbnailSizes[KThumbnailCount] = |
|
39 { |
|
40 //1 2 3 4 5 6 7 8 9 10 |
|
41 22054, 24076, 33281, 24733, 33094, 31443, 29264, 28725, 31798, 29322, //1 |
|
42 25002, 26926, 31097, 21988, 33659, 29081, 33050, 36857, 37686, 24034, //2 |
|
43 21093, 28314, 20186, 27222, 28600, 32735, 27279, 31898, 31380, 36316, //3 |
|
44 34295, 31642, 21829, 32912, 31584, 32557, 36601, 22744, 32808, 26130, //4 |
|
45 31222, 21545, 35899, 22257, 25856, 31169, 34893, 23496, 23034, 30381, //5 |
|
46 25810, 27123, 33442, 22275, 30260, 31028, 32415, 27345, 26614, 33704 //6 |
|
47 }; |
|
48 |
|
49 TInt TheFastCounterFreq = 0; |
|
50 |
|
51 TInt TheCreateDbTime = 0; |
|
52 TInt TheCreateTablesTime = 0; |
|
53 TInt TheBindParamsTime = 0; |
|
54 TInt TheStmtExecTime = 0; |
|
55 TInt TheStmtResetTime = 0; |
|
56 TInt ThePopulateTempTableTime = 0; |
|
57 TInt TheFlushTime = 0; |
|
58 |
|
59 //////////////////////////////////////////////////////////////////////////////////////////////////// |
|
60 |
|
61 void TestEnvDestroy() |
|
62 { |
|
63 TheDb.Close(); |
|
64 (void)RSqlDatabase::Delete(TheDbFileName); |
|
65 ResetSoftHeapLimit(); |
|
66 } |
|
67 |
|
68 /////////////////////////////////////////////////////////////////////////////////////// |
|
69 /////////////////////////////////////////////////////////////////////////////////////// |
|
70 //Test macros and functions |
|
71 void Check1(TInt aValue, TInt aLine) |
|
72 { |
|
73 if(!aValue) |
|
74 { |
|
75 TestEnvDestroy(); |
|
76 TheTest.Printf(_L("*** Line %d\r\n"), aLine); |
|
77 TheTest(EFalse, aLine); |
|
78 } |
|
79 } |
|
80 void Check2(TInt aValue, TInt aExpected, TInt aLine) |
|
81 { |
|
82 if(aValue != aExpected) |
|
83 { |
|
84 TSqlRetCodeClass cl = SqlRetCodeClass(aValue); |
|
85 if(cl == ESqlDbError) |
|
86 { |
|
87 TPtrC errmsg = TheDb.LastErrorMessage(); |
|
88 TheTest.Printf(_L("*** SQLite err=\"%S\"\r\n"), &errmsg); |
|
89 } |
|
90 TestEnvDestroy(); |
|
91 TheTest.Printf(_L("*** Line %d, Expected error: %d, got: %d\r\n"), aLine, aExpected, aValue); |
|
92 TheTest(EFalse, aLine); |
|
93 } |
|
94 } |
|
95 #define TEST(arg) ::Check1((arg), __LINE__) |
|
96 #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__) |
|
97 |
|
98 /////////////////////////////////////////////////////////////////////////////////////// |
|
99 |
|
100 void TestEnvInit() |
|
101 { |
|
102 RFs fs; |
|
103 TInt err = fs.Connect(); |
|
104 TEST2(err, KErrNone); |
|
105 err = fs.MkDirAll(TheDbFileName); |
|
106 TEST(err == KErrNone || err == KErrAlreadyExists); |
|
107 fs.Close(); |
|
108 } |
|
109 |
|
110 TInt TimeDiffUs(TUint32 aStartTicks, TUint32 aEndTicks) |
|
111 { |
|
112 if(TheFastCounterFreq == 0) |
|
113 { |
|
114 TEST2(HAL::Get(HAL::EFastCounterFrequency, TheFastCounterFreq), KErrNone); |
|
115 TheTest.Printf(_L("==Fast counter frequency: %d Hz\r\n"), TheFastCounterFreq); |
|
116 } |
|
117 TInt64 diffTicks = (TInt64)aEndTicks - (TInt64)aStartTicks; |
|
118 if(diffTicks < 0) |
|
119 { |
|
120 diffTicks = KMaxTUint32 + diffTicks + 1; |
|
121 } |
|
122 const TInt KMicroSecIn1Sec = 1000000; |
|
123 TInt us = (diffTicks * KMicroSecIn1Sec) / TheFastCounterFreq; |
|
124 return us; |
|
125 } |
|
126 |
|
127 void PrintTime(const TDesC& aFmt, TUint32 aStartTicks, TUint32 aEndTicks) |
|
128 { |
|
129 TInt us = TimeDiffUs(aStartTicks, aEndTicks); |
|
130 TheTest.Printf(aFmt, us); |
|
131 } |
|
132 |
|
133 //============================================================================= |
|
134 |
|
135 /** |
|
136 @SYMTestCaseID PDS-SQL-CT-4205 |
|
137 @SYMTestCaseDesc Thumbnail database performance test. |
|
138 @SYMTestPriority Medium |
|
139 @SYMTestActions The test executes statements to create the thumbnail database. |
|
140 @SYMTestExpectedResults The test must not fail |
|
141 @SYMDEF ou1cimx1#362240 |
|
142 */ |
|
143 void CreateDb() |
|
144 { |
|
145 (void)RSqlDatabase::Delete(TheDbFileName); |
|
146 |
|
147 TUint32 fc1 = User::FastCounter(); |
|
148 |
|
149 TInt err = TheDb.Create(TheDbFileName, &TheSqlConfigString); |
|
150 |
|
151 TUint32 fc2 = User::FastCounter(); |
|
152 TheCreateDbTime = TimeDiffUs(fc1, fc2); |
|
153 |
|
154 TEST2(err, KErrNone); |
|
155 |
|
156 fc1 = User::FastCounter(); |
|
157 |
|
158 err = TheDb.Exec(_L("CREATE TABLE ThumbnailInfo (Path TEXT COLLATE NOCASE,TNId INTEGER,Size INTEGER,Format INTEGER,TNPath TEXT COLLATE NOCASE,Width INTEGER,Height INTEGER,OrigWidth INTEGER,OrigHeight INTEGER,Flags INTEGER,VideoPosition INTEGER,Orientation INTEGER,humbFromPath INTEGER,Modified LARGEINT);")); |
|
159 TEST(err >= 0); |
|
160 |
|
161 err = TheDb.Exec(_L("CREATE TABLE ThumbnailInfoData(Data BLOB);")); |
|
162 TEST(err >= 0); |
|
163 |
|
164 err = TheDb.Exec(_L("CREATE TABLE ThumbnailDeleted(Path TEXT UNIQUE COLLATE NOCASE);")); |
|
165 TEST(err >= 0); |
|
166 |
|
167 err = TheDb.Exec(_L("CREATE INDEX idx1 ON ThumbnailInfo(Path, Size);")); |
|
168 TEST(err >= 0); |
|
169 |
|
170 err = TheDb.Exec(_L("CREATE INDEX idx4 ON ThumbnailDeleted(Path);")); |
|
171 TEST(err >= 0); |
|
172 |
|
173 err = TheDb.Exec(_L("CREATE TABLE ThumbnailVersion (Major INTEGER,Minor INTEGER,IMEI TEXT COLLATE NOCASE);")); |
|
174 TEST(err >= 0); |
|
175 |
|
176 fc2 = User::FastCounter(); |
|
177 TheCreateTablesTime = TimeDiffUs(fc1, fc2); |
|
178 |
|
179 TheDb.Close(); |
|
180 } |
|
181 |
|
182 void PoulateTempTables(RSqlStatement& aStmt1, RSqlStatement& aStmt2) |
|
183 { |
|
184 HBufC8* thumbnailBuf = HBufC8::New(KMaxThumbnailSize); |
|
185 TEST(thumbnailBuf != NULL); |
|
186 TPtr8 thumbnailData = thumbnailBuf->Des(); |
|
187 thumbnailData.SetLength(KMaxThumbnailSize); |
|
188 thumbnailData.Fill(TChar('A')); |
|
189 |
|
190 TUint32 fc3 = User::FastCounter(); |
|
191 |
|
192 for(TInt i=0;i<KThumbnailCount;++i) |
|
193 { |
|
194 TUint32 fc1 = User::FastCounter(); |
|
195 |
|
196 TInt paramIndex = aStmt1.ParameterIndex(_L(":Path")); |
|
197 TEST(paramIndex >= 0); |
|
198 TInt err = aStmt1.BindText(paramIndex, _L("c:\\test\\abcdefgh123456789.jpg")); |
|
199 TEST2(err, KErrNone); |
|
200 |
|
201 paramIndex = aStmt1.ParameterIndex(_L(":Width")); |
|
202 TEST(paramIndex >= 0); |
|
203 err = aStmt1.BindInt(paramIndex, 50); |
|
204 TEST2(err, KErrNone); |
|
205 |
|
206 paramIndex = aStmt1.ParameterIndex(_L(":Height")); |
|
207 TEST(paramIndex >= 0); |
|
208 err = aStmt1.BindInt(paramIndex, 40); |
|
209 TEST2(err, KErrNone); |
|
210 |
|
211 paramIndex = aStmt1.ParameterIndex(_L(":OrigWidth")); |
|
212 TEST(paramIndex >= 0); |
|
213 err = aStmt1.BindInt(paramIndex, 1000); |
|
214 TEST2(err, KErrNone); |
|
215 |
|
216 paramIndex = aStmt1.ParameterIndex(_L(":OrigHeight")); |
|
217 TEST(paramIndex >= 0); |
|
218 err = aStmt1.BindInt(paramIndex, 2000); |
|
219 TEST2(err, KErrNone); |
|
220 |
|
221 paramIndex = aStmt1.ParameterIndex(_L(":Format")); |
|
222 TEST(paramIndex >= 0); |
|
223 err = aStmt1.BindInt(paramIndex, 10); |
|
224 TEST2(err, KErrNone); |
|
225 |
|
226 paramIndex = aStmt1.ParameterIndex(_L(":Flags")); |
|
227 TEST(paramIndex >= 0); |
|
228 err = aStmt1.BindInt(paramIndex, 0x1E); |
|
229 TEST2(err, KErrNone); |
|
230 |
|
231 paramIndex = aStmt1.ParameterIndex(_L(":Size")); |
|
232 TEST(paramIndex >= 0); |
|
233 err = aStmt1.BindInt(paramIndex, 1200); |
|
234 TEST2(err, KErrNone); |
|
235 |
|
236 paramIndex = aStmt1.ParameterIndex(_L(":Orient")); |
|
237 TEST(paramIndex >= 0); |
|
238 err = aStmt1.BindInt(paramIndex, 2); |
|
239 TEST2(err, KErrNone); |
|
240 |
|
241 paramIndex = aStmt1.ParameterIndex(_L(":ThumbFromPath")); |
|
242 TEST(paramIndex >= 0); |
|
243 err = aStmt1.BindInt(paramIndex, 1); |
|
244 TEST2(err, KErrNone); |
|
245 |
|
246 paramIndex = aStmt1.ParameterIndex(_L(":Modified")); |
|
247 TEST(paramIndex >= 0); |
|
248 err = aStmt1.BindInt64(paramIndex, 3212398543392LL); |
|
249 TEST2(err, KErrNone); |
|
250 |
|
251 TUint32 fc2 = User::FastCounter(); |
|
252 TheBindParamsTime += TimeDiffUs(fc1, fc2); |
|
253 |
|
254 fc1 = User::FastCounter(); |
|
255 err = aStmt1.Exec(); |
|
256 fc2 = User::FastCounter(); |
|
257 TheStmtExecTime += TimeDiffUs(fc1, fc2); |
|
258 |
|
259 TEST2(err, 1); |
|
260 |
|
261 fc1 = User::FastCounter(); |
|
262 err = aStmt1.Reset(); |
|
263 fc2 = User::FastCounter(); |
|
264 TheStmtResetTime += TimeDiffUs(fc1, fc2); |
|
265 |
|
266 TEST2(err, KErrNone); |
|
267 |
|
268 thumbnailData.SetLength(KThumbnailSizes[i]); |
|
269 |
|
270 fc1 = User::FastCounter(); |
|
271 paramIndex = aStmt2.ParameterIndex(_L(":Data")); |
|
272 TEST(paramIndex >= 0); |
|
273 err = aStmt2.BindBinary(paramIndex, thumbnailData); |
|
274 TEST2(err, KErrNone); |
|
275 fc2 = User::FastCounter(); |
|
276 TheBindParamsTime += TimeDiffUs(fc1, fc2); |
|
277 |
|
278 fc1 = User::FastCounter(); |
|
279 err = aStmt2.Exec(); |
|
280 fc2 = User::FastCounter(); |
|
281 TheStmtExecTime += TimeDiffUs(fc1, fc2); |
|
282 |
|
283 TEST2(err, 1); |
|
284 |
|
285 fc1 = User::FastCounter(); |
|
286 err = aStmt2.Reset(); |
|
287 fc2 = User::FastCounter(); |
|
288 TheStmtResetTime += TimeDiffUs(fc1, fc2); |
|
289 |
|
290 TEST2(err, KErrNone); |
|
291 } |
|
292 |
|
293 TUint32 fc4 = User::FastCounter(); |
|
294 ThePopulateTempTableTime += TimeDiffUs(fc3, fc4); |
|
295 |
|
296 delete thumbnailBuf; |
|
297 } |
|
298 |
|
299 void FlushTemptTables() |
|
300 { |
|
301 TUint32 fc1 = User::FastCounter(); |
|
302 |
|
303 TInt err = TheDb.Exec(_L("BEGIN TRANSACTION")); |
|
304 TEST(err >= 0); |
|
305 |
|
306 err = TheDb.Exec(_L("INSERT INTO ThumbnailInfo SELECT * FROM TempThumbnailInfo;")); |
|
307 TEST2(err, KThumbnailCount); |
|
308 |
|
309 err = TheDb.Exec(_L("INSERT INTO ThumbnailInfoData SELECT * FROM TempThumbnailInfoData;")); |
|
310 TEST2(err, KThumbnailCount); |
|
311 |
|
312 err = TheDb.Exec(_L("DELETE FROM TempThumbnailInfo;")); |
|
313 TEST(err >= 0); |
|
314 |
|
315 err = TheDb.Exec(_L("DELETE FROM TempThumbnailInfoData;")); |
|
316 TEST(err >= 0); |
|
317 |
|
318 err = TheDb.Exec(_L("COMMIT;")); |
|
319 TEST(err >= 0); |
|
320 |
|
321 TUint32 fc2 = User::FastCounter(); |
|
322 TheFlushTime += TimeDiffUs(fc1, fc2); |
|
323 } |
|
324 |
|
325 /** |
|
326 @SYMTestCaseID PDS-SQL-CT-4206 |
|
327 @SYMTestCaseDesc Thumbnail database performance test. |
|
328 @SYMTestPriority Medium |
|
329 @SYMTestActions The test inserts 60 thumbnails with summary size of 1.7Mb into the thumbnail database. |
|
330 @SYMTestExpectedResults The test must not fail |
|
331 @SYMDEF ou1cimx1#362240 |
|
332 */ |
|
333 void PopulateDb() |
|
334 { |
|
335 TInt dataToCommit = 0; |
|
336 for(TInt i=0;i<KThumbnailCount;++i) |
|
337 { |
|
338 dataToCommit += KThumbnailSizes[i]; |
|
339 } |
|
340 TReal d = dataToCommit / 1024.0; |
|
341 TheTest.Printf(_L("==dataToCommit=%d bytes (%8.2lf Mb)\r\n"), dataToCommit, d); |
|
342 |
|
343 TInt err = TheDb.Open(TheDbFileName, &TheSqlConfigString); |
|
344 TEST2(err, KErrNone); |
|
345 |
|
346 err = TheDb.Exec(_L("CREATE TEMP TABLE TempThumbnailInfo (Path TEXT COLLATE NOCASE,TNId INTEGER,Size INTEGER,Format INTEGER,TNPath TEXT COLLATE NOCASE,Width INTEGER,Height INTEGER,OrigWidth INTEGER,OrigHeight INTEGER,Flags INTEGER,VideoPosition INTEGER,Orientation INTEGER,ThumbFromPath INTEGER,Modified LARGEINT);")); |
|
347 TEST(err >= 0); |
|
348 |
|
349 err = TheDb.Exec(_L("CREATE TEMP TABLE TempThumbnailInfoData (Data BLOB);")); |
|
350 TEST(err >= 0); |
|
351 |
|
352 RSqlStatement stmt1; |
|
353 err = stmt1.Prepare(TheDb, _L("INSERT INTO TempThumbnailInfo(Path,Size,Format,Width,Height,OrigWidth,OrigHeight,Flags,Orientation,ThumbFromPath,Modified) VALUES (:Path,:Size,:Format,:Width,:Height,:OrigWidth,:OrigHeight,:Flags,:Orient,:ThumbFromPath,:Modified);")); |
|
354 TEST2(err, KErrNone); |
|
355 |
|
356 RSqlStatement stmt2; |
|
357 err = stmt2.Prepare(TheDb, _L("INSERT INTO TempThumbnailInfoData (Data) VALUES (:Data);")); |
|
358 TEST2(err, KErrNone); |
|
359 |
|
360 PoulateTempTables(stmt1, stmt2); |
|
361 FlushTemptTables(); |
|
362 |
|
363 stmt2.Close(); |
|
364 stmt1.Close(); |
|
365 TheDb.Close(); |
|
366 |
|
367 TheTest.Printf(_L("==Create database, time=%d microseconds\r\n"), TheCreateDbTime); |
|
368 TheTest.Printf(_L("==Create tables, time=%d microseconds\r\n"), TheCreateTablesTime); |
|
369 TheTest.Printf(_L("==Bind parameters time, time=%d microseconds\r\n"), TheBindParamsTime); |
|
370 TheTest.Printf(_L("==Temp tables, statement exec, time=%d microseconds\r\n"), TheStmtExecTime); |
|
371 TheTest.Printf(_L("==Temp tables, statement reset, time=%d microseconds\r\n"), TheStmtResetTime); |
|
372 TheTest.Printf(_L("==Populate temp tables, time=%d microseconds\r\n"), ThePopulateTempTableTime); |
|
373 TheTest.Printf(_L("==Copy temp tables to main tables, time=%d microseconds\r\n"), TheFlushTime); |
|
374 } |
|
375 |
|
376 void DoTestsL() |
|
377 { |
|
378 TheTestTitle.Format(_L("@SYMTestCaseID:PDS-SQL-CT-4205 Create database, encoding: \"%S\", page size: %d\r\n"), |
|
379 TheCmdLineParams.iDbEncoding == TCmdLineParams::EDbUtf16 ? &KUtf16 : &KUtf8, TheCmdLineParams.iPageSize); |
|
380 TheTest.Start(TheTestTitle); |
|
381 CreateDb(); |
|
382 |
|
383 TheTestTitle.Format(_L("@SYMTestCaseID:PDS-SQL-CT-4206 Populate database, encoding: \"%S\", page size: %d\r\n"), |
|
384 TheCmdLineParams.iDbEncoding == TCmdLineParams::EDbUtf16 ? &KUtf16 : &KUtf8, TheCmdLineParams.iPageSize); |
|
385 TheTest.Next(TheTestTitle); |
|
386 PopulateDb(); |
|
387 |
|
388 (void)RSqlDatabase::Delete(TheDbFileName); |
|
389 } |
|
390 |
|
391 TInt E32Main() |
|
392 { |
|
393 TheTest.Title(); |
|
394 |
|
395 CTrapCleanup* tc = CTrapCleanup::New(); |
|
396 TheTest(tc != NULL); |
|
397 |
|
398 __UHEAP_MARK; |
|
399 |
|
400 GetCmdLineParamsAndSqlConfigString(TheTest, _L("t_sqlperformance5"), TheCmdLineParams, TheSqlConfigString); |
|
401 PrepareDbName(KDbName, TheCmdLineParams.iDriveName, TheDbFileName); |
|
402 SetSoftHeapLimit(TheCmdLineParams.iSoftHeapLimitKb); |
|
403 |
|
404 TheTest.Printf(_L("==Databases: %S\r\n"), &TheDbFileName); |
|
405 |
|
406 TestEnvDestroy(); |
|
407 TestEnvInit(); |
|
408 TRAPD(err, DoTestsL()); |
|
409 TestEnvDestroy(); |
|
410 TEST2(err, KErrNone); |
|
411 |
|
412 __UHEAP_MARKEND; |
|
413 |
|
414 TheTest.End(); |
|
415 TheTest.Close(); |
|
416 |
|
417 delete tc; |
|
418 |
|
419 User::Heap().Check(); |
|
420 return KErrNone; |
|
421 } |