|
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 // Old Test CaseID APPFWK-SSS-0006 |
|
15 // New Test CaseID DEVSRVS-SSMA-STARTSAFE-0006 |
|
16 // |
|
17 // |
|
18 |
|
19 /** |
|
20 @file |
|
21 @test |
|
22 @internalComponent - Internal Symbian test code |
|
23 */ |
|
24 |
|
25 |
|
26 #include <ssm/ssmstartsafe.h> |
|
27 #include "tss_procstartmon.h" |
|
28 #include "ssmtestapps.h" |
|
29 |
|
30 |
|
31 const TInt KThrottleTime = 15000000; //15s |
|
32 const TInt KStartMonStopperTimeout = 5000000; // Could (probably) be shaved. |
|
33 |
|
34 |
|
35 TVerdict CSsTestStepProcStartMon::doTestStepL( void ) |
|
36 { |
|
37 //Creating the semaphore |
|
38 TInt err = iSem.CreateGlobal(KStartProcSignalSemaphore, 0); |
|
39 INFO_PRINTF2(_L("Created semaphore with err %d"),err); |
|
40 TEST(err == KErrNone); |
|
41 |
|
42 __UHEAP_MARK; |
|
43 |
|
44 TRAP(err, DoTestMonForAlreadyStartedProcL()); |
|
45 TEST(err == KErrNone); |
|
46 INFO_PRINTF2(_L("DoTestMonForAlreadyStartedProcL completed with err = %d"), err); |
|
47 |
|
48 TRAP(err, DoTestMonSyncL()); |
|
49 TEST(err == KErrNone); |
|
50 INFO_PRINTF2(_L("DoTestMonSyncL completed with err = %d"), err); |
|
51 |
|
52 __UHEAP_MARKEND; |
|
53 iSem.Close(); |
|
54 return TestStepResult(); |
|
55 } |
|
56 |
|
57 |
|
58 |
|
59 /** |
|
60 Starts an instance of ssmtestprocgood.exe synchronously, in a process, as a server, specifying 1 retry. |
|
61 Kill it and ensure that it is restarted. Tell it to stop being monitored and kill it again. |
|
62 Ensure that it stays killed. |
|
63 */ |
|
64 void CSsTestStepProcStartMon::DoTestMonSyncL() |
|
65 { |
|
66 INFO_PRINTF1( _L("\n\nPerforming Process-monitor sync") ); |
|
67 |
|
68 CSsmStartupProperties* startupProperties = CSsmStartupProperties::NewL(); |
|
69 CleanupStack::PushL( startupProperties ); |
|
70 |
|
71 // Need to start testprocess as a server so that we can tell it to stop being monitored. |
|
72 startupProperties->SetFileParamsL( KTestProcGood, KLaunchServerCommandLineOption ); |
|
73 startupProperties->SetCommandTypeL( ESsmCmdStartProcess ); |
|
74 startupProperties->SetExecutionBehaviour( ESsmWaitForSignal ); // Rem: EssmFireAndForget is disallowed |
|
75 |
|
76 const TInt KMonitorTimeout = 3000; // milliseconds I presume |
|
77 TSsmMonitorInfo monitorInfo; |
|
78 monitorInfo.iRestartPolicy = ESsmIgnoreOnFailure; |
|
79 monitorInfo.iRestartMode = 0; |
|
80 monitorInfo.iTimeout = KMonitorTimeout; |
|
81 monitorInfo.iRetries = 1; |
|
82 startupProperties->SetMonitorInfoL(monitorInfo); |
|
83 |
|
84 RProcess process; |
|
85 CleanupClosePushL( process ); |
|
86 CSsmStartSafe* ss = CSsmStartSafe::NewLC(); |
|
87 |
|
88 CTestAndStopper* testAndStopper = new(ELeave) CTestAndStopper( *ss, *startupProperties, process, KStartMonStopperTimeout, this ); |
|
89 CleanupStack::PushL( testAndStopper ); |
|
90 CActiveScheduler::Start(); |
|
91 |
|
92 //Waiting to decrement the count of the semaphore which is being signalled as the application is started first time |
|
93 iSem.Wait(); |
|
94 |
|
95 // Check that the killed process is restarted by SysMon |
|
96 TEST( 1 == FindAndKill(KTestProcGood) ); |
|
97 INFO_PRINTF1( _L("Await Restart before killing the process again") ); |
|
98 //Waiting using semaphore |
|
99 iSem.Wait(); |
|
100 |
|
101 TEST( 1 == FindAndKill(KTestProcGood) ); |
|
102 INFO_PRINTF1( _L("Await Restart -> connect -> cancel monitor -> kill") ); |
|
103 //Waiting using semaphore |
|
104 iSem.Wait(); |
|
105 |
|
106 // Stop monitoring to stop restarts. |
|
107 RTestProcGoodSession testProcServerSession; |
|
108 |
|
109 if( KErrNone == testProcServerSession.Connect() ) |
|
110 { |
|
111 testProcServerSession.CancelMonitor(); |
|
112 testProcServerSession.Close(); |
|
113 } |
|
114 |
|
115 TEST( 1 == FindAndKill(KTestProcGood) ); |
|
116 INFO_PRINTF1( _L("Ensure the test-process is dead") ); |
|
117 User::After( KThrottleTime ); |
|
118 // Ensure it's not hanging around |
|
119 TEST( 0 == FindAndKill(KTestProcGood) ); |
|
120 |
|
121 CleanupStack::PopAndDestroy( 4, startupProperties ); |
|
122 } |
|
123 |
|
124 void CSsTestStepProcStartMon::DoTestMonForAlreadyStartedProcL() |
|
125 { |
|
126 INFO_PRINTF1( _L("Performing Process-monitor test for already started process") ); |
|
127 |
|
128 RProcess process; |
|
129 CleanupClosePushL(process); |
|
130 User::LeaveIfError(process.Create(KTestProcGood, KLaunchServerCommandLineOption)); |
|
131 |
|
132 TRequestStatus status; |
|
133 process.Rendezvous(status); |
|
134 if (status == KRequestPending) |
|
135 { |
|
136 process.Resume(); |
|
137 } |
|
138 else |
|
139 { |
|
140 process.Kill(KErrGeneral); |
|
141 TESTEL(EFalse, status.Int()); |
|
142 } |
|
143 |
|
144 //Waiting to decrement the count of the semaphore which is being signalled as the application is started first time |
|
145 iSem.Wait(); |
|
146 User::WaitForRequest(status); |
|
147 INFO_PRINTF1(_L("Process started")); |
|
148 TEST(process.ExitType() == EExitPending); |
|
149 |
|
150 CSsmStartupProperties* startupProperties = CSsmStartupProperties::NewL(); |
|
151 CleanupStack::PushL( startupProperties ); |
|
152 |
|
153 // Need to start testprocess as a server so that we can tell it to stop being monitored. |
|
154 startupProperties->SetFileParamsL(KTestProcGood, KLaunchServerCommandLineOption); |
|
155 startupProperties->SetCommandTypeL(ESsmCmdStartProcess); |
|
156 startupProperties->SetExecutionBehaviour(ESsmWaitForSignal); |
|
157 |
|
158 const TInt KMonitorTimeout = 3000; // milliseconds I presume |
|
159 TSsmMonitorInfo monitorInfo; |
|
160 monitorInfo.iRestartPolicy = ESsmIgnoreOnFailure; |
|
161 monitorInfo.iRestartMode = 0; |
|
162 monitorInfo.iTimeout = KMonitorTimeout; |
|
163 monitorInfo.iRetries = 1; |
|
164 startupProperties->SetMonitorInfoL(monitorInfo); |
|
165 |
|
166 CSsmStartSafe* ss = CSsmStartSafe::NewLC(); |
|
167 |
|
168 // Try to start and monitor the process which already started using RProcess::Create(). |
|
169 TRAPD(err, ss->StartAndMonitorL(*startupProperties, process)); |
|
170 |
|
171 // Trying to start and monitor an already running process is treated as successful. Startsafe would monitor the |
|
172 // already running process. |
|
173 TEST(err == KErrNone); |
|
174 INFO_PRINTF3( _L("StartAndMonitorL() completed with %d. anticipated value %d"),err, KErrNone ); |
|
175 |
|
176 RTestProcGoodSession testProcServerSession; |
|
177 err = testProcServerSession.Connect(); |
|
178 TEST(KErrNone == err); |
|
179 INFO_PRINTF1( _L("Asserted that server is running")); |
|
180 process.Kill(KErrNone); |
|
181 //In multiprocessor environment, potentially objects can be deleted on a different CPU |
|
182 //from the code which requested the deletion. Hence the delay of 5 seconds has been added. |
|
183 User::After(5000000); //5sec delay. |
|
184 |
|
185 err = testProcServerSession.Connect(); |
|
186 TEST(KErrNotFound == err); |
|
187 INFO_PRINTF3( _L("Connect to test proc server session failed with %d. anticipated value %d"),err, KErrNotFound); |
|
188 |
|
189 TEST(process.ExitType() == EExitKill); |
|
190 //Waiting using semaphore |
|
191 iSem.Wait(); |
|
192 |
|
193 // Check that the killed process is restarted by SysMon |
|
194 err = testProcServerSession.Connect(); |
|
195 TEST(KErrNone == err); |
|
196 INFO_PRINTF1( _L("Asserted that server is re-started by sysmon")); |
|
197 |
|
198 // Stop monitoring to stop restarts. |
|
199 if(KErrNone == testProcServerSession.Connect()) |
|
200 { |
|
201 testProcServerSession.CancelMonitor(); |
|
202 testProcServerSession.Close(); |
|
203 } |
|
204 TEST(1 == FindAndKill(KTestProcGood)); |
|
205 CleanupStack::PopAndDestroy(3, &process); |
|
206 } |
|
207 |
|
208 void CSsTestStepProcStartMon::SsTestNotify( TInt aNotify ) |
|
209 { |
|
210 INFO_PRINTF2( _L("StartAndMonitorL( left with %d"), aNotify ); |
|
211 |
|
212 TEST( 0 ); |
|
213 } |
|
214 |
|
215 |
|
216 |
|
217 TVerdict CSsTestStepProcStartMon::doTestStepPreambleL() |
|
218 { |
|
219 iActiveScheduler = new(ELeave) CActiveScheduler; |
|
220 CActiveScheduler::Install ( iActiveScheduler ); |
|
221 |
|
222 return CTestStep::doTestStepPreambleL(); |
|
223 } |
|
224 |
|
225 |
|
226 |
|
227 /** */ |
|
228 TVerdict CSsTestStepProcStartMon::doTestStepPostambleL() |
|
229 { |
|
230 return CTestStep::doTestStepPostambleL(); |
|
231 } |
|
232 |
|
233 |
|
234 |
|
235 CSsTestStepProcStartMon::CSsTestStepProcStartMon() |
|
236 { |
|
237 SetTestStepName(KCTestCaseProcStartMon); |
|
238 } |
|
239 |
|
240 |
|
241 |
|
242 CSsTestStepProcStartMon::~CSsTestStepProcStartMon() |
|
243 { |
|
244 delete iActiveScheduler; |
|
245 } |
|
246 |
|
247 |