|
1 // Copyright (c) 2004-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 // @file TS_PARAM_SVR_SUITENAMEServer.cpp |
|
15 // for (WINS && !EKA2) versions will be xxxServer.Dll and require a thread to be started |
|
16 // in the process of the client. The client initialises the server by calling the |
|
17 // one and only ordinal. |
|
18 // |
|
19 // |
|
20 |
|
21 // EPOC includes |
|
22 #include <e32base.h> |
|
23 #include <e32cmn.h> |
|
24 |
|
25 #if (!defined TS_PARAM_SVR_SUITENAME_SERVER_H_) |
|
26 #include "CSuite.h" |
|
27 #endif |
|
28 |
|
29 |
|
30 //ADD TEST STEP HEADERS HERE |
|
31 PARAM_FOREACH_MESS_BEGIN |
|
32 #include "PARAM_MESS_NAME_CStep.h" |
|
33 PARAM_FOREACH_MESS_END |
|
34 |
|
35 // __EDIT_ME__ - Substitute the name of your test server |
|
36 _LIT(KServerName,"PARAM_SVR_SUITENAME_sc"); |
|
37 // __EDIT_ME__ - Use your own server class name |
|
38 |
|
39 CTestPARAM_SVR_SUITENAMEServer* CTestPARAM_SVR_SUITENAMEServer::NewL() |
|
40 /** |
|
41 * @return - Instance of the test server |
|
42 * Same code for Secure and non-secure variants |
|
43 * Called inside the MainL() function to create and start the |
|
44 * CTestServer derived server. |
|
45 */ |
|
46 { |
|
47 // __EDIT_ME__ - Use your own server class name |
|
48 CTestPARAM_SVR_SUITENAMEServer * server = new (ELeave) CTestPARAM_SVR_SUITENAMEServer(); |
|
49 CleanupStack::PushL(server); |
|
50 // CServer base class call |
|
51 server->StartL(KServerName); |
|
52 CleanupStack::Pop(server); |
|
53 return server; |
|
54 } |
|
55 |
|
56 CTestStep* CTestPARAM_SVR_SUITENAMEServer::CreateTestStep(const TDesC& aStepName) |
|
57 /** |
|
58 * @return - A CTestStep derived instance |
|
59 * Secure and non-secure variants |
|
60 * Implementation of CTestServer pure virtual |
|
61 */ |
|
62 { |
|
63 CTestStep* testStep = NULL; |
|
64 // add test steps |
|
65 PARAM_FOREACH_MESS_BEGIN |
|
66 if (aStepName == _L("CPARAM_MESS_NAMEStep")) |
|
67 { |
|
68 // removed ELeave as harness will test ptr. This is more efficient |
|
69 // than using TRAP_IGNORE |
|
70 testStep = new CPARAM_MESS_NAMEStep; |
|
71 |
|
72 //return because of PARAM_FOREACH_MESS_BEGIN keyword |
|
73 //which is used by capTestWiz.pl to retrive information from table. |
|
74 return testStep; |
|
75 } |
|
76 |
|
77 PARAM_FOREACH_MESS_END |
|
78 return testStep; |
|
79 } |
|
80 |
|
81 |
|
82 |
|
83 // Secure variants much simpler |
|
84 // Just an E32Main and a MainL() |
|
85 LOCAL_C void MainL() |
|
86 /** |
|
87 * Secure variant |
|
88 * Much simpler, uses the new Rendezvous() call to sync with the client |
|
89 */ |
|
90 { |
|
91 #if (defined __DATA_CAGING__) |
|
92 RProcess().DataCaging(RProcess::EDataCagingOn); |
|
93 RProcess().DataCaging(RProcess::ESecureApiOn); |
|
94 #endif |
|
95 CActiveScheduler* sched=NULL; |
|
96 sched=new(ELeave) CActiveScheduler; |
|
97 CActiveScheduler::Install(sched); |
|
98 // __EDIT_ME__ - Use your own server class name |
|
99 CTestPARAM_SVR_SUITENAMEServer* server = NULL; |
|
100 // Create the CTestServer derived server |
|
101 TRAPD(err,server = CTestPARAM_SVR_SUITENAMEServer::NewL()); |
|
102 if(!err) |
|
103 { |
|
104 // Sync with the client and enter the active scheduler |
|
105 RProcess::Rendezvous(KErrNone); |
|
106 sched->Start(); |
|
107 } |
|
108 delete server; |
|
109 delete sched; |
|
110 } |
|
111 |
|
112 |
|
113 GLDEF_C TInt E32Main() |
|
114 /** |
|
115 * @return - Standard Epoc error code on process exit |
|
116 * Secure variant only |
|
117 * Process entry point. Called by client using RProcess API |
|
118 */ |
|
119 { |
|
120 __UHEAP_MARK; |
|
121 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
122 if(cleanup == NULL) |
|
123 { |
|
124 return KErrNoMemory; |
|
125 } |
|
126 TRAPD(err,MainL()); |
|
127 delete cleanup; |
|
128 __UHEAP_MARKEND; |
|
129 return KErrNone; |
|
130 } |
|
131 |
|
132 |
|
133 TVerdict CCapabilityTestStep::doTestStepPreambleL( void ) |
|
134 { |
|
135 //If Preamble is not required just pass a success value |
|
136 TVerdict testResult = CTestStep::doTestStepPreambleL(); |
|
137 SetTestStepResult(testResult); |
|
138 |
|
139 return TestStepResult(); |
|
140 |
|
141 } |
|
142 TVerdict CCapabilityTestStep::doTestStepPostambleL( void ) |
|
143 { |
|
144 //If Postamble is not required just pass a success value |
|
145 TVerdict testResult = CTestStep::doTestStepPostambleL(); |
|
146 SetTestStepResult(testResult); |
|
147 |
|
148 return TestStepResult(); |
|
149 |
|
150 } |
|
151 |
|
152 |
|
153 // Moved from CStep.cpp |
|
154 |
|
155 enum TVerdict CCapabilityTestStep::doTestStepL() |
|
156 { |
|
157 //DEF! INFO_PRINTF2(_L("%S - Starting ..."), &iTestStepName); |
|
158 |
|
159 //The MainThread()creates a separate thread that executes SendReceive |
|
160 TVerdict vResult = MainThread(); |
|
161 |
|
162 SetTestStepResult(vResult); |
|
163 return TestStepResult(); |
|
164 } |
|
165 |
|
166 /* |
|
167 ThreadStartFn: |
|
168 Called by: The Child thread |
|
169 Function: Calls the Exec_SendReceive |
|
170 */ |
|
171 static TInt ThreadStartFn( TAny * ptr ) |
|
172 { |
|
173 return(((CCapabilityTestStep *)ptr)->Exec_SendReceive()); |
|
174 } |
|
175 |
|
176 /* |
|
177 TVerdict GetVerdict(TInt aAPIretValue) |
|
178 |
|
179 Called by: "MainThread" for returning verdict |
|
180 |
|
181 Parameters(TInt aRetValue) : 0 if API call gets thru without any rejection |
|
182 1 if API call is rejected for capability error |
|
183 */ |
|
184 enum TVerdict CCapabilityTestStep::GetVerdict(TInt aAPIretValue) |
|
185 { |
|
186 TSecurityInfo info; |
|
187 info.Set(RProcess()); |
|
188 |
|
189 // INFO_PRINTF4(_L("The loaded Process has: capability: %x with SID:%x and VID: %x"), info.iCaps,info.iSecureId, info.iVendorId); |
|
190 INFO_PRINTF1(_L(" ")); |
|
191 INFO_PRINTF2(_L("The capability of the loaded Process is [%x] "), info.iCaps); |
|
192 INFO_PRINTF2(_L("The required capability for the test step is [%x] "), iStepCap); |
|
193 INFO_PRINTF1(_L("Therefore ... ")); |
|
194 TVerdict vVerdict[] = {EPass, EFail}; |
|
195 |
|
196 //please leave the following if/else block as the information printed by INFO_PRINTF1 is used bu CapTestSumm |
|
197 if(iExpect_Rejection)//[Inverse Test] EPass for 1 while EFail for 0 |
|
198 { |
|
199 INFO_PRINTF1(_L("Test Expected to Fail due to lack of capabilities")); |
|
200 return vVerdict[(aAPIretValue)?0:1]; |
|
201 |
|
202 } |
|
203 else //[Direct Test] EPass for 0 while EFail for 1 |
|
204 { |
|
205 INFO_PRINTF1(_L("Test Expected to Pass with correct capabilities")); |
|
206 return vVerdict[(aAPIretValue)?1:0]; |
|
207 } |
|
208 } |
|
209 |
|
210 |
|
211 /* |
|
212 TVerdict MainThread() |
|
213 |
|
214 Called by: "doTestStepL" |
|
215 |
|
216 Purpose: Creates the child thread(which calls the respective function with regard |
|
217 to the server and also implements the Message Call). Then this fn.waits for the |
|
218 completion of the childthread( doesnt matter how the thread did die!) |
|
219 |
|
220 Return Value(Verdict of the TestStep): |
|
221 |
|
222 A.Reporting PASS/FAIL |
|
223 Direct Test: |
|
224 When a message call gets thru. Please note that in such cases |
|
225 actually the implementation of the message has started. As we |
|
226 are passing "0" Parameters, server may panic, though our botheration |
|
227 stops once the call gets thru. |
|
228 NOTE: The style is the same when CONNECTION capabilities |
|
229 are tested, the only diff is you dont have to expect a |
|
230 panic from server |
|
231 Inverse Test: |
|
232 The call should be either failed or panicked with |
|
233 "KErrPermissionDenied" flag. |
|
234 |
|
235 General Case: |
|
236 If a thread creation failed or if the server couldnt be connected |
|
237 apart from the above two cases, then a FAIL is reported |
|
238 |
|
239 B.Reporting INCONCLUSIVE |
|
240 Any panic say from unexpected source (eg:KERN-EXEC) will be |
|
241 reported INCONCLUSIVE |
|
242 */ |
|
243 TVerdict CCapabilityTestStep::MainThread() |
|
244 { |
|
245 |
|
246 TBuf<100> tExitCategory; |
|
247 TInt tExitReason = 0; |
|
248 TBuf<100> TestStyle; |
|
249 |
|
250 iExpect_Rejection?TestStyle = _L("Inverse"):TestStyle = _L("Direct"); |
|
251 //TCapabilitySet theCaps = TSecurityInfo(RProcess()).iCaps ; |
|
252 const TInt KMaxTestThreadHeapSize = 0x10000; |
|
253 |
|
254 //Initialize return values |
|
255 iResult_SR = iResult_Server = KErrNone; |
|
256 |
|
257 |
|
258 // Create a child thread, with a new heap |
|
259 TInt nRes_Thread = tChildThread.Create( |
|
260 ChildThread_SR, |
|
261 ThreadStartFn, |
|
262 KDefaultStackSize, |
|
263 KMinHeapSize, |
|
264 KMaxTestThreadHeapSize, |
|
265 this, |
|
266 EOwnerProcess); |
|
267 |
|
268 |
|
269 if(nRes_Thread == KErrNone)//Thread Created |
|
270 { |
|
271 |
|
272 //Let me know when the thread is dead |
|
273 TRequestStatus ThreadStatus; |
|
274 tChildThread.Logon(ThreadStatus); |
|
275 tChildThread.Resume(); |
|
276 //Is the thread dead? |
|
277 User::WaitForRequest( ThreadStatus ); |
|
278 |
|
279 //yes, he is dead. RIP! Now the Killer's profile |
|
280 tExitCategory = tChildThread.ExitCategory(); |
|
281 tExitReason = tChildThread.ExitReason(); |
|
282 |
|
283 |
|
284 //Somebody Please say what are we testing!! |
|
285 if(iSessionCreated && (SR_MESSAGE_ID >=0))//Flag set by Child thread when connected to Server |
|
286 { |
|
287 //DEF INFO_PRINTF5(_L("Connected to Server(%S) for %S Test [MessageID: %d,Req.Cap: 0x%x,Present.Cap: 0x%x]"),&SR_ServerName,&TestStyle,SR_MESSAGE_ID,iStepCap,TSecurityInfo(RProcess())); |
|
288 } |
|
289 else if(SR_MESSAGE_ID < 0) |
|
290 { |
|
291 //DEF INFO_PRINTF5(_L("Testing Connection capabilities[%S Test] for Server(%S) [Req.Cap: 0x%x,Present.Cap: 0x%x]"),&TestStyle, |
|
292 //&SR_ServerName,TSecurityInfo(RProcess())); |
|
293 } |
|
294 else if(!iSessionCreated)// NO Connection |
|
295 { |
|
296 INFO_PRINTF4(_L("Couldnt connect to the Server(%S) ErrorCode - ServerRet: %d C32ret: %d"),&SR_ServerName,iResult_Server,iResult_C32); |
|
297 //INFO_PRINTF3(_L("Child Thread: ExitCategory : %S ExitReason : %d"),&tExitCategory,tExitReason); |
|
298 return EFail; |
|
299 } |
|
300 |
|
301 |
|
302 |
|
303 switch(tChildThread.ExitType()) |
|
304 { |
|
305 case EExitPanic: |
|
306 //1.A Panic from the connected Server |
|
307 //2.A CServer Panic normally for capability rejection |
|
308 //3.A kernel Panic (consider yourself doomed!) |
|
309 if((tExitReason == KErrPermissionDenied) || |
|
310 //DEF ? it's old version (tExitReason == CServer::EClientDoesntHaveRequiredCaps))//Rejected for Insufficient Cap. |
|
311 // is it correct ? |
|
312 (tExitReason == CServer2::EClientDoesntHaveRequiredCaps))//Rejected for Insufficient Cap. |
|
313 { |
|
314 INFO_PRINTF2(_L("Rejected for insufficient capabilities [Return Value : %d] "),tExitReason); |
|
315 return(GetVerdict(API_RetValue_PermissionDenied)); |
|
316 } |
|
317 else if(tExitCategory == iServer_Panic) //Panic from Server |
|
318 { |
|
319 INFO_PRINTF2(_L("Server(%S) Panic to child thread"),&tExitCategory); |
|
320 INFO_PRINTF3(_L("Child Thread: ExitCategory : %S ExitReason : %d"),&tExitCategory,tExitReason); |
|
321 return(GetVerdict(API_RetValue_ServerPanic)); |
|
322 } |
|
323 else//A kernel Panic possibly |
|
324 { |
|
325 INFO_PRINTF3(_L("Child Thread: Panic from unexpected source (ExitCategory: %S ExitReason : %d)!"),&tExitCategory,tExitReason); |
|
326 return EInconclusive; |
|
327 } |
|
328 |
|
329 case EExitKill: |
|
330 if(iResult_SR != KErrPermissionDenied) |
|
331 { |
|
332 INFO_PRINTF2(_L("A Successfull call (Return Value : %d)"),((SR_MESSAGE_ID >=0)?iResult_SR:iResult_Server)); |
|
333 return(GetVerdict(API_RetValue_NoCapError)); |
|
334 } |
|
335 else |
|
336 { |
|
337 INFO_PRINTF2(_L("Rejected for insufficient capabilities [Return Value : %d] "),((SR_MESSAGE_ID >=0)?iResult_SR:iResult_Server)); |
|
338 return(GetVerdict(API_RetValue_PermissionDenied)); |
|
339 } |
|
340 |
|
341 default: |
|
342 break; |
|
343 } |
|
344 } |
|
345 else //Our thread couldnt start :o( |
|
346 { |
|
347 INFO_PRINTF2(_L("ERROR: Failed to create Child thread, ErrorCode:(%d)"),nRes_Thread); |
|
348 return EFail; |
|
349 } |
|
350 |
|
351 return EInconclusive; |
|
352 } |
|
353 |
|
354 TInt CCapabilityTestStep::StartServer() |
|
355 { |
|
356 TInt err = KErrNone ; |
|
357 // EKA2 is simple No path required |
|
358 TBuf<32> serverFile; |
|
359 serverFile.Copy(_L("PARAM_SVR_SUITENAME")); |
|
360 _LIT(KExe,".exe"); |
|
361 serverFile.Append(KExe); |
|
362 RProcess server; |
|
363 err = server.Create(serverFile,_L("")); |
|
364 if(err != KErrNone) |
|
365 return err; |
|
366 // Synchronise with the server |
|
367 TRequestStatus reqStatus; |
|
368 server.Rendezvous(reqStatus); |
|
369 server.Resume(); |
|
370 //Server will call the reciprocal static synchronise call |
|
371 User::WaitForRequest(reqStatus); |
|
372 //server.Close(); |
|
373 if(reqStatus.Int() != KErrNone) |
|
374 return reqStatus.Int(); |
|
375 server.Close(); |
|
376 return err; |
|
377 } |
|
378 |
|
379 TInt CCapabilityTestStep::TestDebugHeap(TInt* iDbgIPCNo) |
|
380 { |
|
381 |
|
382 //TDbgFns {MarkHeapStart, MarkHeapEnd, CheckHeap, FailNext, ResetFailNext}; |
|
383 TInt aFnToTest= iDbgIPCNo[5]; |
|
384 |
|
385 |
|
386 TInt iResult_SR [6] ={0}; |
|
387 TInt i = 1; |
|
388 TInt testedFn = 0; |
|
389 |
|
390 TInt dbgTestSequence[5][6] = { {MarkHeapStart ,2,0,1,-1,-1}, |
|
391 {MarkHeapEnd ,2,0,1,-1,-1}, |
|
392 {CheckHeap ,3,0,2, 1,-1}, |
|
393 {FailNext ,4,0,3, 4, 1}, |
|
394 {ResetFailNext ,4,0,3, 4, 1} |
|
395 |
|
396 }; |
|
397 |
|
398 |
|
399 TInt aCount = dbgTestSequence[aFnToTest][i]; |
|
400 |
|
401 while(aCount-- ) |
|
402 { |
|
403 testedFn = dbgTestSequence[aFnToTest][(++i)]; |
|
404 |
|
405 iResult_SR[testedFn ]= SendReceive( iDbgIPCNo[testedFn],TIpcArgs(((iDbgIPCNo[testedFn]==3 )?4:0),0,0,0)); |
|
406 |
|
407 |
|
408 if( ((testedFn !=aFnToTest)?iResult_SR[testedFn]:KErrNone) == KErrPermissionDenied) |
|
409 |
|
410 User::Panic(_L("Failed at Initialization"),iResult_SR[testedFn]); |
|
411 |
|
412 } |
|
413 |
|
414 return iResult_SR[aFnToTest]; |
|
415 } |
|
416 |
|
417 |
|
418 |