72 TBool gHaveSharedRes = ETrue; |
71 TBool gHaveSharedRes = ETrue; |
73 TInt gSharedResStateDelta = -1; |
72 TInt gSharedResStateDelta = -1; |
74 #endif |
73 #endif |
75 |
74 |
76 TBool gUseCached = EFalse; |
75 TBool gUseCached = EFalse; |
|
76 |
|
77 class RTestSafe: public RTest |
|
78 { |
|
79 public: |
|
80 RTestSafe(const TDesC &aTitle) : |
|
81 RTest(aTitle), iCleanUpLevelMask (0), iFailHdnFunc(NULL) |
|
82 { |
|
83 } |
|
84 RTestSafe(const TDesC &aTitle, void(*func)(RTestSafe &aTest)) : |
|
85 RTest(aTitle), iFailHdnFunc(func) |
|
86 { |
|
87 } |
|
88 |
|
89 // new version of operator(int), which calls our cleanup handler if check has failed |
|
90 void operator()(TInt aResult) |
|
91 { |
|
92 if(!aResult && iFailHdnFunc) |
|
93 iFailHdnFunc(*this); |
|
94 RTest::operator ()(aResult); |
|
95 } |
|
96 |
|
97 void operator()(TInt aResult, TInt aLineNum) |
|
98 { |
|
99 if(!aResult && iFailHdnFunc) |
|
100 iFailHdnFunc(*this); |
|
101 RTest::operator ()(aResult, aLineNum); |
|
102 } |
|
103 |
|
104 void operator()(TInt aResult, TInt aLineNum, const TText* aFileName) |
|
105 { |
|
106 if(!aResult && iFailHdnFunc) |
|
107 iFailHdnFunc(*this); |
|
108 RTest::operator ()(aResult, aLineNum, aFileName); |
|
109 } |
|
110 |
|
111 // new version of End, which calls handler before exit.. |
|
112 void End() |
|
113 { |
|
114 if(iFailHdnFunc) |
|
115 iFailHdnFunc(*this); |
|
116 RTest::End(); |
|
117 } |
|
118 |
|
119 void SetCleanupFlag(TUint aFlag) |
|
120 { |
|
121 iCleanUpLevelMask |= 1 << aFlag; |
|
122 } |
|
123 |
|
124 TBool CleanupNeeded(TUint aFlag) |
|
125 { |
|
126 return (iCleanUpLevelMask & (1 << aFlag)) >> aFlag; |
|
127 } |
|
128 |
|
129 TUint iCleanUpLevelMask; |
|
130 void (*iFailHdnFunc)(RTestSafe &aTest); |
|
131 }; |
|
132 |
|
133 // cleanup handler |
|
134 enum TCleanupLevels |
|
135 { |
|
136 EPddLoaded = 0, |
|
137 ELddLoaded, |
|
138 EChannelOpened |
|
139 }; |
|
140 |
|
141 |
|
142 void TestCleanup(RTestSafe &aTest) |
|
143 { |
|
144 // cleanup for all 3 levels.. |
|
145 if(aTest.CleanupNeeded(EChannelOpened)) |
|
146 { |
|
147 gChannel.Close(); |
|
148 } |
|
149 |
|
150 if(aTest.CleanupNeeded(ELddLoaded)) |
|
151 { |
|
152 User::FreeLogicalDevice(KLddRootName); |
|
153 } |
|
154 |
|
155 if(aTest.CleanupNeeded(EPddLoaded)) |
|
156 { |
|
157 User::FreePhysicalDevice(PDD_NAME); |
|
158 } |
|
159 } |
|
160 |
|
161 // global gTest object.. |
|
162 RTestSafe gTest(testName, &TestCleanup); |
|
163 |
|
164 LOCAL_C TInt CheckCaps() |
|
165 { |
|
166 TInt r = KErrNone; |
|
167 RDevice d; |
|
168 TPckgBuf<TCapsDevResManUs> caps; |
|
169 r = d.Open(KLddRootName); |
|
170 if(r == KErrNone) |
|
171 { |
|
172 d.GetCaps(caps); |
|
173 d.Close(); |
|
174 |
|
175 TVersion ver = caps().version; |
|
176 if(ver.iMajor != 1 || ver.iMinor != 0 || ver.iBuild != KE32BuildVersionNumber) |
|
177 { |
|
178 gTest.Printf(_L("Capabilities returned wrong version")); |
|
179 gTest.Printf(_L("Expected(1, 0, %d), got (%d , %d, %d)"), |
|
180 KE32BuildVersionNumber, ver.iMajor, ver.iMinor, ver.iBuild); |
|
181 r = KErrGeneral; |
|
182 } |
|
183 } |
|
184 return r; |
|
185 } |
77 |
186 |
78 LOCAL_C TInt OpenChannel(TDesC16& aName, RBusDevResManUs& aChannel) |
187 LOCAL_C TInt OpenChannel(TDesC16& aName, RBusDevResManUs& aChannel) |
79 { |
188 { |
80 TInt r = KErrNone; |
189 TInt r = KErrNone; |
81 // API accepts 8-bit descriptors, only - so convert name accordingly |
190 // API accepts 8-bit descriptors, only - so convert name accordingly |
1522 return r; |
1632 return r; |
1523 } |
1633 } |
1524 |
1634 |
1525 // 8) Call API to get the state of a long latency resource then call API without operation-type qualifier to cancel the request. |
1635 // 8) Call API to get the state of a long latency resource then call API without operation-type qualifier to cancel the request. |
1526 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); |
1636 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); |
|
1637 |
|
1638 // NOTE: Cancel operation can only remove request which is still inside the resource controller |
|
1639 // message queue. If the queue is empty, the resource controller may process the request very quickly |
|
1640 // after it is sent. It may cause the test fail. To solve this, two get long latency resource state |
|
1641 // requests are submitted. So that the second one must be inside the resource controller. |
|
1642 // And we will always test the second request |
|
1643 |
1527 gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId); |
1644 gChannel.GetResourceState(status,gLongLatencyResource,cached,&readValue,&levelOwnerId); |
|
1645 gChannel.GetResourceState(status2,gLongLatencyResource,cached,&readValue2,&levelOwnerId); |
1528 gChannel.CancelAsyncOperation(&status); |
1646 gChannel.CancelAsyncOperation(&status); |
|
1647 gChannel.CancelAsyncOperation(&status2); |
1529 User::WaitForRequest(status); |
1648 User::WaitForRequest(status); |
1530 if(status.Int() != KErrCancel) |
1649 User::WaitForRequest(status2); |
|
1650 if(status2.Int() != KErrCancel) |
1531 { |
1651 { |
1532 gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status = %d\n"),r); |
1652 gTest.Printf(_L("TestGetSetResourceStateOps, cancelled get state status = %d\n"),r); |
1533 return r; |
1653 return r; |
1534 } |
1654 } |
1535 |
1655 |
1536 // 9) Call API to modify the state of the long latency resource then call API without operation-type qualifier to cancel the request. |
1656 // 9) Call API to modify the state of the long latency resource then call API without operation-type qualifier to cancel the request. |
1537 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); |
1657 gTest.Printf(_L("TestGetSetResourceStateOps, starting test %d\n"),testNo++); |
|
1658 |
|
1659 // NOTE: Cancel operation can only remove request which is still inside the resource controller |
|
1660 // message queue. If the queue is empty, the resource controller may process the request very quickly |
|
1661 // after it is sent. It may cause the test fail. To solve this, two get long latency resource state |
|
1662 // requests are submitted. So that the second one must be inside the resource controller. |
|
1663 // And we will always test the second request |
|
1664 |
1538 newLevel = (TUint)(readValue + gAsyncResStateDelta); |
1665 newLevel = (TUint)(readValue + gAsyncResStateDelta); |
1539 gChannel.ChangeResourceState(status,gLongLatencyResource,newLevel); |
1666 gChannel.ChangeResourceState(status,gLongLatencyResource,newLevel); |
|
1667 gChannel.ChangeResourceState(status2,gLongLatencyResource,newLevel); |
1540 gChannel.CancelAsyncOperation(&status); |
1668 gChannel.CancelAsyncOperation(&status); |
|
1669 gChannel.CancelAsyncOperation(&status2); |
1541 User::WaitForRequest(status); |
1670 User::WaitForRequest(status); |
1542 if(status.Int() != KErrCancel) |
1671 User::WaitForRequest(status2); |
|
1672 if(status2.Int() != KErrCancel) |
1543 { |
1673 { |
1544 gTest.Printf(_L("TestGetSetResourceStateOps, cancelled change state status = %d\n"),r); |
1674 gTest.Printf(_L("TestGetSetResourceStateOps, cancelled change state status = %d\n"),r); |
1545 return r; |
1675 return r; |
1546 } |
1676 } |
1547 |
1677 |
4078 |
4236 |
4079 EXPORT_C TInt E32Main() |
4237 EXPORT_C TInt E32Main() |
4080 // |
4238 // |
4081 // Main |
4239 // Main |
4082 // |
4240 // |
4083 { |
4241 { |
|
4242 gTest.Title(); |
4084 gTest.Start(_L("Test Power Resource Manager user side API\n")); |
4243 gTest.Start(_L("Test Power Resource Manager user side API\n")); |
4085 |
|
4086 TInt r = KErrNone; |
|
4087 |
4244 |
4088 // Test attempted load of PDD |
4245 // Test attempted load of PDD |
4089 gTest.Next(_L("**Load PDD\n")); |
4246 gTest.Next(_L("**Load PDD\n")); |
4090 r=User::LoadPhysicalDevice(PDD_NAME); |
4247 TInt r = User::LoadPhysicalDevice(PDD_NAME); |
4091 if((r!=KErrNone)&&(r!=KErrAlreadyExists)) |
4248 gTest((r == KErrNone) || (r == KErrAlreadyExists)); |
4092 { |
4249 gTest.SetCleanupFlag(EPddLoaded); |
4093 gTest.Printf(_L("User::LoadPhysicalDevice error %d\n"),r); |
4250 |
4094 } |
4251 // Test attempted load of LDD |
4095 else |
4252 gTest.Next(_L("**Load LDD\n")); |
4096 { |
4253 r = User::LoadLogicalDevice(LDD_NAME); |
4097 // Test attempted load of LDD |
4254 gTest((r == KErrNone) || (r == KErrAlreadyExists)); |
4098 gTest.Next(_L("**Load LDD\n")); |
4255 r = KErrNone; // Re-initialise in case set to KErrAlreadyExists |
4099 r=User::LoadLogicalDevice(LDD_NAME); |
4256 gTest.SetCleanupFlag(ELddLoaded); |
4100 if((r!=KErrNone)&&(r!=KErrAlreadyExists)) |
4257 |
4101 gTest.Printf(_L("User::LoadLogicalDevice error - expected %d, got %d\n"),KErrAlreadyExists,r); |
4258 // test caps |
4102 } |
4259 gTest(CheckCaps() == KErrNone); |
4103 if((r==KErrNone)||(r==KErrAlreadyExists)) |
4260 |
4104 { |
4261 // Need a channel open for the following tests |
4105 r = KErrNone; // Re-initialise in case set to KErrAlreadyExists |
4262 gTest.Next(_L("**OpenAndRegisterChannel\n")); |
4106 // |
4263 r = OpenAndRegisterChannel(); |
4107 // Need a channel open for the following tests |
4264 gTest(r == KErrNone); |
4108 gTest.Next(_L("**OpenAndRegisterChannel\n")); |
4265 gTest.SetCleanupFlag(EChannelOpened); |
4109 r=OpenAndRegisterChannel(); |
4266 |
4110 if (r==KErrNone) |
4267 // Get the version of the ResourceController |
4111 { |
4268 TUint version; |
4112 // Get the version of the ResourceController |
4269 r = gChannel.GetResourceControllerVersion(version); |
4113 TUint version; |
4270 gTest.Printf(_L("TestTransientHandling: ResourceController version =0x%x\n"), version); |
4114 if((r=gChannel.GetResourceControllerVersion(version))!=KErrNone) |
4271 gTest(r == KErrNone); |
4115 { |
4272 |
4116 gTest.Printf(_L("TestTransientHandling: GetResourceControllerVersion returned %d\n"),r); |
4273 gTest.Next(_L("**TestThreadExclusiveAccess\n")); |
4117 return r; |
4274 r = TestThreadExclusiveAccess(); |
4118 } |
4275 gTest(r == KErrNone); |
4119 gTest.Printf(_L("TestTransientHandling: ResourceController version =0x%x\n"),version); |
4276 |
4120 } |
4277 gTest.Next(_L("**TestGetClientGetResourceInfo - initial state\n")); |
4121 if (r==KErrNone) |
4278 r = TestGetClientGetResourceInfo(); |
4122 { |
4279 gTest(r == KErrNone); |
4123 gTest.Next(_L("**TestThreadExclusiveAccess\n")); |
4280 |
4124 r=TestThreadExclusiveAccess(); |
4281 gTest.Next(_L("**TestGetSetResourceStateOps\n")); |
4125 } |
4282 r = TestGetSetResourceStateOps(); |
4126 if (r==KErrNone) |
4283 gTest(r == KErrNone); |
4127 { |
4284 |
4128 gTest.Next(_L("**TestGetClientGetResourceInfo - initial state\n")); |
4285 gTest.Next(_L("**TestGetClientGetResourceInfo - after changing stateof Async resource\n")); |
4129 r=TestGetClientGetResourceInfo(); |
4286 r = TestGetClientGetResourceInfo(); |
4130 } |
4287 gTest(r == KErrNone); |
4131 if (r==KErrNone) |
4288 |
4132 { |
4289 gTest.Next(_L("**TestGetSetResourceStateQuota\n")); |
4133 gTest.Next(_L("**TestGetSetResourceStateOps\n")); |
4290 r = TestGetSetResourceStateQuota(); |
4134 r=TestGetSetResourceStateOps(); |
4291 gTest(r == KErrNone); |
4135 } |
4292 |
4136 if (r==KErrNone) |
4293 gTest.Next(_L("**TestNotificationOps\n")); |
4137 { |
4294 r = TestNotificationOps(); |
4138 gTest.Next(_L("**TestGetClientGetResourceInfo - after changing stateof Async resource\n")); |
4295 gTest(r == KErrNone); |
4139 r=TestGetClientGetResourceInfo(); |
4296 |
4140 } |
4297 gTest.Next(_L("**TestNotificationQuota\n")); |
4141 if (r==KErrNone) |
4298 r = TestNotificationQuota(); |
4142 { |
4299 gTest(r == KErrNone); |
4143 gTest.Next(_L("**TestGetSetResourceStateQuota\n")); |
4300 |
4144 r=TestGetSetResourceStateQuota(); |
4301 // Should be no change since last invocation (assuming that |
4145 } |
4302 // no clients other than those in this test) |
4146 if (r==KErrNone) |
4303 gTest.Next(_L("**TestGetClientGetResourceInfo - last invocation\n")); |
4147 { |
4304 r = TestGetClientGetResourceInfo(); |
4148 gTest.Next(_L("**TestNotificationOps\n")); |
4305 gTest(r == KErrNone); |
4149 r=TestNotificationOps(); |
4306 |
4150 } |
4307 gTest.Next(_L("**TestAdditionalThread\n")); |
4151 if (r==KErrNone) |
4308 r = TestAdditionalThread(); |
4152 { |
4309 gTest(r == KErrNone); |
4153 gTest.Next(_L("**TestNotificationQuota\n")); |
4310 |
4154 r=TestNotificationQuota(); |
4311 gTest.Next(_L("**TestTransientHandling\n")); |
4155 } |
4312 r = TestTransientHandling(); |
4156 if (r==KErrNone) |
4313 gTest(r == KErrNone); |
4157 { |
|
4158 // Should be no change since last invocation (assuming that |
|
4159 // no clients other than those in this test) |
|
4160 gTest.Next(_L("**TestGetClientGetResourceInfo - last invocation\n")); |
|
4161 r=TestGetClientGetResourceInfo(); |
|
4162 } |
|
4163 if (r==KErrNone) |
|
4164 { |
|
4165 gTest.Next(_L("**TestAdditionalThread\n")); |
|
4166 r=TestAdditionalThread(); |
|
4167 } |
|
4168 if (r==KErrNone) |
|
4169 { |
|
4170 gTest.Next(_L("**TestTransientHandling\n")); |
|
4171 r=TestTransientHandling(); |
|
4172 } |
|
4173 } |
|
4174 gChannel.Close(); |
|
4175 |
|
4176 User::FreeLogicalDevice(KLddRootName); |
|
4177 User::FreePhysicalDevice(PDD_NAME); |
|
4178 User::After(100000); // Allow idle thread to run for driver unloading |
|
4179 |
4314 |
4180 gTest.End(); |
4315 gTest.End(); |
4181 return r; |
4316 return KErrNone; |
4182 } |
4317 } |
4183 |
4318 |
|
4319 |