|
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 // Ost Performance Tests API Test Object |
|
15 // |
|
16 |
|
17 |
|
18 |
|
19 /** |
|
20 @file te_perfapicall.cpp |
|
21 @internalTechnology |
|
22 @prototype |
|
23 */ |
|
24 |
|
25 |
|
26 #include "te_perfapicall.h" |
|
27 #include "te_apirunconfig.h" |
|
28 #include "te_perftracetester.h" |
|
29 #include "te_lightlogger.h" |
|
30 #include "te_instrumentationpoints.h" //for TUptTraceCalls::IsKernelTrace |
|
31 #include "te_perfstackinfo.h" |
|
32 |
|
33 |
|
34 CApiCallTest::CApiCallTest() |
|
35 { |
|
36 } |
|
37 |
|
38 CApiCallTest::~CApiCallTest() |
|
39 { |
|
40 } |
|
41 |
|
42 |
|
43 /** This user-side method uses takes the parameters passed by the user to carry out a single API call test run |
|
44 @param aApiId is the API call method or API printf method, passed as an enum. (NB: enum is different for user vs kernel printf calls, and for static and nonstatic etc.) |
|
45 @param aUptPc is the TBool specifying the Program Counter parameter to pass to the UTrace API |
|
46 @param aUptContext is the TBool specifying the Context parameter to pass to the UTrace API |
|
47 @param aSizeOfUptData is the size in bytes of the Data field being used in the relevant API calls containing a data field, passed as a TInt |
|
48 @param aTestPrimary is the boolean specifying whether to test the Primary filter setting (ETrue does test the primary filter, EFalse doesn't) |
|
49 @param aTestSecondary is the boolean specifying whether to test the Secondary filter setting (ETrue does test the secondary filter, EFalse doesn't) |
|
50 @param aTestUTraceULoggerMatch is the boolean specifying whether the filter settings in ULogger match the filter parameters assigned to the Trace points (ETrue matches, EFalse doesn't match) |
|
51 @param aTestMinimumExecution is the boolean specifying whether to test the minimum execution time for the API call |
|
52 ETrue = minimum execution time, i.e. cached trace |
|
53 EFalse = typical execution time, i.e. uncached trace |
|
54 @return ApiTestResult is the API Call test result struct object returned to the calling program, which contains all the test results from the relevent test run |
|
55 */ |
|
56 TInt CApiCallTest::DoTestL(const TApiRunConfig& /*aApiRunConfig*/, TApiTestResult& /*aApiTestResult*/) |
|
57 { |
|
58 TInt error = KErrNotSupported; |
|
59 |
|
60 //create a dummy time variable to be used for the baseline measurement |
|
61 //TUint64 baselinetime = 0; |
|
62 |
|
63 //now run tests to fill the results variables |
|
64 |
|
65 __TEST_LOG("member functions initialised"); |
|
66 |
|
67 //Sorry, I cut out all the functionality here and stuck it in the methods below... |
|
68 //I needed to know where the errors came from... |
|
69 |
|
70 //err = HeapUsage(iApiTestResult->iApiHeapUsage); |
|
71 __TEST_LOG("all trace ok - stack ERR IS"); |
|
72 __TEST_LOGNUM(error); |
|
73 |
|
74 //return the results of the API call tests to the calling program |
|
75 return error; |
|
76 } |
|
77 |
|
78 TInt CApiCallTest::CachedTraceTime(TApiRunConfig& aApiRunConfig, TApiTestResult& aApiTestResult) |
|
79 { |
|
80 TInt error = KErrNotSupported; |
|
81 //create a dummy time variable to be used for the baseline measurement |
|
82 TInt32 baselinetime = 0; |
|
83 |
|
84 //carry out the APIcall tests as required by the user |
|
85 __TEST_LOG("about to carry out cache trace"); |
|
86 if(aApiRunConfig.iDoMinExecution) |
|
87 { |
|
88 CachedTraceBaselineTime(aApiRunConfig, baselinetime); |
|
89 __TEST_LOG("cache baseline"); |
|
90 __TEST_LOGNUM(baselinetime); |
|
91 error = CachedTraceTime(aApiRunConfig, aApiTestResult.iMinimumExecutionTime, baselinetime); |
|
92 __TEST_LOG("cache"); |
|
93 __TEST_LOGNUM(aApiTestResult.iMinimumExecutionTime); |
|
94 } |
|
95 return error; |
|
96 } |
|
97 |
|
98 TInt CApiCallTest::NonCachedTraceTime(TApiRunConfig& aApiRunConfig, TApiTestResult& aApiTestResult) |
|
99 { |
|
100 TInt error = KErrNotSupported; |
|
101 //create a dummy time variable to be used for the baseline measurement |
|
102 TInt32 baselinetime = 0; |
|
103 __TEST_LOG("about to carry out non cache trace"); |
|
104 if(aApiRunConfig.iDoTypicalExecution) |
|
105 { |
|
106 NonCachedTraceBaselineTime(aApiRunConfig, baselinetime); |
|
107 __TEST_LOG("noncache baseline"); |
|
108 __TEST_LOGNUM(baselinetime); |
|
109 error = NonCachedTraceTime(aApiRunConfig, aApiTestResult.iTypicalExecutionTime, baselinetime); |
|
110 __TEST_LOG("noncache"); |
|
111 __TEST_LOGNUM(aApiTestResult.iTypicalExecutionTime); |
|
112 } |
|
113 return error; |
|
114 } |
|
115 |
|
116 TInt CApiCallTest::StackUsage(TApiRunConfig& aApiRunConfig, TApiTestResult& aApiTestResult) |
|
117 { |
|
118 __TEST_LOG("about to carry out stack usage trace"); |
|
119 TInt error = StackUsage(aApiRunConfig, aApiTestResult.iRunResults.iApiStackUsage); |
|
120 if(aApiTestResult.iRunResults.iApiStackUsage == KErrNotSupported && !error) |
|
121 error = KErrNotSupported; |
|
122 return error; |
|
123 } |
|
124 |
|
125 /** This user-side method is used to ensure that the cache has been flushed for calculating the API typical execution times |
|
126 @return KErrNone if command was prepared correctly and a system wide error code otherwise. |
|
127 */ |
|
128 TInt CApiCallTest::FlushTheCache() |
|
129 { |
|
130 //Put in empty call of certain size to flush the cache |
|
131 TInt err=0; |
|
132 /* |
|
133 #ifndef __WINSCW__ |
|
134 err=Te_Flush_The_Cache(); |
|
135 #endif |
|
136 */ |
|
137 return err; |
|
138 } |
|
139 |
|
140 /** This user-side method calculates the minimum execution baseline time taken for a single commented API call. |
|
141 @param aMinimumExecutionBaselineTime is the minimum execution baseline time taken for the commented API call, calculated in nanoseconds |
|
142 @return KErrNone if command was prepared correctly and a system wide error code otherwise. |
|
143 */ |
|
144 TInt CApiCallTest::CachedTraceBaselineTime(TApiRunConfig& aApiRunConfig, TInt32& aMinimumExecutionBaselineTime) |
|
145 { |
|
146 //****NB: update this routine to something more maintainable |
|
147 TUptTraceTester timer; |
|
148 TInt error = KErrNone; |
|
149 |
|
150 TApiRunResults apiRunResults; |
|
151 TRunConfigurer::Init(apiRunResults); |
|
152 TInt originalApiId = aApiRunConfig.iApiId; |
|
153 if(TUptTraceCalls::IsKernelTrace(originalApiId)) |
|
154 aApiRunConfig.iApiId = UPTKernelBaseline; |
|
155 else |
|
156 aApiRunConfig.iApiId = UPTBaseline; |
|
157 aApiRunConfig.iDoTrace=EFalse; |
|
158 aApiRunConfig.iDoStack=EFalse; |
|
159 aApiRunConfig.iDoFlush=EFalse; |
|
160 |
|
161 error = timer.TimeTraceL(aApiRunConfig, apiRunResults); |
|
162 |
|
163 aApiRunConfig.iApiId = originalApiId; |
|
164 aMinimumExecutionBaselineTime = apiRunResults.iApiTraceTime; |
|
165 return error; |
|
166 |
|
167 } |
|
168 |
|
169 /** This user-side method calculates the minimum execution time taken for a single API call. |
|
170 @param aMinimumExecutionTime is the minimum execution time taken for the API call, calculated in nanoseconds |
|
171 @param aMinimumExecutionBaselineTime is the minimum execution baseline time taken for commented API call, calculated in nanoseconds |
|
172 @return KErrNone if command was prepared correctly and a system wide error code otherwise. |
|
173 */ |
|
174 TInt CApiCallTest::CachedTraceTime(TApiRunConfig& aApiRunConfig, TInt32& aMinimumExecutionTime, TInt32& aMinimumExecutionBaselineTime) |
|
175 { |
|
176 //NB!!! any changes to this routine and you have to update the baseline calculation as well |
|
177 TUptTraceTester timer; |
|
178 |
|
179 TInt err =KErrNone; |
|
180 TApiRunResults apiRunResults; |
|
181 TRunConfigurer::Init(apiRunResults); |
|
182 aApiRunConfig.iDoTrace=ETrue; |
|
183 aApiRunConfig.iDoStack=EFalse; |
|
184 aApiRunConfig.iDoFlush=EFalse; |
|
185 |
|
186 err=timer.TimeTraceL(aApiRunConfig, apiRunResults); |
|
187 |
|
188 aMinimumExecutionTime = apiRunResults.iApiTraceTime - aMinimumExecutionBaselineTime; |
|
189 |
|
190 return err; |
|
191 } |
|
192 |
|
193 /** This user-side method calculates the typical execution baseline time taken for a single commented API call. |
|
194 @param aTypicalExecutionBaselineTime is the typical execution baseline time taken for the API call, calculated in nanoseconds |
|
195 @return KErrNone if command was prepared correctly and a system wide error code otherwise. |
|
196 */ |
|
197 TInt CApiCallTest::NonCachedTraceBaselineTime(TApiRunConfig& aApiRunConfig, TInt32& aTypicalExecutionBaselineTime) |
|
198 { |
|
199 //****NB: update this routine to something more maintainable |
|
200 TUptTraceTester timer; |
|
201 |
|
202 TInt error = KErrNone; |
|
203 |
|
204 TApiRunResults apiRunResults; |
|
205 TRunConfigurer::Init(apiRunResults); |
|
206 TInt originalApiId = aApiRunConfig.iApiId; |
|
207 if(TUptTraceCalls::IsKernelTrace(originalApiId)) |
|
208 aApiRunConfig.iApiId = UPTKernelBaseline; |
|
209 else |
|
210 aApiRunConfig.iApiId = UPTBaseline; |
|
211 aApiRunConfig.iDoTrace = EFalse; |
|
212 aApiRunConfig.iDoStack = EFalse; |
|
213 aApiRunConfig.iDoFlush = ETrue; |
|
214 |
|
215 error=timer.TimeTraceL(aApiRunConfig, apiRunResults); |
|
216 |
|
217 aApiRunConfig.iApiId = originalApiId; |
|
218 aTypicalExecutionBaselineTime = apiRunResults.iApiTraceTime; |
|
219 return error; |
|
220 } |
|
221 |
|
222 /** This user-side method calculates the typical execution time taken for a single API call. |
|
223 @param aTypicalExecutionTime is the typical execution time taken for the API call, calculated in nanoseconds |
|
224 @return KErrNone if command was prepared correctly and a system wide error code otherwise. |
|
225 */ |
|
226 TInt CApiCallTest::NonCachedTraceTime(TApiRunConfig& aApiRunConfig, TInt32& aTypicalExecutionTime, TInt32& aTypicalExecutionBaselineTime) |
|
227 { |
|
228 |
|
229 TUptTraceTester timer; |
|
230 |
|
231 TInt err =KErrNone; |
|
232 TApiRunResults apiRunResults; |
|
233 TRunConfigurer::Init(apiRunResults); |
|
234 aApiRunConfig.iDoTrace=ETrue; |
|
235 aApiRunConfig.iDoStack=EFalse; |
|
236 aApiRunConfig.iDoFlush=ETrue; |
|
237 |
|
238 err=timer.TimeTraceL(aApiRunConfig, apiRunResults); |
|
239 |
|
240 aTypicalExecutionTime = apiRunResults.iApiTraceTime - aTypicalExecutionBaselineTime; |
|
241 |
|
242 return err; |
|
243 |
|
244 } |
|
245 |
|
246 /*A test function available for use by TestStackUsage() |
|
247 * */ |
|
248 void foo() |
|
249 { |
|
250 volatile int gt[100]; //expect 400 bytes stack use - i.e. 100 words of 4bytes each |
|
251 for(int i=0; i<100;++i) |
|
252 gt[i] = i; |
|
253 } |
|
254 |
|
255 |
|
256 /** This calculates the typical stack usage for a single API call. |
|
257 * This is only done on hardware, but this is taken care of in the |
|
258 * actual stack usage methods. For emulator the result will always be 0. |
|
259 * |
|
260 * @return KErrNone if command was prepared correctly and a system wide error code otherwise. |
|
261 */ |
|
262 TInt CApiCallTest::StackUsage(TApiRunConfig& aApiRunConfig, TInt& aApiStackUsage) |
|
263 { |
|
264 /* |
|
265 PSEUDOCODE |
|
266 1) initiate a variable forced to the cleanup stack |
|
267 static volatile int foo = 0; |
|
268 2) initiate a pointer to this variable |
|
269 int* p=&foo; |
|
270 3) now fill the stack from this point to 0K with e.g. DEADBEEF bitpattern |
|
271 memid=(foo, p, 0xDEADBEEF); |
|
272 4) (note will wind the pointer on to p = p & 0xFFFC000 (0k) |
|
273 5) take a copy of this bitmap pattern (memcopy (foo)); |
|
274 6) take pointer back to foo |
|
275 7) execute UTrace(...) |
|
276 8) take a copy of the new bitmap patterm (memcopy (foo)); |
|
277 9) compare the bitmap pattern from 5) and 9) to give stack usage |
|
278 10) verify this result with Lauterbach |
|
279 */ |
|
280 TUptTraceTester tracecall; |
|
281 |
|
282 TInt err=KErrNone; |
|
283 TApiRunResults apiRunResults; |
|
284 TRunConfigurer::Init(apiRunResults); |
|
285 aApiRunConfig.iDoTrace=ETrue; |
|
286 aApiRunConfig.iDoStack=ETrue; |
|
287 aApiRunConfig.iDoFlush=EFalse; //not really needed but kept for consistency |
|
288 |
|
289 |
|
290 err = tracecall.SendTraceL(aApiRunConfig, apiRunResults); |
|
291 aApiStackUsage = apiRunResults.iApiStackUsage; |
|
292 return err; |
|
293 } |
|
294 |
|
295 /** This user-side method calculates the typical heap usage for a single API call. (Expected to be zero, but included for sanity) |
|
296 @return KErrNone if command was prepared correctly and a system wide error code otherwise. |
|
297 */ |
|
298 TInt CApiCallTest::HeapUsage(TInt& aApiHeapUsage) |
|
299 { |
|
300 aApiHeapUsage=-1; |
|
301 return KErrNone; |
|
302 } |
|
303 |
|
304 /** This sanity test method is executed at the start of the test run to verify that UPT methods in |
|
305 this class are stable before any of the performance tests are carried out |
|
306 @return KErrNone if command was prepared correctly and system wide error code otherwise. |
|
307 */ |
|
308 TInt CApiCallTest::Test() |
|
309 { |
|
310 TInt err=TestStackUsage(); |
|
311 return err; |
|
312 } |
|
313 |
|
314 /** This sanity test method is executed in Test() to verify that UPT StackUsage() method in |
|
315 this class are stable before any of the stack size performance tests are carried out |
|
316 @return KErrNone if command was prepared correctly and system wide error code otherwise. |
|
317 */ |
|
318 TInt CApiCallTest::TestStackUsage() |
|
319 { |
|
320 TInt err=KErrNone; |
|
321 #ifndef __WINSCW__ |
|
322 err=KErrGeneral; |
|
323 TInt32 stackBase=0; |
|
324 TInt32 before=0; |
|
325 TInt fooSize=400; |
|
326 TBool doStack=ETrue; |
|
327 |
|
328 //TTeUptStackInfo::MarkInitialStack(doStack, stackBase, before); |
|
329 __MARK_INITIAL_STACK(doStack, stackBase, before); |
|
330 foo(); |
|
331 // TTeUptStackInfo::ReturnStackSize(doStack, stackBase, before, fooSize); |
|
332 __RETURN_STACK_SIZE(doStack, stackBase, before, fooSize); |
|
333 |
|
334 if(fooSize==400) |
|
335 err=KErrNone; |
|
336 else |
|
337 err=fooSize; |
|
338 #endif |
|
339 |
|
340 return err; |
|
341 } |
|
342 |
|
343 |
|
344 |
|
345 |
|
346 |