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