|
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 * Test program exercises the skeleton UPS server API. |
|
16 * See individual test functions for more information. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 /** |
|
22 @file |
|
23 */ |
|
24 |
|
25 #include <e32ldr.h> |
|
26 #include <scs/rtestwrapper.h> |
|
27 |
|
28 #include <ups/upsclient.h> |
|
29 #include "f32file.h" |
|
30 |
|
31 using namespace UserPromptService; |
|
32 |
|
33 /** Top-level test object renders stages and confirms conditions. */ |
|
34 static RTestWrapper test(_L("UPSTESTOOM")); |
|
35 |
|
36 |
|
37 static void TestFlurryL() |
|
38 /** |
|
39 Launch multiple requests |
|
40 */ |
|
41 { |
|
42 RUpsSession session; |
|
43 User::LeaveIfError(session.Connect()); |
|
44 CleanupClosePushL(session); |
|
45 |
|
46 RThread thd; |
|
47 |
|
48 #if 0 |
|
49 RUpsSubsession testSubsession1; |
|
50 testSubsession1.Initialise(session, thd); |
|
51 |
|
52 TServiceId serviceId = {42}; |
|
53 TRequestStatus rs1; |
|
54 |
|
55 // complete normally - no opaque data |
|
56 TUpsDecision dec1 = EUpsDecYes; |
|
57 testSubsession1.Authorise(EFalse, serviceId, _L("req1"), dec1, rs1); |
|
58 |
|
59 User::After(1000); |
|
60 |
|
61 User::WaitForRequest(rs1); |
|
62 User::LeaveIfError(rs1.Int()); |
|
63 test(dec1 == EUpsDecNo); |
|
64 #else |
|
65 RUpsSubsession testSubsession1; |
|
66 testSubsession1.Initialise(session, thd); |
|
67 RUpsSubsession testSubsession2; |
|
68 testSubsession2.Initialise(session, thd); |
|
69 RUpsSubsession testSubsession3; |
|
70 testSubsession3.Initialise(session, thd); |
|
71 RUpsSubsession testSubsession4; |
|
72 testSubsession4.Initialise(session, thd); |
|
73 RUpsSubsession testSubsession5; |
|
74 testSubsession5.Initialise(session, thd); |
|
75 RUpsSubsession testSubsession6; |
|
76 testSubsession6.Initialise(session, thd); |
|
77 |
|
78 TServiceId serviceId = {42}; |
|
79 TRequestStatus rs1; |
|
80 TRequestStatus rs2; |
|
81 TRequestStatus rs3; |
|
82 TRequestStatus rs4; |
|
83 TRequestStatus rs5; |
|
84 TRequestStatus rs6; |
|
85 |
|
86 // complete normally - no opaque data |
|
87 TUpsDecision dec1 = EUpsDecYes; |
|
88 TUpsDecision dec2 = EUpsDecYes; |
|
89 TUpsDecision dec3 = EUpsDecYes; |
|
90 TUpsDecision dec4 = EUpsDecYes; |
|
91 TUpsDecision dec5 = EUpsDecYes; |
|
92 TUpsDecision dec6 = EUpsDecYes; |
|
93 testSubsession1.Authorise(EFalse, serviceId, _L("req1"), dec1, rs1); |
|
94 testSubsession2.Authorise(EFalse, serviceId, _L("reqX"), dec2, rs2); |
|
95 testSubsession3.Authorise(EFalse, serviceId, _L("req2"), dec3, rs3); |
|
96 testSubsession4.Authorise(EFalse, serviceId, _L("reqX"), dec4, rs4); |
|
97 testSubsession5.Authorise(EFalse, serviceId, _L("req3"), dec5, rs5); |
|
98 testSubsession6.Authorise(EFalse, serviceId, _L("req4"), dec6, rs6); |
|
99 |
|
100 User::After(1000); |
|
101 |
|
102 User::WaitForRequest(rs1); |
|
103 |
|
104 User::WaitForRequest(rs2); |
|
105 User::WaitForRequest(rs4); |
|
106 |
|
107 User::WaitForRequest(rs3); |
|
108 User::WaitForRequest(rs5); |
|
109 User::WaitForRequest(rs6); |
|
110 User::LeaveIfError(rs1.Int()); |
|
111 User::LeaveIfError(rs2.Int()); |
|
112 User::LeaveIfError(rs3.Int()); |
|
113 User::LeaveIfError(rs4.Int()); |
|
114 User::LeaveIfError(rs5.Int()); |
|
115 User::LeaveIfError(rs6.Int()); |
|
116 test(dec1 == EUpsDecNo); |
|
117 test(dec2 == EUpsDecNo); |
|
118 test(dec3 == EUpsDecNo); |
|
119 test(dec4 == EUpsDecNo); |
|
120 test(dec5 == EUpsDecNo); |
|
121 test(dec6 == EUpsDecNo); |
|
122 #endif |
|
123 |
|
124 CleanupStack::PopAndDestroy(&session); |
|
125 } |
|
126 |
|
127 static void TestRUpsManagementL() |
|
128 /** |
|
129 Attempt to delete database |
|
130 */ |
|
131 { |
|
132 // test.Start(_L("Testing RUpsManagement")); |
|
133 RThread thd; |
|
134 TRequestStatus rs; |
|
135 TInt r; |
|
136 |
|
137 // Create filter |
|
138 TServiceId serviceId = {43}; |
|
139 CDecisionFilter *filter = CDecisionFilter::NewLC(); |
|
140 filter->SetClientSid(thd.SecureId(), EEqual); |
|
141 filter->SetServerSid(thd.SecureId(), EEqual); |
|
142 filter->SetServiceId(serviceId, EEqual); |
|
143 |
|
144 RUpsSession session; |
|
145 User::LeaveIfError(session.Connect()); |
|
146 CleanupClosePushL(session); |
|
147 |
|
148 RUpsSubsession clientSubsession; |
|
149 User::LeaveIfError(clientSubsession.Initialise(session, thd)); |
|
150 CleanupClosePushL(clientSubsession); |
|
151 |
|
152 test.Printf(_L("Open management session\n")); |
|
153 RUpsManagement mngmnt; |
|
154 User::LeaveIfError(mngmnt.Connect()); |
|
155 CleanupClosePushL(mngmnt); |
|
156 |
|
157 test.Printf(_L("View create - then delete DB\n")); |
|
158 mngmnt.CreateView(*filter, rs); |
|
159 |
|
160 test.Printf(_L("Delete database\n")); |
|
161 TRAP(r, mngmnt.DeleteDatabaseL()); |
|
162 test((r == KErrNone) || (r == KErrNoMemory)); |
|
163 |
|
164 test.Printf(_L("Now see what view create completed with....\n")); |
|
165 User::WaitForRequest(rs); |
|
166 // The createview may actually complete if the DeleteDatabase fails due to OOM |
|
167 // test((rs.Int() == KErrAbort) || (rs.Int() == KErrNoMemory) || (rs.Int() == KErrNone)); |
|
168 test((rs.Int() == KErrAbort) || (rs.Int() == KErrNoMemory)); |
|
169 |
|
170 test.Printf(_L("Add entry to new database\n")); |
|
171 TUpsDecision dec = EUpsDecYes; |
|
172 clientSubsession.Authorise(EFalse, serviceId, _L("DB delete 1"), _L8("Opaque data"), dec, rs); |
|
173 User::WaitForRequest(rs); |
|
174 test(rs == KErrNone); |
|
175 test(dec == EUpsDecNo); |
|
176 |
|
177 dec = EUpsDecYes; |
|
178 clientSubsession.Authorise(EFalse, serviceId, _L("DB delete 2"), _L8("Opaque data"), dec, rs); |
|
179 User::WaitForRequest(rs); |
|
180 test(rs == KErrNone); |
|
181 test(dec == EUpsDecNo); |
|
182 |
|
183 |
|
184 test.Printf(_L("View create - immediate cancel\n")); |
|
185 mngmnt.CreateView(*filter, rs); |
|
186 mngmnt.CancelAndCloseView(); |
|
187 User::WaitForRequest(rs); |
|
188 test((rs.Int() == KErrCancel) || (rs.Int() == KErrNoMemory)); |
|
189 |
|
190 test.Printf(_L("View create - iterate through it\n")); |
|
191 mngmnt.CreateView(*filter, rs); |
|
192 |
|
193 User::WaitForRequest(rs); |
|
194 test((rs.Int() == KErrNone) || (rs.Int() == KErrNoMemory)); |
|
195 |
|
196 |
|
197 CDecisionRecord *record = 0; |
|
198 r = KErrNone; |
|
199 while(r == KErrNone) |
|
200 { |
|
201 TRAP(r, record = mngmnt.NextMatchL()); |
|
202 if(record == 0) |
|
203 { |
|
204 break; |
|
205 } |
|
206 test(r == KErrNone); |
|
207 if(r == KErrNone) |
|
208 { |
|
209 CleanupStack::PushL(record); |
|
210 CDecisionFilter *exactFilter = CDecisionFilter::NewLC(record->iClientSid, |
|
211 record->iEvaluatorId, |
|
212 record->iServiceId, |
|
213 record->iServerSid, |
|
214 record->iFingerprint, |
|
215 record->iClientEntity, |
|
216 record->iMajorPolicyVersion); |
|
217 |
|
218 mngmnt.UpdateDecision(record->iRecordId, ETrue, rs); |
|
219 User::WaitForRequest(rs); |
|
220 test(rs.Int() == KErrNone); |
|
221 TRAP(r, mngmnt.RemoveDecisionsL(*exactFilter)); |
|
222 test(r == KErrNone); |
|
223 |
|
224 CleanupStack::PopAndDestroy(exactFilter); |
|
225 CleanupStack::PopAndDestroy(record); |
|
226 } |
|
227 |
|
228 }; |
|
229 |
|
230 |
|
231 TRAP(r, record = mngmnt.NextMatchL()); |
|
232 test((r == KErrNone) && (record == 0)); |
|
233 |
|
234 mngmnt.CancelAndCloseView(); |
|
235 |
|
236 test.Printf(_L("Close management session and clientSubsession\n")); |
|
237 CleanupStack::PopAndDestroy(&mngmnt); |
|
238 CleanupStack::PopAndDestroy(&clientSubsession); |
|
239 CleanupStack::PopAndDestroy(&session); |
|
240 CleanupStack::PopAndDestroy(filter); |
|
241 |
|
242 // test.End(); |
|
243 } |
|
244 |
|
245 void MainL() |
|
246 { |
|
247 test.Title(_L("c:\\upstestoom.log")); |
|
248 test.Start(_L(" @SYMTestCaseID:SEC-UPS-OOM-0001 Testing UPS OOM ")); |
|
249 |
|
250 // We need to increase the priority of the thread running the test code to make sure |
|
251 // that asynchronous ups management calls, for example CreateView() , won't finish |
|
252 // before following synchronous cancellation or termination calls, for example: |
|
253 // DeleteDatabaseL() or CancelAndCloseView(). |
|
254 RThread thread; |
|
255 TThreadPriority currentPri = thread.Priority(); |
|
256 currentPri = (TThreadPriority)((TInt)currentPri+10); |
|
257 thread.SetPriority(currentPri); |
|
258 |
|
259 RFs fs; |
|
260 User::LeaveIfError(fs.Connect()); |
|
261 CleanupClosePushL(fs); |
|
262 |
|
263 TBuf<21> notifierConfig(_L("!:\\upsrefnotifier.txt")); |
|
264 notifierConfig[0] = fs.GetSystemDriveChar(); |
|
265 |
|
266 TBuf<35> database(_L("!:\\Private\\10283558\\database\\ups.db")); |
|
267 database[0] = fs.GetSystemDriveChar(); |
|
268 |
|
269 TInt lineLength = User::CommandLineLength(); |
|
270 switch(lineLength) |
|
271 { |
|
272 default: |
|
273 // fall through - extra command line arguments are ignored |
|
274 case 2: |
|
275 (void) fs.Delete(database); |
|
276 // Fall through to also delete notifier config file |
|
277 case 1: |
|
278 (void) fs.Delete(notifierConfig); |
|
279 break; |
|
280 case 0: |
|
281 { |
|
282 // No args so run in silent mode |
|
283 (void) fs.Delete(database); |
|
284 (void) fs.Delete(notifierConfig); |
|
285 RFile file; |
|
286 User::LeaveIfError(file.Create(fs, notifierConfig, EFileShareExclusive | EFileWrite)); |
|
287 User::LeaveIfError(file.Write(_L8("Never"))); |
|
288 file.Close(); |
|
289 break; |
|
290 } |
|
291 } |
|
292 |
|
293 // Connect to server |
|
294 RUpsSession session; |
|
295 User::LeaveIfError(session.Connect()); |
|
296 CleanupClosePushL(session); |
|
297 |
|
298 TInt err = KErrNone; |
|
299 TInt err2 = KErrNone; |
|
300 TInt run = 0; |
|
301 TInt passingRuns = 0; |
|
302 static const TInt maxRun = 1000; |
|
303 static const TInt passThreshold = 5; |
|
304 for(run=1; run<=maxRun; ++run) |
|
305 { |
|
306 test.Printf(_L("\n\nOOM -- Run %d\n"), run); |
|
307 err = session.SetServerHeapFail(run); |
|
308 if(err == KErrNoMemory) |
|
309 { |
|
310 // Reinitialisation failed |
|
311 test.Printf(_L("\tReinitialisation failed\n")); |
|
312 session.ResetServerHeapFail(); |
|
313 continue; |
|
314 } |
|
315 if(err != KErrNone) |
|
316 { |
|
317 // Failed to set heap fail, maybe the previous loop crashed the server?? |
|
318 test.Printf(_L("Failed to set heap fail with error code %d\n"), err); |
|
319 test(EFalse); |
|
320 break; |
|
321 } |
|
322 |
|
323 // Run the test |
|
324 //test.Start(_L("TestFlurry")); |
|
325 test.Printf(_L("TestFlurry\n")); |
|
326 TRAP(err, TestFlurryL()); |
|
327 test.Printf(_L("TestRUpsManagementL\n")); |
|
328 TRAP(err2, TestRUpsManagementL()); |
|
329 if(err == KErrNone) |
|
330 { |
|
331 err = err2; |
|
332 } |
|
333 test.Printf(_L("done\n")); |
|
334 //test.End(); |
|
335 // Clear the heap fail |
|
336 test.Printf(_L("Reseting heap failure\n")); |
|
337 err2 = session.ResetServerHeapFail(); |
|
338 if((err == KErrServerTerminated) || (err2 == KErrServerTerminated)) |
|
339 { |
|
340 test.Printf(_L("\tUPS server died\n")); |
|
341 test(EFalse); |
|
342 break; |
|
343 } |
|
344 if((err == KErrNone) && (err2 != KErrNone)) |
|
345 { |
|
346 err = err2; |
|
347 } |
|
348 |
|
349 // Did it work? |
|
350 if(err == KErrNone) |
|
351 { |
|
352 ++passingRuns; |
|
353 } |
|
354 else |
|
355 { |
|
356 passingRuns = 0; |
|
357 } |
|
358 |
|
359 if(passingRuns > passThreshold) break; |
|
360 } // End of OOM loop |
|
361 |
|
362 if(run > maxRun) |
|
363 { |
|
364 User::Leave(err); |
|
365 } |
|
366 |
|
367 // Synchronous call to shutdown the server |
|
368 session.ShutdownServer(); |
|
369 // Close top level session (low level session was closed by |
|
370 // ShutdownServer, but we still need to do the RUpsSession |
|
371 // cleanup). |
|
372 CleanupStack::PopAndDestroy(&session); |
|
373 |
|
374 (void) fs.Delete(notifierConfig); |
|
375 CleanupStack::PopAndDestroy(&fs); |
|
376 |
|
377 test.End(); |
|
378 test.Close(); |
|
379 } |
|
380 |
|
381 void PanicIfError(TInt r) |
|
382 { |
|
383 if(r != KErrNone) |
|
384 { |
|
385 User::Panic(_L("upstestoom failed: "), r); |
|
386 } |
|
387 } |
|
388 |
|
389 |
|
390 // -------- entrypoint -------- |
|
391 TInt E32Main() |
|
392 /** |
|
393 Executable entrypoint establishes connection with UPS server |
|
394 and then invokes tests for each functional area. |
|
395 |
|
396 @return Symbian OS error code where KErrNone indicates |
|
397 success and any other value indicates failure. |
|
398 */ |
|
399 { |
|
400 // disable lazy DLL unloading so kernel heap balances at end |
|
401 RLoader l; |
|
402 PanicIfError(l.Connect()); |
|
403 PanicIfError(l.CancelLazyDllUnload()); |
|
404 l.Close(); |
|
405 |
|
406 __UHEAP_MARK; |
|
407 //__KHEAP_MARK; |
|
408 |
|
409 // allocating a cleanup stack also installs it |
|
410 CTrapCleanup* tc = CTrapCleanup::New(); |
|
411 if (tc == 0) |
|
412 return KErrNoMemory; |
|
413 |
|
414 TRAPD(err, MainL()); |
|
415 PanicIfError(err); |
|
416 delete tc; |
|
417 |
|
418 //__KHEAP_MARKEND; |
|
419 __UHEAP_MARKEND; |
|
420 |
|
421 |
|
422 return KErrNone; |
|
423 } |
|
424 |
|
425 // End of file |