|
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 "testapp_loadsysmon.h" |
|
23 #include "testapps.h" |
|
24 |
|
25 _LIT(KTestAppLoadSysmon, "testapp_loadsysmon.exe"); |
|
26 _LIT(KLoadSysMonDLL, "loadsysmon.dll"); |
|
27 typedef MSsmLoadSysMon* (*TFuncNewL)(void); |
|
28 |
|
29 void TestLoadSysMonDllL() |
|
30 { |
|
31 CTLoadSysMon* loadSysMon = CTLoadSysMon::NewLC(); |
|
32 |
|
33 //Tests Sysmon functionlities using SsmStartupProperties |
|
34 CSsmStartupProperties *ssmPropForSelfMon = CSsmStartupProperties::NewLC(KTestAppLoadSysmon, KNullDesC); |
|
35 ssmPropForSelfMon->SetExecutionBehaviour(ESsmWaitForSignal); |
|
36 TSsmMonitorInfo monitorInfo; |
|
37 monitorInfo.iRestartPolicy = ESsmIgnoreOnFailure; |
|
38 monitorInfo.iRestartMode = 0; |
|
39 monitorInfo.iTimeout = 0; |
|
40 monitorInfo.iRetries = 0; |
|
41 ssmPropForSelfMon->SetMonitorInfoL(monitorInfo);// SysMon will not do any restart attempts |
|
42 |
|
43 CSsmStartupProperties *ssmForOtherProcMon = CSsmStartupProperties::NewLC(KTestProcGood, KNullDesC); |
|
44 ssmForOtherProcMon->SetExecutionBehaviour(ESsmWaitForSignal); |
|
45 ssmForOtherProcMon->SetMonitorInfoL(monitorInfo);// SysMon will not do any restart attempts |
|
46 |
|
47 loadSysMon->TestForSysMonFuncUsingSsmStartupPropL(*ssmPropForSelfMon, *ssmForOtherProcMon); |
|
48 |
|
49 CleanupStack::PopAndDestroy(ssmForOtherProcMon); |
|
50 CleanupStack::PopAndDestroy(ssmPropForSelfMon); |
|
51 |
|
52 //Tests Sysmon functionlities using StartupProperties |
|
53 CStartupProperties *propForSelfMon = CStartupProperties::NewLC(KTestAppLoadSysmon, KNullDesC); |
|
54 propForSelfMon->SetMonitored(ETrue); |
|
55 propForSelfMon->SetNoOfRetries(0); // SysMon will not do any restart attempts |
|
56 |
|
57 CStartupProperties *propForOtherProcMon = CStartupProperties::NewLC(KTestProcGood, KNullDesC); |
|
58 propForOtherProcMon->SetMonitored(ETrue); |
|
59 propForOtherProcMon->SetNoOfRetries(0); // SysMon will not do any restart attempts |
|
60 |
|
61 loadSysMon->TestForSysMonFuncUsingStartupPropL(*propForSelfMon, *propForOtherProcMon); |
|
62 |
|
63 CleanupStack::PopAndDestroy(propForOtherProcMon); |
|
64 CleanupStack::PopAndDestroy(propForSelfMon); |
|
65 CleanupStack::PopAndDestroy(loadSysMon); |
|
66 } |
|
67 |
|
68 CTLoadSysMon* CTLoadSysMon::NewLC() |
|
69 { |
|
70 CTLoadSysMon* self = new (ELeave) CTLoadSysMon(); |
|
71 CleanupStack::PushL(self); |
|
72 self->ConstructL(); |
|
73 return self; |
|
74 } |
|
75 |
|
76 CTLoadSysMon::CTLoadSysMon() |
|
77 { |
|
78 } |
|
79 |
|
80 void CTLoadSysMon::ConstructL() |
|
81 { |
|
82 User::LeaveIfError(iMonitorProxyLib.Load(KLoadSysMonDLL)); |
|
83 |
|
84 TFuncNewL sysMonNewL = reinterpret_cast<TFuncNewL>(iMonitorProxyLib.Lookup(1)); |
|
85 iSysMonCli = sysMonNewL(); |
|
86 } |
|
87 |
|
88 CTLoadSysMon::~CTLoadSysMon() |
|
89 { |
|
90 delete iSysMonCli; |
|
91 iMonitorProxyLib.Close(); |
|
92 } |
|
93 |
|
94 void CTLoadSysMon::TestForSysMonFuncUsingSsmStartupPropL(const CSsmStartupProperties& aSsmStartupPropForSelfMonitor, const CSsmStartupProperties& aSsmStartupPropForOtherProcMonitor) |
|
95 { |
|
96 // Opens session with sysmoncli through loadsysmon interface |
|
97 iSysMonCli->OpenL(); |
|
98 |
|
99 // Sets up monitor for self |
|
100 iSysMonCli->MonitorSelfL(aSsmStartupPropForSelfMonitor); |
|
101 // Cancel the Monitor |
|
102 iSysMonCli->CancelMonitorSelfL(); |
|
103 |
|
104 RProcess process; |
|
105 CleanupClosePushL(process); |
|
106 User::LeaveIfError(process.Create(KTestProcGood, KNullDesC)); |
|
107 ResumeL(process); |
|
108 |
|
109 // Sets up monitor for KTestProcGood |
|
110 iSysMonCli->MonitorL(aSsmStartupPropForOtherProcMonitor, process); |
|
111 // Cancel the Monitor |
|
112 iSysMonCli->CancelMonitorSelfL(); |
|
113 |
|
114 //Killing the process |
|
115 process.Kill(KErrNone); |
|
116 CleanupStack::PopAndDestroy(&process); |
|
117 |
|
118 // Closes the session with sysmoncli |
|
119 iSysMonCli->Close(); |
|
120 } |
|
121 |
|
122 void CTLoadSysMon::TestForSysMonFuncUsingStartupPropL(const CStartupProperties& aStartupPropForSelfMonitor, const CStartupProperties& aStartupPropForOtherProcMonitor) |
|
123 { |
|
124 // Opens session with sysmoncli through loadsysmon interface |
|
125 iSysMonCli->OpenL(); |
|
126 |
|
127 // Sets up monitor for self |
|
128 iSysMonCli->MonitorSelfL(aStartupPropForSelfMonitor); |
|
129 // Cancel the Monitor |
|
130 iSysMonCli->CancelMonitorSelfL(); |
|
131 |
|
132 RProcess process; |
|
133 CleanupClosePushL(process); |
|
134 User::LeaveIfError(process.Create(KTestProcGood, KNullDesC)); |
|
135 ResumeL(process); |
|
136 |
|
137 // Sets up monitor for KTestProcGood |
|
138 iSysMonCli->MonitorL(aStartupPropForOtherProcMonitor, process); |
|
139 // Cancel the Monitor |
|
140 iSysMonCli->CancelMonitorSelfL(); |
|
141 |
|
142 //Killing the process |
|
143 process.Kill(KErrNone); |
|
144 CleanupStack::PopAndDestroy(&process); |
|
145 |
|
146 // Closes the session with sysmoncli |
|
147 iSysMonCli->Close(); |
|
148 } |
|
149 |
|
150 /** |
|
151 Waits for the process to rendevouz, then resumes it. |
|
152 */ |
|
153 void CTLoadSysMon::ResumeL(RProcess& aProcess) |
|
154 { |
|
155 TRequestStatus status; |
|
156 aProcess.Rendezvous(status); |
|
157 if (status == KRequestPending) |
|
158 { |
|
159 aProcess.Resume(); |
|
160 } |
|
161 else |
|
162 { |
|
163 aProcess.Kill(KErrGeneral); |
|
164 User::Leave(status.Int()); |
|
165 } |
|
166 |
|
167 User::WaitForRequest(status); |
|
168 } |
|
169 |
|
170 // Global Functions |
|
171 TInt E32Main() |
|
172 { |
|
173 // Create cleanup stack |
|
174 __UHEAP_MARK; |
|
175 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
176 |
|
177 if (!cleanup) |
|
178 { |
|
179 RProcess().Terminate(KErrNoMemory); |
|
180 } |
|
181 |
|
182 // Run application code inside TRAP harness |
|
183 TRAPD(testError, TestLoadSysMonDllL()); |
|
184 if (testError) |
|
185 { |
|
186 RProcess().Terminate(testError); |
|
187 } |
|
188 |
|
189 delete cleanup; |
|
190 __UHEAP_MARKEND; |
|
191 return KErrNone; |
|
192 } //lint -e714 Suppress 'not referenced' |