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