|
1 // Copyright (c) 2008-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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @test |
|
19 @internalComponent - Internal Symbian test code |
|
20 */ |
|
21 |
|
22 #include "ssmserverpanic.h" |
|
23 #include "ssmswppolicyframe.h" |
|
24 #include "ssmswppolicyresolver.h" |
|
25 #include "ssmswptransitionengine.h" |
|
26 #include "ssmswptransitionscheduler.h" |
|
27 #include "ssmswprequesthandler.h" |
|
28 #include "clesessionproxy.h" |
|
29 |
|
30 #include "ssmatest_utils.h" |
|
31 #include "tssm_step_validswplist.h" |
|
32 #include "tssm_swppolicy_invalidlist.h" |
|
33 |
|
34 |
|
35 const TInt KTestInvalidPanicCategory = -988; |
|
36 _LIT(KSsmSwpPolicyServerName, "TestSsmSwpPolicyServer"); |
|
37 |
|
38 //---------------------------------------------------------------------------------------------------------------- |
|
39 //---------------------------------------- Thread creation framework --------------------------------------------- |
|
40 //---------------------------------------------------------------------------------------------------------------- |
|
41 |
|
42 |
|
43 /** |
|
44 Test framework to check for panic scenarios |
|
45 It requires to create a separate thread so we can check the panic category and code. |
|
46 */ |
|
47 TInt StartSwpInvalidListInThreadL(CSsmValidSwpListTest* aSsmValidSwpListTest) |
|
48 { |
|
49 RThread thread; |
|
50 // Give each thread a unique name to avoid KErrAlreadyExists error on thread creation |
|
51 _LIT(KThreadNamePrefix, "SsmTestThread"); |
|
52 |
|
53 RBuf threadName; |
|
54 CleanupClosePushL(threadName); |
|
55 threadName.CreateL(KThreadNamePrefix().Length() + 6); // 6 digit thread number |
|
56 threadName = KThreadNamePrefix; |
|
57 threadName.AppendNumFixedWidth(aSsmValidSwpListTest->Function(), EDecimal, 6); |
|
58 const TInt KMinHeapSize = 0xc800; // 50k - NOTE just an arbitrary value, please feel free to change it |
|
59 const TInt KMaxHeapSize = 0x19000; // 100k - NOTE just an arbitrary value, please feel free to change it |
|
60 User::LeaveIfError(thread.Create(threadName, ThreadStartSwpInvalidListFn, KDefaultStackSize, KMinHeapSize, KMaxHeapSize, aSsmValidSwpListTest)); |
|
61 CleanupStack::PopAndDestroy(&threadName); |
|
62 TRequestStatus status; |
|
63 thread.Logon(status); |
|
64 TBool jit = User::JustInTime(); |
|
65 User::SetJustInTime(EFalse); |
|
66 thread.Resume(); |
|
67 User::WaitForRequest(status); |
|
68 |
|
69 // always expecting a state transition engine panic |
|
70 TExitCategoryName category = thread.ExitCategory(); |
|
71 if (category.Compare(KPanicSysStateMgr) != 0) |
|
72 { |
|
73 User::Leave(KTestInvalidPanicCategory); |
|
74 } |
|
75 const TInt exitReason = thread.ExitReason(); |
|
76 thread.Close(); |
|
77 User::SetJustInTime(jit); |
|
78 |
|
79 // return the exit reason for the caller to verify the expected panic value |
|
80 return exitReason; |
|
81 } |
|
82 |
|
83 TInt ThreadStartSwpInvalidListFn(TAny* aPtr) |
|
84 { |
|
85 CTrapCleanup* trapCleanup = CTrapCleanup::New(); |
|
86 if (!trapCleanup) |
|
87 { |
|
88 return KErrNoMemory; |
|
89 } |
|
90 |
|
91 CSsmValidSwpListTest* ssmValidSwpListTest = static_cast<CSsmValidSwpListTest*>(aPtr); |
|
92 TRAPD(err, ThreadDispatchSwpInvalidListFunctionL(ssmValidSwpListTest)); |
|
93 |
|
94 delete trapCleanup; |
|
95 return err; |
|
96 } |
|
97 |
|
98 void ThreadDispatchSwpInvalidListFunctionL(CSsmValidSwpListTest* aSsmValidSwpListTest) |
|
99 { |
|
100 CActiveScheduler* sched = new(ELeave) CActiveScheduler(); |
|
101 CleanupStack::PushL(sched); |
|
102 CActiveScheduler::Install(sched); |
|
103 |
|
104 // property uids should be real uids (use these temporarily for test purposes) |
|
105 const TUint key={0x01}; |
|
106 |
|
107 // Create a swp policy resolver and register our property |
|
108 CSsmSwpPolicyResolver* resolver = CSsmSwpPolicyResolver::NewL(); |
|
109 CleanupStack::PushL(resolver); |
|
110 resolver->RegisterSwpMappingL(key, KTestSwpPolicyInvalidListFile); |
|
111 |
|
112 |
|
113 // Create a cle session proxy |
|
114 CCleSessionProxy* cleSession = CCleSessionProxy::NewL(); |
|
115 CleanupStack::PushL(cleSession); |
|
116 cleSession->ConnectL(); |
|
117 |
|
118 // Create the swp request handler and wire it up to the proxies |
|
119 CSsmSwpRequestHandler* handler = CSsmSwpRequestHandler::NewL(); |
|
120 handler->SetSwpPolicyResolverProxy(resolver); |
|
121 handler->SetCleSessionProxy(cleSession); |
|
122 CleanupStack::Pop(cleSession); |
|
123 CleanupStack::Pop(resolver); |
|
124 CleanupStack::PushL(handler); |
|
125 |
|
126 //To get the handle to testssmswppolicyserver, since we have to test the exit reason |
|
127 if (aSsmValidSwpListTest->Function() == ESwpCmdTooManyMultipleWaitErr1) |
|
128 aSsmValidSwpListTest->GetSsmSwpPolicyServerThreadIdL(); |
|
129 |
|
130 //Request transition according to the reason action, which will define the invalid list |
|
131 const TSsmSwp swp(key, aSsmValidSwpListTest->Function()); |
|
132 handler->SubmitRequestL(swp); |
|
133 |
|
134 sched->Start(); |
|
135 |
|
136 CleanupStack::PopAndDestroy(3, sched); |
|
137 } |
|
138 |
|
139 |
|
140 |
|
141 //---------------- CSsmValidSwpListTest step --------------------------------------- |
|
142 |
|
143 |
|
144 CSsmValidSwpListTest::~CSsmValidSwpListTest() |
|
145 { |
|
146 iThread.Close(); |
|
147 } |
|
148 |
|
149 CSsmValidSwpListTest::CSsmValidSwpListTest() |
|
150 { |
|
151 SetTestStepName(KTSsmValidSwpListStep); |
|
152 } |
|
153 |
|
154 TVerdict CSsmValidSwpListTest::doTestStepPreambleL() |
|
155 { |
|
156 return CTestStep::doTestStepPreambleL(); |
|
157 } |
|
158 |
|
159 TVerdict CSsmValidSwpListTest::doTestStepPostambleL() |
|
160 { |
|
161 return CTestStep::doTestStepPostambleL(); |
|
162 } |
|
163 |
|
164 TInt CSsmValidSwpListTest::Function() |
|
165 { |
|
166 return iFunction; |
|
167 } |
|
168 |
|
169 void CSsmValidSwpListTest::SetFunction(TInt aFunction) |
|
170 { |
|
171 iFunction = aFunction; |
|
172 } |
|
173 |
|
174 void CSsmValidSwpListTest::GetSsmSwpPolicyServerThreadIdL() |
|
175 { |
|
176 TPtrC ptr(KSsmSwpPolicyServerName()); |
|
177 TFullName procSerchTerm(_L("*")); |
|
178 procSerchTerm += ptr; |
|
179 ptr.Set(ptr.Ptr(), KSsmSwpPolicyServerName().Length()); |
|
180 procSerchTerm += _L("*"); |
|
181 |
|
182 TFindThread find(procSerchTerm); |
|
183 TFullName name; |
|
184 TInt err = find.Next(name); |
|
185 TEST(err == KErrNone); |
|
186 User::LeaveIfError(err); |
|
187 |
|
188 err = iThread.Open(find); |
|
189 TEST(err == KErrNone); |
|
190 User::LeaveIfError(err); |
|
191 } |
|
192 |
|
193 /** |
|
194 Old Test CaseID APPFWK-SSM-0012 |
|
195 New Test CaseID DEVSRVS-SSMA-SSM-0012 |
|
196 */ |
|
197 TVerdict CSsmValidSwpListTest::doTestStepL() |
|
198 { |
|
199 INFO_PRINTF1(_L("CSsmValidSwpListTest started....")); |
|
200 |
|
201 __UHEAP_MARK; |
|
202 |
|
203 INFO_PRINTF1(_L("Checking cmd list without a Publish System Swp command")); |
|
204 TInt exitReason(0); |
|
205 SetFunction(ESwpCmdWithoutPublishSwp); |
|
206 TRAPD(err, exitReason = StartSwpInvalidListInThreadL(this)); |
|
207 TEST(err == KErrNone); |
|
208 INFO_PRINTF2(_L(" -- StartSwpInvalidListInThreadL method completed with '%d'."), err); |
|
209 TEST(exitReason == ESwpTransitionEngineError16); |
|
210 INFO_PRINTF3(_L(" -- received panic '%d', expected was '%d'."), exitReason, ESwpTransitionEngineError16); |
|
211 |
|
212 INFO_PRINTF1(_L("Checking cmd list with more than one Publish System Swp command")); |
|
213 exitReason=0; |
|
214 SetFunction(ESwpCmdTwoPublishSwp); |
|
215 TRAP(err, exitReason = StartSwpInvalidListInThreadL(this)); |
|
216 TEST(err == KErrNone); |
|
217 INFO_PRINTF2(_L(" -- StartSwpInvalidListInThreadL method completed with '%d'."), err); |
|
218 TEST(exitReason == ESwpTransitionEngineError16); |
|
219 INFO_PRINTF3(_L(" -- received panic '%d', expected was '%d'."), exitReason, ESwpTransitionEngineError16); |
|
220 |
|
221 INFO_PRINTF1(_L("Checking cmd list with a Publish System State")); |
|
222 exitReason=0; |
|
223 SetFunction(ESwpCmdPublishState); |
|
224 TRAP(err, exitReason = StartSwpInvalidListInThreadL(this)); |
|
225 TEST(err == KErrNone); |
|
226 INFO_PRINTF2(_L(" -- StartSwpInvalidListInThreadL method completed with '%d'."), err); |
|
227 TEST(exitReason == ESwpTransitionEngineError16); |
|
228 INFO_PRINTF3(_L(" -- received panic '%d', expected was '%d'."), exitReason, ESwpTransitionEngineError16); |
|
229 |
|
230 INFO_PRINTF1(_L("Checking cmd list with no Multiple Wait command and more than one deferred commands")); |
|
231 exitReason=0; |
|
232 SetFunction(ESwpCmdNoMultipleWait); |
|
233 TRAP(err, exitReason = StartSwpInvalidListInThreadL(this)); |
|
234 TEST(err == KErrNone); |
|
235 INFO_PRINTF2(_L(" -- StartSwpInvalidListInThreadL method completed with '%d'."), err); |
|
236 TEST(exitReason == ESwpTransitionEngineError16); |
|
237 INFO_PRINTF3(_L(" -- received panic '%d', expected was '%d'."), exitReason, ESwpTransitionEngineError16); |
|
238 |
|
239 INFO_PRINTF1(_L("Checking cmd list with too many Multiple Wait command and and no deferred commands - Validation should be OK - Panic comes from HandleCleReturnValue")); |
|
240 exitReason=0; |
|
241 SetFunction(ESwpCmdTooManyMultipleWaitErr1); |
|
242 TRAP(err, exitReason = StartSwpInvalidListInThreadL(this)); |
|
243 TEST(err == KErrNone); |
|
244 INFO_PRINTF2(_L(" -- StartSwpInvalidListInThreadL method completed with '%d'."), err); |
|
245 const TInt threadExitReason = iThread.ExitReason(); |
|
246 // This is the exit reason for the ssmswppolicyserver |
|
247 TEST(threadExitReason == KSsmTestAppRvError); |
|
248 // this is the exit reason for the engine. |
|
249 TEST(exitReason == ESwpTransitionEngineError20); |
|
250 iThread.Close(); |
|
251 INFO_PRINTF3(_L(" -- received panic '%d', expected was '%d'."), threadExitReason, KSsmTestAppRvError); |
|
252 |
|
253 INFO_PRINTF1(_L("Checking cmd list with too many Multiple Wait command and and no deferred commands - Validation should be OK - Panic originates in HandleCleReturnValue returning an error")); |
|
254 exitReason=0; |
|
255 SetFunction(ESwpCmdTooManyMultipleWaitErr2); |
|
256 TRAP(err, exitReason = StartSwpInvalidListInThreadL(this)); |
|
257 TEST(err == KErrNone); |
|
258 INFO_PRINTF2(_L(" -- StartSwpInvalidListInThreadL method completed with '%d'."), err); |
|
259 TEST(exitReason == ESwpTransitionEngineError20); |
|
260 INFO_PRINTF3(_L(" -- received panic '%d', expected was '%d'."), exitReason, ESwpTransitionEngineError20); |
|
261 |
|
262 INFO_PRINTF1(_L("Checking cmd list which leaves with an error when it is being prepared")); |
|
263 exitReason=0; |
|
264 SetFunction(ESwpCmdPrepareCmdListFailed); |
|
265 TRAP(err, exitReason = StartSwpInvalidListInThreadL(this)); |
|
266 TEST(err == KErrNone); |
|
267 INFO_PRINTF2(_L(" -- StartSwpInvalidListInThreadL method completed with '%d'."), err); |
|
268 TEST(exitReason == ESwpTransitionEngineError20); |
|
269 INFO_PRINTF3(_L(" -- received panic '%d', expected was '%d'."), exitReason, ESwpTransitionEngineError20); |
|
270 |
|
271 __UHEAP_MARKEND; |
|
272 |
|
273 // this test raises panics due to negative testing - close them to clear the screen. |
|
274 CloseAllPanicWindowsL(); |
|
275 |
|
276 INFO_PRINTF1(_L("....CSsmValidSwpListTest completed!!")); |
|
277 return TestStepResult(); |
|
278 } |
|
279 |
|
280 |