|
1 // Copyright (c) 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 #include <e32test.h> |
|
17 #include <hal.h> |
|
18 #include <featmgr.h> |
|
19 #include <featureuids.h> |
|
20 #include <featurecontrol.h> |
|
21 #include <featdiscovery.h> |
|
22 |
|
23 using namespace NFeature; |
|
24 |
|
25 TInt TheFastCounterFreq = 0; |
|
26 |
|
27 const TInt KInvalidFeatureId1 = 90901671; |
|
28 const TUid KInvalidFeatureUid1 = {KInvalidFeatureId1}; |
|
29 const TUid KNewFeatureUid = {0x7888ABC1}; |
|
30 |
|
31 /////////////////////////////////////////////////////////////////////////////////////// |
|
32 |
|
33 static RTest TheTest(_L("t_fmgrperformance")); |
|
34 |
|
35 /////////////////////////////////////////////////////////////////////////////////////// |
|
36 |
|
37 //Deletes all created test files. |
|
38 void DestroyTestEnv() |
|
39 { |
|
40 } |
|
41 |
|
42 /////////////////////////////////////////////////////////////////////////////////////// |
|
43 /////////////////////////////////////////////////////////////////////////////////////// |
|
44 //Test macros and functions |
|
45 void Check1(TInt aValue, TInt aLine) |
|
46 { |
|
47 if(!aValue) |
|
48 { |
|
49 DestroyTestEnv(); |
|
50 RDebug::Print(_L("*** Expression evaluated to false. Line %d\r\n"), aLine); |
|
51 TheTest(EFalse, aLine); |
|
52 } |
|
53 } |
|
54 void Check2(TInt aValue, TInt aExpected, TInt aLine) |
|
55 { |
|
56 if(aValue != aExpected) |
|
57 { |
|
58 DestroyTestEnv(); |
|
59 RDebug::Print(_L("*** Expected: %d, got: %d. Line %d\r\n"), aExpected, aValue, aLine); |
|
60 TheTest(EFalse, aLine); |
|
61 } |
|
62 } |
|
63 #define TEST(arg) ::Check1((arg), __LINE__) |
|
64 #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__) |
|
65 |
|
66 /////////////////////////////////////////////////////////////////////////////////////// |
|
67 |
|
68 TInt TimeDiffUs(TUint32 aStartTicks, TUint32 aEndTicks) |
|
69 { |
|
70 if(TheFastCounterFreq == 0) |
|
71 { |
|
72 TEST2(HAL::Get(HAL::EFastCounterFrequency, TheFastCounterFreq), KErrNone); |
|
73 TheTest.Printf(_L("===Fast counter frequency = %d Hz\r\n"), TheFastCounterFreq); |
|
74 } |
|
75 TInt64 diffTicks = (TInt64)aEndTicks - (TInt64)aStartTicks; |
|
76 if(diffTicks < 0) |
|
77 { |
|
78 diffTicks = KMaxTUint32 + diffTicks + 1; |
|
79 } |
|
80 const TInt KMicroSecIn1Sec = 1000000; |
|
81 TInt us = (diffTicks * KMicroSecIn1Sec) / TheFastCounterFreq; |
|
82 return us; |
|
83 } |
|
84 |
|
85 void PrintTime(const TDesC& aFmt, TUint32 aStartTicks, TUint32 aEndTicks) |
|
86 { |
|
87 TInt us = TimeDiffUs(aStartTicks, aEndTicks); |
|
88 TheTest.Printf(aFmt, us); |
|
89 } |
|
90 |
|
91 /** |
|
92 @SYMTestCaseID PDS-EFM-CT-4106 |
|
93 @SYMTestCaseDesc |
|
94 @SYMTestPriority High |
|
95 @SYMTestActions |
|
96 @SYMTestExpectedResults Test must not fail |
|
97 @SYMDEF DEF144262 |
|
98 */ |
|
99 void FeatureControlTest() |
|
100 { |
|
101 TFeatureEntry fentry; |
|
102 |
|
103 TUint32 start = User::FastCounter(); |
|
104 RFeatureControl ctrl; |
|
105 |
|
106 TInt err = ctrl.Open(); |
|
107 TEST2(err, KErrNone); |
|
108 TUint32 end = User::FastCounter(); |
|
109 PrintTime(_L("===1 RFeatureControl::Open(), time=%d us\r\n"), start, end); |
|
110 |
|
111 //The second RFeatureControl::Open() call is "free", because only one connection per thread is kept in TLS |
|
112 RFeatureControl ctrl2; |
|
113 start = User::FastCounter(); |
|
114 err = ctrl2.Open(); |
|
115 TEST2(err, KErrNone); |
|
116 end = User::FastCounter(); |
|
117 PrintTime(_L("===2 RFeatureControl::Open(), time=%d us\r\n"), start, end); |
|
118 |
|
119 // |
|
120 start = User::FastCounter(); |
|
121 ctrl2.Close(); |
|
122 end = User::FastCounter(); |
|
123 PrintTime(_L("===2 RFeatureControl::Close(), time=%d us\r\n"), start, end); |
|
124 |
|
125 // |
|
126 TBitFlags32 flags; |
|
127 flags.ClearAll(); |
|
128 flags.Set(EFeatureSupported); |
|
129 flags.Set(EFeatureModifiable); |
|
130 |
|
131 fentry = TFeatureEntry(KNewFeatureUid, flags, 0x0); |
|
132 start = User::FastCounter(); |
|
133 err = ctrl.AddFeature(fentry); |
|
134 TEST2(err, KErrNone); |
|
135 end = User::FastCounter(); |
|
136 PrintTime(_L("===RFeatureControl::AddFeature(), time=%d us\r\n"), start, end); |
|
137 // |
|
138 start = User::FastCounter(); |
|
139 err = ctrl.FeatureSupported(KNewFeatureUid); |
|
140 TEST2(err, 1); |
|
141 end = User::FastCounter(); |
|
142 PrintTime(_L("===RFeatureControl::FeatureSupported(TUid), time=%d us\r\n"), start, end); |
|
143 // |
|
144 start = User::FastCounter(); |
|
145 err = ctrl.FeatureSupported(KInvalidFeatureUid1); |
|
146 TEST2(err, KErrNotFound); |
|
147 end = User::FastCounter(); |
|
148 PrintTime(_L("===RFeatureControl::FeatureSupported(invalid TUid), time=%d us\r\n"), start, end); |
|
149 // |
|
150 fentry = TFeatureEntry(KNewFeatureUid); |
|
151 start = User::FastCounter(); |
|
152 err = ctrl.FeatureSupported(fentry); |
|
153 TEST2(err, 1); |
|
154 end = User::FastCounter(); |
|
155 PrintTime(_L("===RFeatureControl::FeatureSupported(TFeatureEntry), time=%d us\r\n"), start, end); |
|
156 // |
|
157 RFeatureArray farray; |
|
158 err = farray.Append(TFeatureEntry(KNewFeatureUid)); |
|
159 TEST2(err, KErrNone); |
|
160 err = farray.Append(TFeatureEntry(KInvalidFeatureUid1)); |
|
161 TEST2(err, KErrNone); |
|
162 err = farray.Append(TFeatureEntry(KConnectivity)); |
|
163 TEST2(err, KErrNone); |
|
164 err = farray.Append(TFeatureEntry(KUsb)); |
|
165 TEST2(err, KErrNone); |
|
166 start = User::FastCounter(); |
|
167 err = ctrl.FeaturesSupported(farray); |
|
168 end = User::FastCounter(); |
|
169 PrintTime(_L("===RFeatureControl::FeaturesSupported(), time=%d us\r\n"), start, end); |
|
170 TEST2(farray.Count(), 3);//KInvalidFeatureUid1 should have been removed from the array |
|
171 farray.Close(); |
|
172 // |
|
173 start = User::FastCounter(); |
|
174 err = ctrl.DisableFeature(KNewFeatureUid); |
|
175 TEST2(err, KErrNone); |
|
176 end = User::FastCounter(); |
|
177 PrintTime(_L("===1 RFeatureControl::DisableFeature(), time=%d us\r\n"), start, end); |
|
178 //Disable the same feature again |
|
179 start = User::FastCounter(); |
|
180 err = ctrl.DisableFeature(KNewFeatureUid); |
|
181 TEST2(err, KErrNone); |
|
182 end = User::FastCounter(); |
|
183 PrintTime(_L("===2 RFeatureControl::DisableFeature(already disabled), time=%d us\r\n"), start, end); |
|
184 // |
|
185 start = User::FastCounter(); |
|
186 err = ctrl.DisableFeature(KFax); |
|
187 TEST2(err, KErrAccessDenied); |
|
188 end = User::FastCounter(); |
|
189 PrintTime(_L("===3 RFeatureControl::DisableFeature(access denied), time=%d us\r\n"), start, end); |
|
190 // |
|
191 start = User::FastCounter(); |
|
192 err = ctrl.EnableFeature(KNewFeatureUid); |
|
193 TEST2(err, KErrNone); |
|
194 end = User::FastCounter(); |
|
195 PrintTime(_L("===1 RFeatureControl::EnableFeature(), time=%d us\r\n"), start, end); |
|
196 //Enable the same feature again |
|
197 start = User::FastCounter(); |
|
198 err = ctrl.EnableFeature(KNewFeatureUid); |
|
199 TEST2(err, KErrNone); |
|
200 end = User::FastCounter(); |
|
201 PrintTime(_L("===2 RFeatureControl::EnableFeature(already enabled), time=%d us\r\n"), start, end); |
|
202 // |
|
203 start = User::FastCounter(); |
|
204 err = ctrl.EnableFeature(KFax); |
|
205 TEST2(err, KErrAccessDenied); |
|
206 end = User::FastCounter(); |
|
207 PrintTime(_L("===3 RFeatureControl::EnableFeature(access denied), time=%d us\r\n"), start, end); |
|
208 // |
|
209 start = User::FastCounter(); |
|
210 err = ctrl.SetFeature(KNewFeatureUid, EFalse, 100); |
|
211 TEST2(err, KErrNone); |
|
212 end = User::FastCounter(); |
|
213 PrintTime(_L("===1 RFeatureControl::SetFeature(), time=%d us\r\n"), start, end); |
|
214 // |
|
215 start = User::FastCounter(); |
|
216 err = ctrl.SetFeature(KNewFeatureUid, 200); |
|
217 TEST2(err, KErrNone); |
|
218 end = User::FastCounter(); |
|
219 PrintTime(_L("===2 RFeatureControl::SetFeature(), time=%d us\r\n"), start, end); |
|
220 // |
|
221 RFeatureUidArray farray2; |
|
222 start = User::FastCounter(); |
|
223 err = ctrl.ListSupportedFeatures(farray2); |
|
224 TEST2(err, KErrNone); |
|
225 end = User::FastCounter(); |
|
226 PrintTime(_L("===RFeatureControl::ListSupportedFeatures(), time=%d us\r\n"), start, end); |
|
227 TEST(farray2.Count() > 0); |
|
228 farray2.Close(); |
|
229 // |
|
230 start = User::FastCounter(); |
|
231 ctrl.DeleteFeature(KNewFeatureUid); |
|
232 end = User::FastCounter(); |
|
233 PrintTime(_L("===RFeatureControl::DeleteFeature(), time=%d us\r\n"), start, end); |
|
234 // |
|
235 start = User::FastCounter(); |
|
236 ctrl.Close(); |
|
237 end = User::FastCounter(); |
|
238 PrintTime(_L("===1 RFeatureControl::Close(), time=%d us\r\n"), start, end); |
|
239 } |
|
240 |
|
241 /** |
|
242 @SYMTestCaseID PDS-EFM-CT-4107 |
|
243 @SYMTestCaseDesc |
|
244 @SYMTestPriority High |
|
245 @SYMTestActions |
|
246 @SYMTestExpectedResults Test must not fail |
|
247 @SYMDEF DEF144262 |
|
248 */ |
|
249 void FeatureManagerTest() |
|
250 { |
|
251 TUint32 start = User::FastCounter(); |
|
252 FeatureManager::InitializeLibL(); |
|
253 TUint32 end = User::FastCounter(); |
|
254 PrintTime(_L("===FeatureManager::InitializeLibL(server already loaded by the previous test), time=%d us\r\n"), start, end); |
|
255 // |
|
256 start = User::FastCounter(); |
|
257 TBool rc = FeatureManager::FeatureSupported(KConnectivity.iUid); |
|
258 TEST(rc); |
|
259 end = User::FastCounter(); |
|
260 PrintTime(_L("===FeatureManager::FeatureSupported(), time=%d us\r\n"), start, end); |
|
261 // |
|
262 start = User::FastCounter(); |
|
263 FeatureManager::UnInitializeLib(); |
|
264 end = User::FastCounter(); |
|
265 PrintTime(_L("===FeatureManager::UnInitializeLib(), time=%d us\r\n"), start, end); |
|
266 } |
|
267 |
|
268 void DoTestsL() |
|
269 { |
|
270 TheTest.Start(_L("@SYMTestCaseID:PDS-EFM-CT-4106 RFeatureControl performance test")); |
|
271 FeatureControlTest(); |
|
272 |
|
273 TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4107 FeatureManager performance test")); |
|
274 FeatureManagerTest(); |
|
275 } |
|
276 |
|
277 TInt E32Main() |
|
278 { |
|
279 TheTest.Title(); |
|
280 |
|
281 CTrapCleanup* tc = CTrapCleanup::New(); |
|
282 TheTest(tc != NULL); |
|
283 |
|
284 __UHEAP_MARK; |
|
285 |
|
286 TRAPD(err, DoTestsL()); |
|
287 DestroyTestEnv(); |
|
288 TEST2(err, KErrNone); |
|
289 |
|
290 __UHEAP_MARKEND; |
|
291 |
|
292 TheTest.End(); |
|
293 TheTest.Close(); |
|
294 |
|
295 delete tc; |
|
296 |
|
297 User::Heap().Check(); |
|
298 return KErrNone; |
|
299 } |