First public contribution.
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * Test program exercises the skeleton UPS server API.
16 * See individual test functions for more information.
26 #include <e32ldr_private.h>
27 #include "rtestwrapper.h"
29 #include <ups/upsclient.h>
32 using namespace UserPromptService;
34 /** Top-level test object renders stages and confirms conditions. */
35 static RTestWrapper test(_L("UPSTESTOOM"));
38 static void TestFlurryL()
40 Launch multiple requests
44 User::LeaveIfError(session.Connect());
45 CleanupClosePushL(session);
50 RUpsSubsession testSubsession1;
51 testSubsession1.Initialise(session, thd);
53 TServiceId serviceId = {42};
56 // complete normally - no opaque data
57 TUpsDecision dec1 = EUpsDecYes;
58 testSubsession1.Authorise(EFalse, serviceId, _L("req1"), dec1, rs1);
62 User::WaitForRequest(rs1);
63 User::LeaveIfError(rs1.Int());
64 test(dec1 == EUpsDecNo);
66 RUpsSubsession testSubsession1;
67 testSubsession1.Initialise(session, thd);
68 RUpsSubsession testSubsession2;
69 testSubsession2.Initialise(session, thd);
70 RUpsSubsession testSubsession3;
71 testSubsession3.Initialise(session, thd);
72 RUpsSubsession testSubsession4;
73 testSubsession4.Initialise(session, thd);
74 RUpsSubsession testSubsession5;
75 testSubsession5.Initialise(session, thd);
76 RUpsSubsession testSubsession6;
77 testSubsession6.Initialise(session, thd);
79 TServiceId serviceId = {42};
87 // complete normally - no opaque data
88 TUpsDecision dec1 = EUpsDecYes;
89 TUpsDecision dec2 = EUpsDecYes;
90 TUpsDecision dec3 = EUpsDecYes;
91 TUpsDecision dec4 = EUpsDecYes;
92 TUpsDecision dec5 = EUpsDecYes;
93 TUpsDecision dec6 = EUpsDecYes;
94 testSubsession1.Authorise(EFalse, serviceId, _L("req1"), dec1, rs1);
95 testSubsession2.Authorise(EFalse, serviceId, _L("reqX"), dec2, rs2);
96 testSubsession3.Authorise(EFalse, serviceId, _L("req2"), dec3, rs3);
97 testSubsession4.Authorise(EFalse, serviceId, _L("reqX"), dec4, rs4);
98 testSubsession5.Authorise(EFalse, serviceId, _L("req3"), dec5, rs5);
99 testSubsession6.Authorise(EFalse, serviceId, _L("req4"), dec6, rs6);
103 User::WaitForRequest(rs1);
105 User::WaitForRequest(rs2);
106 User::WaitForRequest(rs4);
108 User::WaitForRequest(rs3);
109 User::WaitForRequest(rs5);
110 User::WaitForRequest(rs6);
111 User::LeaveIfError(rs1.Int());
112 User::LeaveIfError(rs2.Int());
113 User::LeaveIfError(rs3.Int());
114 User::LeaveIfError(rs4.Int());
115 User::LeaveIfError(rs5.Int());
116 User::LeaveIfError(rs6.Int());
117 test(dec1 == EUpsDecNo);
118 test(dec2 == EUpsDecNo);
119 test(dec3 == EUpsDecNo);
120 test(dec4 == EUpsDecNo);
121 test(dec5 == EUpsDecNo);
122 test(dec6 == EUpsDecNo);
125 CleanupStack::PopAndDestroy(&session);
128 static void TestRUpsManagementL()
130 Attempt to delete database
133 // test.Start(_L("Testing RUpsManagement"));
139 TServiceId serviceId = {43};
140 CDecisionFilter *filter = CDecisionFilter::NewLC();
141 filter->SetClientSid(thd.SecureId(), EEqual);
142 filter->SetServerSid(thd.SecureId(), EEqual);
143 filter->SetServiceId(serviceId, EEqual);
146 User::LeaveIfError(session.Connect());
147 CleanupClosePushL(session);
149 RUpsSubsession clientSubsession;
150 User::LeaveIfError(clientSubsession.Initialise(session, thd));
151 CleanupClosePushL(clientSubsession);
153 test.Printf(_L("Open management session\n"));
154 RUpsManagement mngmnt;
155 User::LeaveIfError(mngmnt.Connect());
156 CleanupClosePushL(mngmnt);
158 test.Printf(_L("View create - then delete DB\n"));
159 mngmnt.CreateView(*filter, rs);
161 test.Printf(_L("Delete database\n"));
162 TRAP(r, mngmnt.DeleteDatabaseL());
163 test((r == KErrNone) || (r == KErrNoMemory));
165 test.Printf(_L("Now see what view create completed with....\n"));
166 User::WaitForRequest(rs);
167 // The createview may actually complete if the DeleteDatabase fails due to OOM
168 // test((rs.Int() == KErrAbort) || (rs.Int() == KErrNoMemory) || (rs.Int() == KErrNone));
169 test((rs.Int() == KErrAbort) || (rs.Int() == KErrNoMemory));
171 test.Printf(_L("Add entry to new database\n"));
172 TUpsDecision dec = EUpsDecYes;
173 clientSubsession.Authorise(EFalse, serviceId, _L("DB delete 1"), _L8("Opaque data"), dec, rs);
174 User::WaitForRequest(rs);
175 test(rs == KErrNone);
176 test(dec == EUpsDecNo);
179 clientSubsession.Authorise(EFalse, serviceId, _L("DB delete 2"), _L8("Opaque data"), dec, rs);
180 User::WaitForRequest(rs);
181 test(rs == KErrNone);
182 test(dec == EUpsDecNo);
185 test.Printf(_L("View create - immediate cancel\n"));
186 mngmnt.CreateView(*filter, rs);
187 mngmnt.CancelAndCloseView();
188 User::WaitForRequest(rs);
189 test((rs.Int() == KErrCancel) || (rs.Int() == KErrNoMemory));
191 test.Printf(_L("View create - iterate through it\n"));
192 mngmnt.CreateView(*filter, rs);
194 User::WaitForRequest(rs);
195 test((rs.Int() == KErrNone) || (rs.Int() == KErrNoMemory));
198 CDecisionRecord *record = 0;
202 TRAP(r, record = mngmnt.NextMatchL());
210 CleanupStack::PushL(record);
211 CDecisionFilter *exactFilter = CDecisionFilter::NewLC(record->iClientSid,
212 record->iEvaluatorId,
215 record->iFingerprint,
216 record->iClientEntity,
217 record->iMajorPolicyVersion);
219 mngmnt.UpdateDecision(record->iRecordId, ETrue, rs);
220 User::WaitForRequest(rs);
221 test(rs.Int() == KErrNone);
222 TRAP(r, mngmnt.RemoveDecisionsL(*exactFilter));
225 CleanupStack::PopAndDestroy(exactFilter);
226 CleanupStack::PopAndDestroy(record);
232 TRAP(r, record = mngmnt.NextMatchL());
233 test((r == KErrNone) && (record == 0));
235 mngmnt.CancelAndCloseView();
237 test.Printf(_L("Close management session and clientSubsession\n"));
238 CleanupStack::PopAndDestroy(&mngmnt);
239 CleanupStack::PopAndDestroy(&clientSubsession);
240 CleanupStack::PopAndDestroy(&session);
241 CleanupStack::PopAndDestroy(filter);
248 test.Title(_L("c:\\upstestoom.log"));
249 test.Start(_L(" @SYMTestCaseID:SEC-UPS-OOM-0001 Testing UPS OOM "));
251 // We need to increase the priority of the thread running the test code to make sure
252 // that asynchronous ups management calls, for example CreateView() , won't finish
253 // before following synchronous cancellation or termination calls, for example:
254 // DeleteDatabaseL() or CancelAndCloseView().
256 TThreadPriority currentPri = thread.Priority();
257 currentPri = (TThreadPriority)((TInt)currentPri+10);
258 thread.SetPriority(currentPri);
261 User::LeaveIfError(fs.Connect());
262 CleanupClosePushL(fs);
264 TBuf<21> notifierConfig(_L("!:\\upsrefnotifier.txt"));
265 notifierConfig[0] = fs.GetSystemDriveChar();
267 TBuf<35> database(_L("!:\\Private\\10283558\\database\\ups.db"));
268 database[0] = fs.GetSystemDriveChar();
270 TInt lineLength = User::CommandLineLength();
274 // fall through - extra command line arguments are ignored
276 (void) fs.Delete(database);
277 // Fall through to also delete notifier config file
279 (void) fs.Delete(notifierConfig);
283 // No args so run in silent mode
284 (void) fs.Delete(database);
285 (void) fs.Delete(notifierConfig);
287 User::LeaveIfError(file.Create(fs, notifierConfig, EFileShareExclusive | EFileWrite));
288 User::LeaveIfError(file.Write(_L8("Never")));
296 User::LeaveIfError(session.Connect());
297 CleanupClosePushL(session);
300 TInt err2 = KErrNone;
302 TInt passingRuns = 0;
303 static const TInt maxRun = 1000;
304 static const TInt passThreshold = 5;
305 for(run=1; run<=maxRun; ++run)
307 test.Printf(_L("\n\nOOM -- Run %d\n"), run);
308 err = session.SetServerHeapFail(run);
309 if(err == KErrNoMemory)
311 // Reinitialisation failed
312 test.Printf(_L("\tReinitialisation failed\n"));
313 session.ResetServerHeapFail();
318 // Failed to set heap fail, maybe the previous loop crashed the server??
319 test.Printf(_L("Failed to set heap fail with error code %d\n"), err);
325 //test.Start(_L("TestFlurry"));
326 test.Printf(_L("TestFlurry\n"));
327 TRAP(err, TestFlurryL());
328 test.Printf(_L("TestRUpsManagementL\n"));
329 TRAP(err2, TestRUpsManagementL());
334 test.Printf(_L("done\n"));
336 // Clear the heap fail
337 test.Printf(_L("Reseting heap failure\n"));
338 err2 = session.ResetServerHeapFail();
339 if((err == KErrServerTerminated) || (err2 == KErrServerTerminated))
341 test.Printf(_L("\tUPS server died\n"));
345 if((err == KErrNone) && (err2 != KErrNone))
360 if(passingRuns > passThreshold) break;
368 // Synchronous call to shutdown the server
369 session.ShutdownServer();
370 // Close top level session (low level session was closed by
371 // ShutdownServer, but we still need to do the RUpsSession
373 CleanupStack::PopAndDestroy(&session);
375 (void) fs.Delete(notifierConfig);
376 CleanupStack::PopAndDestroy(&fs);
382 void PanicIfError(TInt r)
386 User::Panic(_L("upstestoom failed: "), r);
391 // -------- entrypoint --------
394 Executable entrypoint establishes connection with UPS server
395 and then invokes tests for each functional area.
397 @return Symbian OS error code where KErrNone indicates
398 success and any other value indicates failure.
401 // disable lazy DLL unloading so kernel heap balances at end
403 PanicIfError(l.Connect());
404 PanicIfError(l.CancelLazyDllUnload());
410 // allocating a cleanup stack also installs it
411 CTrapCleanup* tc = CTrapCleanup::New();