Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
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!
21 #include "t_dbplatsecutl.h"
23 static RTest TheTest(_L("t_dbplatsecperf: DBMS platform security - Performance test"));
26 static RDbNamedDatabase TheDb;
28 const TUid KSecureDbUid = {0x11335579};
29 _LIT(KSecure, "SECURE");
30 _LIT(KDbNameC, "C:TestDB.DB");
34 _LIT(KDbDirNSC, "C:\\DBMS-TST\\");
35 _LIT(KDbNameNSC,"C:\\DBMS-TST\\TestDB.DB");
37 static void DeleteNsDb()
40 if(fileSess.Connect() == KErrNone)
42 fileSess.Delete(KDbNameNSC);
47 static void CleanupTest()
52 TDBSCUtils TheDbscUtils(TheTest, &CleanupTest);
54 const TInt KGetPolicyCallCnt = 10000;
55 const TInt KInsertRecCnt = 10000;
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()
61 TUint time = User::TickCount();
62 RDbs::TPolicyType tblPolicyType[2] = {RDbs::EReadPolicy, RDbs::EWritePolicy};
63 TSecurityPolicy dbPolicy;
64 TSecurityPolicy tblPolicy;
66 for(i=0,k=0;i<KGetPolicyCallCnt;++i,k=(k+1)%2)
68 TInt err = TheDbs.GetDatabasePolicy(KSecureDbUid, tblPolicyType[k], dbPolicy);
70 err = TheDbs.GetTablePolicy(KSecureDbUid, KTblNameA, tblPolicyType[k], tblPolicy);
73 time = User::TickCount() - time;
74 TheTest.Printf(_L("GetDatabasePolicy(), GetTablePolicy(). Time=%d\r\n"), time);
77 //Measures the performance of RDbs::GetTablePolicies() call.
78 //The DBMS server session connected before each GetTablePolicies() call and disconnected
80 static void GetPolicyTest2()
83 TUint time = User::TickCount();
84 RDbs::TPolicyType tblPolicyType[2] = {RDbs::EReadPolicy, RDbs::EWritePolicy};
85 TSecurityPolicy dbPolicy;
86 TSecurityPolicy tblPolicy;
88 for(i=0,k=0;i<KGetPolicyCallCnt;++i,k=(k+1)%2)
90 TInt err = TheDbs.Connect();
92 err = TheDbs.GetTablePolicies(KSecureDbUid, KTblNameA, tblPolicyType[k], dbPolicy, tblPolicy);
96 time = User::TickCount() - time;
97 TheTest.Printf(_L("GetTablePolicies(). Time=%d\r\n"), time);
98 TInt err = TheDbs.Connect();
102 //Measures the performance of RDbs::GetTablePolicies() call.
103 //The DBMS server session kept alive during the test.
104 static void GetPolicyTest3()
106 TUint time = User::TickCount();
107 RDbs::TPolicyType tblPolicyType[2] = {RDbs::EReadPolicy, RDbs::EWritePolicy};
108 TSecurityPolicy dbPolicy;
109 TSecurityPolicy tblPolicy;
111 for(i=0,k=0;i<KGetPolicyCallCnt;++i,k=(k+1)%2)
113 TInt err = TheDbs.GetTablePolicies(KSecureDbUid, KTblNameA, tblPolicyType[k], dbPolicy, tblPolicy);
114 TEST2(err, KErrNone);
116 time = User::TickCount() - time;
117 TheTest.Printf(_L("GetTablePolicies(). Time=%d\r\n"), time);
120 static void CreateNonsecureDbL()
122 TColDef const KColumns[]=
124 {_S("ID"), EDbColInt32, TDbCol::ENotNull | TDbCol::EAutoIncrement},
125 {_S("DATA1"), EDbColInt32, TDbCol::ENotNull},
126 {_S("DATA2"), EDbColInt32, TDbCol::ENotNull},
130 CleanupClosePushL(fileSess);
131 TInt err = fileSess.Connect();
132 TEST2(err, KErrNone);
134 err = fileSess.MkDir(KDbDirNSC);
135 TEST(err == KErrNone || err == KErrAlreadyExists);
138 err = db.Create(fileSess, KDbNameNSC);
139 TEST2(err, KErrNone);
140 CleanupClosePushL(db);
141 err = db.Open(fileSess, KDbNameNSC);
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);
151 CleanupStack::PopAndDestroy(colset);
152 CleanupStack::PopAndDestroy(&db);
153 CleanupStack::PopAndDestroy(&fileSess);
156 static void DoInsertRecL(RDbNamedDatabase& aDb, RDbTable& aTbl)
158 TUint time = User::TickCount();
159 TInt err = aDb.Begin();
160 TEST2(err, KErrNone);
161 for(TInt i=0;i<KInsertRecCnt;++i)
169 TEST2(err, KErrNone);
170 time = User::TickCount() - time;
171 TheTest.Printf(_L("Insert. Time=%d\r\n"), time);
174 //Measures the performance of "Insert" operations in a non-secure database.
175 static void InsertRec1L()
178 CleanupClosePushL(db);
179 TInt err = db.Open(TheDbs, KDbNameNSC);
180 TEST2(err, KErrNone);
183 CleanupClosePushL(tblA);
184 err = tblA.Open(db, KTblNameA);
185 TEST2(err, KErrNone);
187 ::DoInsertRecL(db, tblA);
189 CleanupStack::PopAndDestroy(&tblA);
190 CleanupStack::PopAndDestroy(&db);
193 //Measures the performance of "Insert" operations in a secure shared database.
194 static void InsertRec2L()
197 format.Copy(KSecure);
198 format.Append(KSecureDbUid.Name());
200 CleanupClosePushL(TheDb);
201 TInt err = TheDb.Open(TheDbs, KDbNameC, format);
202 TEST2(err, KErrNone);
205 CleanupClosePushL(tblA);
206 err = tblA.Open(TheDb, KTblNameA);
207 TEST2(err, KErrNone);
209 ::DoInsertRecL(TheDb, tblA);
211 CleanupStack::PopAndDestroy(&tblA);
212 CleanupStack::PopAndDestroy(&TheDb);
215 //Measures the performance of "Update" SQL operations in a non-secure database.
216 static void UpdateRec1L()
219 CleanupClosePushL(db);
220 TInt err = db.Open(TheDbs, KDbNameNSC);
221 TEST2(err, KErrNone);
223 TUint time = User::TickCount();
226 TEST2(err, KErrNone);
228 TInt cnt = db.Execute(_L("UPDATE A SET DATA1=10, DATA2=20 WHERE ID >= 0"));
232 TEST2(err, KErrNone);
234 time = User::TickCount() - time;
235 TheTest.Printf(_L("Update. Time=%d\r\n"), time);
237 CleanupStack::PopAndDestroy(&db);
240 //Measures the performance of "Update" SQL operations in a secure shared database.
241 static void UpdateRec2L()
244 format.Copy(KSecure);
245 format.Append(KSecureDbUid.Name());
247 CleanupClosePushL(TheDb);
248 TInt err = TheDb.Open(TheDbs, KDbNameC, format);
249 TEST2(err, KErrNone);
251 TUint time = User::TickCount();
254 TEST2(err, KErrNone);
256 TInt cnt = TheDb.Execute(_L("UPDATE A SET DATA1=10, DATA2=20 WHERE ID >= 0"));
259 err = TheDb.Commit();
260 TEST2(err, KErrNone);
262 time = User::TickCount() - time;
263 TheTest.Printf(_L("Update. Time=%d\r\n"), time);
265 CleanupStack::PopAndDestroy(&TheDb);
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()
275 RDBTable: insert operation measured, SQL: update operation measured.
276 @SYMTestExpectedResults The test must not fail.
278 DBMS shall provide an API to apply security policies to database tables.
282 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0020 GetPolicy performance test "));
287 ::CreateNonsecureDbL();
289 TheTest.Next(_L("Insert records performance test"));
293 TheTest.Next(_L("Update records performance test"));
301 CTrapCleanup* tc = CTrapCleanup::New();
304 TInt err = TheDbs.Connect();
305 TEST2(err, KErrNone);
309 TRAP(err, ::DoRunL());
310 TEST2(err, KErrNone);
322 User::Heap().Check();