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