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