|
1 // Copyright (c) 2005-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 the License "Symbian Foundation License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // The following tests are performed to test the Child behaviour on its Parent's termination. |
|
15 // |
|
16 // |
|
17 |
|
18 |
|
19 |
|
20 /** |
|
21 @file |
|
22 @test |
|
23 @internalComponent - Internal Symbian test code |
|
24 */ |
|
25 |
|
26 #include "T_ProcStep.h" |
|
27 const TInt KTProcTerminatingChildI = 1246; |
|
28 const TInt KTProcTerminatingChildII = 1247; |
|
29 const TInt KTProcTerminatingChildIII = 1248; |
|
30 const TInt KTProcTerminatingParent = 1249; |
|
31 |
|
32 CChildProcess* CChildProcess::NewL(RProcess& aParentProcess,TProcessId aChildProcessId) |
|
33 { |
|
34 CChildProcess* self= new(ELeave) CChildProcess(aParentProcess,aChildProcessId); |
|
35 CleanupStack::PushL(self); |
|
36 self->ConstructL(); |
|
37 CleanupStack::Pop(); |
|
38 return self; |
|
39 } |
|
40 |
|
41 CChildProcess::~CChildProcess() |
|
42 /** |
|
43 * Destructor |
|
44 */ |
|
45 { |
|
46 Cancel(); |
|
47 } |
|
48 |
|
49 void CChildProcess::ConstructL() |
|
50 /** |
|
51 * Sets active, so that control goes into RunL() |
|
52 * where parent is terminated and child process logged on. |
|
53 */ |
|
54 { |
|
55 User::LeaveIfError(iChildProcess.Open(iChildProcessId)); |
|
56 SetActive(); |
|
57 TRequestStatus *status=&iStatus; |
|
58 User::RequestComplete(status,KErrNone); |
|
59 CActiveScheduler::Start(); |
|
60 } |
|
61 |
|
62 CChildProcess::CChildProcess(RProcess& aParentProcess,TProcessId aChildProcessId):CActive(0),iChildProcessId(aChildProcessId),iParentProcess(aParentProcess),iCount(0) |
|
63 { |
|
64 CActiveScheduler::Add(this); |
|
65 } |
|
66 |
|
67 void CChildProcess::RunL() |
|
68 /** |
|
69 * Opens the parent process, on failure leaves. |
|
70 * Logs on the child process status, sets it active and terminates the parent process. |
|
71 * When child terminates scheduler is stopped. |
|
72 */ |
|
73 { |
|
74 switch(iCount) |
|
75 { |
|
76 case 0: |
|
77 iCount++; |
|
78 iChildProcess.Logon(iStatus); |
|
79 SetActive(); |
|
80 iParentProcess.Terminate(KErrNone); |
|
81 break; |
|
82 case 1: |
|
83 CActiveScheduler::Stop(); |
|
84 default: |
|
85 break; |
|
86 } |
|
87 } |
|
88 |
|
89 void CChildProcess::DoCancel() |
|
90 { |
|
91 switch(iCount) |
|
92 { |
|
93 case 0: |
|
94 iChildProcess.LogonCancel(iStatus); |
|
95 iCount++; |
|
96 break; |
|
97 case 1: |
|
98 iChildProcess.LogonCancel(iStatus); |
|
99 break; |
|
100 default: |
|
101 break; |
|
102 } |
|
103 } |
|
104 |
|
105 |
|
106 //////////////////////////////////////////////////////////////////////////// |
|
107 // |
|
108 // T_ProcStep.cpp |
|
109 // ------------ |
|
110 // |
|
111 // Implements the test cases to test Child behaviour on Parent termination. |
|
112 // |
|
113 //////////////////////////////////////////////////////////////////////////// |
|
114 |
|
115 CT_ProcStep::CT_ProcStep() |
|
116 /** |
|
117 * Constructor |
|
118 */ |
|
119 { |
|
120 } |
|
121 |
|
122 |
|
123 CT_ProcStep::~CT_ProcStep() |
|
124 /** |
|
125 * Destructor |
|
126 */ |
|
127 { |
|
128 } |
|
129 |
|
130 /** |
|
131 @SYMTestCaseID APPFWK-APPARC-0015 |
|
132 |
|
133 @SYMPREQ PREQ1123 |
|
134 |
|
135 @SYMTestCaseDesc The Test determines that the Child dies when its Parent is terminated. |
|
136 |
|
137 @SYMTestPriority Critical |
|
138 |
|
139 @SYMTestStatus Implemented |
|
140 |
|
141 @SYMTestActions. Creates and launches a process (parent). Creates another process (child) passing the first(parent) process ID. |
|
142 Launches the child process. Terminates parent and checks the existance of child process. The child should die. |
|
143 API Calls:\n |
|
144 RProcess::Create(const TDesC &aFileName, const TDesC &aCommand, TOwnerType aType=EOwnerProcess);\n |
|
145 RProcess::Resume(); |
|
146 RProcess::ExitType() const; |
|
147 RProcess::ExitReason() const; |
|
148 RProcess::Id() const; |
|
149 CApaCommandLine::SetProcessEnvironmentL(RProcess &aProcess) const; |
|
150 CApaCommandLine::NewLC(); |
|
151 CApaCommandLine::SetParentProcessId(TProcessId); |
|
152 |
|
153 @SYMTestExpectedResults Termination of child process automatically.\n |
|
154 |
|
155 */ |
|
156 void CT_ProcStep::testChildSetToTerminateL(void) |
|
157 { |
|
158 TInt ret(0); |
|
159 |
|
160 //commandline for parent process |
|
161 CApaCommandLine* parentProcCmdln=CApaCommandLine::NewLC(); |
|
162 INFO_PRINTF1(_L(" CommandLine for Parent Process created ")); |
|
163 |
|
164 //parent process |
|
165 RProcess parentProc; |
|
166 ret = parentProc.Create(KParentExe,KNullDesC); |
|
167 TEST(ret == KErrNone); |
|
168 User::LeaveIfError(ret); |
|
169 CleanupClosePushL(parentProc); |
|
170 INFO_PRINTF2(_L(" Create Parent Process returned : %d"),ret); |
|
171 |
|
172 //attach commandline to parent process |
|
173 TRAP(ret,parentProcCmdln->SetProcessEnvironmentL(parentProc)); |
|
174 TEST(ret == KErrNone); |
|
175 User::LeaveIfError(ret); |
|
176 INFO_PRINTF1(_L(" Attach CommandLine to Process ")); |
|
177 |
|
178 INFO_PRINTF1(_L(" Run Parent Process ")); |
|
179 parentProc.Resume(); |
|
180 //Time for the parent process to launch itself |
|
181 User::After(500000); |
|
182 |
|
183 //commandline for child process |
|
184 //Get parent process ID here |
|
185 TUint64 parentProcId = parentProc.Id(); |
|
186 INFO_PRINTF2(_L(" Parent Process Id = 0x%lx "),parentProcId); |
|
187 |
|
188 CApaCommandLine* childProcCmdln=CApaCommandLine::NewLC(); |
|
189 INFO_PRINTF1(_L(" CommandLine for Child Process created ")); |
|
190 |
|
191 //setting the parent process ID to child |
|
192 childProcCmdln->SetParentProcessId(parentProcId); |
|
193 INFO_PRINTF1(_L(" Set ParentProcessId to Child ")); |
|
194 |
|
195 //child process |
|
196 RProcess childProc; |
|
197 ret = childProc.Create(KChildOneExe,KNullDesC); |
|
198 TEST(ret == KErrNone); |
|
199 User::LeaveIfError(ret); |
|
200 CleanupClosePushL(childProc); |
|
201 |
|
202 INFO_PRINTF2(_L(" Create Child Process returned : %d"),ret); |
|
203 |
|
204 //attach commandline to child process |
|
205 TRAP(ret,childProcCmdln->SetProcessEnvironmentL(childProc)); |
|
206 TEST(ret == KErrNone); |
|
207 User::LeaveIfError(ret); |
|
208 INFO_PRINTF1(_L(" Attach CommandLine to Process ")); |
|
209 |
|
210 INFO_PRINTF1(_L(" Run Child Process ")); |
|
211 childProc.Resume(); |
|
212 //Time for the child process to launch itself |
|
213 User::After(500000); |
|
214 |
|
215 //child process Id is reqd to monitor if it gets killed on its parent's termination |
|
216 TUint64 childProcId = childProc.Id(); |
|
217 INFO_PRINTF2(_L(" Child Process Id = 0x%lx "),childProcId); |
|
218 |
|
219 CChildProcess* childProcess=NULL; |
|
220 TRAP(ret, childProcess=CChildProcess::NewL(parentProc,childProcId)); |
|
221 TEST(ret == KErrNone); |
|
222 User::LeaveIfError(ret); |
|
223 CleanupStack::PushL(childProcess); |
|
224 |
|
225 TExitType exitType = parentProc.ExitType(); |
|
226 TEST(exitType == EExitTerminate); |
|
227 TInt exitReason = parentProc.ExitReason(); |
|
228 TEST(exitReason == 0); |
|
229 if(exitType==EExitTerminate && exitReason==0) |
|
230 { |
|
231 INFO_PRINTF1(_L(" Parent process is Terminated")); |
|
232 } |
|
233 |
|
234 exitType = childProc.ExitType(); |
|
235 TEST(exitType == EExitTerminate); |
|
236 exitReason = childProc.ExitReason(); |
|
237 TEST(exitReason == 0); |
|
238 if(exitType == EExitTerminate && exitReason==0) |
|
239 { |
|
240 INFO_PRINTF1(_L(" The child process is killed automatically ... ")); |
|
241 } |
|
242 |
|
243 CleanupStack::PopAndDestroy(childProcess); |
|
244 CleanupStack::PopAndDestroy(&childProc); |
|
245 CleanupStack::PopAndDestroy(childProcCmdln); |
|
246 CleanupStack::PopAndDestroy(&parentProc); |
|
247 CleanupStack::PopAndDestroy(parentProcCmdln); |
|
248 } |
|
249 |
|
250 /** |
|
251 @SYMTestCaseID APPFWK-APPARC-0016 |
|
252 |
|
253 @SYMPREQ PREQ1123 |
|
254 |
|
255 @SYMTestCaseDesc Test determines that the Child remains when its Parent is terminated. |
|
256 |
|
257 @SYMTestPriority Critical |
|
258 |
|
259 @SYMTestStatus Implemented |
|
260 |
|
261 @SYMTestActions. Creates and launches a process (parent). Creates another process (child) without passing the first(parent) process ID. |
|
262 Launches the child process. Terminates parent and checks the existance of child process. The child process should be alive. |
|
263 API Calls:\n |
|
264 RProcess::Create(const TDesC &aFileName, const TDesC &aCommand, TOwnerType aType=EOwnerProcess);\n |
|
265 RProcess::Resume(); |
|
266 RProcess::ExitType() const; |
|
267 RProcess::ExitReason() const; |
|
268 RProcess::Id() const; |
|
269 RProcess::Terminate(TInt aReason); |
|
270 CApaCommandLine::SetProcessEnvironmentL(RProcess &aProcess) const; |
|
271 CApaCommandLine::NewLC(); |
|
272 |
|
273 @SYMTestExpectedResults Existence of child process.\n |
|
274 |
|
275 */ |
|
276 void CT_ProcStep::testChildSetToRemainL(void) |
|
277 { |
|
278 TInt ret(0); |
|
279 |
|
280 //commandline for parent process |
|
281 CApaCommandLine* parentProcCmdln=CApaCommandLine::NewLC(); |
|
282 INFO_PRINTF1(_L(" CommandLine for Parent Process created ")); |
|
283 |
|
284 //parent process |
|
285 RProcess parentProc; |
|
286 ret = parentProc.Create(KParentExe,KNullDesC); |
|
287 TEST(ret == KErrNone); |
|
288 User::LeaveIfError(ret); |
|
289 CleanupClosePushL(parentProc); |
|
290 INFO_PRINTF2(_L(" Create Parent Process returned : %d"),ret); |
|
291 |
|
292 //attach commandline to parent process |
|
293 TRAP(ret,parentProcCmdln->SetProcessEnvironmentL(parentProc)); |
|
294 TEST(ret == KErrNone); |
|
295 User::LeaveIfError(ret); |
|
296 INFO_PRINTF1(_L(" Attach CommandLine to Process ")); |
|
297 |
|
298 INFO_PRINTF1(_L(" Run Parent Process ")); |
|
299 parentProc.Resume(); |
|
300 //Time for the parent process to launch itself |
|
301 User::After(500000); |
|
302 |
|
303 //commandline for child process |
|
304 //Get parent process ID here |
|
305 TUint64 parentProcId = parentProc.Id(); |
|
306 INFO_PRINTF2(_L(" Parent Process Id = 0x%lx "),parentProcId); |
|
307 |
|
308 CApaCommandLine* childProcCmdln=CApaCommandLine::NewLC(); |
|
309 INFO_PRINTF1(_L(" CommandLine for Child Process created ")); |
|
310 |
|
311 //child process |
|
312 RProcess childProc; |
|
313 ret = childProc.Create(KChildOneExe,KNullDesC); |
|
314 TEST(ret == KErrNone); |
|
315 User::LeaveIfError(ret); |
|
316 CleanupClosePushL(childProc); |
|
317 |
|
318 INFO_PRINTF2(_L(" Create Child Process returned : %d"),ret); |
|
319 |
|
320 //attach commandline to child process |
|
321 TRAP(ret,childProcCmdln->SetProcessEnvironmentL(childProc)); |
|
322 TEST(ret == KErrNone); |
|
323 User::LeaveIfError(ret); |
|
324 INFO_PRINTF1(_L(" Attach CommandLine to Process ")); |
|
325 |
|
326 INFO_PRINTF1(_L(" Run Child Process ")); |
|
327 childProc.Resume(); |
|
328 //Time for the child process to launch itself |
|
329 User::After(500000); |
|
330 |
|
331 parentProc.Terminate(KTProcTerminatingParent); |
|
332 INFO_PRINTF1(_L(" Kill Parent Process ... ")); |
|
333 TExitType exitType = parentProc.ExitType(); |
|
334 TEST(exitType == EExitTerminate); |
|
335 TInt exitReason = parentProc.ExitReason(); |
|
336 TEST(exitReason == KTProcTerminatingParent); |
|
337 |
|
338 //child process Id is reqd to monitor if it gets killed on its parent's termination |
|
339 TUint64 childProcId = childProc.Id(); |
|
340 INFO_PRINTF2(_L(" Child Process Id = 0x%lx "),childProcId); |
|
341 |
|
342 //Wait for child to terminate ... if it really does |
|
343 User::After(10000000); |
|
344 |
|
345 exitType = childProc.ExitType(); |
|
346 TEST(exitType == EExitPending); |
|
347 if(exitType == EExitPending) |
|
348 { |
|
349 INFO_PRINTF1(_L(" Child process is still running ")); |
|
350 INFO_PRINTF1(_L(" so terminating it manually ...")); |
|
351 childProc.Terminate(KTProcTerminatingChildI); |
|
352 exitType = childProc.ExitType(); |
|
353 TEST(exitType == EExitTerminate); |
|
354 exitReason = childProc.ExitReason(); |
|
355 TEST(exitReason == KTProcTerminatingChildI); |
|
356 } |
|
357 |
|
358 CleanupStack::PopAndDestroy(&childProc); |
|
359 CleanupStack::PopAndDestroy(childProcCmdln); |
|
360 CleanupStack::PopAndDestroy(&parentProc); |
|
361 CleanupStack::PopAndDestroy(parentProcCmdln); |
|
362 } |
|
363 |
|
364 /** |
|
365 @SYMTestCaseID APPFWK-APPARC-0017 |
|
366 |
|
367 @SYMPREQ PREQ1123 |
|
368 |
|
369 @SYMTestCaseDesc Test determines that one Child remains and another terminates when their Parent terminates, based on their creation. |
|
370 |
|
371 @SYMTestPriority High |
|
372 |
|
373 @SYMTestStatus Implemented |
|
374 |
|
375 @SYMTestActions. Creates and launches a process (parent). Creates a process (child I) passing the first (parent) process ID. |
|
376 Creates a second process (child II) without passing the first (parent) process ID. Launches both the child processes. |
|
377 Terminates parent and checks the existance of both the child processes. Child I should die and Child II should remain alive. |
|
378 API Calls:\n |
|
379 RProcess::Create(const TDesC &aFileName, const TDesC &aCommand, TOwnerType aType=EOwnerProcess);\n |
|
380 RProcess::Resume(); |
|
381 RProcess::ExitType() const; |
|
382 RProcess::ExitReason() const; |
|
383 RProcess::Id() const; |
|
384 RProcess::Terminate(TInt aReason); |
|
385 CApaCommandLine::SetProcessEnvironmentL(RProcess &aProcess) const; |
|
386 CApaCommandLine::NewLC(); |
|
387 CApaCommandLine::SetParentProcessId(TProcessId); |
|
388 |
|
389 @SYMTestExpectedResults Termination of first child process and existence of the second.\n |
|
390 |
|
391 */ |
|
392 void CT_ProcStep::testTwoChildsOneToTerminateAndOtherToRemainL(void) |
|
393 { |
|
394 TInt ret(0); |
|
395 TExitType exitType; |
|
396 |
|
397 //commandline for parent process |
|
398 CApaCommandLine* parentProcCmdln=CApaCommandLine::NewLC(); |
|
399 INFO_PRINTF1(_L(" CommandLine for Parent Process created ")); |
|
400 |
|
401 //parent process |
|
402 RProcess parentProc; |
|
403 ret = parentProc.Create(KParentExe,KNullDesC); |
|
404 TEST(ret == KErrNone); |
|
405 User::LeaveIfError(ret); |
|
406 CleanupClosePushL(parentProc); |
|
407 INFO_PRINTF2(_L(" Create Parent Process returned : %d"),ret); |
|
408 |
|
409 //attach commandline to parent process |
|
410 TRAP(ret,parentProcCmdln->SetProcessEnvironmentL(parentProc)); |
|
411 TEST(ret == KErrNone); |
|
412 User::LeaveIfError(ret); |
|
413 INFO_PRINTF1(_L(" Attach CommandLine to Process ")); |
|
414 |
|
415 INFO_PRINTF1(_L(" Run Parent Process ")); |
|
416 parentProc.Resume(); |
|
417 //Time for the parent process to launch itself |
|
418 User::After(500000); |
|
419 |
|
420 //commandline for child process |
|
421 //Get parent process ID here |
|
422 TUint64 parentProcId = parentProc.Id(); |
|
423 INFO_PRINTF2(_L(" Parent Process Id = 0x%lx"),parentProcId); |
|
424 |
|
425 //For Child ONE |
|
426 CApaCommandLine* childProcOneCmdln=CApaCommandLine::NewLC(); |
|
427 INFO_PRINTF1(_L(" CommandLine for Child One created ")); |
|
428 |
|
429 //setting the parent process ID to child I |
|
430 childProcOneCmdln->SetParentProcessId(parentProcId); |
|
431 INFO_PRINTF1(_L(" Set ParentProcessId to Child One ")); |
|
432 |
|
433 //child process ONE |
|
434 RProcess childProcOne; |
|
435 ret = childProcOne.Create(KChildOneExe,KNullDesC); |
|
436 TEST(ret == KErrNone); |
|
437 User::LeaveIfError(ret); |
|
438 CleanupClosePushL(childProcOne); |
|
439 |
|
440 INFO_PRINTF2(_L(" Create Child One returned : %d"),ret); |
|
441 |
|
442 //attach commandline to child process |
|
443 TRAP(ret,childProcOneCmdln->SetProcessEnvironmentL(childProcOne)); |
|
444 TEST(ret == KErrNone); |
|
445 User::LeaveIfError(ret); |
|
446 INFO_PRINTF1(_L(" Attach CommandLine of Child One to its Process ")); |
|
447 |
|
448 INFO_PRINTF1(_L(" Run Child One ")); |
|
449 childProcOne.Resume(); |
|
450 //Time for the child one to launch itself |
|
451 User::After(500000); |
|
452 |
|
453 //child process Id is reqd to monitor if it gets killed on its parent's termination |
|
454 TUint64 childProcOneId = childProcOne.Id(); |
|
455 INFO_PRINTF2(_L(" Child One Id = 0x%lx "),childProcOneId); |
|
456 |
|
457 //For Child TWO |
|
458 CApaCommandLine* childProcTwoCmdln=CApaCommandLine::NewLC(); |
|
459 INFO_PRINTF1(_L(" CommandLine for Child Two created ")); |
|
460 |
|
461 //child process TWO |
|
462 RProcess childProcTwo; |
|
463 ret = childProcTwo.Create(KChildTwoExe,KNullDesC); |
|
464 TEST(ret == KErrNone); |
|
465 User::LeaveIfError(ret); |
|
466 CleanupClosePushL(childProcTwo); |
|
467 |
|
468 INFO_PRINTF2(_L(" Create Child Two returned : %d"),ret); |
|
469 |
|
470 //attach commandline to child process |
|
471 TRAP(ret,childProcTwoCmdln->SetProcessEnvironmentL(childProcTwo)); |
|
472 TEST(ret == KErrNone); |
|
473 User::LeaveIfError(ret); |
|
474 INFO_PRINTF1(_L(" Attach CommandLine of Child Two to its Process ")); |
|
475 |
|
476 INFO_PRINTF1(_L(" Run Child Two ")); |
|
477 childProcTwo.Resume(); |
|
478 //Time for the child one to launch itself |
|
479 User::After(500000); |
|
480 |
|
481 //child II process Id is reqd to monitor if it gets killed on its parent's termination |
|
482 TUint64 childProcTwoId = childProcTwo.Id(); |
|
483 INFO_PRINTF2(_L(" Child Two Id = 0x%lx "),childProcTwoId); |
|
484 |
|
485 CChildProcess* childProcess=NULL; |
|
486 TRAP(ret, childProcess=CChildProcess::NewL(parentProc,childProcOneId)); |
|
487 TEST(ret == KErrNone); |
|
488 User::LeaveIfError(ret); |
|
489 CleanupStack::PushL(childProcess); |
|
490 |
|
491 exitType = parentProc.ExitType(); |
|
492 TEST(exitType == EExitTerminate); |
|
493 TInt exitReason = parentProc.ExitReason(); |
|
494 TEST(exitReason == 0); |
|
495 if(exitType==EExitTerminate && exitReason==0) |
|
496 { |
|
497 INFO_PRINTF1(_L(" Parent process is Terminated")); |
|
498 } |
|
499 |
|
500 exitType = childProcOne.ExitType(); |
|
501 TEST(exitType == EExitTerminate); |
|
502 exitReason = childProcOne.ExitReason(); |
|
503 TEST(exitReason == 0); |
|
504 if(exitType==EExitTerminate && exitReason==0) |
|
505 { |
|
506 INFO_PRINTF1(_L(" Child I is killed automatically ... ")); |
|
507 } |
|
508 |
|
509 //Wait and see if child II terminates automatically... |
|
510 User::After(10000000); |
|
511 |
|
512 exitType = childProcTwo.ExitType(); |
|
513 TEST(exitType == EExitPending); |
|
514 if(exitType==EExitPending) |
|
515 { |
|
516 INFO_PRINTF1(_L(" Child II running successfully")); |
|
517 childProcTwo.Terminate(KTProcTerminatingChildII); |
|
518 exitType = childProcTwo.ExitType(); |
|
519 TEST(exitType==EExitTerminate); |
|
520 exitReason = childProcTwo.ExitReason(); |
|
521 TEST(exitReason == KTProcTerminatingChildII); |
|
522 INFO_PRINTF1(_L(" So Terminated it manually ...")); |
|
523 } |
|
524 |
|
525 CleanupStack::PopAndDestroy(childProcess); |
|
526 CleanupStack::PopAndDestroy(&childProcTwo); |
|
527 CleanupStack::PopAndDestroy(childProcTwoCmdln); |
|
528 CleanupStack::PopAndDestroy(&childProcOne); |
|
529 CleanupStack::PopAndDestroy(childProcOneCmdln); |
|
530 CleanupStack::PopAndDestroy(&parentProc); |
|
531 CleanupStack::PopAndDestroy(parentProcCmdln); |
|
532 } |
|
533 |
|
534 /** |
|
535 @SYMTestCaseID APPFWK-APPARC-0018 |
|
536 |
|
537 @SYMPREQ PREQ1123 |
|
538 |
|
539 @SYMTestCaseDesc The Test determines that a process is launched and terminated without any problem.\n |
|
540 |
|
541 @SYMTestPriority Low |
|
542 |
|
543 @SYMTestStatus Implemented |
|
544 |
|
545 @SYMTestActions. Creates and launches a process. No Child is created. Parent should launch properly, and on termination should die. |
|
546 API Calls:\n |
|
547 RProcess::Create(const TDesC &aFileName, const TDesC &aCommand, TOwnerType aType=EOwnerProcess);\n |
|
548 RProcess::Resume(); |
|
549 RProcess::ExitType() const; |
|
550 RProcess::ExitReason() const; |
|
551 RProcess::Id() const; |
|
552 RProcess::Terminate(TInt aReason); |
|
553 |
|
554 @SYMTestExpectedResults Proper creation and termination.\n |
|
555 |
|
556 */ |
|
557 void CT_ProcStep::testParentWithoutAChildL(void) |
|
558 { |
|
559 TInt ret(0) ; |
|
560 |
|
561 //process |
|
562 RProcess parentProc; |
|
563 ret = parentProc.Create(KParentExe,KNullDesC); |
|
564 TEST(ret == KErrNone); |
|
565 User::LeaveIfError(ret); |
|
566 CleanupClosePushL(parentProc); |
|
567 INFO_PRINTF2(_L(" Create Parent Process returned : %d"),ret); |
|
568 |
|
569 TUint64 parentProcId=parentProc.Id(); |
|
570 INFO_PRINTF2(_L(" Process Id = 0x%lx "),parentProcId); |
|
571 |
|
572 INFO_PRINTF1(_L(" Run the Process ")); |
|
573 parentProc.Resume(); |
|
574 //Time for the parent process to launch itself |
|
575 User::After(5000000); |
|
576 |
|
577 TExitType exitType = parentProc.ExitType(); |
|
578 TEST(exitType == EExitKill||exitType == EExitPending); |
|
579 if(exitType==EExitPending) |
|
580 { |
|
581 INFO_PRINTF1(_L(" Process running normally ")); |
|
582 parentProc.Terminate(KTProcTerminatingParent); |
|
583 exitType = parentProc.ExitType(); |
|
584 TEST(exitType==EExitTerminate); |
|
585 TInt exitReason = parentProc.ExitReason(); |
|
586 TEST(exitReason == KTProcTerminatingParent); |
|
587 INFO_PRINTF1(_L(" Terminating the process ")); |
|
588 } |
|
589 CleanupStack::PopAndDestroy(&parentProc); |
|
590 } |
|
591 |
|
592 /** |
|
593 @SYMTestCaseID APPFWK-APPARC-0019 |
|
594 |
|
595 @SYMPREQ PREQ1123 |
|
596 |
|
597 @SYMTestCaseDesc The Test determines that more than one Child for a parent terminate on their Parent's termination. |
|
598 |
|
599 @SYMTestPriority Medium |
|
600 |
|
601 @SYMTestStatus Implemented |
|
602 |
|
603 @SYMTestActions. Creates and launches a process (parent). Creates 3 processes (child I,II,III) passing the first (parent) process ID. |
|
604 Launches all the 3 processes. Terminates parent and checks the existance of the child processes. All 3 children should die. |
|
605 API Calls:\n |
|
606 RProcess::Create(const TDesC &aFileName, const TDesC &aCommand, TOwnerType aType=EOwnerProcess);\n |
|
607 RProcess::Resume(); |
|
608 RProcess::ExitType() const; |
|
609 RProcess::ExitReason() const; |
|
610 RProcess::Id() const; |
|
611 RProcess::Terminate(TInt aReason); |
|
612 CApaCommandLine::SetProcessEnvironmentL(RProcess &aProcess) const; |
|
613 CApaCommandLine::NewLC(); |
|
614 CApaCommandLine::SetParentProcessId(TProcessId); |
|
615 |
|
616 @SYMTestExpectedResults Termination of all child processes automatically.\n |
|
617 |
|
618 */ |
|
619 void CT_ProcStep::testAllChildsSetToTerminateL(void) |
|
620 { |
|
621 TInt ret(0); |
|
622 |
|
623 //commandline for parent process |
|
624 CApaCommandLine* parentProcCmdln=CApaCommandLine::NewLC(); |
|
625 INFO_PRINTF1(_L(" CommandLine for Parent Process created ")); |
|
626 |
|
627 //parent process |
|
628 RProcess parentProc; |
|
629 ret = parentProc.Create(KParentExe,KNullDesC); |
|
630 TEST(ret == KErrNone); |
|
631 User::LeaveIfError(ret); |
|
632 CleanupClosePushL(parentProc); |
|
633 INFO_PRINTF2(_L(" Create Parent Process returned : %d"),ret); |
|
634 |
|
635 //attach commandline to parent process |
|
636 TRAP(ret,parentProcCmdln->SetProcessEnvironmentL(parentProc)); |
|
637 TEST(ret == KErrNone); |
|
638 User::LeaveIfError(ret); |
|
639 INFO_PRINTF1(_L(" Attach CommandLine to Process ")); |
|
640 |
|
641 INFO_PRINTF1(_L(" Run Parent Process ")); |
|
642 parentProc.Resume(); |
|
643 //Time for the parent process to launch itself |
|
644 User::After(500000); |
|
645 |
|
646 //Get parent process ID here |
|
647 TUint64 parentProcId = parentProc.Id(); |
|
648 INFO_PRINTF2(_L(" Parent Process Id = 0x%lx "),parentProcId); |
|
649 |
|
650 //Child I |
|
651 CApaCommandLine* childProcOneCmdln=CApaCommandLine::NewLC(); |
|
652 INFO_PRINTF1(_L(" CommandLine for Child One created ")); |
|
653 |
|
654 //setting the parent process ID to child |
|
655 childProcOneCmdln->SetParentProcessId(parentProcId); |
|
656 INFO_PRINTF1(_L(" Set ParentProcessId to Child One ")); |
|
657 |
|
658 //Child process I |
|
659 RProcess childProcOne; |
|
660 ret = childProcOne.Create(KChildOneExe,KNullDesC); |
|
661 TEST(ret == KErrNone); |
|
662 User::LeaveIfError(ret); |
|
663 CleanupClosePushL(childProcOne); |
|
664 |
|
665 INFO_PRINTF2(_L(" Create Child One returned : %d"),ret); |
|
666 |
|
667 //attach commandline to child process |
|
668 TRAP(ret,childProcOneCmdln->SetProcessEnvironmentL(childProcOne)); |
|
669 TEST(ret == KErrNone); |
|
670 User::LeaveIfError(ret); |
|
671 INFO_PRINTF1(_L(" Attach CommandLine of Child One to its Process ")); |
|
672 |
|
673 INFO_PRINTF1(_L(" Run Child One ")); |
|
674 childProcOne.Resume(); |
|
675 //Time for the child process to launch itself |
|
676 User::After(1000000); |
|
677 |
|
678 //child process Id is reqd to monitor if it gets killed on its parent's termination |
|
679 TUint64 childProcOneId = childProcOne.Id(); |
|
680 INFO_PRINTF2(_L(" Child One Id = 0x%lx "),childProcOneId); |
|
681 |
|
682 //Child II |
|
683 CApaCommandLine* childProcTwoCmdln=CApaCommandLine::NewLC(); |
|
684 INFO_PRINTF1(_L(" CommandLine for Child Two created ")); |
|
685 |
|
686 //setting the parent process ID to child |
|
687 childProcTwoCmdln->SetParentProcessId(parentProcId); |
|
688 INFO_PRINTF1(_L(" Set ParentProcessId to Child Two ")); |
|
689 |
|
690 //child process II |
|
691 RProcess childProcTwo; |
|
692 ret = childProcTwo.Create(KChildTwoExe,KNullDesC); |
|
693 TEST(ret == KErrNone); |
|
694 User::LeaveIfError(ret); |
|
695 CleanupClosePushL(childProcTwo); |
|
696 |
|
697 INFO_PRINTF2(_L(" Create Child Two returned : %d"),ret); |
|
698 |
|
699 //attach commandline to child process |
|
700 TRAP(ret,childProcTwoCmdln->SetProcessEnvironmentL(childProcTwo)); |
|
701 TEST(ret == KErrNone); |
|
702 User::LeaveIfError(ret); |
|
703 INFO_PRINTF1(_L(" Attach CommandLine of Child Two to its Process ")); |
|
704 |
|
705 INFO_PRINTF1(_L(" Run Child Two ")); |
|
706 childProcTwo.Resume(); |
|
707 //Time for the child process to launch itself |
|
708 User::After(1000000); |
|
709 |
|
710 //child process Id is reqd to monitor if it gets killed on its parent's termination |
|
711 TUint64 childProcTwoId = childProcTwo.Id(); |
|
712 INFO_PRINTF2(_L(" Child Two Id = 0x%lx "),childProcTwoId); |
|
713 |
|
714 //Child III |
|
715 CApaCommandLine* childProcThreeCmdln=CApaCommandLine::NewLC(); |
|
716 INFO_PRINTF1(_L(" CommandLine for Child Three created ")); |
|
717 |
|
718 //setting the parent process ID to child |
|
719 childProcThreeCmdln->SetParentProcessId(parentProcId); |
|
720 INFO_PRINTF1(_L(" Set ParentProcessId to Child Three ")); |
|
721 |
|
722 //child process III |
|
723 RProcess childProcThree; |
|
724 ret = childProcThree.Create(KChildThreeExe,KNullDesC); |
|
725 TEST(ret == KErrNone); |
|
726 User::LeaveIfError(ret); |
|
727 CleanupClosePushL(childProcThree); |
|
728 |
|
729 INFO_PRINTF2(_L(" Create Child Three returned : %d"),ret); |
|
730 |
|
731 //attach commandline to child process |
|
732 TRAP(ret,childProcThreeCmdln->SetProcessEnvironmentL(childProcThree)); |
|
733 TEST(ret == KErrNone); |
|
734 User::LeaveIfError(ret); |
|
735 INFO_PRINTF1(_L(" Attach CommandLine of Child Three to its Process ")); |
|
736 |
|
737 childProcThree.Resume(); |
|
738 |
|
739 //Time for the child process to launch itself |
|
740 User::After(1000000); |
|
741 |
|
742 //child process Id is reqd to monitor if it gets killed on its parent's termination |
|
743 TUint64 childProcThreeId = childProcThree.Id(); |
|
744 INFO_PRINTF2(_L(" Child Three Id = 0x%lx "),childProcThreeId); |
|
745 |
|
746 CChildProcess* childProcess=NULL; |
|
747 TRAP(ret, childProcess=CChildProcess::NewL(parentProc,childProcOneId)); |
|
748 TEST(ret == KErrNone); |
|
749 User::LeaveIfError(ret); |
|
750 CleanupStack::PushL(childProcess); |
|
751 |
|
752 TExitType exitType = parentProc.ExitType(); |
|
753 TEST(exitType == EExitTerminate); |
|
754 TInt exitReason = parentProc.ExitReason(); |
|
755 TEST(exitReason == 0); |
|
756 if(exitType == EExitTerminate && exitReason == 0) |
|
757 { |
|
758 INFO_PRINTF1(_L(" Parent process is Terminated ")); |
|
759 } |
|
760 |
|
761 exitType = childProcOne.ExitType(); |
|
762 TEST(exitType == EExitTerminate); |
|
763 exitReason = childProcOne.ExitReason(); |
|
764 TEST(exitReason == 0); |
|
765 if(exitType == EExitTerminate && exitReason == 0) |
|
766 { |
|
767 INFO_PRINTF1(_L(" Child I is killed ")); |
|
768 } |
|
769 |
|
770 exitType = childProcTwo.ExitType(); |
|
771 TEST(exitType == EExitTerminate); |
|
772 exitReason = childProcTwo.ExitReason(); |
|
773 TEST(exitReason == 0); |
|
774 if(exitType == EExitTerminate && exitReason == 0) |
|
775 { |
|
776 INFO_PRINTF1(_L(" Child II is killed ")); |
|
777 } |
|
778 |
|
779 //Wait 1sec to close the child process |
|
780 User::After(1000000); |
|
781 exitType = childProcThree.ExitType(); |
|
782 TEST(exitType == EExitTerminate); |
|
783 exitReason = childProcThree.ExitReason(); |
|
784 TEST(exitReason == 0); |
|
785 if(exitType == EExitTerminate && exitReason == 0) |
|
786 { |
|
787 INFO_PRINTF1(_L(" Child III is killed ")); |
|
788 } |
|
789 |
|
790 CleanupStack::PopAndDestroy(childProcess); |
|
791 CleanupStack::PopAndDestroy(&childProcThree); |
|
792 CleanupStack::PopAndDestroy(childProcThreeCmdln); |
|
793 CleanupStack::PopAndDestroy(&childProcTwo); |
|
794 CleanupStack::PopAndDestroy(childProcTwoCmdln); |
|
795 CleanupStack::PopAndDestroy(&childProcOne); |
|
796 CleanupStack::PopAndDestroy(childProcOneCmdln); |
|
797 CleanupStack::PopAndDestroy(&parentProc); |
|
798 CleanupStack::PopAndDestroy(parentProcCmdln); |
|
799 } |
|
800 |
|
801 /** |
|
802 @SYMTestCaseID APPFWK-APPARC-0020 |
|
803 |
|
804 @SYMPREQ PREQ1123 |
|
805 |
|
806 @SYMTestCaseDesc The Test determines that more than one Child for a Parent remain alive on their parent's termination. |
|
807 |
|
808 @SYMTestPriority Medium |
|
809 |
|
810 @SYMTestStatus Implemented |
|
811 |
|
812 @SYMTestActions. Creates and launches a process (parent). Creates 3 processes (child I,II,III) without passing the first (parent) process ID. |
|
813 Launches all the 3 processes. Terminates parent and checks the existance of the child processes. All 3 children should remain alive. |
|
814 API Calls:\n |
|
815 RProcess::Create(const TDesC &aFileName, const TDesC &aCommand, TOwnerType aType=EOwnerProcess);\n |
|
816 RProcess::Resume(); |
|
817 RProcess::ExitType() const; |
|
818 RProcess::ExitReason() const; |
|
819 RProcess::Id() const; |
|
820 RProcess::Terminate(TInt aReason); |
|
821 CApaCommandLine::SetProcessEnvironmentL(RProcess &aProcess) const; |
|
822 CApaCommandLine::NewLC(); |
|
823 |
|
824 @SYMTestExpectedResults Existence of all child processes.\n |
|
825 |
|
826 */ |
|
827 void CT_ProcStep::testNoChildSetToTerminateL(void) |
|
828 { |
|
829 TInt ret(0); |
|
830 |
|
831 //commandline for parent process |
|
832 CApaCommandLine* parentProcCmdln=CApaCommandLine::NewLC(); |
|
833 INFO_PRINTF1(_L(" CommandLine for Parent Process created ")); |
|
834 |
|
835 //parent process |
|
836 RProcess parentProc; |
|
837 ret = parentProc.Create(KParentExe,KNullDesC); |
|
838 TEST(ret == KErrNone); |
|
839 User::LeaveIfError(ret); |
|
840 CleanupClosePushL(parentProc); |
|
841 INFO_PRINTF2(_L(" Create Parent Process returned : %d"),ret); |
|
842 |
|
843 //attach commandline to parent process |
|
844 TRAP(ret,parentProcCmdln->SetProcessEnvironmentL(parentProc)); |
|
845 TEST(ret == KErrNone); |
|
846 User::LeaveIfError(ret); |
|
847 INFO_PRINTF1(_L(" Attach CommandLine to Process ")); |
|
848 |
|
849 INFO_PRINTF1(_L(" Run Parent Process ")); |
|
850 parentProc.Resume(); |
|
851 //Time for the parent process to launch itself |
|
852 User::After(500000); |
|
853 |
|
854 //commandline for child process |
|
855 //Get parent process ID here |
|
856 TUint64 parentProcId = parentProc.Id(); |
|
857 INFO_PRINTF2(_L(" Parent Process Id = 0x%lx "),parentProcId); |
|
858 |
|
859 //Child I |
|
860 CApaCommandLine* childProcOneCmdln=CApaCommandLine::NewLC(); |
|
861 INFO_PRINTF1(_L(" CommandLine for Child One created ")); |
|
862 |
|
863 //child process |
|
864 RProcess childProcOne; |
|
865 ret = childProcOne.Create(KChildOneExe,KNullDesC); |
|
866 TEST(ret == KErrNone); |
|
867 User::LeaveIfError(ret); |
|
868 CleanupClosePushL(childProcOne); |
|
869 |
|
870 INFO_PRINTF2(_L(" Create Child One returned : %d"),ret); |
|
871 |
|
872 //attach commandline to child process |
|
873 TRAP(ret,childProcOneCmdln->SetProcessEnvironmentL(childProcOne)); |
|
874 TEST(ret == KErrNone); |
|
875 User::LeaveIfError(ret); |
|
876 INFO_PRINTF1(_L(" Attach CommandLine of Child One to its Process ")); |
|
877 |
|
878 childProcOne.Resume(); |
|
879 |
|
880 //Time for the child process to launch itself |
|
881 User::After(1000000); |
|
882 |
|
883 //child process Id is reqd to monitor if it gets killed on its parent's termination |
|
884 TUint64 childProcOneId = childProcOne.Id(); |
|
885 INFO_PRINTF2(_L(" Child Process Id = 0x%lx "),childProcOneId); |
|
886 |
|
887 //Child II |
|
888 CApaCommandLine* childProcTwoCmdln=CApaCommandLine::NewLC(); |
|
889 INFO_PRINTF1(_L(" CommandLine for Child Two created ")); |
|
890 |
|
891 //child process |
|
892 RProcess childProcTwo; |
|
893 ret = childProcTwo.Create(KChildTwoExe,KNullDesC); |
|
894 TEST(ret == KErrNone); |
|
895 User::LeaveIfError(ret); |
|
896 CleanupClosePushL(childProcTwo); |
|
897 |
|
898 INFO_PRINTF2(_L(" Create Child Two returned : %d "),ret); |
|
899 |
|
900 //attach commandline to child process |
|
901 TRAP(ret,childProcTwoCmdln->SetProcessEnvironmentL(childProcTwo)); |
|
902 TEST(ret == KErrNone); |
|
903 User::LeaveIfError(ret); |
|
904 INFO_PRINTF1(_L(" Attach CommandLine of Child Two to its Process ")); |
|
905 |
|
906 INFO_PRINTF1(_L(" Run Child Two ")); |
|
907 childProcTwo.Resume(); |
|
908 //Time for the child process to launch itself |
|
909 User::After(1000000); |
|
910 |
|
911 //child process Id is reqd to monitor if it gets killed on its parent's termination |
|
912 TUint64 childProcTwoId = childProcTwo.Id(); |
|
913 INFO_PRINTF2(_L(" Child Two Id = 0x%lx "),childProcTwoId); |
|
914 |
|
915 //Child III |
|
916 CApaCommandLine* childProcThreeCmdln=CApaCommandLine::NewLC(); |
|
917 INFO_PRINTF1(_L(" CommandLine for Child Three created ")); |
|
918 |
|
919 //child process |
|
920 RProcess childProcThree; |
|
921 ret = childProcThree.Create(KChildThreeExe,KNullDesC); |
|
922 TEST(ret == KErrNone); |
|
923 User::LeaveIfError(ret); |
|
924 CleanupClosePushL(childProcThree); |
|
925 |
|
926 INFO_PRINTF2(_L(" Create Child Three returned : %d"),ret); |
|
927 |
|
928 //attach commandline to child process |
|
929 TRAP(ret,childProcThreeCmdln->SetProcessEnvironmentL(childProcThree)); |
|
930 TEST(ret == KErrNone); |
|
931 User::LeaveIfError(ret); |
|
932 INFO_PRINTF1(_L(" Attach CommandLine of Child Three to its Process ")); |
|
933 |
|
934 childProcThree.Resume(); |
|
935 |
|
936 //Time for the child process to launch itself |
|
937 User::After(1000000); |
|
938 |
|
939 //child process Id is reqd to monitor if it gets killed on its parent's termination |
|
940 TUint64 childProcThreeId = childProcThree.Id(); |
|
941 INFO_PRINTF2(_L(" Child Three Id = 0x%lx "),childProcThreeId); |
|
942 |
|
943 parentProc.Terminate(KTProcTerminatingParent); |
|
944 TExitType exitType = parentProc.ExitType(); |
|
945 TEST(exitType == EExitTerminate); |
|
946 TInt exitReason = parentProc.ExitReason(); |
|
947 TEST(exitReason == KTProcTerminatingParent); |
|
948 INFO_PRINTF1(_L(" Terminating parent process ")); |
|
949 |
|
950 //Time for the child processes to terminate if they really do |
|
951 User::After(500000); |
|
952 |
|
953 exitType = childProcOne.ExitType(); |
|
954 TEST(exitType == EExitPending); |
|
955 if(exitType == EExitPending) |
|
956 { |
|
957 INFO_PRINTF1(_L(" Child I is still running ")); |
|
958 INFO_PRINTF1(_L(" So Terminating it manually ... ")); |
|
959 childProcOne.Terminate(KTProcTerminatingChildI); |
|
960 exitType = childProcOne.ExitType(); |
|
961 TEST(exitType==EExitTerminate); |
|
962 exitReason = childProcOne.ExitReason(); |
|
963 TEST(exitReason == KTProcTerminatingChildI); |
|
964 } |
|
965 |
|
966 exitType = childProcTwo.ExitType(); |
|
967 TEST(exitType == EExitPending); |
|
968 if(exitType == EExitPending) |
|
969 { |
|
970 INFO_PRINTF1(_L(" Child II is still running ")); |
|
971 INFO_PRINTF1(_L(" So Terminating it manually ... ")); |
|
972 childProcTwo.Terminate(KTProcTerminatingChildII); |
|
973 exitType = childProcTwo.ExitType(); |
|
974 TEST(exitType==EExitTerminate); |
|
975 exitReason = childProcTwo.ExitReason(); |
|
976 TEST(exitReason == KTProcTerminatingChildII); |
|
977 } |
|
978 |
|
979 exitType = childProcThree.ExitType(); |
|
980 TEST(exitType == EExitPending); |
|
981 if(exitType == EExitPending) |
|
982 { |
|
983 INFO_PRINTF1(_L(" Child III is still running ")); |
|
984 INFO_PRINTF1(_L(" So Terminating it manually ... ")); |
|
985 childProcThree.Terminate(KTProcTerminatingChildIII); |
|
986 exitType = childProcThree.ExitType(); |
|
987 TEST(exitType==EExitTerminate); |
|
988 exitReason = childProcThree.ExitReason(); |
|
989 TEST(exitReason == KTProcTerminatingChildIII); |
|
990 } |
|
991 |
|
992 CleanupStack::PopAndDestroy(&childProcThree); |
|
993 CleanupStack::PopAndDestroy(childProcThreeCmdln); |
|
994 CleanupStack::PopAndDestroy(&childProcTwo); |
|
995 CleanupStack::PopAndDestroy(childProcTwoCmdln); |
|
996 CleanupStack::PopAndDestroy(&childProcOne); |
|
997 CleanupStack::PopAndDestroy(childProcOneCmdln); |
|
998 CleanupStack::PopAndDestroy(&parentProc); |
|
999 CleanupStack::PopAndDestroy(parentProcCmdln); |
|
1000 } |
|
1001 |
|
1002 /** |
|
1003 @SYMTestCaseID APPFWK-APPARC-0021 |
|
1004 |
|
1005 @SYMPREQ PREQ1123 |
|
1006 |
|
1007 @SYMTestCaseDesc The Test determines that the child receives its parent process ID correctly, when set during its creation. |
|
1008 |
|
1009 @SYMTestPriority Medium |
|
1010 |
|
1011 @SYMTestStatus Implemented |
|
1012 |
|
1013 @SYMTestActions. Creates and launches a process (parent). Creates another process (child) setting the first(parent) process ID. |
|
1014 Parent Process Id is passed to child through SetParameter API. Launches the child process. Child obtains the parent process Id from within. |
|
1015 Child compares both the Id's and writes the results to a file. The Id's should match each other. |
|
1016 API Calls:\n |
|
1017 RProcess::Create(const TDesC &aFileName, const TDesC &aCommand, TOwnerType aType=EOwnerProcess);\n |
|
1018 RProcess::Resume(); |
|
1019 RProcess::ExitType() const; |
|
1020 RProcess::ExitReason() const; |
|
1021 RProcess::Id() const; |
|
1022 RProcess::SetParameter(TInt aSlot, TInt aData); |
|
1023 CApaCommandLine::SetProcessEnvironmentL(RProcess &aProcess) const; |
|
1024 CApaCommandLine::NewLC(); |
|
1025 CApaCommandLine::SetParentProcessId(TProcessId); |
|
1026 RFile::Open(RFs &aFs, const TDesC &aName, TUint aFileMode); |
|
1027 RFile::Read(TInt aPos, TDes8 &aDes) const; |
|
1028 RFile::Close(); |
|
1029 RFs::Connect(TInt aMessageSlots=KFileServerDefaultMessageSlots); |
|
1030 RFs::Delete(const TDesC &aName); |
|
1031 RFs::Close(); |
|
1032 @SYMTestExpectedResults Id received by child process should match its parent process Id.\n |
|
1033 |
|
1034 */ |
|
1035 void CT_ProcStep::testIdAvailableToChildL(void) |
|
1036 { |
|
1037 TInt ret(0); |
|
1038 |
|
1039 //commandline for parent process |
|
1040 CApaCommandLine* parentProcCmdln=CApaCommandLine::NewLC(); |
|
1041 INFO_PRINTF1(_L(" CommandLine for Parent process created ")); |
|
1042 |
|
1043 //parent process |
|
1044 RProcess parentProc; |
|
1045 ret = parentProc.Create(KParentExe,KNullDesC); |
|
1046 TEST(ret == KErrNone); |
|
1047 User::LeaveIfError(ret); |
|
1048 CleanupClosePushL(parentProc); |
|
1049 INFO_PRINTF2(_L(" Create Parent Process returned : %d"),ret); |
|
1050 |
|
1051 //attach commandline to parent process |
|
1052 TRAP(ret,parentProcCmdln->SetProcessEnvironmentL(parentProc)); |
|
1053 TEST(ret == KErrNone); |
|
1054 User::LeaveIfError(ret); |
|
1055 INFO_PRINTF1(_L(" Attach CommandLine to Process ")); |
|
1056 |
|
1057 INFO_PRINTF1(_L(" Run Parent Process ")); |
|
1058 parentProc.Resume(); |
|
1059 //Time for the parent process to launch itself |
|
1060 User::After(500000); |
|
1061 |
|
1062 //commandline for child process |
|
1063 //Get parent process ID here |
|
1064 TUint64 parentProcId = parentProc.Id(); |
|
1065 INFO_PRINTF2(_L(" Parent Process Id = 0x%lx "),parentProcId); |
|
1066 |
|
1067 CApaCommandLine* childProcCmdln=CApaCommandLine::NewLC(); |
|
1068 INFO_PRINTF1(_L(" CommandLine for Child process created ")); |
|
1069 |
|
1070 //setting the parent process ID to child |
|
1071 childProcCmdln->SetParentProcessId(parentProcId); |
|
1072 INFO_PRINTF1(_L(" Set ParentProcessId to Child ")); |
|
1073 |
|
1074 //child process |
|
1075 RProcess childProc; |
|
1076 ret = childProc.Create(KChildThreeExe,KNullDesC); |
|
1077 TEST(ret == KErrNone); |
|
1078 User::LeaveIfError(ret); |
|
1079 CleanupClosePushL(childProc); |
|
1080 |
|
1081 INFO_PRINTF2(_L(" Create Child Process returned : %d"),ret); |
|
1082 |
|
1083 //attach commandline to child process |
|
1084 TRAP(ret,childProcCmdln->SetProcessEnvironmentL(childProc)); |
|
1085 TEST(ret == KErrNone); |
|
1086 User::LeaveIfError(ret); |
|
1087 INFO_PRINTF1(_L(" Attach CommandLine to Process ")); |
|
1088 |
|
1089 // Setting the parent process Id in an environment slot for the child to receive. |
|
1090 ret = childProc.SetParameter(12,parentProcId); |
|
1091 TEST(ret == KErrNone); |
|
1092 INFO_PRINTF2(_L(" Set the Parent Process Id - 0x%lx to Child through SetParameter API in Slot 12 "),parentProcId); |
|
1093 |
|
1094 INFO_PRINTF1(_L(" Run Child Process ")); |
|
1095 childProc.Resume(); |
|
1096 //Time for the child process to launch itself |
|
1097 User::After(1000000); |
|
1098 |
|
1099 RFs fs; |
|
1100 RFile file; |
|
1101 ret=fs.Connect(); |
|
1102 TEST(ret == KErrNone); |
|
1103 User::LeaveIfError(ret); |
|
1104 INFO_PRINTF1(_L(" Create File server session ")); |
|
1105 |
|
1106 ret = file.Open(fs,KFilePath,EFileWrite | EFileShareAny); |
|
1107 TEST(ret == KErrNone); |
|
1108 if(ret == KErrNone) |
|
1109 { |
|
1110 INFO_PRINTF1(_L(" File opened successfully ")); |
|
1111 TBuf8<5> readData; |
|
1112 file.Read(0,readData); |
|
1113 TBuf8<5> result(KTResultPass); |
|
1114 TEST(result==readData); |
|
1115 if(result==readData) |
|
1116 { |
|
1117 INFO_PRINTF1(_L(" Child received the parent process ID correctly ...")); |
|
1118 } |
|
1119 else |
|
1120 { |
|
1121 INFO_PRINTF1(_L(" Child Failed to receive the parent process ID ...")); |
|
1122 } |
|
1123 file.Close(); |
|
1124 fs.Delete(KFilePath); |
|
1125 fs.Close(); |
|
1126 INFO_PRINTF1(_L(" File Close & Delete and Session Close ")); |
|
1127 } |
|
1128 |
|
1129 //child process Id is reqd to monitor if it gets killed on its parent's termination |
|
1130 TUint64 childProcId = childProc.Id(); |
|
1131 INFO_PRINTF2(_L(" Child Process Id = 0x%lx "),childProcId); |
|
1132 |
|
1133 CChildProcess* childProcess=NULL; |
|
1134 TRAP(ret, childProcess=CChildProcess::NewL(parentProc,childProcId)); |
|
1135 TEST(ret == KErrNone); |
|
1136 User::LeaveIfError(ret); |
|
1137 CleanupStack::PushL(childProcess); |
|
1138 |
|
1139 TExitType exitType = parentProc.ExitType(); |
|
1140 TEST(exitType == EExitTerminate); |
|
1141 TInt exitReason = parentProc.ExitReason(); |
|
1142 TEST(exitReason == 0); |
|
1143 if(exitType==EExitTerminate && exitReason == 0) |
|
1144 { |
|
1145 INFO_PRINTF1(_L(" Parent process is Terminated")); |
|
1146 } |
|
1147 |
|
1148 exitType = childProc.ExitType(); |
|
1149 TEST(exitType == EExitTerminate); |
|
1150 exitReason = childProc.ExitReason(); |
|
1151 TEST(exitReason == 0); |
|
1152 if(exitType==EExitTerminate && exitReason == 0) |
|
1153 { |
|
1154 INFO_PRINTF1(_L(" The child process is killed ")); |
|
1155 } |
|
1156 CleanupStack::PopAndDestroy(childProcess); |
|
1157 CleanupStack::PopAndDestroy(&childProc); |
|
1158 CleanupStack::PopAndDestroy(childProcCmdln); |
|
1159 CleanupStack::PopAndDestroy(&parentProc); |
|
1160 CleanupStack::PopAndDestroy(parentProcCmdln); |
|
1161 } |
|
1162 |
|
1163 /** |
|
1164 @SYMTestCaseID APPFWK-APPARC-0022 |
|
1165 |
|
1166 @SYMPREQ PREQ1123 |
|
1167 |
|
1168 @SYMTestCaseDesc The Test determines that the child doesn't receive its parent process ID correctly, when not set during its creation. |
|
1169 |
|
1170 @SYMTestPriority Medium |
|
1171 |
|
1172 @SYMTestStatus Implemented |
|
1173 |
|
1174 @SYMTestActions. Creates and launches a process (parent). Creates another process (child) without setting any parent. |
|
1175 Parent Process Id is passed to child through SetParameter API. Launches the child process. Child obtains the parent process Id from within. |
|
1176 Child compares both the Id's. The Id's should not match each other. |
|
1177 API Calls:\n |
|
1178 RProcess::Create(const TDesC &aFileName, const TDesC &aCommand, TOwnerType aType=EOwnerProcess);\n |
|
1179 RProcess::Resume(); |
|
1180 RProcess::ExitType() const; |
|
1181 RProcess::ExitReason() const; |
|
1182 RProcess::Id() const; |
|
1183 RProcess::SetParameter(TInt aSlot, TInt aData); |
|
1184 CApaCommandLine::SetProcessEnvironmentL(RProcess &aProcess) const; |
|
1185 CApaCommandLine::NewLC(); |
|
1186 RFile::Open(RFs &aFs, const TDesC &aName, TUint aFileMode); |
|
1187 RFile::Read(TInt aPos, TDes8 &aDes) const; |
|
1188 RFile::Close(); |
|
1189 RFs::Connect(TInt aMessageSlots=KFileServerDefaultMessageSlots); |
|
1190 RFs::Delete(const TDesC &aName); |
|
1191 RFs::Close(); |
|
1192 @SYMTestExpectedResults Id received by child process should not match its parent process Id.\n |
|
1193 |
|
1194 */ |
|
1195 void CT_ProcStep::testIdNotAvailableToChildL(void) |
|
1196 { |
|
1197 TInt ret(0); |
|
1198 TInt exitReason(0); |
|
1199 |
|
1200 //commandline for parent process |
|
1201 CApaCommandLine* parentProcCmdln=CApaCommandLine::NewLC(); |
|
1202 INFO_PRINTF1(_L(" CommandLine for Parent Process created ")); |
|
1203 |
|
1204 //parent process |
|
1205 RProcess parentProc; |
|
1206 ret = parentProc.Create(KParentExe,KNullDesC); |
|
1207 TEST(ret == KErrNone); |
|
1208 User::LeaveIfError(ret); |
|
1209 CleanupClosePushL(parentProc); |
|
1210 INFO_PRINTF2(_L(" Create Parent Process returned : %d"),ret); |
|
1211 |
|
1212 //attach commandline to parent process |
|
1213 TRAP(ret,parentProcCmdln->SetProcessEnvironmentL(parentProc)); |
|
1214 TEST(ret == KErrNone); |
|
1215 User::LeaveIfError(ret); |
|
1216 INFO_PRINTF1(_L(" Attach CommandLine to Process ")); |
|
1217 |
|
1218 INFO_PRINTF1(_L(" Run Parent Process ")); |
|
1219 parentProc.Resume(); |
|
1220 //Time for the parent process to launch itself |
|
1221 User::After(500000); |
|
1222 |
|
1223 //commandline for child process |
|
1224 //Get parent process ID here |
|
1225 TUint64 parentProcId = parentProc.Id(); |
|
1226 INFO_PRINTF2(_L(" Parent Process Id = 0x%lx "),parentProcId); |
|
1227 |
|
1228 CApaCommandLine* childProcCmdln=CApaCommandLine::NewLC(); |
|
1229 INFO_PRINTF1(_L(" CommandLine for Child Process created ")); |
|
1230 |
|
1231 //child process |
|
1232 RProcess childProc; |
|
1233 ret = childProc.Create(KChildThreeExe,KNullDesC); |
|
1234 TEST(ret == KErrNone); |
|
1235 User::LeaveIfError(ret); |
|
1236 CleanupClosePushL(childProc); |
|
1237 |
|
1238 INFO_PRINTF2(_L(" Create Child Process returned : %d"),ret); |
|
1239 |
|
1240 //attach commandline to child process |
|
1241 TRAP(ret,childProcCmdln->SetProcessEnvironmentL(childProc)); |
|
1242 TEST(ret == KErrNone); |
|
1243 User::LeaveIfError(ret); |
|
1244 INFO_PRINTF1(_L(" Attach CommandLine to Process ")); |
|
1245 |
|
1246 //Setting the parent process Id in an environment slot for the child to receive. |
|
1247 ret = childProc.SetParameter(12,parentProcId); |
|
1248 TEST(ret == KErrNone); |
|
1249 INFO_PRINTF2(_L(" Set the Parent Process Id - 0x%lx to Child through SetParameter API in Slot 12 "),parentProcId); |
|
1250 |
|
1251 INFO_PRINTF1(_L(" Run Child Process ")); |
|
1252 childProc.Resume(); |
|
1253 //Time for the child process to launch itself |
|
1254 User::After(1000000); |
|
1255 |
|
1256 RFs fs; |
|
1257 RFile file; |
|
1258 ret = fs.Connect(); |
|
1259 TEST(ret == KErrNone); |
|
1260 User::LeaveIfError(ret); |
|
1261 INFO_PRINTF1(_L(" Create File server session ")); |
|
1262 |
|
1263 ret = file.Open(fs,KFilePath,EFileWrite | EFileShareAny); |
|
1264 TEST(ret == KErrNone); |
|
1265 if(ret == KErrNone) |
|
1266 { |
|
1267 INFO_PRINTF1(_L(" File opened successfully ")); |
|
1268 TBuf8<5> readData; |
|
1269 file.Read(0,readData); |
|
1270 TBuf8<5> result(KTResultFail); |
|
1271 TEST(result==readData); |
|
1272 if(result==readData) |
|
1273 { |
|
1274 INFO_PRINTF1(_L(" Child did not receive the parent process ID as intended...")); |
|
1275 } |
|
1276 else |
|
1277 { |
|
1278 INFO_PRINTF1(_L(" Child received the Wrong parent process ID ...")); |
|
1279 } |
|
1280 file.Close(); |
|
1281 fs.Delete(KFilePath); |
|
1282 fs.Close(); |
|
1283 INFO_PRINTF1(_L(" File Close & Delete and Session Close ")); |
|
1284 } |
|
1285 |
|
1286 TExitType exitType = parentProc.ExitType(); |
|
1287 TEST(exitType == EExitPending); |
|
1288 if(exitType == EExitPending) |
|
1289 { |
|
1290 INFO_PRINTF1(_L(" Parent is still running ")); |
|
1291 INFO_PRINTF1(_L(" So Terminating it manually ... ")); |
|
1292 parentProc.Terminate(KTProcTerminatingParent); |
|
1293 exitType = parentProc.ExitType(); |
|
1294 TEST(exitType==EExitTerminate); |
|
1295 exitReason = parentProc.ExitReason(); |
|
1296 TEST(exitReason == KTProcTerminatingParent); |
|
1297 } |
|
1298 |
|
1299 exitType = childProc.ExitType(); |
|
1300 TEST(exitType == EExitPending); |
|
1301 if(exitType == EExitPending) |
|
1302 { |
|
1303 INFO_PRINTF1(_L(" Child is still running ")); |
|
1304 INFO_PRINTF1(_L(" So Terminating it manually ... ")); |
|
1305 childProc.Terminate(KTProcTerminatingChildIII); |
|
1306 exitType = childProc.ExitType(); |
|
1307 TEST(exitType==EExitTerminate); |
|
1308 exitReason = childProc.ExitReason(); |
|
1309 TEST(exitReason == KTProcTerminatingChildIII); |
|
1310 } |
|
1311 |
|
1312 CleanupStack::PopAndDestroy(&childProc); |
|
1313 CleanupStack::PopAndDestroy(childProcCmdln); |
|
1314 CleanupStack::PopAndDestroy(&parentProc); |
|
1315 CleanupStack::PopAndDestroy(parentProcCmdln); |
|
1316 } |
|
1317 |
|
1318 void CT_ProcStep::testChildExistsL(void) |
|
1319 /** |
|
1320 * Calls other functions which implement the test cases. |
|
1321 */ |
|
1322 { |
|
1323 INFO_PRINTF1(_L("Begin - testChildSetToTerminateL ----------- ")); |
|
1324 TRAPD(ret,testChildSetToTerminateL()); |
|
1325 TEST(ret==KErrNone); |
|
1326 INFO_PRINTF1(_L("End - testChildSetToTerminateL ----------- \n")); |
|
1327 |
|
1328 INFO_PRINTF1(_L("Begin - testChildSetToRemainL ----------- ")); |
|
1329 TRAP(ret,testChildSetToRemainL()); |
|
1330 TEST(ret==KErrNone); |
|
1331 INFO_PRINTF1(_L("End - testChildSetToRemainL ----------- \n")); |
|
1332 |
|
1333 INFO_PRINTF1(_L("Begin - testTwoChildsOneToTerminateAndOtherToRemainL ----------- ")); |
|
1334 TRAP(ret,testTwoChildsOneToTerminateAndOtherToRemainL()); |
|
1335 TEST(ret==KErrNone); |
|
1336 INFO_PRINTF1(_L("End - testTwoChildsOneToTerminateAndOtherToRemainL ----------- \n")); |
|
1337 |
|
1338 INFO_PRINTF1(_L("Begin - testParentWithoutAChildL ----------- ")); |
|
1339 TRAP(ret,testParentWithoutAChildL()); |
|
1340 TEST(ret==KErrNone); |
|
1341 INFO_PRINTF1(_L("End - testParentWithoutAChildL ----------- \n")); |
|
1342 |
|
1343 INFO_PRINTF1(_L("Begin - testAllChildsSetToTerminateL ----------- ")); |
|
1344 TRAP(ret,testAllChildsSetToTerminateL()); |
|
1345 TEST(ret==KErrNone); |
|
1346 INFO_PRINTF1(_L("End - testAllChildsSetToTerminateL ----------- \n")); |
|
1347 |
|
1348 INFO_PRINTF1(_L("Begin - testNoChildSetToTerminateL ----------- ")); |
|
1349 TRAP(ret,testNoChildSetToTerminateL()); |
|
1350 TEST(ret==KErrNone); |
|
1351 INFO_PRINTF1(_L("End - testNoChildSetToTerminateL ----------- \n")); |
|
1352 |
|
1353 INFO_PRINTF1(_L("Begin - testIdAvailableToChildL ----------- ")); |
|
1354 TRAP(ret,testIdAvailableToChildL()); |
|
1355 TEST(ret==KErrNone); |
|
1356 INFO_PRINTF1(_L("End - testIdAvailableToChildL ----------- \n")); |
|
1357 |
|
1358 INFO_PRINTF1(_L("Begin - testIdNotAvailableToChildL ----------- ")); |
|
1359 TRAP(ret,testIdNotAvailableToChildL()); |
|
1360 TEST(ret==KErrNone); |
|
1361 INFO_PRINTF1(_L("End - testIdNotAvailableToChildL ----------- \n")); |
|
1362 } |
|
1363 |
|
1364 TVerdict CT_ProcStep::doTestStepL() |
|
1365 /** |
|
1366 @return - TVerdict code |
|
1367 Override of base class virtual |
|
1368 */ |
|
1369 { |
|
1370 INFO_PRINTF1(_L("Test child process existence when parent terminates/exists begins here ------- \n")); |
|
1371 |
|
1372 __UHEAP_MARK; |
|
1373 |
|
1374 CActiveScheduler* scheduler = new(ELeave) CActiveScheduler; |
|
1375 CActiveScheduler::Install(scheduler); |
|
1376 CleanupStack::PushL(scheduler); |
|
1377 |
|
1378 TRAPD(ret,testChildExistsL()); |
|
1379 TEST(ret==KErrNone); |
|
1380 |
|
1381 CleanupStack::PopAndDestroy(scheduler); |
|
1382 |
|
1383 __UHEAP_MARKEND; |
|
1384 |
|
1385 INFO_PRINTF1(_L("Test child process existence when parent terminates/exists ends here ------- \n")); |
|
1386 |
|
1387 return TestStepResult(); |
|
1388 } |