First public contribution.
1 // Copyright (c) 1998-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.
20 #ifndef __TOOLS2__ // we aren't interested in timings for tools2
29 #undef __UHEAP_MARKEND
30 #define __UHEAP_MARKEND
32 LOCAL_D TDBMS_CRCChecks TheCrcChecker;
34 #ifndef __linux__ //No CRC test on LINUX
36 const TPtrC KCrcRecord=_L("\\epoc32\\winscw\\c\\dbms-tst\\T_BENCH.CRC");
38 const TPtrC KCrcRecord=_L("C:\\dbms-tst\\T_BENCH.CRC");
42 // MSVC++ up to 5.0 has problems with expanding inline functions
43 // This disables the mad warnings for the whole project
44 #if defined(NDEBUG) && defined(__VC32__) && _MSC_VER<=1100
45 #pragma warning(disable : 4710) // function not expanded. MSVC 5.0 is stupid
59 LOCAL_D RTest test(_L("T_BENCH"));
60 LOCAL_D CTrapCleanup* TheTrapCleanup;
61 LOCAL_D RDbNamedDatabase TheDatabase;
62 LOCAL_D RDbView TheView;
65 const TInt KTestCleanupStack=0x20;
66 //T_BENCH file shall not be deleted at the end of the test! It will be used by T_COMP test.
69 const TPtrC KTestDatabase=_L(".\\dbms-tst\\T_BENCH.DB");
71 const TPtrC KTestDatabase=_L("C:\\dbms-tst\\T_BENCH.DB");
73 const TPtrC KTableName=_S("Test");
74 const TPtrC KColCluster=_S("Cluster");
75 const TPtrC KColXcluster=_S("xCluster");
76 const TPtrC KColRandom=_S("Random");
77 const TPtrC KColXrandom=_S("xRandom");
78 const TInt KRecords=2000;
81 static TTimer TheTimer;
85 iTicks=User::FastCounter();
88 TReal TTimer::Stop() const
90 TUint ticks = User::FastCounter() - iTicks;
92 test(HAL::Get(HAL::EFastCounterFrequency, freq) == KErrNone);
93 const TInt KMicroSecIn1Sec = 1000000;
94 const TInt KMsIn1Sec = 1000;
95 double v = ((double)ticks * KMicroSecIn1Sec) / (double)freq; TInt v2 = (TInt)v;
96 return v2 / KMsIn1Sec;
100 LOCAL_C void CloseDatabase()
103 TheCrcChecker.GenerateCrcL(KTestDatabase);
107 Create the database: keep the code 050 compatible
109 @SYMTestCaseID SYSLIB-DBMS-CT-0577
110 @SYMTestCaseDesc Benchmark Tests. Creation of a local Database test
111 @SYMTestPriority Medium
112 @SYMTestActions Attempt to test RDbNamedDatabase::CreateTable(),RDbNamedDatabase::CreateIndex(),
113 RDbNamedDatabase::Compact(),RDbView::Prepare() functions
114 @SYMTestExpectedResults Test must not fail
117 LOCAL_C void CreateDatabase()
119 test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0577 "));
120 User::LeaveIfError(TheDatabase.Replace(TheFs,KTestDatabase));
121 CDbColSet& set=*CDbColSet::NewLC();
122 TDbCol col(KColCluster,EDbColInt32);
123 col.iAttributes=col.ENotNull;
125 col.iName=KColXcluster;
127 col.iName=KColRandom;
129 col.iName=KColXrandom;
131 TInt r=TheDatabase.CreateTable(KTableName,set);
133 CleanupStack::PopAndDestroy();
137 r=TheView.Prepare(TheDatabase,_L("select * from test"),TheView.EInsertOnly);
141 for (TInt ii=0;ii<KRecords;++ii)
147 TheView.SetColL(1,ii);
148 TheView.SetColL(2,ii);
149 TheView.SetColL(3,jj);
150 TheView.SetColL(4,jj);
153 r=TheDatabase.Commit();
157 test.Printf(_L("Build table: %7.1f ms\n"),TheTimer.Stop());
160 CDbKey& key=*CDbKey::NewLC();
161 key.AddL(KColXcluster);
163 r=TheDatabase.CreateIndex(KColXcluster,KTableName,key);
166 test.Printf(_L("Cluster index: %7.1f ms\n"),TheTimer.Stop());
170 key.AddL(KColXrandom);
171 r=TheDatabase.CreateIndex(KColXrandom,KTableName,key);
173 CleanupStack::PopAndDestroy();
175 test.Printf(_L("Random index: %7.1f ms\n"),TheTimer.Stop());
178 r = TheDatabase.Compact();
180 test.Printf(_L("Compact: %7.1f ms\n"),TheTimer.Stop());
182 test (r == KErrNone);
185 LOCAL_C TReal Evaluate(const TDesC& aSql)
193 for (TInt ii=0;ii<m;++ii)
195 TInt r=TheView.Prepare(TheDatabase,aSql,KDbUnlimitedWindow,TheView.EReadOnly);
198 r=TheView.EvaluateAll();
203 TReal t=TheTimer.Stop();
208 // We aren't interested in timings for tools2.
209 return(1.0/m); // is this right?
219 const TTest KQuery[]=
221 {_S("project"),_S("select cluster,xcluster,random,xrandom from test")},
222 {_S("restrict 1"),_S("select * from test where cluster=0")},
223 {_S("restrict 2"),_S("select * from test where xrandom=0")},
224 {_S("restrict 3"),_S("select * from test where xcluster<500 and xrandom <500")},
225 {_S("order 1"),_S("select * from test order by xrandom")},
226 {_S("order 2"),_S("select * from test order by cluster")},
227 {_S("all 1"),_S("select * from test where random<500 order by xrandom")},
228 {_S("all 2"),_S("select * from test where xcluster<500 order by xrandom")},
229 {_S("all 3"),_S("select * from test where xcluster<500 order by xcluster")},
230 {_S("all 4"),_S("select * from test where xcluster<500 and xrandom<200 order by xcluster")}
234 @SYMTestCaseID SYSLIB-DBMS-CT-0578
235 @SYMTestCaseDesc Benchmark Test.Querying a local Database Test
236 @SYMTestPriority Medium
237 @SYMTestActions Evaluate SELECT queries on the created database
238 @SYMTestExpectedResults Test must not fail
241 LOCAL_C void Queries()
243 test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0578 "));
244 for (TUint ii=0;ii<sizeof(KQuery)/sizeof(KQuery[0]);++ii)
246 test.Printf(_L("%15s: "),KQuery[ii].iName);
247 TReal t=Evaluate(TPtrC(KQuery[ii].iQuery));
249 test.Printf(_L("-\n"));
251 test.Printf(_L("%7.1f ms\n"),t);
258 LOCAL_C void BenchTest()
266 // Prepare the test directory.
268 LOCAL_C void setupTestDirectory()
270 TInt r=TheFs.Connect();
275 TheFs.DriveList(drives);
276 if (drives[EDriveK] == KDriveAbsent)
278 TInt r = TheFs.AddFileSystem(_L("ELFFS"));
279 test (r == KErrNone);
280 r = TheFs.MountFileSystem(_L("Lffs"),EDriveK);
281 if (r == KErrCorrupt || r == KErrNotReady)
285 r = format.Open(TheFs, _L("K:\\"), EHighDensity, count);
286 test (r == KErrNone);
292 test (r == KErrNone);
296 r=TheFs.MkDir(KTestDatabase);
297 test(r==KErrNone || r==KErrAlreadyExists);
301 // Initialise the cleanup stack.
303 LOCAL_C void setupCleanup()
305 TheTrapCleanup=CTrapCleanup::New();
306 test(TheTrapCleanup!=NULL);
309 for (TInt i=KTestCleanupStack;i>0;i--)\
310 CleanupStack::PushL((TAny*)0);\
311 CleanupStack::Pop(KTestCleanupStack);\
319 GLDEF_C TInt E32Main()
322 setupTestDirectory();
326 test.Start(_L("Benchmarking..."));
327 TRAPD(r,BenchTest();)
333 TRAPD(lc, err = TheCrcChecker.DumpCrcRecordsL(KCrcRecord));
337 TRAPD(lc, err = TheCrcChecker.ValidateCrcRecordsL(KCrcRecord));
339 TheCrcChecker.ErrorReportL(err, errmsg);
340 RDebug::Print(errmsg);
341 test(err==KErrNone || err==TDBMS_CRCChecks::ECrcCheckOk);
348 delete TheTrapCleanup;
350 //T_BENCH.DB cannot be deleted here, because it is used by T_COMP test!