|
1 // Copyright (c) 2007-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 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @test |
|
19 @internalComponent - Internal Symbian test code |
|
20 */ |
|
21 |
|
22 #include <sysmonclisess.h> |
|
23 #include <startupproperties.h> |
|
24 #include <ssm/ssmstartupproperties.h> |
|
25 #include "testapps.h" |
|
26 #include "tsysmon_stepmultiprocmon.h" |
|
27 |
|
28 |
|
29 CStepMultiProcMon::CStepMultiProcMon() |
|
30 { |
|
31 SetTestStepName(KCTestCaseMultiProcMon); |
|
32 } |
|
33 |
|
34 CStepMultiProcMon::~CStepMultiProcMon() |
|
35 { |
|
36 iProcess1.Close(); |
|
37 iProcess2.Close(); |
|
38 } |
|
39 |
|
40 /** |
|
41 Old Test CaseID APPFWK-SYSMON-0002 |
|
42 New Test CaseID DEVSRVS-SHMA-SYSMON-0002 |
|
43 */ |
|
44 |
|
45 TVerdict CStepMultiProcMon::doTestStepL() |
|
46 { |
|
47 INFO_PRINTF1(_L("TEST APPFWK-SYSMON-0002")); |
|
48 |
|
49 CreateProcessL(); |
|
50 // Do the testing |
|
51 DoTestMonitorUsingStartupPropL(); |
|
52 // Tidy up |
|
53 iProcess1.Kill(KErrNone); |
|
54 iProcess2.Kill(KErrNone); |
|
55 |
|
56 CreateProcessL(); |
|
57 DoTestMonitorUsingSsmStartupPropL(); |
|
58 // Tidy up |
|
59 iProcess1.Kill(KErrNone); |
|
60 iProcess2.Kill(KErrNone); |
|
61 |
|
62 INFO_PRINTF1(_L("Test Step completed")); |
|
63 return TestStepResult(); |
|
64 } |
|
65 |
|
66 void CStepMultiProcMon::CreateProcessL() |
|
67 { |
|
68 // Launch two instances of the same executable |
|
69 INFO_PRINTF1(_L("Going to set first process running")); |
|
70 User::LeaveIfError(iProcess1.Create(KTestProcGood, KNullDesC)); |
|
71 ResumeL(iProcess1); |
|
72 |
|
73 INFO_PRINTF1(_L("Starting a second instance of the same executable")); |
|
74 User::LeaveIfError(iProcess2.Create(KTestProcGood, KNullDesC)); |
|
75 ResumeL(iProcess2); |
|
76 } |
|
77 |
|
78 /** |
|
79 * Contains the actual testing. Verifying that it is possible to monitor more than one |
|
80 * instance of the same executable. |
|
81 */ |
|
82 void CStepMultiProcMon::DoTestMonitorUsingStartupPropL() |
|
83 { |
|
84 RSysMonSession sess; |
|
85 CleanupClosePushL(sess); |
|
86 sess.OpenL(); |
|
87 |
|
88 INFO_PRINTF1(_L("Going to request process monitoring using startupproperties")); |
|
89 CStartupProperties *prop = CStartupProperties::NewLC(KTestProcGood, KNullDesC); |
|
90 prop->SetMonitored(ETrue); |
|
91 prop->SetNoOfRetries(0); // SysMon will not do any restart attempts |
|
92 |
|
93 INFO_PRINTF1(_L("Going to monitor first process")); |
|
94 sess.MonitorL(*prop, iProcess1); |
|
95 INFO_PRINTF1(_L("Successfully setup monitoring of first process.")); |
|
96 |
|
97 INFO_PRINTF1(_L("Going to monitor second process")); |
|
98 sess.MonitorL(*prop, iProcess2); |
|
99 INFO_PRINTF1(_L("Successfully setup monitoring of second process.")); |
|
100 |
|
101 INFO_PRINTF1(_L("Try to register monitoring for second time")); |
|
102 TRAPD(err, sess.MonitorL(*prop, iProcess1)); |
|
103 TESTE(err == KErrAlreadyExists, err); |
|
104 if(err == KErrAlreadyExists) |
|
105 { |
|
106 INFO_PRINTF1(_L("Second monitor request for first process returned KErrAlreadyExists as expected")); |
|
107 } |
|
108 TRAP(err, sess.MonitorL(*prop, iProcess2)); |
|
109 TESTE(err == KErrAlreadyExists, err); |
|
110 if(err == KErrAlreadyExists) |
|
111 { |
|
112 INFO_PRINTF1(_L("Second monitor request for second process returned KErrAlreadyExists as expected")); |
|
113 } |
|
114 |
|
115 CleanupStack::PopAndDestroy(prop); |
|
116 CleanupStack::PopAndDestroy(&sess); |
|
117 INFO_PRINTF1(_L("Process monitoring using startupproperties Completed")); |
|
118 } |
|
119 |
|
120 void CStepMultiProcMon::DoTestMonitorUsingSsmStartupPropL() |
|
121 { |
|
122 RSysMonSession sess; |
|
123 CleanupClosePushL(sess); |
|
124 sess.OpenL(); |
|
125 |
|
126 INFO_PRINTF1(_L("Going to request process monitoring using ssmstartupproperties")); |
|
127 CSsmStartupProperties *ssmProp = CSsmStartupProperties::NewLC(KTestProcGood, KNullDesC); |
|
128 ssmProp->SetExecutionBehaviour(ESsmWaitForSignal); |
|
129 TSsmMonitorInfo monitorInfo; |
|
130 monitorInfo.iRestartPolicy = ESsmIgnoreOnFailure; |
|
131 monitorInfo.iRestartMode = 0; |
|
132 monitorInfo.iTimeout = 0; |
|
133 monitorInfo.iRetries = 0; |
|
134 |
|
135 ssmProp->SetMonitorInfoL(monitorInfo);// SysMon will not do any restart attempts |
|
136 |
|
137 INFO_PRINTF1(_L("Going to monitor first process")); |
|
138 sess.MonitorL(*ssmProp, iProcess1); |
|
139 INFO_PRINTF1(_L("Successfully setup monitoring of first process.")); |
|
140 |
|
141 INFO_PRINTF1(_L("Going to monitor second process")); |
|
142 sess.MonitorL(*ssmProp, iProcess2); |
|
143 INFO_PRINTF1(_L("Successfully setup monitoring of second process.")); |
|
144 |
|
145 INFO_PRINTF1(_L("Try to register monitoring for second time")); |
|
146 TRAPD(err, sess.MonitorL(*ssmProp, iProcess1)); |
|
147 TESTE(err == KErrAlreadyExists, err); |
|
148 if(err == KErrAlreadyExists) |
|
149 { |
|
150 INFO_PRINTF1(_L("Second monitor request for first process returned KErrAlreadyExists as expected")); |
|
151 } |
|
152 TRAP(err, sess.MonitorL(*ssmProp, iProcess2)); |
|
153 TESTE(err == KErrAlreadyExists, err); |
|
154 if(err == KErrAlreadyExists) |
|
155 { |
|
156 INFO_PRINTF1(_L("Second monitor request for second process returned KErrAlreadyExists as expected")); |
|
157 } |
|
158 |
|
159 CleanupStack::PopAndDestroy(ssmProp); |
|
160 CleanupStack::PopAndDestroy(&sess); |
|
161 INFO_PRINTF1(_L("Process monitoring using ssmstartupproperties Completed")); |
|
162 } |