Update contrib.
1 // Copyright (c) 2002-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 the License "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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\power\t_power.cpp
16 // Test power down and wakeup event notification
18 // Power::PowerDown(), Power::RequestWakeupEventNotification()
20 // - Arm a wakeup timer, enable wakeup events, enter standby mode, get woken up.
21 // - Test RequestWakeupEventNotification(): arm a timer, request notification,
22 // wait for timer to expire, verify event has been notified, issue another
23 // notification request, disable wakeup events, arm another timer, verify
24 // wakeup event has not been notified, cancel the notification request and
26 // - Verify that a slave process panics because it hasn't and capability.
27 // - Confirm the number of open handles and pending requests are as expected.
28 // Platforms/Drives/Compatibility:
30 // Assumptions/Requirement/Pre-requisites:
31 // Failures and causes:
32 // Base Port information:
36 #define __E32TEST_EXTENSION__
43 #include <e32ldr_private.h>
45 LOCAL_D RTest test(_L(" T_POWER "));
47 void SetAbsoluteTimeout(RTimer& aTimer, TUint aUs, TRequestStatus& aStatus)
51 wakeup += TTimeIntervalMicroSeconds(aUs);
52 aTimer.At(aStatus, wakeup);
57 test.Next(_L("test PowerDown()"));
59 TInt r = Power::PowerDown();
60 test (r == KErrNotReady);
62 for (int i = 0; i < 4; ++i)
64 test.Printf(_L(" %d "), i);
65 // Arm an absolute timer wakeup event after 5 sec
66 TRequestStatus absstatus;
68 r = abstimer.CreateLocal();
70 SetAbsoluteTimeout(abstimer, 5000000, absstatus); // 5 sec
72 r = Power::EnableWakeupEvents(EPwStandby);
74 r = Power::PowerDown();
76 User::WaitForRequest(absstatus);
79 test.Printf(_L(" OK\n"));
81 test.Next(_L("test RequestWakeupEventNotification()"));
84 TInt r = Power::EnableWakeupEvents(EPwActive);
85 test (r == KErrArgument);
87 // Request wakup event notification and enable wakeup events
88 TRequestStatus status;
89 Power::RequestWakeupEventNotification(status);
90 test(status.Int() == KRequestPending);
91 r = Power::EnableWakeupEvents(EPwStandby);
93 // Arm an absolute timer wakeup event
94 TRequestStatus absstatus;
96 r = abstimer.CreateLocal();
98 SetAbsoluteTimeout(abstimer, 100000, absstatus); // 100ms
100 User::WaitForRequest(absstatus);
101 test(absstatus.Int() == KErrNone);
102 // Wakup event has to be already notified
103 test(status.Int() == KErrNone);
104 User::WaitForRequest(status); // collect it
105 // Issue another notification request
106 Power::RequestWakeupEventNotification(status);
107 test(status.Int() == KRequestPending);
108 // Disable wakeup events
109 Power::DisableWakeupEvents();
110 // Arm another absolute timer wakeup event
111 SetAbsoluteTimeout(abstimer, 100000, absstatus); // 100ms
112 // Wait for the timer
113 User::WaitForRequest(absstatus);
114 test(absstatus.Int() == KErrNone);
115 // Wakeup event has not to be notified
116 test(status.Int() == KRequestPending);
117 // Cancel the notification request
118 Power::CancelWakeupEventNotification();
119 test(status.Int() == KErrCancel);
120 User::WaitForRequest(status); // collect it
121 // Cancel again just for fun ...
122 Power::CancelWakeupEventNotification();
123 test(status.Int() == KErrCancel);
129 _LIT(KSecuritySlavePath, "t_power_slave.exe");
131 void ExecSlave(TUint aArg)
134 TInt r = proc.Create(KSecuritySlavePath, TPtrC((TUint16*) &aArg, sizeof(aArg)/sizeof(TUint16)));
136 TRequestStatus status;
139 User::WaitForRequest(status);
140 // The slave must panic
141 test_Equal(EExitPanic, proc.ExitType());
142 test_Equal(EPlatformSecurityTrap, proc.ExitReason());
143 CLOSE_AND_WAIT(proc);
146 GLDEF_C TInt E32Main()
149 test.Start(_L("Testing"));
151 // Turn off evil lazy dll unloading
153 test(l.Connect()==KErrNone);
154 test(l.CancelLazyDllUnload()==KErrNone);
158 // Perform the number of iterations specifed by the command line argument.
160 // If no arguments - perform two iterations
163 TInt len = User::CommandLineLength();
166 // Copy the command line in a buffer
167 HBufC* hb = HBufC::NewMax(len);
169 TPtr cmd((TUint16*) hb->Ptr(), len);
170 User::CommandLine(cmd);
171 // Extract the number of iterations
178 // strange command - silently ignore
183 test.Printf(_L("Go for %d iterations\n"), iter);
187 // Remember the number of open handles. Just for a sanity check ....
188 TInt start_thc, start_phc;
189 RThread().HandleCount(start_phc, start_thc);
193 test.Start(_L("test platform security"));
194 // The slave process must panic because it hasn't any capability
195 if(!PlatSec::IsCapabilityEnforced(ECapabilityPowerMgmt))
196 test.Printf(_L("TESTS NOT RUN - PowerMgmt capability isn't enforced on system"));
199 test.Next(_L("PowerDown()"));
201 test.Next(_L("EnableWakeupEvents()"));
203 test.Next(_L("DisableWakeupEvents()"));
205 test.Next(_L("RequestWakeupEventNotification()"));
207 test.Next(_L("CancelWakeupEventNotification()"));
212 // Sanity check for open handles
213 TInt end_thc, end_phc;
214 RThread().HandleCount(end_phc, end_thc);
215 test(start_thc == end_thc);
216 test(start_phc == end_phc);
217 // and also for pending requests ...
218 test(RThread().RequestCount() == 0);