|
1 // Copyright (c) 2008-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 <e32test.h> |
|
17 #include <bautils.h> |
|
18 #include <e32math.h> |
|
19 #include <hal.h> |
|
20 #include <sqlite3.h> |
|
21 #include <string.h> |
|
22 #include <stdio.h> |
|
23 |
|
24 /////////////////////////////////////////////////////////////////////////////////////// |
|
25 |
|
26 enum TPerfTestType |
|
27 { |
|
28 EPerfTestMultiInsert, |
|
29 EPerfTestMultiUpdate, |
|
30 EPerfTestMultiDelete, |
|
31 EPerfTestMultiSelect, |
|
32 EPerfTestSingleInsert, |
|
33 EPerfTestSingleUpdate, |
|
34 EPerfTestSingleDelete, |
|
35 EPerfTestSingleSelect, |
|
36 // |
|
37 EPerfTestTypeCnt |
|
38 }; |
|
39 |
|
40 //The performance test case results are stored in the ThePerfTestResult array. |
|
41 static TUint32 ThePerfTestResult[EPerfTestTypeCnt]; |
|
42 |
|
43 static RTest TheTest(_L("t_sqliteperf2 test")); |
|
44 |
|
45 _LIT(KTestDir, "c:\\test\\"); |
|
46 _LIT(KTestDbName, "c:\\test\\t_sqliteperf2.db"); |
|
47 const char KTestDbName8[] = "c:\\test\\t_sqliteperf2.db"; |
|
48 |
|
49 RFs TheFs; |
|
50 |
|
51 sqlite3* TheDb = 0; |
|
52 |
|
53 const TInt KInsertRecCnt = 1000; |
|
54 |
|
55 const TInt KUpdateRecCnt = KInsertRecCnt / 10; |
|
56 const TInt KDeleteRecCnt = KInsertRecCnt / 10; |
|
57 const TInt KSelectRecCnt = KInsertRecCnt / 10; |
|
58 |
|
59 const TInt KInsertRecIds[KInsertRecCnt] = |
|
60 { |
|
61 18920,515,22944,32238,20164,9592,32360,29280,6219,26241,11175,15824,20409,14659,30084,4630,21646,24582,12976,21104,1834, |
|
62 23425,15260,9692,8601,12375,10729,2244,4784,9697,11296,8672,3929,25134,16803,24153,20011,1864,29411,6442,8510, |
|
63 13753,22996,20940,25149,6222,3742,13842,25788,23835,19606,850,25292,16319,25452,709,6093,2282,18597,9520,32132, |
|
64 10012,23884,452,24430,17583,15333,15427,14419,32535,8867,5733,3613,9065,19931,12410,16363,5146,22199,15696,31330, |
|
65 15369,27183,11607,17987,12992,27701,5379,25923,30199,23344,21106,28951,23642,1964,13903,28878,9613,29776,13302,22627, |
|
66 19308,29200,23769,9875,30871,19620,11042,5356,18478,6968,24474,3623,13017,2405,30409,24247,19724,11360,31071,21410, |
|
67 14985,14449,11218,15248,31526,10919,24905,32289,29904,15051,30137,15748,24272,10642,13133,13894,29261,16150,9996,20839, |
|
68 1042,3463,10422,7347,27538,19486,6638,7503,23337,24147,8350,12435,3493,23376,24728,28439,27909,10661,30841,17937, |
|
69 5761,829,17875,15070,24522,30097,13451,3294,16786,12827,7551,10629,19279,17166,30828,9903,1084,30788,25872,14132, |
|
70 23969,8312,20363,19901,6741,25269,13323,25046,20353,19470,17832,2884,25254,26000,31885,26520,10466,26229,20313,32260, |
|
71 2927,22170,7109,5486,21868,13620,646,12483,3808,30654,14965,9614,2300,30006,7917,201,32672,4488,32116,11762, |
|
72 29729,15691,26270,5218,9546,7595,1583,7899,18592,28838,18048,24928,26858,380,17188,20809,3569,16736,20170,17302, |
|
73 4485,22644,4197,9604,17856,17140,31627,9054,20623,20145,10267,12694,24685,3266,19747,11284,7794,2934,25345,32718, |
|
74 397,27789,12488,4761,26382,18661,23870,5223,10492,14594,27601,1587,19534,28970,14398,12407,21532,9774,4901,5160, |
|
75 9497,13128,3816,19950,11740,16127,8450,552,10058,28058,18992,5776,30968,29015,1760,29188,30287,32119,15445,4463, |
|
76 28916,14875,23282,10548,31499,8933,6568,22293,13214,12741,17781,17318,12867,11280,10795,30721,22009,30835,15292,31572, |
|
77 3942,19729,3864,24026,24900,15722,5499,10412,14873,3395,1057,31337,17181,29131,26894,24655,28321,1500,24135,3235, |
|
78 25831,21374,32065,19539,13111,5805,9882,32731,28975,7516,29191,7013,20571,26809,23182,29236,18950,29619,31477,20802, |
|
79 24399,17081,28282,11560,8063,8389,10692,26431,26777,11674,24602,28165,5683,8522,18643,15554,4741,26874,22797,32363, |
|
80 32192,233,17826,22470,24481,12207,24920,7375,5957,1731,11096,30043,32063,19520,8674,13563,27624,12777,11582,27171, |
|
81 8694,32106,14070,26763,13136,1505,16706,21206,31777,10908,4804,26482,18987,10020,19061,5311,12383,26747,28640,6259, |
|
82 14506,18339,21390,11837,26641,19807,21441,4520,18688,25406,22885,22339,28639,5588,8515,24831,11751,19531,29144,26164, |
|
83 6427,15141,9399,14619,2069,14441,19095,31165,3494,13964,29671,8668,31578,17533,10544,14318,7583,5880,23408,26316, |
|
84 14367,12518,27517,19297,16745,4135,31647,13200,22619,4367,2789,9725,7578,29700,12598,4035,27492,1432,14052,19895, |
|
85 18886,4597,19076,23280,29455,10110,18686,18567,31876,27827,19424,25243,30549,3413,29176,9880,7632,715,5665,28345, |
|
86 24789,15301,26717,30412,27018,26399,7460,7734,25423,26120,9980,2870,8693,10595,11850,4974,30762,32365,15208,3487, |
|
87 21048,3745,18167,28852,26864,5849,9335,25602,8416,6581,31509,9422,27085,4416,16579,25871,12893,25553,27534,1910, |
|
88 17427,8240,19756,23724,7040,17658,19669,17883,4280,5959,29525,24687,25604,19593,32094,7966,726,3000,26658,29733, |
|
89 6402,2476,11297,28885,16938,17610,6720,32335,28538,9186,3868,5004,21910,31832,28829,3232,30417,17282,10702,1855, |
|
90 7584,28498,6380,26752,23374,18997,9149,28641,24305,15930,26146,14492,23415,12016,25048,23766,7593,16124,1043,31819, |
|
91 13594,32373,32383,962,22216,7287,6554,22607,22467,19676,24738,9162,6103,6230,345,17791,32619,29371,22790,15143, |
|
92 5289,2975,21180,5656,27615,3368,31454,20664,30501,15646,27619,6199,31041,13378,30807,24190,8135,8161,13858,18530, |
|
93 2181,16808,20237,13853,8634,14978,5120,14324,9984,17555,31074,2379,2496,1599,11228,27564,21618,13040,22712,16520, |
|
94 26319,24391,26278,9758,12074,9500,6577,23454,3587,18625,13170,12431,6106,17287,25476,878,10561,22404,7224,5016, |
|
95 309,4243,8073,10858,21934,22171,22610,24486,5749,29973,21438,32024,21046,15304,28416,17786,29142,7383,3397,8854, |
|
96 15878,27646,27111,32426,25369,8985,23268,19728,26386,20454,6030,1566,17922,3851,6732,10385,14427,24032,8340,26842, |
|
97 8277,17586,17439,22908,4845,7342,13597,749,27536,13601,8437,19218,28258,8234,30110,15117,18122,18214,29772,22359, |
|
98 20272,9068,22352,15886,1541,28475,3897,32656,21508,25328,23360,25928,1976,21116,16611,6856,10815,9935,27928,4429, |
|
99 12589,5891,5198,21108,27699,15199,31650,24882,28266,14901,13547,16697,8948,13826,12168,22678,21371,7123,1568,29161, |
|
100 4208,10600,29255,18437,12973,30787,31557,2465,8280,536,17745,22794,15587,20156,20917,3376,951,681,1520,5078, |
|
101 5278,22108,22739,32389,14749,10621,17753,643,24374,31027,5357,22242,6921,5171,27844,6164,13191,5047,31615,2889, |
|
102 9720,22901,20304,11257,19906,22367,14268,4328,13897,5228,11362,13777,11327,15541,27712,17995,7128,22298,31944,9167, |
|
103 19254,4479,4957,12551,18927,22130,25701,13453,22721,26125,26783,22774,31105,30238,3254,28175,15189,7558,20326,5923, |
|
104 3807,4096,5132,28745,26210,22490,27546,3471,3847,6089,19570,7769,2177,22343,8226,27389,2907,5088,14373,25035, |
|
105 29096,27416,21853,23996,20037,554,11952,1646,1392,23339,29032,31060,3801,24280,13282,16801,7676,13202,138,1896, |
|
106 9391,1447,3335,14849,25591,9427,29106,14766,32544,6919,30029,17534,17677,8296,16626,10866,9164,4251,4169,3295, |
|
107 31341,17728,12798,11539,15637,31164,27762,3643,8014,7228,6833,28293,14497,12279,5541,22375,9395,15753,26061,30172, |
|
108 18314,14239,14321,1397,12526,13350,5256,1140,21483,20615,32673,4537,4780,27087,5988,29403,31809,29537,24569,16503, |
|
109 6047,9709,1701,11464,24552,6812,24630,6264,21997,9869,9890,27062,19186,2693,14827,22921,18609,19170,26693,11108, |
|
110 15009,17361,379,762,15479,19905,14735,12781,1560,7841,27168,3011,4132,9745,7756,24068,25172,5352,24787 |
|
111 }; |
|
112 |
|
113 const TInt KUpdateRecIds[KUpdateRecCnt] = |
|
114 { |
|
115 6638,22607,5776,31477,10815,6919,32116,31041,18609,7224,18167,12992,11751,22721,29619,21048,22170,30084,23408,26278, |
|
116 8437,9164,31509,552,16786,10544,29776,9604,26061,18314,23360,2884,11762,25134,31526,17826,29131,15753,12827,4035,5849, |
|
117 8073,25788,27789,7516,19905,18478,2465,5289,13601,4784,13453,7583,309,9725,16503,14321,30835,14849,29236,19539,27087, |
|
118 32365,29176,138,23642,9745,9880,28175,17555,12867,22921,17987,17318,15117,6554,17781,3569,23337,380,27085,24522,17583, |
|
119 27844,19676,21618,30137,9520,24272,1541,32718,6030,25604,28282,15333,20037,10858,31777,18048,16706 |
|
120 }; |
|
121 |
|
122 const TInt KSelectRecIds[KSelectRecCnt] = |
|
123 { |
|
124 5683,4367,1432,9725,15824,6030,16697,5379,26520,1447,21116,17728,2927,11362,30172,11228,32260,15930,25292,17753,12867, |
|
125 17534,12488,26164,3745,31164,30287,6230,16319,27909,6577,3471,5988,24272,2069,26270,21532,7769,23344,18987,6921,536,6164, |
|
126 30199,11108,3847,4597,28266,31509,31819,8510,12777,14449,31650,9996,7460,30412,24147,10908,19906,31876,24247,6732,5957, |
|
127 10815,17995,23337,7584,12383,26858,5665,11850,5749,5088,5486,643,13826,32094,15886,21910,4520,4630,7516,10110,24687,7558, |
|
128 22627,27171,14492,11175,18688,27546,27087,29772,20353,9520,15878,25046,15696,22921, |
|
129 }; |
|
130 |
|
131 const TInt KDeleteRecIds[KDeleteRecCnt] = |
|
132 { |
|
133 20623,19095,26210,18048,8416,18167,13200,22944,1057,31337,17875,29973,1140,23374,24552,19931,13017,10385,10058,11360, |
|
134 30029,6581,22170,15824,2300,32389,25345,3494,17302,3807,19728,17832,11362,27909,30006,17361,28266,16319,22908,27564, |
|
135 13853,24026,17586,25269,646,15141,15753,24655,22644,9882,9725,26763,6968,29191,27087,26864,13620,23884,27789,8161,643, |
|
136 27062,1447,14506,29619,24153,8312,32544,31060,18530,13753,13826,8933,23408,20615,7013,18122,233,27712,536,3942,28852, |
|
137 22921,31876,9613,397,26717,18997,23835,15292,5891,30968,24685,30835,29537,15051,13128,31477,28416,8135 |
|
138 }; |
|
139 |
|
140 const TInt KInsertRecId = 6184; |
|
141 const TInt KUpdateRecId = 26658; |
|
142 const TInt KSelectRecId = 9592; |
|
143 const TInt KDeleteRecId = 24481; |
|
144 |
|
145 const char KMultiInsertSql[] = "INSERT INTO Tbl VALUES(:Id, 9234567890, 99.998, 'TEXT VALUE', x'AABBCCDDEEFF')"; |
|
146 const char KMultiUpdateSql[] = "UPDATE Tbl SET D=11.113 WHERE I IN"; |
|
147 const char KMultiDeleteSql[] = "DELETE FROM Tbl WHERE I IN"; |
|
148 const char KMultiSelectSql[] = "SELECT I64,D,T,B FROM Tbl WHERE I IN"; |
|
149 |
|
150 const char KSingleInsertSql[] = "INSERT INTO Tbl VALUES(%d, 9234567890, 99.998, 'TEXT VALUE', x'AABBCCDDEEFF')"; |
|
151 const char KSingleUpdateSql[] = "UPDATE Tbl SET D=11.113 WHERE I="; |
|
152 const char KSingleDeleteSql[] = "DELETE FROM Tbl WHERE I="; |
|
153 const char KSingleSelectSql[] = "SELECT I64,D,T,B FROM Tbl WHERE I="; |
|
154 |
|
155 //This buffer is used for SQL statement formatting. 2000 bytes should be enough as a buffer max length. |
|
156 static char TheSqlBuf[2000]; |
|
157 //This buffer is used for printf related formatting. 500 characters should be enough. |
|
158 static TBuf<500> ThePrintBuf; |
|
159 |
|
160 #define UNUSED_VAR(a) (a) = (a) |
|
161 #define UNUSED_PTR(a) a.Set(a) |
|
162 |
|
163 /////////////////////////////////////////////////////////////////////////////////////// |
|
164 |
|
165 static void DeleteTestFiles() |
|
166 { |
|
167 (void)TheFs.Delete(KTestDbName); |
|
168 } |
|
169 |
|
170 /////////////////////////////////////////////////////////////////////////////////////// |
|
171 static void PrintSqliteErrMsg() |
|
172 { |
|
173 if(TheDb) |
|
174 { |
|
175 const char* msg = sqlite3_errmsg(TheDb); |
|
176 TBuf<200> buf; |
|
177 buf.Copy(TPtrC8((const TUint8*)msg)); |
|
178 TheTest.Printf(_L("*** SQLite error message: \"%S\"\r\n"), &buf); |
|
179 } |
|
180 } |
|
181 |
|
182 //Test macros and functions |
|
183 static void Check(TInt aValue, TInt aLine) |
|
184 { |
|
185 if(!aValue) |
|
186 { |
|
187 DeleteTestFiles(); |
|
188 PrintSqliteErrMsg(); |
|
189 TheTest(EFalse, aLine); |
|
190 } |
|
191 } |
|
192 static void Check(TInt aValue, TInt aExpected, TInt aLine) |
|
193 { |
|
194 if(aValue != aExpected) |
|
195 { |
|
196 DeleteTestFiles(); |
|
197 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); |
|
198 PrintSqliteErrMsg(); |
|
199 TheTest(EFalse, aLine); |
|
200 } |
|
201 } |
|
202 #define TEST(arg) ::Check((arg), __LINE__) |
|
203 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) |
|
204 |
|
205 /////////////////////////////////////////////////////////////////////////////////////// |
|
206 |
|
207 static TInt TheCounterFreq = -10000000; |
|
208 const TInt KMicroSecIn1Sec = 1000000; |
|
209 |
|
210 //Prints aFastCount parameter (converted to us) |
|
211 static TInt FcDiff2Us(TUint32 aFastCount) |
|
212 { |
|
213 double v = ((double)aFastCount * KMicroSecIn1Sec) / (double)TheCounterFreq; |
|
214 TInt v2 = (TInt)v; |
|
215 return v2; |
|
216 } |
|
217 |
|
218 static void GetFastCounterFrequency() |
|
219 { |
|
220 TEST2(HAL::Get(HAL::EFastCounterFrequency, TheCounterFreq), KErrNone); |
|
221 TheTest.Printf(_L("Counter frequency=%d\r\n"), TheCounterFreq); |
|
222 } |
|
223 |
|
224 TUint32 FastCounterValue(void) |
|
225 { |
|
226 return User::FastCounter(); |
|
227 } |
|
228 |
|
229 void StorePerfTestResult(TPerfTestType aType, TUint32 aStartTicks, TUint32 aEndTicks) |
|
230 { |
|
231 TInt64 diffTicks = (TInt64)aEndTicks - (TInt64)aStartTicks; |
|
232 if(diffTicks < 0) |
|
233 { |
|
234 diffTicks = KMaxTUint32 + diffTicks + 1; |
|
235 } |
|
236 ThePerfTestResult[aType] = (TUint32)diffTicks; |
|
237 } |
|
238 |
|
239 static void PrintPerfTestResults() |
|
240 { |
|
241 TInt r = FcDiff2Us(ThePerfTestResult[EPerfTestMultiInsert]); |
|
242 TheTest.Printf(_L("###Mutli Insert: %8dus\r\n"), r); |
|
243 |
|
244 r = FcDiff2Us(ThePerfTestResult[EPerfTestMultiUpdate]); |
|
245 TheTest.Printf(_L("###Mutli Update: %8dus\r\n"), r); |
|
246 |
|
247 r = FcDiff2Us(ThePerfTestResult[EPerfTestMultiSelect]); |
|
248 TheTest.Printf(_L("###Mutli Select: %8dus\r\n"), r); |
|
249 |
|
250 r = FcDiff2Us(ThePerfTestResult[EPerfTestMultiDelete]); |
|
251 TheTest.Printf(_L("###Mutli Delete: %8dus\r\n"), r); |
|
252 |
|
253 |
|
254 r = FcDiff2Us(ThePerfTestResult[EPerfTestSingleInsert]); |
|
255 TheTest.Printf(_L("##Single Insert: %8dus\r\n"), r); |
|
256 |
|
257 r = FcDiff2Us(ThePerfTestResult[EPerfTestSingleUpdate]); |
|
258 TheTest.Printf(_L("##Single Update: %8dus\r\n"), r); |
|
259 |
|
260 r = FcDiff2Us(ThePerfTestResult[EPerfTestSingleSelect]); |
|
261 TheTest.Printf(_L("##Single Select: %8dus\r\n"), r); |
|
262 |
|
263 r = FcDiff2Us(ThePerfTestResult[EPerfTestSingleDelete]); |
|
264 TheTest.Printf(_L("##Single Delete: %8dus\r\n"), r); |
|
265 } |
|
266 |
|
267 /////////////////////////////////////////////////////////////////////////////////////// |
|
268 |
|
269 static void CreateTestDir() |
|
270 { |
|
271 TInt err = TheFs.MkDir(KTestDir); |
|
272 TEST(err == KErrNone || err == KErrAlreadyExists); |
|
273 } |
|
274 |
|
275 static void CreateTestDatabase() |
|
276 { |
|
277 (void)TheFs.Delete(KTestDbName); |
|
278 |
|
279 const char* ver = sqlite3_libversion(); |
|
280 TBuf<20> buf; |
|
281 buf.Copy(TPtrC8((const TUint8*)ver)); |
|
282 TheTest.Printf(_L("*** SQLite library version: \"%S\"\r\n"), &buf); |
|
283 |
|
284 TInt err = sqlite3_open(KTestDbName8, &TheDb); |
|
285 TEST2(err, SQLITE_OK); |
|
286 |
|
287 err = sqlite3_exec(TheDb, "CREATE TABLE Tbl(I INTEGER PRIMARY KEY, I64 BIGINT, D DOUBLE, T TEXT, B BINARY)", 0, 0, 0); |
|
288 TEST2(err, SQLITE_OK); |
|
289 |
|
290 sqlite3_close(TheDb); |
|
291 TheDb = 0; |
|
292 } |
|
293 |
|
294 /////////////////////////////////////////////////////////////////////////////////////// |
|
295 |
|
296 /** |
|
297 @SYMTestCaseID PDS-SQLITE3-UT-4030 |
|
298 @SYMTestCaseDesc SQLite library multi-insert performance test. |
|
299 The test inserts 1000 records in a single transaction and stores |
|
300 the execution time for later use (comparison and printing). |
|
301 The main purpose of this test is - regression performance testing. |
|
302 @SYMTestPriority High |
|
303 @SYMTestActions SQLite library multi-insert performance test. |
|
304 @SYMTestExpectedResults Test must not fail |
|
305 @SYMREQ REQ10424 |
|
306 */ |
|
307 static void SqliteMultiInsertTest() |
|
308 { |
|
309 const char* tail = 0; |
|
310 sqlite3_stmt* stmt = 0; |
|
311 |
|
312 TEST(!TheDb); |
|
313 TInt err = sqlite3_open(KTestDbName8, &TheDb); |
|
314 TEST2(err, SQLITE_OK); |
|
315 |
|
316 err = sqlite3_prepare(TheDb, KMultiInsertSql, -1, &stmt, &tail); |
|
317 TEST2(err, SQLITE_OK); |
|
318 |
|
319 TUint32 fc = FastCounterValue(); |
|
320 err = sqlite3_exec(TheDb, "BEGIN", 0, 0, 0); |
|
321 TEST2(err, SQLITE_OK); |
|
322 |
|
323 for(TInt i=0;i<KInsertRecCnt;++i) |
|
324 { |
|
325 err = sqlite3_bind_int(stmt, 1, KInsertRecIds[i]); |
|
326 TEST2(err, SQLITE_OK); |
|
327 |
|
328 err = sqlite3_step(stmt); |
|
329 TEST2(err, SQLITE_DONE); |
|
330 |
|
331 err = sqlite3_reset(stmt); |
|
332 TEST2(err, SQLITE_OK); |
|
333 } |
|
334 |
|
335 err = sqlite3_exec(TheDb, "COMMIT", 0, 0, 0); |
|
336 TEST2(err, SQLITE_OK); |
|
337 |
|
338 StorePerfTestResult(EPerfTestMultiInsert, fc, FastCounterValue()); |
|
339 |
|
340 sqlite3_finalize(stmt); |
|
341 sqlite3_close(TheDb); |
|
342 TheDb = 0; |
|
343 } |
|
344 |
|
345 static void FormatSqlStmt(const char aSql[], const TInt aRecIds[], const TInt aRecCnt) |
|
346 { |
|
347 strcpy(TheSqlBuf, aSql); |
|
348 strcat(TheSqlBuf, "("); |
|
349 for(TInt i=0;i<aRecCnt;++i) |
|
350 { |
|
351 char tmp[10]; |
|
352 sprintf(tmp, "%d,", aRecIds[i]); |
|
353 strcat(TheSqlBuf, tmp); |
|
354 } |
|
355 TheSqlBuf[strlen(TheSqlBuf) - 1] = ')'; |
|
356 } |
|
357 |
|
358 /** |
|
359 @SYMTestCaseID PDS-SQLITE3-UT-4031 |
|
360 @SYMTestCaseDesc SQLite library multi-update performance test. |
|
361 The test updates 100 records and stores |
|
362 the execution time for later use (comparison and printing). |
|
363 The main purpose of this test is - regression performance testing. |
|
364 @SYMTestPriority High |
|
365 @SYMTestActions SQLite library multi-update performance test. |
|
366 @SYMTestExpectedResults Test must not fail |
|
367 @SYMREQ REQ10424 |
|
368 */ |
|
369 static void SqliteMultiUpdateTest() |
|
370 { |
|
371 TEST(!TheDb); |
|
372 TInt err = sqlite3_open(KTestDbName8, &TheDb); |
|
373 TEST2(err, SQLITE_OK); |
|
374 |
|
375 FormatSqlStmt(KMultiUpdateSql, KUpdateRecIds, KUpdateRecCnt); |
|
376 |
|
377 TUint32 fc = FastCounterValue(); |
|
378 |
|
379 err = sqlite3_exec(TheDb, TheSqlBuf, 0, 0, 0); |
|
380 TEST2(err, SQLITE_OK); |
|
381 |
|
382 StorePerfTestResult(EPerfTestMultiUpdate, fc, FastCounterValue()); |
|
383 |
|
384 TInt cnt = sqlite3_changes(TheDb); |
|
385 TEST2(cnt, KUpdateRecCnt); |
|
386 |
|
387 sqlite3_close(TheDb); |
|
388 TheDb = 0; |
|
389 } |
|
390 |
|
391 /** |
|
392 @SYMTestCaseID PDS-SQLITE3-UT-4032 |
|
393 @SYMTestCaseDesc SQLite library multi-select performance test. |
|
394 The test selects 100 records and stores |
|
395 the execution time for later use (comparison and printing). |
|
396 The main purpose of this test is - regression performance testing. |
|
397 @SYMTestPriority High |
|
398 @SYMTestActions SQLite library multi-select performance test. |
|
399 @SYMTestExpectedResults Test must not fail |
|
400 @SYMREQ REQ10424 |
|
401 */ |
|
402 static void SqliteMultiSelectTest() |
|
403 { |
|
404 const char* tail = 0; |
|
405 sqlite3_stmt* stmt = 0; |
|
406 |
|
407 TEST(!TheDb); |
|
408 TInt err = sqlite3_open(KTestDbName8, &TheDb); |
|
409 TEST2(err, SQLITE_OK); |
|
410 |
|
411 FormatSqlStmt(KMultiSelectSql, KSelectRecIds, KSelectRecCnt); |
|
412 |
|
413 err = sqlite3_prepare(TheDb, TheSqlBuf, -1, &stmt, &tail); |
|
414 TEST2(err, SQLITE_OK); |
|
415 |
|
416 TUint32 fc = FastCounterValue(); |
|
417 |
|
418 TInt recCnt = 0; |
|
419 while((err = sqlite3_step(stmt)) == SQLITE_ROW) |
|
420 { |
|
421 __int64 i64; |
|
422 double d; |
|
423 const unsigned short* t; |
|
424 const unsigned char* b; |
|
425 |
|
426 i64 = sqlite3_column_int64(stmt, 0); |
|
427 UNUSED_VAR(i64); |
|
428 d = sqlite3_column_double(stmt, 1); |
|
429 UNUSED_VAR(d); |
|
430 t = (const unsigned short*)sqlite3_column_text16(stmt, 2); |
|
431 UNUSED_VAR(t); |
|
432 b = (const unsigned char*)sqlite3_column_blob(stmt, 3); |
|
433 UNUSED_VAR(b); |
|
434 ++recCnt; |
|
435 } |
|
436 TEST2(err, SQLITE_DONE); |
|
437 TEST2(recCnt, KSelectRecCnt); |
|
438 |
|
439 StorePerfTestResult(EPerfTestMultiSelect, fc, FastCounterValue()); |
|
440 |
|
441 sqlite3_finalize(stmt); |
|
442 sqlite3_close(TheDb); |
|
443 TheDb = 0; |
|
444 } |
|
445 |
|
446 /** |
|
447 @SYMTestCaseID PDS-SQLITE3-UT-4033 |
|
448 @SYMTestCaseDesc SQLite library multi-delete performance test. |
|
449 The test deletes 100 records and stores |
|
450 the execution time for later use (comparison and printing). |
|
451 The main purpose of this test is - regression performance testing. |
|
452 @SYMTestPriority High |
|
453 @SYMTestActions SQLite library multi-delete performance test. |
|
454 @SYMTestExpectedResults Test must not fail |
|
455 @SYMREQ REQ10424 |
|
456 */ |
|
457 static void SqliteMultiDeleteTest() |
|
458 { |
|
459 TEST(!TheDb); |
|
460 TInt err = sqlite3_open(KTestDbName8, &TheDb); |
|
461 TEST2(err, SQLITE_OK); |
|
462 |
|
463 FormatSqlStmt(KMultiDeleteSql, KDeleteRecIds, KDeleteRecCnt); |
|
464 |
|
465 TUint32 fc = FastCounterValue(); |
|
466 |
|
467 err = sqlite3_exec(TheDb, TheSqlBuf, 0, 0, 0); |
|
468 TEST2(err, SQLITE_OK); |
|
469 |
|
470 StorePerfTestResult(EPerfTestMultiDelete, fc, FastCounterValue()); |
|
471 |
|
472 TInt cnt = sqlite3_changes(TheDb); |
|
473 TEST2(cnt, KDeleteRecCnt); |
|
474 |
|
475 sqlite3_close(TheDb); |
|
476 TheDb = 0; |
|
477 } |
|
478 |
|
479 /** |
|
480 @SYMTestCaseID PDS-SQLITE3-UT-4034 |
|
481 @SYMTestCaseDesc SQLite library single-insert performance test. |
|
482 The test inserts one record and stores |
|
483 the execution time for later use (comparison and printing). |
|
484 The main purpose of this test is - regression performance testing. |
|
485 @SYMTestPriority High |
|
486 @SYMTestActions SQLite library single-insert performance test. |
|
487 @SYMTestExpectedResults Test must not fail |
|
488 @SYMREQ REQ10424 |
|
489 */ |
|
490 static void SqliteSingleInsertTest() |
|
491 { |
|
492 TEST(!TheDb); |
|
493 TInt err = sqlite3_open(KTestDbName8, &TheDb); |
|
494 TEST2(err, SQLITE_OK); |
|
495 |
|
496 sprintf(TheSqlBuf, KSingleInsertSql, KInsertRecId); |
|
497 |
|
498 TUint32 fc = FastCounterValue(); |
|
499 |
|
500 err = sqlite3_exec(TheDb, TheSqlBuf, 0, 0, 0); |
|
501 TEST2(err, SQLITE_OK); |
|
502 |
|
503 StorePerfTestResult(EPerfTestSingleInsert, fc, FastCounterValue()); |
|
504 |
|
505 TInt cnt = sqlite3_changes(TheDb); |
|
506 TEST2(cnt, 1); |
|
507 |
|
508 sqlite3_close(TheDb); |
|
509 TheDb = 0; |
|
510 } |
|
511 |
|
512 /** |
|
513 @SYMTestCaseID PDS-SQLITE3-UT-4035 |
|
514 @SYMTestCaseDesc SQLite library single-update performance test. |
|
515 The test updates one record and stores |
|
516 the execution time for later use (comparison and printing). |
|
517 The main purpose of this test is - regression performance testing. |
|
518 @SYMTestPriority High |
|
519 @SYMTestActions SQLite library single-update performance test. |
|
520 @SYMTestExpectedResults Test must not fail |
|
521 @SYMREQ REQ10424 |
|
522 */ |
|
523 static void SqliteSingleUpdateTest() |
|
524 { |
|
525 TEST(!TheDb); |
|
526 TInt err = sqlite3_open(KTestDbName8, &TheDb); |
|
527 TEST2(err, SQLITE_OK); |
|
528 |
|
529 char tmp[10]; |
|
530 sprintf(tmp, "%d", KUpdateRecId); |
|
531 strcpy(TheSqlBuf, KSingleUpdateSql); |
|
532 strcat(TheSqlBuf, tmp); |
|
533 |
|
534 TUint32 fc = FastCounterValue(); |
|
535 |
|
536 err = sqlite3_exec(TheDb, TheSqlBuf, 0, 0, 0); |
|
537 TEST2(err, SQLITE_OK); |
|
538 |
|
539 StorePerfTestResult(EPerfTestSingleUpdate, fc, FastCounterValue()); |
|
540 |
|
541 TInt cnt = sqlite3_changes(TheDb); |
|
542 TEST2(cnt, 1); |
|
543 |
|
544 sqlite3_close(TheDb); |
|
545 TheDb = 0; |
|
546 } |
|
547 |
|
548 /** |
|
549 @SYMTestCaseID PDS-SQLITE3-UT-4036 |
|
550 @SYMTestCaseDesc SQLite library single-select performance test. |
|
551 The test selects one record and stores |
|
552 the execution time for later use (comparison and printing). |
|
553 The main purpose of this test is - regression performance testing. |
|
554 @SYMTestPriority High |
|
555 @SYMTestActions SQLite library single-select performance test. |
|
556 @SYMTestExpectedResults Test must not fail |
|
557 @SYMREQ REQ10424 |
|
558 */ |
|
559 static void SqliteSingleSelectTest() |
|
560 { |
|
561 const char* tail = 0; |
|
562 sqlite3_stmt* stmt = 0; |
|
563 |
|
564 TEST(!TheDb); |
|
565 TInt err = sqlite3_open(KTestDbName8, &TheDb); |
|
566 TEST2(err, SQLITE_OK); |
|
567 |
|
568 char tmp[10]; |
|
569 sprintf(tmp, "%d", KSelectRecId); |
|
570 strcpy(TheSqlBuf, KSingleSelectSql); |
|
571 strcat(TheSqlBuf, tmp); |
|
572 |
|
573 err = sqlite3_prepare(TheDb, TheSqlBuf, -1, &stmt, &tail); |
|
574 TEST2(err, SQLITE_OK); |
|
575 |
|
576 TUint32 fc = FastCounterValue(); |
|
577 |
|
578 TInt recCnt = 0; |
|
579 while((err = sqlite3_step(stmt)) == SQLITE_ROW) |
|
580 { |
|
581 __int64 i64; |
|
582 double d; |
|
583 const unsigned short* t; |
|
584 const unsigned char* b; |
|
585 |
|
586 i64 = sqlite3_column_int64(stmt, 0); |
|
587 UNUSED_VAR(i64); |
|
588 d = sqlite3_column_double(stmt, 1); |
|
589 UNUSED_VAR(d); |
|
590 t = (const unsigned short*)sqlite3_column_text16(stmt, 2); |
|
591 UNUSED_VAR(t); |
|
592 b = (const unsigned char*)sqlite3_column_blob(stmt, 3); |
|
593 UNUSED_VAR(b); |
|
594 ++recCnt; |
|
595 } |
|
596 TEST2(err, SQLITE_DONE); |
|
597 TEST2(recCnt, 1); |
|
598 |
|
599 StorePerfTestResult(EPerfTestSingleSelect, fc, FastCounterValue()); |
|
600 |
|
601 sqlite3_finalize(stmt); |
|
602 sqlite3_close(TheDb); |
|
603 TheDb = 0; |
|
604 } |
|
605 |
|
606 /** |
|
607 @SYMTestCaseID PDS-SQLITE3-UT-4037 |
|
608 @SYMTestCaseDesc SQLite library single-delete performance test. |
|
609 The test deletes one record and stores |
|
610 the execution time for later use (comparison and printing). |
|
611 The main purpose of this test is - regression performance testing. |
|
612 @SYMTestPriority High |
|
613 @SYMTestActions SQLite library single-delete performance test. |
|
614 @SYMTestExpectedResults Test must not fail |
|
615 @SYMREQ REQ10424 |
|
616 */ |
|
617 void SqliteSingleDeleteTest() |
|
618 { |
|
619 TEST(!TheDb); |
|
620 TInt err = sqlite3_open(KTestDbName8, &TheDb); |
|
621 TEST2(err, SQLITE_OK); |
|
622 |
|
623 char tmp[10]; |
|
624 sprintf(tmp, "%d", KDeleteRecId); |
|
625 strcpy(TheSqlBuf, KSingleDeleteSql); |
|
626 strcat(TheSqlBuf, tmp); |
|
627 |
|
628 TUint32 fc = FastCounterValue(); |
|
629 |
|
630 err = sqlite3_exec(TheDb, TheSqlBuf, 0, 0, 0); |
|
631 TEST2(err, SQLITE_OK); |
|
632 |
|
633 StorePerfTestResult(EPerfTestSingleDelete, fc, FastCounterValue()); |
|
634 |
|
635 TInt cnt = sqlite3_changes(TheDb); |
|
636 TEST2(cnt, 1); |
|
637 |
|
638 sqlite3_close(TheDb); |
|
639 TheDb = 0; |
|
640 } |
|
641 |
|
642 /////////////////////////////////////////////////////////////////////////////////////// |
|
643 |
|
644 static void DoTests() |
|
645 { |
|
646 TheTest.Start(_L("Get fast counter frequency")); |
|
647 GetFastCounterFrequency(); |
|
648 |
|
649 TheTest.Next( _L("SQLite: Create the test database")); |
|
650 CreateTestDatabase(); |
|
651 |
|
652 TBuf<100> msgbuf; |
|
653 |
|
654 msgbuf.Format(_L("@SYMTestCaseID:PDS-SQLITE3-UT-4030: Insert %d records in a single transaction"), KInsertRecCnt); |
|
655 TheTest.Next(msgbuf); |
|
656 SqliteMultiInsertTest(); |
|
657 |
|
658 msgbuf.Format(_L("@SYMTestCaseID:PDS-SQLITE3-UT-4031: Update %d records in a single transaction"), KUpdateRecCnt); |
|
659 TheTest.Next(msgbuf); |
|
660 SqliteMultiUpdateTest(); |
|
661 |
|
662 msgbuf.Format(_L("@SYMTestCaseID:PDS-SQLITE3-UT-4032: Select %d records"), KSelectRecCnt); |
|
663 TheTest.Next(msgbuf); |
|
664 SqliteMultiSelectTest(); |
|
665 |
|
666 msgbuf.Format(_L("@SYMTestCaseID:PDS-SQLITE3-UT-4033: Delete %d records in a single transaction"), KDeleteRecCnt); |
|
667 TheTest.Next(msgbuf); |
|
668 SqliteMultiDeleteTest(); |
|
669 |
|
670 msgbuf.Format(_L("@SYMTestCaseID:PDS-SQLITE3-UT-4034: Insert a single record")); |
|
671 TheTest.Next(msgbuf); |
|
672 SqliteSingleInsertTest(); |
|
673 |
|
674 msgbuf.Format(_L("@SYMTestCaseID:PDS-SQLITE3-UT-4035: Update a single record")); |
|
675 TheTest.Next(msgbuf); |
|
676 SqliteSingleUpdateTest(); |
|
677 |
|
678 msgbuf.Format(_L("@SYMTestCaseID:PDS-SQLITE3-UT-4036: Select a single record")); |
|
679 TheTest.Next(msgbuf); |
|
680 SqliteSingleSelectTest(); |
|
681 |
|
682 msgbuf.Format(_L("@SYMTestCaseID:PDS-SQLITE3-UT-4037: Delete a single record")); |
|
683 TheTest.Next(msgbuf); |
|
684 SqliteSingleDeleteTest(); |
|
685 |
|
686 (void)TheFs.Delete(KTestDbName); |
|
687 |
|
688 PrintPerfTestResults(); |
|
689 } |
|
690 |
|
691 TInt E32Main() |
|
692 { |
|
693 TheTest.Title(); |
|
694 |
|
695 CTrapCleanup* tc = CTrapCleanup::New(); |
|
696 |
|
697 __UHEAP_MARK; |
|
698 |
|
699 TInt err = TheFs.Connect(); |
|
700 TheTest(err == KErrNone); |
|
701 |
|
702 CreateTestDir(); |
|
703 DeleteTestFiles(); |
|
704 DoTests(); |
|
705 DeleteTestFiles(); |
|
706 |
|
707 __UHEAP_MARKEND; |
|
708 |
|
709 TheFs.Close(); |
|
710 TheTest.End(); |
|
711 TheTest.Close(); |
|
712 |
|
713 delete tc; |
|
714 |
|
715 User::Heap().Check(); |
|
716 return KErrNone; |
|
717 } |