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