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