|
1 /* |
|
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Performs UPS Database Performance Tests |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 /** |
|
21 @file |
|
22 @test |
|
23 */ |
|
24 |
|
25 #include "tupsdbstep.h" |
|
26 #include <test/testexecutelog.h> |
|
27 |
|
28 using namespace UserPromptService; |
|
29 |
|
30 // |
|
31 // The rest of the code |
|
32 |
|
33 |
|
34 CUpsDbStepPerformance::CUpsDbStepPerformance() |
|
35 { |
|
36 // Destructor Code |
|
37 delete iWaiter; |
|
38 delete iScheduler; |
|
39 } |
|
40 |
|
41 CUpsDbStepPerformance::~CUpsDbStepPerformance() |
|
42 { |
|
43 //Constructor Code |
|
44 } |
|
45 |
|
46 TVerdict CUpsDbStepPerformance::doTestStepPreambleL() |
|
47 { |
|
48 TBuf<KUpsDescriptionLength> keyNotFound; |
|
49 ReadConfigurationFile(keyNotFound); |
|
50 |
|
51 if(keyNotFound.Length()) |
|
52 { |
|
53 ERR_PRINTF2(_L("Failed to read '%S' key of configuration"),&keyNotFound); |
|
54 SetTestStepResult(EFail); |
|
55 User::Leave(KErrNotFound); |
|
56 } |
|
57 |
|
58 //Create a database name |
|
59 User::LeaveIfError(iFs.Connect()); |
|
60 User::LeaveIfError(iFs.CreatePrivatePath(EDriveC)); |
|
61 User::LeaveIfError(iFs.PrivatePath(iDbLocation)); |
|
62 iPerformanceLog.Copy(iDbLocation); |
|
63 iDbLocation.Append(KDbName); |
|
64 iPerformanceLog.Append(KLogName); |
|
65 |
|
66 //Delete the database if left from previous execution |
|
67 iFs.Delete(iDbLocation); |
|
68 |
|
69 //Open the log file where the performance results are written in CSV format |
|
70 TInt err = iFile.Open(iFs,iPerformanceLog,EFileWrite); |
|
71 if(KErrNotFound == err) |
|
72 { |
|
73 User::LeaveIfError(iFile.Replace(iFs,iPerformanceLog,EFileWrite)); |
|
74 //Write the column headers to the log file |
|
75 PrintHeader(); |
|
76 } |
|
77 else if(KErrNone != err) |
|
78 { |
|
79 User::Leave(err); |
|
80 } |
|
81 |
|
82 TInt pos = 0; |
|
83 iFile.Seek(ESeekEnd, pos); |
|
84 iLog = ETrue; |
|
85 |
|
86 //Create and install active scheduler |
|
87 iScheduler = new(ELeave) CActiveScheduler; |
|
88 CActiveScheduler::Install(iScheduler); |
|
89 iWaiter = new(ELeave)CActiveWaiter(Logger()); |
|
90 |
|
91 return TestStepResult(); |
|
92 } |
|
93 |
|
94 TVerdict CUpsDbStepPerformance::doTestStepL() |
|
95 { |
|
96 INFO_PRINTF1(_L("Running Step: Measuring Database Performance")); |
|
97 |
|
98 //Create a decision database |
|
99 CDecisionDbW* decisionDb = CreateDatabaseLC(iDbLocation, iFs); |
|
100 |
|
101 //Fill the table with decision records |
|
102 FillTableL(*decisionDb,iRecordNum,iClientNum,iServiceNum,iServerNum,iEvaluatorNum); |
|
103 |
|
104 //Get a set of decision records with ClientSid |
|
105 TUid clientId = TUid::Uid(iRetrieveNum%iClientNum + iRecordNum); |
|
106 CDecisionFilter* filter = CDecisionFilter::NewLC(); |
|
107 filter->SetClientSid(clientId,EEqual); |
|
108 |
|
109 INFO_PRINTF2(_L("Lookup for ClientSid=%d"),clientId.iUid); |
|
110 |
|
111 RPointerArray<CDecisionRecord> recordList = GetDecisionsL(*decisionDb,*filter,EFalse); |
|
112 recordList.Reset(); |
|
113 CleanupStack::PopAndDestroy(filter); |
|
114 |
|
115 //Get a set of decision records with EvaluatorId |
|
116 TUid evaluatorId = TUid::Uid(iRetrieveNum%iEvaluatorNum + 1000000 + iRecordNum); |
|
117 filter = CDecisionFilter::NewLC(); |
|
118 filter->SetEvaluatorId(evaluatorId,EEqual); |
|
119 |
|
120 INFO_PRINTF2(_L("Lookup for EvaluatorId=%d"),evaluatorId.iUid); |
|
121 |
|
122 GetDecisionsL(*decisionDb,*filter,EFalse); |
|
123 CleanupStack::PopAndDestroy(filter); |
|
124 |
|
125 //Get a set of decision records with ServiceId |
|
126 TUid serviceId = TUid::Uid(iRetrieveNum%iServiceNum + 10000 + iRecordNum); |
|
127 filter = CDecisionFilter::NewLC(); |
|
128 filter->SetServiceId(serviceId,EEqual); |
|
129 |
|
130 INFO_PRINTF2(_L("Lookup for ServiceId=%d"),serviceId.iUid); |
|
131 |
|
132 GetDecisionsL(*decisionDb,*filter,EFalse); |
|
133 CleanupStack::PopAndDestroy(filter); |
|
134 |
|
135 //Get a set of decision records with ServerSid |
|
136 TUid serverId = TUid::Uid(iRetrieveNum%iServerNum + 100000 + iRecordNum); |
|
137 filter = CDecisionFilter::NewLC(); |
|
138 filter->SetServerSid(serverId,EEqual); |
|
139 |
|
140 INFO_PRINTF2(_L("Lookup for ServerSid=%d"),serverId.iUid); |
|
141 |
|
142 GetDecisionsL(*decisionDb,*filter,EFalse); |
|
143 CleanupStack::PopAndDestroy(filter); |
|
144 |
|
145 //Lookup for Fingerprint |
|
146 TBuf8<KDbMaxName>bufFP; |
|
147 CMD5* md5FP = CMD5::NewL(); |
|
148 CleanupStack::PushL(md5FP); |
|
149 |
|
150 bufFP.AppendFormat(KFingerprint,iRetrieveNum); |
|
151 filter = CDecisionFilter::NewLC(); |
|
152 |
|
153 filter->SetFingerprintL(md5FP->Hash(bufFP),EEqual); |
|
154 |
|
155 INFO_PRINTF1(_L("Lookup for a Fingerprint")); |
|
156 |
|
157 GetDecisionsL(*decisionDb,*filter,EFalse); |
|
158 CleanupStack::PopAndDestroy(filter); |
|
159 |
|
160 //Lookup for ClientEntity |
|
161 TBuf8<KDbMaxName>bufCE; |
|
162 CMD5* md5CE = CMD5::NewL(); |
|
163 CleanupStack::PushL(md5CE); |
|
164 |
|
165 bufCE.AppendFormat(KClientEntity,iRetrieveNum); |
|
166 filter = CDecisionFilter::NewLC(); |
|
167 |
|
168 filter->SetClientEntityL(md5CE->Hash(bufCE),EEqual); |
|
169 |
|
170 INFO_PRINTF1(_L("Lookup for a ClientEntity")); |
|
171 |
|
172 GetDecisionsL(*decisionDb,*filter,EFalse); |
|
173 CleanupStack::PopAndDestroy(filter); |
|
174 |
|
175 //Get a single record |
|
176 md5FP->Reset(); |
|
177 md5CE->Reset(); |
|
178 filter = CDecisionFilter::NewLC(clientId,evaluatorId,serviceId,serverId,md5FP->Hash(bufFP),md5CE->Hash(bufCE),2); |
|
179 |
|
180 INFO_PRINTF1(_L("Lookup for a single,unique record")); |
|
181 |
|
182 CDecisionRecord *retRecord (0); |
|
183 retRecord = GetDecisionLC(*decisionDb,*filter); |
|
184 CleanupStack::PopAndDestroy(retRecord); |
|
185 CleanupStack::PopAndDestroy(filter); |
|
186 |
|
187 //Delete a set of records with ClientSid |
|
188 filter = CDecisionFilter::NewLC(); |
|
189 filter->SetClientSid(clientId,EEqual); |
|
190 |
|
191 INFO_PRINTF2(_L("Delete a set of records where ClientSid=%d"),clientId.iUid); |
|
192 |
|
193 RemoveDecisionsL(*decisionDb,*filter); |
|
194 CleanupStack::PopAndDestroy(filter); |
|
195 |
|
196 //Delete a set of records with ServiceId |
|
197 filter = CDecisionFilter::NewLC(); |
|
198 filter->SetServiceId(serviceId,EEqual); |
|
199 |
|
200 INFO_PRINTF2(_L("Delete a set of records where ServiceId=%d"),serviceId.iUid); |
|
201 |
|
202 RemoveDecisionsL(*decisionDb,*filter); |
|
203 CleanupStack::PopAndDestroy(filter); |
|
204 |
|
205 //Delete a set of records with ServerSid |
|
206 filter = CDecisionFilter::NewLC(); |
|
207 filter->SetServerSid(serverId,EEqual); |
|
208 |
|
209 INFO_PRINTF2(_L("Delete a set of records where ServerSid=%d"),serverId.iUid); |
|
210 |
|
211 RemoveDecisionsL(*decisionDb,*filter); |
|
212 CleanupStack::PopAndDestroy(filter); |
|
213 |
|
214 //Insert a record |
|
215 TBuf<KDbMaxName>bufDes; |
|
216 bufDes.AppendFormat(KDescription,iRetrieveNum); |
|
217 CDecisionRecord* record = CDecisionRecord::NewLC(clientId,evaluatorId,serviceId,serverId,md5FP->Hash(bufFP),md5CE->Hash(bufCE),bufDes,1,2,0); |
|
218 |
|
219 INFO_PRINTF1(_L("Insert a decision record")); |
|
220 |
|
221 InsertRecordL(*decisionDb,*record); |
|
222 CleanupStack::PopAndDestroy(record); |
|
223 |
|
224 //Delete All Records |
|
225 INFO_PRINTF1(_L("Delete all decision records")); |
|
226 RemoveAllDecisionsL(*decisionDb, iFs); |
|
227 |
|
228 CleanupStack::PopAndDestroy(3,decisionDb);//md5FP, MD5CE & decisionDb |
|
229 |
|
230 iFile.Write(_L8("\n")); |
|
231 |
|
232 return TestStepResult(); |
|
233 } |
|
234 |
|
235 TVerdict CUpsDbStepPerformance::doTestStepPostambleL() |
|
236 { |
|
237 iFile.Close(); |
|
238 iFs.Close(); |
|
239 // Override base class virtual function |
|
240 return TestStepResult(); |
|
241 } |
|
242 |
|
243 void CUpsDbStepPerformance::PrintHeader() |
|
244 { |
|
245 iFile.Write(_L8("\"Create Database\";")); |
|
246 iFile.Write(_L8("\"Lookup with ClientSid\";")); |
|
247 iFile.Write(_L8("\"Lookup with EvaluatorId\";")); |
|
248 iFile.Write(_L8("\"Lookup with ServiceId\";")); |
|
249 iFile.Write(_L8("\"Lookup with ServerSid\";")); |
|
250 iFile.Write(_L8("\"Lookup with Fingerprint\";")); |
|
251 iFile.Write(_L8("\"Lookup with ClientEntity\";")); |
|
252 iFile.Write(_L8("\"Lookup Single Record\";")); |
|
253 iFile.Write(_L8("\"Delete with ClientSid\";")); |
|
254 iFile.Write(_L8("\"Delete with ServiceId\";")); |
|
255 iFile.Write(_L8("\"Delete with ServerSid\";")); |
|
256 iFile.Write(_L8("\"Insert A Record\";")); |
|
257 iFile.Write(_L8("\"Delete All Records\";")); |
|
258 iFile.Write(_L8("\n")); |
|
259 } |
|
260 |