sl@0
|
1 |
// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// e32test\power\t_power.cpp
|
sl@0
|
15 |
// Overview:
|
sl@0
|
16 |
// Test power down and wakeup event notification
|
sl@0
|
17 |
// API Information:
|
sl@0
|
18 |
// Power::PowerDown(), Power::RequestWakeupEventNotification()
|
sl@0
|
19 |
// Details:
|
sl@0
|
20 |
// - Arm a wakeup timer, enable wakeup events, enter standby mode, get woken up.
|
sl@0
|
21 |
// - Test RequestWakeupEventNotification(): arm a timer, request notification,
|
sl@0
|
22 |
// wait for timer to expire, verify event has been notified, issue another
|
sl@0
|
23 |
// notification request, disable wakeup events, arm another timer, verify
|
sl@0
|
24 |
// wakeup event has not been notified, cancel the notification request and
|
sl@0
|
25 |
// close the timer.
|
sl@0
|
26 |
// - Verify that a slave process panics because it hasn't and capability.
|
sl@0
|
27 |
// - Confirm the number of open handles and pending requests are as expected.
|
sl@0
|
28 |
// Platforms/Drives/Compatibility:
|
sl@0
|
29 |
// All.
|
sl@0
|
30 |
// Assumptions/Requirement/Pre-requisites:
|
sl@0
|
31 |
// Failures and causes:
|
sl@0
|
32 |
// Base Port information:
|
sl@0
|
33 |
//
|
sl@0
|
34 |
//
|
sl@0
|
35 |
|
sl@0
|
36 |
#define __E32TEST_EXTENSION__
|
sl@0
|
37 |
|
sl@0
|
38 |
#include <e32power.h>
|
sl@0
|
39 |
#include <e32test.h>
|
sl@0
|
40 |
#include <e32kpan.h>
|
sl@0
|
41 |
#include <f32file.h>
|
sl@0
|
42 |
#include <e32ldr.h>
|
sl@0
|
43 |
#include <e32ldr_private.h>
|
sl@0
|
44 |
|
sl@0
|
45 |
LOCAL_D RTest test(_L(" T_POWER "));
|
sl@0
|
46 |
|
sl@0
|
47 |
void SetAbsoluteTimeout(RTimer& aTimer, TUint aUs, TRequestStatus& aStatus)
|
sl@0
|
48 |
{
|
sl@0
|
49 |
TTime wakeup;
|
sl@0
|
50 |
wakeup.HomeTime();
|
sl@0
|
51 |
wakeup += TTimeIntervalMicroSeconds(aUs);
|
sl@0
|
52 |
aTimer.At(aStatus, wakeup);
|
sl@0
|
53 |
}
|
sl@0
|
54 |
|
sl@0
|
55 |
void PowerTests()
|
sl@0
|
56 |
{
|
sl@0
|
57 |
test.Next(_L("test PowerDown()"));
|
sl@0
|
58 |
|
sl@0
|
59 |
TInt r = Power::PowerDown();
|
sl@0
|
60 |
test (r == KErrNotReady);
|
sl@0
|
61 |
|
sl@0
|
62 |
for (int i = 0; i < 4; ++i)
|
sl@0
|
63 |
{
|
sl@0
|
64 |
test.Printf(_L(" %d "), i);
|
sl@0
|
65 |
// Arm an absolute timer wakeup event after 5 sec
|
sl@0
|
66 |
TRequestStatus absstatus;
|
sl@0
|
67 |
RTimer abstimer;
|
sl@0
|
68 |
r = abstimer.CreateLocal();
|
sl@0
|
69 |
test (r == KErrNone);
|
sl@0
|
70 |
SetAbsoluteTimeout(abstimer, 5000000, absstatus); // 5 sec
|
sl@0
|
71 |
// Go to standby
|
sl@0
|
72 |
r = Power::EnableWakeupEvents(EPwStandby);
|
sl@0
|
73 |
test (r == KErrNone);
|
sl@0
|
74 |
r = Power::PowerDown();
|
sl@0
|
75 |
test (r == KErrNone);
|
sl@0
|
76 |
User::WaitForRequest(absstatus);
|
sl@0
|
77 |
abstimer.Close();
|
sl@0
|
78 |
}
|
sl@0
|
79 |
test.Printf(_L(" OK\n"));
|
sl@0
|
80 |
|
sl@0
|
81 |
test.Next(_L("test RequestWakeupEventNotification()"));
|
sl@0
|
82 |
|
sl@0
|
83 |
{
|
sl@0
|
84 |
TInt r = Power::EnableWakeupEvents(EPwActive);
|
sl@0
|
85 |
test (r == KErrArgument);
|
sl@0
|
86 |
|
sl@0
|
87 |
// Request wakup event notification and enable wakeup events
|
sl@0
|
88 |
TRequestStatus status;
|
sl@0
|
89 |
Power::RequestWakeupEventNotification(status);
|
sl@0
|
90 |
test(status.Int() == KRequestPending);
|
sl@0
|
91 |
r = Power::EnableWakeupEvents(EPwStandby);
|
sl@0
|
92 |
test (r == KErrNone);
|
sl@0
|
93 |
// Arm an absolute timer wakeup event
|
sl@0
|
94 |
TRequestStatus absstatus;
|
sl@0
|
95 |
RTimer abstimer;
|
sl@0
|
96 |
r = abstimer.CreateLocal();
|
sl@0
|
97 |
test (r == KErrNone);
|
sl@0
|
98 |
SetAbsoluteTimeout(abstimer, 100000, absstatus); // 100ms
|
sl@0
|
99 |
// Wait for the timer
|
sl@0
|
100 |
User::WaitForRequest(absstatus);
|
sl@0
|
101 |
test(absstatus.Int() == KErrNone);
|
sl@0
|
102 |
// Wakup event has to be already notified
|
sl@0
|
103 |
test(status.Int() == KErrNone);
|
sl@0
|
104 |
User::WaitForRequest(status); // collect it
|
sl@0
|
105 |
// Issue another notification request
|
sl@0
|
106 |
Power::RequestWakeupEventNotification(status);
|
sl@0
|
107 |
test(status.Int() == KRequestPending);
|
sl@0
|
108 |
// Disable wakeup events
|
sl@0
|
109 |
Power::DisableWakeupEvents();
|
sl@0
|
110 |
// Arm another absolute timer wakeup event
|
sl@0
|
111 |
SetAbsoluteTimeout(abstimer, 100000, absstatus); // 100ms
|
sl@0
|
112 |
// Wait for the timer
|
sl@0
|
113 |
User::WaitForRequest(absstatus);
|
sl@0
|
114 |
test(absstatus.Int() == KErrNone);
|
sl@0
|
115 |
// Wakeup event has not to be notified
|
sl@0
|
116 |
test(status.Int() == KRequestPending);
|
sl@0
|
117 |
// Cancel the notification request
|
sl@0
|
118 |
Power::CancelWakeupEventNotification();
|
sl@0
|
119 |
test(status.Int() == KErrCancel);
|
sl@0
|
120 |
User::WaitForRequest(status); // collect it
|
sl@0
|
121 |
// Cancel again just for fun ...
|
sl@0
|
122 |
Power::CancelWakeupEventNotification();
|
sl@0
|
123 |
test(status.Int() == KErrCancel);
|
sl@0
|
124 |
|
sl@0
|
125 |
abstimer.Close();
|
sl@0
|
126 |
}
|
sl@0
|
127 |
}
|
sl@0
|
128 |
|
sl@0
|
129 |
_LIT(KSecuritySlavePath, "t_power_slave.exe");
|
sl@0
|
130 |
|
sl@0
|
131 |
void ExecSlave(TUint aArg)
|
sl@0
|
132 |
{
|
sl@0
|
133 |
RProcess proc;
|
sl@0
|
134 |
TInt r = proc.Create(KSecuritySlavePath, TPtrC((TUint16*) &aArg, sizeof(aArg)/sizeof(TUint16)));
|
sl@0
|
135 |
test(r == KErrNone);
|
sl@0
|
136 |
TRequestStatus status;
|
sl@0
|
137 |
proc.Logon(status);
|
sl@0
|
138 |
proc.Resume();
|
sl@0
|
139 |
User::WaitForRequest(status);
|
sl@0
|
140 |
// The slave must panic
|
sl@0
|
141 |
test_Equal(EExitPanic, proc.ExitType());
|
sl@0
|
142 |
test_Equal(EPlatformSecurityTrap, proc.ExitReason());
|
sl@0
|
143 |
CLOSE_AND_WAIT(proc);
|
sl@0
|
144 |
}
|
sl@0
|
145 |
|
sl@0
|
146 |
GLDEF_C TInt E32Main()
|
sl@0
|
147 |
{
|
sl@0
|
148 |
test.Title();
|
sl@0
|
149 |
test.Start(_L("Testing"));
|
sl@0
|
150 |
|
sl@0
|
151 |
// Turn off evil lazy dll unloading
|
sl@0
|
152 |
RLoader l;
|
sl@0
|
153 |
test(l.Connect()==KErrNone);
|
sl@0
|
154 |
test(l.CancelLazyDllUnload()==KErrNone);
|
sl@0
|
155 |
l.Close();
|
sl@0
|
156 |
|
sl@0
|
157 |
//
|
sl@0
|
158 |
// Perform the number of iterations specifed by the command line argument.
|
sl@0
|
159 |
//
|
sl@0
|
160 |
// If no arguments - perform two iterations
|
sl@0
|
161 |
//
|
sl@0
|
162 |
TInt iter = 2;
|
sl@0
|
163 |
TInt len = User::CommandLineLength();
|
sl@0
|
164 |
if (len)
|
sl@0
|
165 |
{
|
sl@0
|
166 |
// Copy the command line in a buffer
|
sl@0
|
167 |
HBufC* hb = HBufC::NewMax(len);
|
sl@0
|
168 |
test(hb != NULL);
|
sl@0
|
169 |
TPtr cmd((TUint16*) hb->Ptr(), len);
|
sl@0
|
170 |
User::CommandLine(cmd);
|
sl@0
|
171 |
// Extract the number of iterations
|
sl@0
|
172 |
TLex l(cmd);
|
sl@0
|
173 |
TInt i;
|
sl@0
|
174 |
TInt r = l.Val(i);
|
sl@0
|
175 |
if (r == KErrNone)
|
sl@0
|
176 |
iter = i;
|
sl@0
|
177 |
else
|
sl@0
|
178 |
// strange command - silently ignore
|
sl@0
|
179 |
{}
|
sl@0
|
180 |
delete hb;
|
sl@0
|
181 |
}
|
sl@0
|
182 |
|
sl@0
|
183 |
test.Printf(_L("Go for %d iterations\n"), iter);
|
sl@0
|
184 |
|
sl@0
|
185 |
while (iter--)
|
sl@0
|
186 |
{
|
sl@0
|
187 |
// Remember the number of open handles. Just for a sanity check ....
|
sl@0
|
188 |
TInt start_thc, start_phc;
|
sl@0
|
189 |
RThread().HandleCount(start_phc, start_thc);
|
sl@0
|
190 |
|
sl@0
|
191 |
PowerTests();
|
sl@0
|
192 |
|
sl@0
|
193 |
test.Start(_L("test platform security"));
|
sl@0
|
194 |
// The slave process must panic because it hasn't any capability
|
sl@0
|
195 |
if(!PlatSec::IsCapabilityEnforced(ECapabilityPowerMgmt))
|
sl@0
|
196 |
test.Printf(_L("TESTS NOT RUN - PowerMgmt capability isn't enforced on system"));
|
sl@0
|
197 |
else
|
sl@0
|
198 |
{
|
sl@0
|
199 |
test.Next(_L("PowerDown()"));
|
sl@0
|
200 |
ExecSlave(0);
|
sl@0
|
201 |
test.Next(_L("EnableWakeupEvents()"));
|
sl@0
|
202 |
ExecSlave(1);
|
sl@0
|
203 |
test.Next(_L("DisableWakeupEvents()"));
|
sl@0
|
204 |
ExecSlave(2);
|
sl@0
|
205 |
test.Next(_L("RequestWakeupEventNotification()"));
|
sl@0
|
206 |
ExecSlave(3);
|
sl@0
|
207 |
test.Next(_L("CancelWakeupEventNotification()"));
|
sl@0
|
208 |
ExecSlave(4);
|
sl@0
|
209 |
}
|
sl@0
|
210 |
test.End();
|
sl@0
|
211 |
|
sl@0
|
212 |
// Sanity check for open handles
|
sl@0
|
213 |
TInt end_thc, end_phc;
|
sl@0
|
214 |
RThread().HandleCount(end_phc, end_thc);
|
sl@0
|
215 |
test(start_thc == end_thc);
|
sl@0
|
216 |
test(start_phc == end_phc);
|
sl@0
|
217 |
// and also for pending requests ...
|
sl@0
|
218 |
test(RThread().RequestCount() == 0);
|
sl@0
|
219 |
}
|
sl@0
|
220 |
|
sl@0
|
221 |
test.End();
|
sl@0
|
222 |
|
sl@0
|
223 |
return KErrNone;
|
sl@0
|
224 |
}
|