sl@0
|
1 |
// Copyright (c) 1998-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 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include <d32dbms.h>
|
sl@0
|
17 |
#include <s32file.h>
|
sl@0
|
18 |
#include <e32test.h>
|
sl@0
|
19 |
#include <e32math.h>
|
sl@0
|
20 |
#include <e32svr.h>
|
sl@0
|
21 |
#include <hal.h>
|
sl@0
|
22 |
#include <d32dbmsconstants.h>
|
sl@0
|
23 |
|
sl@0
|
24 |
// MSVC++ up to 5.0 has problems with expanding inline functions
|
sl@0
|
25 |
// This disables the mad warnings for the whole project
|
sl@0
|
26 |
#if defined(NDEBUG) && defined(__VC32__) && _MSC_VER<=1100
|
sl@0
|
27 |
#pragma warning(disable : 4710) // function not expanded. MSVC 5.0 is stupid
|
sl@0
|
28 |
#endif
|
sl@0
|
29 |
|
sl@0
|
30 |
class TTimer
|
sl@0
|
31 |
{
|
sl@0
|
32 |
public:
|
sl@0
|
33 |
void Start();
|
sl@0
|
34 |
TReal Stop() const;
|
sl@0
|
35 |
private:
|
sl@0
|
36 |
TUint iTicks;
|
sl@0
|
37 |
};
|
sl@0
|
38 |
|
sl@0
|
39 |
LOCAL_D RTest test(_L("t_dbbench"));
|
sl@0
|
40 |
LOCAL_D CTrapCleanup* TheTrapCleanup;
|
sl@0
|
41 |
LOCAL_D RDbNamedDatabase TheDatabase;
|
sl@0
|
42 |
LOCAL_D RDbView TheView;
|
sl@0
|
43 |
LOCAL_D RFs TheFs;
|
sl@0
|
44 |
|
sl@0
|
45 |
const TInt KTestCleanupStack=0x20;
|
sl@0
|
46 |
//T_BENCH file shall not be deleted at the end of the test! It will be used by T_COMP test.
|
sl@0
|
47 |
const TPtrC KTestDatabase=_S("\\DBMS-TST\\T_BENCH.DB");
|
sl@0
|
48 |
const TPtrC KTableName=_S("Test");
|
sl@0
|
49 |
const TPtrC KColCluster=_S("Cluster");
|
sl@0
|
50 |
const TPtrC KColXcluster=_S("xCluster");
|
sl@0
|
51 |
const TPtrC KColRandom=_S("Random");
|
sl@0
|
52 |
const TPtrC KColXrandom=_S("xRandom");
|
sl@0
|
53 |
const TInt KRecords=2000;
|
sl@0
|
54 |
|
sl@0
|
55 |
static TTimer TheTimer;
|
sl@0
|
56 |
|
sl@0
|
57 |
void TTimer::Start()
|
sl@0
|
58 |
{
|
sl@0
|
59 |
iTicks=User::FastCounter();
|
sl@0
|
60 |
}
|
sl@0
|
61 |
|
sl@0
|
62 |
TReal TTimer::Stop() const
|
sl@0
|
63 |
{
|
sl@0
|
64 |
TUint ticks = User::FastCounter() - iTicks;
|
sl@0
|
65 |
TInt freq = 0;
|
sl@0
|
66 |
test(HAL::Get(HAL::EFastCounterFrequency, freq) == KErrNone);
|
sl@0
|
67 |
const TInt KMicroSecIn1Sec = 1000000;
|
sl@0
|
68 |
const TInt KMsIn1Sec = 1000;
|
sl@0
|
69 |
double v = ((double)ticks * KMicroSecIn1Sec) / (double)freq; TInt v2 = (TInt)v;
|
sl@0
|
70 |
return v2 / KMsIn1Sec;
|
sl@0
|
71 |
}
|
sl@0
|
72 |
|
sl@0
|
73 |
LOCAL_C void CloseDatabase()
|
sl@0
|
74 |
{
|
sl@0
|
75 |
TheDatabase.Close();
|
sl@0
|
76 |
}
|
sl@0
|
77 |
|
sl@0
|
78 |
/**
|
sl@0
|
79 |
Create the database: keep the code 050 compatible
|
sl@0
|
80 |
|
sl@0
|
81 |
@SYMTestCaseID SYSLIB-DBMS-CT-0577
|
sl@0
|
82 |
@SYMTestCaseDesc Benchmark Tests. Creation of a local Database test
|
sl@0
|
83 |
@SYMTestPriority Medium
|
sl@0
|
84 |
@SYMTestActions Attempt to test RDbNamedDatabase::CreateTable(),RDbNamedDatabase::CreateIndex(),
|
sl@0
|
85 |
RDbNamedDatabase::Compact(),RDbView::Prepare() functions
|
sl@0
|
86 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
87 |
@SYMREQ REQ0000
|
sl@0
|
88 |
*/
|
sl@0
|
89 |
LOCAL_C void CreateDatabaseL()
|
sl@0
|
90 |
{
|
sl@0
|
91 |
test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0577 "));
|
sl@0
|
92 |
User::LeaveIfError(TheDatabase.Replace(TheFs,KTestDatabase));
|
sl@0
|
93 |
CDbColSet& set=*CDbColSet::NewLC();
|
sl@0
|
94 |
TDbCol col(KColCluster,EDbColInt32);
|
sl@0
|
95 |
col.iAttributes=col.ENotNull;
|
sl@0
|
96 |
set.AddL(col);
|
sl@0
|
97 |
col.iName=KColXcluster;
|
sl@0
|
98 |
set.AddL(col);
|
sl@0
|
99 |
col.iName=KColRandom;
|
sl@0
|
100 |
set.AddL(col);
|
sl@0
|
101 |
col.iName=KColXrandom;
|
sl@0
|
102 |
set.AddL(col);
|
sl@0
|
103 |
TInt r=TheDatabase.CreateTable(KTableName,set);
|
sl@0
|
104 |
test (r==KErrNone);
|
sl@0
|
105 |
CleanupStack::PopAndDestroy();
|
sl@0
|
106 |
TheTimer.Start();
|
sl@0
|
107 |
r=TheView.Prepare(TheDatabase,_L("select * from test"),TheView.EInsertOnly);
|
sl@0
|
108 |
TheDatabase.Begin();
|
sl@0
|
109 |
test (r==KErrNone);
|
sl@0
|
110 |
TInt jj=0;
|
sl@0
|
111 |
for (TInt ii=0;ii<KRecords;++ii)
|
sl@0
|
112 |
{
|
sl@0
|
113 |
TheView.InsertL();
|
sl@0
|
114 |
jj=(jj+23);
|
sl@0
|
115 |
if (jj>=KRecords)
|
sl@0
|
116 |
jj-=KRecords;
|
sl@0
|
117 |
TheView.SetColL(1,ii);
|
sl@0
|
118 |
TheView.SetColL(2,ii);
|
sl@0
|
119 |
TheView.SetColL(3,jj);
|
sl@0
|
120 |
TheView.SetColL(4,jj);
|
sl@0
|
121 |
TheView.PutL();
|
sl@0
|
122 |
}
|
sl@0
|
123 |
r=TheDatabase.Commit();
|
sl@0
|
124 |
test (r==KErrNone);
|
sl@0
|
125 |
TheView.Close();
|
sl@0
|
126 |
test.Printf(_L("Build table: %7.1f ms\n"),TheTimer.Stop());
|
sl@0
|
127 |
TheTimer.Start();
|
sl@0
|
128 |
CDbKey& key=*CDbKey::NewLC();
|
sl@0
|
129 |
key.AddL(KColXcluster);
|
sl@0
|
130 |
key.MakeUnique();
|
sl@0
|
131 |
r=TheDatabase.CreateIndex(KColXcluster,KTableName,key);
|
sl@0
|
132 |
test (r==KErrNone);
|
sl@0
|
133 |
test.Printf(_L("Cluster index: %7.1f ms\n"),TheTimer.Stop());
|
sl@0
|
134 |
TheTimer.Start();
|
sl@0
|
135 |
key.Clear();
|
sl@0
|
136 |
key.AddL(KColXrandom);
|
sl@0
|
137 |
r=TheDatabase.CreateIndex(KColXrandom,KTableName,key);
|
sl@0
|
138 |
test (r==KErrNone);
|
sl@0
|
139 |
CleanupStack::PopAndDestroy();
|
sl@0
|
140 |
test.Printf(_L("Random index: %7.1f ms\n"),TheTimer.Stop());
|
sl@0
|
141 |
TheTimer.Start();
|
sl@0
|
142 |
r = TheDatabase.Compact();
|
sl@0
|
143 |
test.Printf(_L("Compact: %7.1f ms\n"),TheTimer.Stop());
|
sl@0
|
144 |
test (r == KErrNone);
|
sl@0
|
145 |
}
|
sl@0
|
146 |
|
sl@0
|
147 |
LOCAL_C TReal Evaluate(const TDesC& aSql)
|
sl@0
|
148 |
{
|
sl@0
|
149 |
TInt m=1;
|
sl@0
|
150 |
for (;;)
|
sl@0
|
151 |
{
|
sl@0
|
152 |
TheTimer.Start();
|
sl@0
|
153 |
for (TInt ii=0;ii<m;++ii)
|
sl@0
|
154 |
{
|
sl@0
|
155 |
TInt r=TheView.Prepare(TheDatabase,aSql,KDbUnlimitedWindow,TheView.EReadOnly);
|
sl@0
|
156 |
if (r<0)
|
sl@0
|
157 |
return r;
|
sl@0
|
158 |
r=TheView.EvaluateAll();
|
sl@0
|
159 |
test (r==KErrNone);
|
sl@0
|
160 |
TheView.Close();
|
sl@0
|
161 |
}
|
sl@0
|
162 |
TReal t=TheTimer.Stop();
|
sl@0
|
163 |
if (t>=100.0)
|
sl@0
|
164 |
return t/m;
|
sl@0
|
165 |
m*=4;
|
sl@0
|
166 |
}
|
sl@0
|
167 |
}
|
sl@0
|
168 |
|
sl@0
|
169 |
struct TTest
|
sl@0
|
170 |
{
|
sl@0
|
171 |
const TText* iName;
|
sl@0
|
172 |
const TText* iQuery;
|
sl@0
|
173 |
};
|
sl@0
|
174 |
const TTest KQuery[]=
|
sl@0
|
175 |
{
|
sl@0
|
176 |
{_S("project"),_S("select cluster,xcluster,random,xrandom from test")},
|
sl@0
|
177 |
{_S("restrict 1"),_S("select * from test where cluster=0")},
|
sl@0
|
178 |
{_S("restrict 2"),_S("select * from test where xrandom=0")},
|
sl@0
|
179 |
{_S("restrict 3"),_S("select * from test where xcluster<500 and xrandom <500")},
|
sl@0
|
180 |
{_S("order 1"),_S("select * from test order by xrandom")},
|
sl@0
|
181 |
{_S("order 2"),_S("select * from test order by cluster")},
|
sl@0
|
182 |
{_S("all 1"),_S("select * from test where random<500 order by xrandom")},
|
sl@0
|
183 |
{_S("all 2"),_S("select * from test where xcluster<500 order by xrandom")},
|
sl@0
|
184 |
{_S("all 3"),_S("select * from test where xcluster<500 order by xcluster")},
|
sl@0
|
185 |
{_S("all 4"),_S("select * from test where xcluster<500 and xrandom<200 order by xcluster")}
|
sl@0
|
186 |
};
|
sl@0
|
187 |
|
sl@0
|
188 |
/**
|
sl@0
|
189 |
@SYMTestCaseID SYSLIB-DBMS-CT-0578
|
sl@0
|
190 |
@SYMTestCaseDesc Benchmark Test.Querying a local Database Test
|
sl@0
|
191 |
@SYMTestPriority Medium
|
sl@0
|
192 |
@SYMTestActions Evaluate SELECT queries on the created database
|
sl@0
|
193 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
194 |
@SYMREQ REQ0000
|
sl@0
|
195 |
*/
|
sl@0
|
196 |
LOCAL_C void Queries()
|
sl@0
|
197 |
{
|
sl@0
|
198 |
test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0578 "));
|
sl@0
|
199 |
for (TUint ii=0;ii<sizeof(KQuery)/sizeof(KQuery[0]);++ii)
|
sl@0
|
200 |
{
|
sl@0
|
201 |
test.Printf(_L("%15s: "),KQuery[ii].iName);
|
sl@0
|
202 |
TReal t=Evaluate(TPtrC(KQuery[ii].iQuery));
|
sl@0
|
203 |
if (t<0.0)
|
sl@0
|
204 |
test.Printf(_L("-\n"));
|
sl@0
|
205 |
else
|
sl@0
|
206 |
test.Printf(_L("%7.1f ms\n"),t);
|
sl@0
|
207 |
}
|
sl@0
|
208 |
}
|
sl@0
|
209 |
|
sl@0
|
210 |
//
|
sl@0
|
211 |
// Benchmark tests
|
sl@0
|
212 |
//
|
sl@0
|
213 |
LOCAL_C void BenchTestL()
|
sl@0
|
214 |
{
|
sl@0
|
215 |
CreateDatabaseL();
|
sl@0
|
216 |
Queries();
|
sl@0
|
217 |
CloseDatabase();
|
sl@0
|
218 |
}
|
sl@0
|
219 |
|
sl@0
|
220 |
//
|
sl@0
|
221 |
// Prepare the test directory.
|
sl@0
|
222 |
//
|
sl@0
|
223 |
LOCAL_C void setupTestDirectory()
|
sl@0
|
224 |
{
|
sl@0
|
225 |
TInt r=TheFs.Connect();
|
sl@0
|
226 |
test(r==KErrNone);
|
sl@0
|
227 |
//
|
sl@0
|
228 |
#if 0
|
sl@0
|
229 |
TDriveList drives;
|
sl@0
|
230 |
TheFs.DriveList(drives);
|
sl@0
|
231 |
if (drives[EDriveK] == KDriveAbsent)
|
sl@0
|
232 |
{
|
sl@0
|
233 |
TInt r = TheFs.AddFileSystem(_L("ELFFS"));
|
sl@0
|
234 |
test (r == KErrNone);
|
sl@0
|
235 |
r = TheFs.MountFileSystem(_L("Lffs"),EDriveK);
|
sl@0
|
236 |
if (r == KErrCorrupt || r == KErrNotReady)
|
sl@0
|
237 |
{
|
sl@0
|
238 |
RFormat format;
|
sl@0
|
239 |
TInt count;
|
sl@0
|
240 |
r = format.Open(TheFs, _L("K:\\"), EHighDensity, count);
|
sl@0
|
241 |
test (r == KErrNone);
|
sl@0
|
242 |
while (count)
|
sl@0
|
243 |
format.Next(count);
|
sl@0
|
244 |
format.Close();
|
sl@0
|
245 |
}
|
sl@0
|
246 |
else
|
sl@0
|
247 |
test (r == KErrNone);
|
sl@0
|
248 |
}
|
sl@0
|
249 |
#endif
|
sl@0
|
250 |
//
|
sl@0
|
251 |
r=TheFs.MkDir(KTestDatabase);
|
sl@0
|
252 |
test(r==KErrNone || r==KErrAlreadyExists);
|
sl@0
|
253 |
}
|
sl@0
|
254 |
|
sl@0
|
255 |
//
|
sl@0
|
256 |
// Initialise the cleanup stack.
|
sl@0
|
257 |
//
|
sl@0
|
258 |
LOCAL_C void setupCleanup()
|
sl@0
|
259 |
{
|
sl@0
|
260 |
TheTrapCleanup=CTrapCleanup::New();
|
sl@0
|
261 |
test(TheTrapCleanup!=NULL);
|
sl@0
|
262 |
TRAPD(r,\
|
sl@0
|
263 |
{\
|
sl@0
|
264 |
for (TInt i=KTestCleanupStack;i>0;i--)\
|
sl@0
|
265 |
CleanupStack::PushL((TAny*)0);\
|
sl@0
|
266 |
CleanupStack::Pop(KTestCleanupStack);\
|
sl@0
|
267 |
});
|
sl@0
|
268 |
test(r==KErrNone);
|
sl@0
|
269 |
}
|
sl@0
|
270 |
|
sl@0
|
271 |
//
|
sl@0
|
272 |
// entry point
|
sl@0
|
273 |
//
|
sl@0
|
274 |
GLDEF_C TInt E32Main()
|
sl@0
|
275 |
{
|
sl@0
|
276 |
test.Title();
|
sl@0
|
277 |
setupTestDirectory();
|
sl@0
|
278 |
setupCleanup();
|
sl@0
|
279 |
__UHEAP_MARK;
|
sl@0
|
280 |
//
|
sl@0
|
281 |
test.Start(_L("Benchmarking..."));
|
sl@0
|
282 |
TRAPD(r,BenchTestL());
|
sl@0
|
283 |
test(r==KErrNone);
|
sl@0
|
284 |
test.End();
|
sl@0
|
285 |
//
|
sl@0
|
286 |
__UHEAP_MARKEND;
|
sl@0
|
287 |
delete TheTrapCleanup;
|
sl@0
|
288 |
|
sl@0
|
289 |
//T_BENCH.DB cannot be deleted here, because it is used by T_COMP test!
|
sl@0
|
290 |
|
sl@0
|
291 |
TheFs.Close();
|
sl@0
|
292 |
test.Close();
|
sl@0
|
293 |
return 0;
|
sl@0
|
294 |
}
|