|
1 // Copyright (c) 2004-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 // DBMS security policy - performance tests |
|
15 // Please, ensure that t_dbenvcreate test is executed before t_dbplatsec<N>/t_dbplatsecperf tests! |
|
16 // Please, ensure that t_dbenvdestroy test is executed after t_dbplatsec<N>/t_dbplatsecperf tests! |
|
17 // |
|
18 // |
|
19 |
|
20 #include <e32test.h> |
|
21 #include "t_dbplatsecutl.h" |
|
22 |
|
23 static RTest TheTest(_L("t_dbplatsecperf: DBMS platform security - Performance test")); |
|
24 |
|
25 static RDbs TheDbs; |
|
26 static RDbNamedDatabase TheDb; |
|
27 |
|
28 const TUid KSecureDbUid = {0x11335579}; |
|
29 _LIT(KSecure, "SECURE"); |
|
30 _LIT(KDbNameC, "C:TestDB.DB"); |
|
31 _LIT(KTblNameA, "A"); |
|
32 _LIT(KTblNameB, "B"); |
|
33 _LIT(KTblNameC, "C"); |
|
34 _LIT(KDbDirNSC, "C:\\DBMS-TST\\"); |
|
35 _LIT(KDbNameNSC,"C:\\DBMS-TST\\TestDB.DB"); |
|
36 |
|
37 static void DeleteNsDb() |
|
38 { |
|
39 RFs fileSess; |
|
40 if(fileSess.Connect() == KErrNone) |
|
41 { |
|
42 fileSess.Delete(KDbNameNSC); |
|
43 } |
|
44 fileSess.Close(); |
|
45 } |
|
46 |
|
47 static void CleanupTest() |
|
48 { |
|
49 ::DeleteNsDb(); |
|
50 } |
|
51 |
|
52 TDBSCUtils TheDbscUtils(TheTest, &CleanupTest); |
|
53 |
|
54 const TInt KGetPolicyCallCnt = 10000; |
|
55 const TInt KInsertRecCnt = 10000; |
|
56 |
|
57 //Measures the performance of RDbs::GetDatabasePolicy() and RDbs::GetTablePolicy() calls. |
|
58 //The DBMS server session kept alive during the test. |
|
59 static void GetPolicyTest1() |
|
60 { |
|
61 TUint time = User::TickCount(); |
|
62 RDbs::TPolicyType tblPolicyType[2] = {RDbs::EReadPolicy, RDbs::EWritePolicy}; |
|
63 TSecurityPolicy dbPolicy; |
|
64 TSecurityPolicy tblPolicy; |
|
65 TInt i, k; |
|
66 for(i=0,k=0;i<KGetPolicyCallCnt;++i,k=(k+1)%2) |
|
67 { |
|
68 TInt err = TheDbs.GetDatabasePolicy(KSecureDbUid, tblPolicyType[k], dbPolicy); |
|
69 TEST2(err, KErrNone); |
|
70 err = TheDbs.GetTablePolicy(KSecureDbUid, KTblNameA, tblPolicyType[k], tblPolicy); |
|
71 TEST2(err, KErrNone); |
|
72 } |
|
73 time = User::TickCount() - time; |
|
74 TheTest.Printf(_L("GetDatabasePolicy(), GetTablePolicy(). Time=%d\r\n"), time); |
|
75 } |
|
76 |
|
77 //Measures the performance of RDbs::GetTablePolicies() call. |
|
78 //The DBMS server session connected before each GetTablePolicies() call and disconnected |
|
79 //after the call. |
|
80 static void GetPolicyTest2() |
|
81 { |
|
82 TheDbs.Close(); |
|
83 TUint time = User::TickCount(); |
|
84 RDbs::TPolicyType tblPolicyType[2] = {RDbs::EReadPolicy, RDbs::EWritePolicy}; |
|
85 TSecurityPolicy dbPolicy; |
|
86 TSecurityPolicy tblPolicy; |
|
87 TInt i, k; |
|
88 for(i=0,k=0;i<KGetPolicyCallCnt;++i,k=(k+1)%2) |
|
89 { |
|
90 TInt err = TheDbs.Connect(); |
|
91 TEST2(err, KErrNone); |
|
92 err = TheDbs.GetTablePolicies(KSecureDbUid, KTblNameA, tblPolicyType[k], dbPolicy, tblPolicy); |
|
93 TEST2(err, KErrNone); |
|
94 TheDbs.Close(); |
|
95 } |
|
96 time = User::TickCount() - time; |
|
97 TheTest.Printf(_L("GetTablePolicies(). Time=%d\r\n"), time); |
|
98 TInt err = TheDbs.Connect(); |
|
99 TEST2(err, KErrNone); |
|
100 } |
|
101 |
|
102 //Measures the performance of RDbs::GetTablePolicies() call. |
|
103 //The DBMS server session kept alive during the test. |
|
104 static void GetPolicyTest3() |
|
105 { |
|
106 TUint time = User::TickCount(); |
|
107 RDbs::TPolicyType tblPolicyType[2] = {RDbs::EReadPolicy, RDbs::EWritePolicy}; |
|
108 TSecurityPolicy dbPolicy; |
|
109 TSecurityPolicy tblPolicy; |
|
110 TInt i, k; |
|
111 for(i=0,k=0;i<KGetPolicyCallCnt;++i,k=(k+1)%2) |
|
112 { |
|
113 TInt err = TheDbs.GetTablePolicies(KSecureDbUid, KTblNameA, tblPolicyType[k], dbPolicy, tblPolicy); |
|
114 TEST2(err, KErrNone); |
|
115 } |
|
116 time = User::TickCount() - time; |
|
117 TheTest.Printf(_L("GetTablePolicies(). Time=%d\r\n"), time); |
|
118 } |
|
119 |
|
120 static void CreateNonsecureDbL() |
|
121 { |
|
122 TColDef const KColumns[]= |
|
123 { |
|
124 {_S("ID"), EDbColInt32, TDbCol::ENotNull | TDbCol::EAutoIncrement}, |
|
125 {_S("DATA1"), EDbColInt32, TDbCol::ENotNull}, |
|
126 {_S("DATA2"), EDbColInt32, TDbCol::ENotNull}, |
|
127 {0} |
|
128 }; |
|
129 RFs fileSess; |
|
130 CleanupClosePushL(fileSess); |
|
131 TInt err = fileSess.Connect(); |
|
132 TEST2(err, KErrNone); |
|
133 |
|
134 err = fileSess.MkDir(KDbDirNSC); |
|
135 TEST(err == KErrNone || err == KErrAlreadyExists); |
|
136 |
|
137 RDbNamedDatabase db; |
|
138 err = db.Create(fileSess, KDbNameNSC); |
|
139 TEST2(err, KErrNone); |
|
140 CleanupClosePushL(db); |
|
141 err = db.Open(fileSess, KDbNameNSC); |
|
142 |
|
143 CDbColSet* colset = TDBSCUtils::CreateColSetLC(KColumns); |
|
144 err = db.CreateTable(KTblNameA, *colset); |
|
145 TEST2(err, KErrNone); |
|
146 err = db.CreateTable(KTblNameB, *colset); |
|
147 TEST2(err, KErrNone); |
|
148 err = db.CreateTable(KTblNameC, *colset); |
|
149 TEST2(err, KErrNone); |
|
150 |
|
151 CleanupStack::PopAndDestroy(colset); |
|
152 CleanupStack::PopAndDestroy(&db); |
|
153 CleanupStack::PopAndDestroy(&fileSess); |
|
154 } |
|
155 |
|
156 static void DoInsertRecL(RDbNamedDatabase& aDb, RDbTable& aTbl) |
|
157 { |
|
158 TUint time = User::TickCount(); |
|
159 TInt err = aDb.Begin(); |
|
160 TEST2(err, KErrNone); |
|
161 for(TInt i=0;i<KInsertRecCnt;++i) |
|
162 { |
|
163 aTbl.InsertL(); |
|
164 aTbl.SetColL(2, i); |
|
165 aTbl.SetColL(3, i); |
|
166 aTbl.PutL(); |
|
167 } |
|
168 err = aDb.Commit(); |
|
169 TEST2(err, KErrNone); |
|
170 time = User::TickCount() - time; |
|
171 TheTest.Printf(_L("Insert. Time=%d\r\n"), time); |
|
172 } |
|
173 |
|
174 //Measures the performance of "Insert" operations in a non-secure database. |
|
175 static void InsertRec1L() |
|
176 { |
|
177 RDbNamedDatabase db; |
|
178 CleanupClosePushL(db); |
|
179 TInt err = db.Open(TheDbs, KDbNameNSC); |
|
180 TEST2(err, KErrNone); |
|
181 |
|
182 RDbTable tblA; |
|
183 CleanupClosePushL(tblA); |
|
184 err = tblA.Open(db, KTblNameA); |
|
185 TEST2(err, KErrNone); |
|
186 |
|
187 ::DoInsertRecL(db, tblA); |
|
188 |
|
189 CleanupStack::PopAndDestroy(&tblA); |
|
190 CleanupStack::PopAndDestroy(&db); |
|
191 } |
|
192 |
|
193 //Measures the performance of "Insert" operations in a secure shared database. |
|
194 static void InsertRec2L() |
|
195 { |
|
196 TBuf<32> format; |
|
197 format.Copy(KSecure); |
|
198 format.Append(KSecureDbUid.Name()); |
|
199 |
|
200 CleanupClosePushL(TheDb); |
|
201 TInt err = TheDb.Open(TheDbs, KDbNameC, format); |
|
202 TEST2(err, KErrNone); |
|
203 |
|
204 RDbTable tblA; |
|
205 CleanupClosePushL(tblA); |
|
206 err = tblA.Open(TheDb, KTblNameA); |
|
207 TEST2(err, KErrNone); |
|
208 |
|
209 ::DoInsertRecL(TheDb, tblA); |
|
210 |
|
211 CleanupStack::PopAndDestroy(&tblA); |
|
212 CleanupStack::PopAndDestroy(&TheDb); |
|
213 } |
|
214 |
|
215 //Measures the performance of "Update" SQL operations in a non-secure database. |
|
216 static void UpdateRec1L() |
|
217 { |
|
218 RDbNamedDatabase db; |
|
219 CleanupClosePushL(db); |
|
220 TInt err = db.Open(TheDbs, KDbNameNSC); |
|
221 TEST2(err, KErrNone); |
|
222 |
|
223 TUint time = User::TickCount(); |
|
224 |
|
225 err = db.Begin(); |
|
226 TEST2(err, KErrNone); |
|
227 |
|
228 TInt cnt = db.Execute(_L("UPDATE A SET DATA1=10, DATA2=20 WHERE ID >= 0")); |
|
229 TEST(cnt > 0); |
|
230 |
|
231 err = db.Commit(); |
|
232 TEST2(err, KErrNone); |
|
233 |
|
234 time = User::TickCount() - time; |
|
235 TheTest.Printf(_L("Update. Time=%d\r\n"), time); |
|
236 |
|
237 CleanupStack::PopAndDestroy(&db); |
|
238 } |
|
239 |
|
240 //Measures the performance of "Update" SQL operations in a secure shared database. |
|
241 static void UpdateRec2L() |
|
242 { |
|
243 TBuf<32> format; |
|
244 format.Copy(KSecure); |
|
245 format.Append(KSecureDbUid.Name()); |
|
246 |
|
247 CleanupClosePushL(TheDb); |
|
248 TInt err = TheDb.Open(TheDbs, KDbNameC, format); |
|
249 TEST2(err, KErrNone); |
|
250 |
|
251 TUint time = User::TickCount(); |
|
252 |
|
253 err = TheDb.Begin(); |
|
254 TEST2(err, KErrNone); |
|
255 |
|
256 TInt cnt = TheDb.Execute(_L("UPDATE A SET DATA1=10, DATA2=20 WHERE ID >= 0")); |
|
257 TEST(cnt > 0); |
|
258 |
|
259 err = TheDb.Commit(); |
|
260 TEST2(err, KErrNone); |
|
261 |
|
262 time = User::TickCount() - time; |
|
263 TheTest.Printf(_L("Update. Time=%d\r\n"), time); |
|
264 |
|
265 CleanupStack::PopAndDestroy(&TheDb); |
|
266 } |
|
267 |
|
268 /** |
|
269 @SYMTestCaseID SYSLIB-DBMS-CT-0020 |
|
270 @SYMTestCaseDesc DBMS security - performance tests. Insert/Update and Get<AAA>Policy |
|
271 operations performance measured for non-secure and secure shared database. |
|
272 @SYMTestPriority High |
|
273 @SYMTestActions RDbs::GetDatabasePolicy(), Rdbs::GetTablePolicy() and RDbs::GetTablePolicies() |
|
274 calls measured. |
|
275 RDBTable: insert operation measured, SQL: update operation measured. |
|
276 @SYMTestExpectedResults The test must not fail. |
|
277 @SYMREQ REQ2429 |
|
278 DBMS shall provide an API to apply security policies to database tables. |
|
279 */ |
|
280 static void DoRunL() |
|
281 { |
|
282 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0020 GetPolicy performance test ")); |
|
283 ::GetPolicyTest1(); |
|
284 ::GetPolicyTest2(); |
|
285 ::GetPolicyTest3(); |
|
286 |
|
287 ::CreateNonsecureDbL(); |
|
288 |
|
289 TheTest.Next(_L("Insert records performance test")); |
|
290 InsertRec1L(); |
|
291 InsertRec2L(); |
|
292 |
|
293 TheTest.Next(_L("Update records performance test")); |
|
294 ::UpdateRec1L(); |
|
295 ::UpdateRec2L(); |
|
296 } |
|
297 |
|
298 TInt E32Main() |
|
299 { |
|
300 __UHEAP_MARK; |
|
301 CTrapCleanup* tc = CTrapCleanup::New(); |
|
302 TEST(tc != NULL); |
|
303 |
|
304 TInt err = TheDbs.Connect(); |
|
305 TEST2(err, KErrNone); |
|
306 |
|
307 ::DeleteNsDb(); |
|
308 |
|
309 TRAP(err, ::DoRunL()); |
|
310 TEST2(err, KErrNone); |
|
311 |
|
312 TheDb.Close(); |
|
313 TheDbs.Close(); |
|
314 ::CleanupTest(); |
|
315 |
|
316 TheTest.End(); |
|
317 TheTest.Close(); |
|
318 |
|
319 delete tc; |
|
320 |
|
321 __UHEAP_MARKEND; |
|
322 User::Heap().Check(); |
|
323 return KErrNone; |
|
324 } |