|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implementation of MT_CHSPSTeststep class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <s32mem.h> |
|
21 #include <eunitmacros.h> |
|
22 #include <eunitdecorators.h> |
|
23 #include "mt_hspsteststep.h" |
|
24 |
|
25 #ifdef HSPS_LOG_ACTIVE |
|
26 #include <hspslogbusfile.h> |
|
27 #include <hspslogbus.h> |
|
28 #endif |
|
29 |
|
30 // ======== LOCAL CONSTANTS ==================================================== |
|
31 |
|
32 // Test step timeout |
|
33 const TInt KTestStepTimeout = 5000000; |
|
34 |
|
35 // Max input |
|
36 const TInt KTestStepInputSizeMax = 1000; |
|
37 |
|
38 // Max output |
|
39 const TInt KTestStepOutputSizeMax = 10000; |
|
40 |
|
41 // ======== LOCAL FUNCTIONS ==================================================== |
|
42 |
|
43 // --------------------------------------------------------- |
|
44 // TimeoutCallback |
|
45 // --------------------------------------------------------- |
|
46 // |
|
47 TInt TimeoutCallback( TAny* aPtr ) |
|
48 { |
|
49 TRequestStatus* status = &( ( ( MT_CHSPSTeststep* )aPtr )->iStatus ); |
|
50 |
|
51 if ( ( ( MT_CHSPSTeststep* )aPtr )->iOutParams ) |
|
52 { |
|
53 delete ( ( MT_CHSPSTeststep* )aPtr )->iOutParams; |
|
54 ( ( MT_CHSPSTeststep* )aPtr )->iOutParams = NULL; |
|
55 } |
|
56 if ( ( ( MT_CHSPSTeststep* )aPtr )->iTimeout ) |
|
57 { |
|
58 delete ( ( MT_CHSPSTeststep* )aPtr )->iTimeout; |
|
59 ( ( MT_CHSPSTeststep* )aPtr )->iTimeout = NULL; |
|
60 } |
|
61 |
|
62 User::RequestComplete( status, KErrNone ); |
|
63 |
|
64 return KErrNone; |
|
65 } |
|
66 |
|
67 |
|
68 // ======== MEMBER FUNCTIONS =================================================== |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // Two-phased constructor. |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 MT_CHSPSTeststep* MT_CHSPSTeststep::NewL( |
|
75 MLiwInterface& aInterface, |
|
76 TUint8* aMethod, |
|
77 TUint8* aInParams, |
|
78 TUint8* aExpOutParams, |
|
79 TBool aAsync, |
|
80 TBool aMeasureExecTime ) |
|
81 { |
|
82 MT_CHSPSTeststep* self = new( ELeave ) MT_CHSPSTeststep( |
|
83 aInterface, |
|
84 aMethod, |
|
85 aInParams, |
|
86 aExpOutParams, |
|
87 aAsync, |
|
88 aMeasureExecTime ); |
|
89 |
|
90 return self; |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // Constructor |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 MT_CHSPSTeststep::MT_CHSPSTeststep( |
|
98 MLiwInterface& aInterface, |
|
99 TUint8* aMethod, |
|
100 TUint8* aInParams, |
|
101 TUint8* aExpOutParams, |
|
102 TBool aAsync, |
|
103 TBool aMeasureExecTime ) |
|
104 :CActive( CActive::EPriorityStandard ) |
|
105 ,iOutParams( NULL ) |
|
106 ,iTimeout( NULL ) |
|
107 ,iInterface( aInterface ) |
|
108 ,iMethod( aMethod ) |
|
109 ,iInParams( aInParams ) |
|
110 ,iExpOutParams( aExpOutParams ) |
|
111 ,iAsync( aAsync ) |
|
112 ,iMeasureExecTime( aMeasureExecTime ) |
|
113 { |
|
114 } |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 // Destructor. |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 MT_CHSPSTeststep::~MT_CHSPSTeststep() |
|
121 { |
|
122 if ( iOutParams ) |
|
123 { |
|
124 delete iOutParams; |
|
125 } |
|
126 if ( iTimeout ) |
|
127 { |
|
128 delete iTimeout; |
|
129 } |
|
130 } |
|
131 |
|
132 // ----------------------------------------------------------------------------- |
|
133 // From CActive |
|
134 // ----------------------------------------------------------------------------- |
|
135 // |
|
136 void MT_CHSPSTeststep::RunL() |
|
137 { |
|
138 // Stop test thread active scheduler |
|
139 CActiveScheduler::Stop(); |
|
140 } |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 // From CActive |
|
144 // ----------------------------------------------------------------------------- |
|
145 // |
|
146 TInt MT_CHSPSTeststep::RunError( |
|
147 TInt /*aError*/ ) |
|
148 { |
|
149 if ( iOutParams ) |
|
150 { |
|
151 delete iOutParams; |
|
152 iOutParams = NULL; |
|
153 } |
|
154 if ( iTimeout ) |
|
155 { |
|
156 delete iTimeout; |
|
157 iTimeout = NULL; |
|
158 } |
|
159 |
|
160 return KErrNone; |
|
161 } |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // From CActive |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 void MT_CHSPSTeststep::DoCancel() |
|
168 { |
|
169 if ( iOutParams ) |
|
170 { |
|
171 delete iOutParams; |
|
172 iOutParams = NULL; |
|
173 } |
|
174 if ( iTimeout ) |
|
175 { |
|
176 delete iTimeout; |
|
177 iTimeout = NULL; |
|
178 } |
|
179 } |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // MLiwNotifyCallback::HandleNotifyL |
|
183 // ----------------------------------------------------------------------------- |
|
184 // |
|
185 TInt MT_CHSPSTeststep::HandleNotifyL( |
|
186 TInt aCmdId, |
|
187 TInt aEventId, |
|
188 CLiwGenericParamList& aEventParamList, |
|
189 const CLiwGenericParamList& /*aInParamList*/ ) |
|
190 { |
|
191 aCmdId = aCmdId; |
|
192 aEventId = aEventId; |
|
193 |
|
194 // Copy event parameters as a descriptor stream |
|
195 if ( iOutParams ) |
|
196 { |
|
197 delete iOutParams; |
|
198 iOutParams = NULL; |
|
199 } |
|
200 iOutParams = CreateOutParamsL( aEventParamList ); |
|
201 |
|
202 TRequestStatus* status = &iStatus; |
|
203 User::RequestComplete( status, KErrNone ); |
|
204 |
|
205 return KErrNone; |
|
206 } |
|
207 |
|
208 // ----------------------------------------------------------------------------- |
|
209 // Calls service method |
|
210 // ----------------------------------------------------------------------------- |
|
211 // |
|
212 void MT_CHSPSTeststep::CallServiceL() |
|
213 { |
|
214 |
|
215 CLiwGenericParamList* inParamList; |
|
216 CLiwGenericParamList* outParamList; |
|
217 TInt err; |
|
218 |
|
219 // Create input parameter list |
|
220 if ( iInParams ) |
|
221 { |
|
222 // Create input parameter list from binary stream |
|
223 inParamList = CreateInParamListL( |
|
224 iInParams ); |
|
225 } |
|
226 else |
|
227 { |
|
228 // Create empty input parameter list |
|
229 inParamList = CLiwGenericParamList::NewL(); |
|
230 } |
|
231 |
|
232 // Create empty output parameter list |
|
233 outParamList = CLiwGenericParamList::NewL(); |
|
234 |
|
235 // Execute test step |
|
236 if ( !iAsync ) |
|
237 { |
|
238 TPtrC8 method( iMethod ); |
|
239 |
|
240 if ( iMeasureExecTime ) |
|
241 { |
|
242 StartTiming( method ); |
|
243 } |
|
244 |
|
245 TRAP( err, iInterface.ExecuteCmdL( |
|
246 method, |
|
247 *inParamList, |
|
248 *outParamList ) ); |
|
249 |
|
250 if ( iMeasureExecTime ) |
|
251 { |
|
252 StopTiming(); |
|
253 } |
|
254 |
|
255 if ( err == KErrNone ) |
|
256 { |
|
257 // Store outparams as descriptor stream |
|
258 if ( iOutParams ) |
|
259 { |
|
260 delete iOutParams; |
|
261 iOutParams = NULL; |
|
262 } |
|
263 iOutParams = CreateOutParamsL( *outParamList ); |
|
264 } |
|
265 } |
|
266 else |
|
267 { |
|
268 TPtrC8 method( iMethod ); |
|
269 |
|
270 TRAP( err, iInterface.ExecuteCmdL( |
|
271 method, |
|
272 *inParamList, |
|
273 *outParamList, |
|
274 KLiwOptASyncronous, |
|
275 this ) ); |
|
276 |
|
277 if ( err == KErrNone ) |
|
278 { |
|
279 // Set test step to wait asynchronous response |
|
280 CActiveScheduler::Add( this ); |
|
281 iStatus = KRequestPending; |
|
282 SetActive(); |
|
283 |
|
284 // Start test step timeout |
|
285 iTimeout = CPeriodic::NewL( CActive::EPriorityStandard ); |
|
286 iTimeout->Start( |
|
287 TTimeIntervalMicroSeconds32( KTestStepTimeout ), |
|
288 TTimeIntervalMicroSeconds32( KTestStepTimeout ), |
|
289 TCallBack( TimeoutCallback, this ) ); |
|
290 } |
|
291 } |
|
292 |
|
293 inParamList->Reset(); |
|
294 delete inParamList; |
|
295 outParamList->Reset(); |
|
296 delete outParamList; |
|
297 |
|
298 } |
|
299 |
|
300 #ifdef HSPS_LOG_ACTIVE |
|
301 // ----------------------------------------------------------------------------- |
|
302 // Debugging |
|
303 // ----------------------------------------------------------------------------- |
|
304 // |
|
305 void MT_CHSPSTeststep::DebugL( |
|
306 const TUint8* aOutPtr ) |
|
307 { |
|
308 ChspsLogBus* logBus = ChspsLogBusFile::NewL( _L("LIW_test_comparison.log") ); |
|
309 CleanupStack::PushL( logBus ); |
|
310 |
|
311 logBus->LogText( _L( "index, expected(int, char), actual(int, char)" ) ); |
|
312 |
|
313 TBool exitNow = EFalse; |
|
314 for ( TInt i = 0; |
|
315 i < iOutParams->Length() && !exitNow; |
|
316 i++ ) |
|
317 { |
|
318 logBus->LogText( _L("[%5d], %3d, '%c', %3d, '%c'"), |
|
319 i, // index |
|
320 ( TUint16 )iExpOutParams[i], |
|
321 ( TUint16 )iExpOutParams[i], |
|
322 ( TUint16 )aOutPtr[i], |
|
323 ( TUint16 )aOutPtr[i] ); |
|
324 |
|
325 if ( iExpOutParams[i] != aOutPtr[i] ) |
|
326 { |
|
327 exitNow = ETrue; |
|
328 } |
|
329 } |
|
330 |
|
331 CleanupStack::PopAndDestroy( logBus ); |
|
332 } |
|
333 #endif |
|
334 |
|
335 // ----------------------------------------------------------------------------- |
|
336 // Checks method call output parameters |
|
337 // ----------------------------------------------------------------------------- |
|
338 // |
|
339 TInt MT_CHSPSTeststep::CheckOutParams() |
|
340 { |
|
341 TInt err( KErrArgument ); |
|
342 |
|
343 if ( iExpOutParams && iOutParams ) |
|
344 { |
|
345 err = KErrNone; |
|
346 |
|
347 const TUint8* outPtr = ( iOutParams->Des() ).Ptr(); |
|
348 for ( TInt i = 0; |
|
349 i < iOutParams->Length() && err == KErrNone; |
|
350 i++ ) |
|
351 { |
|
352 if ( *( iExpOutParams + i ) != *( outPtr + i ) ) |
|
353 { |
|
354 EUNIT_PRINT( _L("TEST STEP FAILED: Output mismatch: output[%d] = %d, expected output[%d] = %d "), i, ( *( outPtr + i ) ), i, ( *( iExpOutParams + i ) ) ); |
|
355 err = KErrArgument; |
|
356 } |
|
357 } |
|
358 |
|
359 // Dump comparison file. |
|
360 #ifdef HSPS_LOG_ACTIVE |
|
361 if( err != KErrNone ) |
|
362 { |
|
363 TRAP_IGNORE( DebugL( outPtr ) ); |
|
364 } |
|
365 #endif |
|
366 } |
|
367 |
|
368 return err; |
|
369 } |
|
370 |
|
371 // ----------------------------------------------------------------------------- |
|
372 // Creates input parameter list from a descriptor stream |
|
373 // ----------------------------------------------------------------------------- |
|
374 // |
|
375 CLiwGenericParamList* MT_CHSPSTeststep::CreateInParamListL( |
|
376 TUint8* aInParams ) |
|
377 { |
|
378 HBufC8* inParamBuf = HBufC8::NewL( KTestStepInputSizeMax ); |
|
379 CleanupStack::PushL( inParamBuf ); |
|
380 |
|
381 TPtr8 inParamBufPtr = inParamBuf->Des(); |
|
382 inParamBufPtr.Set( |
|
383 ( ( TUint8* )aInParams ), |
|
384 KTestStepInputSizeMax, |
|
385 KTestStepInputSizeMax ); |
|
386 |
|
387 RDesReadStream inParamStream; |
|
388 inParamStream.Open( inParamBufPtr ); |
|
389 CLiwGenericParamList* inParamList = |
|
390 CLiwGenericParamList::NewL( inParamStream ); |
|
391 inParamStream.Release(); |
|
392 |
|
393 CleanupStack::PopAndDestroy( inParamBuf ); |
|
394 |
|
395 return inParamList; |
|
396 } |
|
397 |
|
398 // ----------------------------------------------------------------------------- |
|
399 // Creates output descriptor stream from output parameter list |
|
400 // ----------------------------------------------------------------------------- |
|
401 // |
|
402 HBufC8* MT_CHSPSTeststep::CreateOutParamsL( |
|
403 CLiwGenericParamList& aOutParamList ) |
|
404 { |
|
405 HBufC8* outParams = HBufC8::NewL( KTestStepOutputSizeMax ); |
|
406 CleanupStack::PushL( outParams ); |
|
407 |
|
408 TPtr8 outParamBufPtr = outParams->Des(); |
|
409 RDesWriteStream outParamStream; |
|
410 outParamStream.Open( outParamBufPtr ); |
|
411 aOutParamList.ExternalizeL( outParamStream ); |
|
412 outParamStream.CommitL(); |
|
413 outParamStream.Close(); |
|
414 |
|
415 CleanupStack::Pop( outParams ); |
|
416 |
|
417 return outParams; |
|
418 } |
|
419 |
|
420 // ----------------------------------------------------------------------------- |
|
421 // Starts timing of SAPI method execution |
|
422 // ----------------------------------------------------------------------------- |
|
423 // |
|
424 void MT_CHSPSTeststep::StartTiming( |
|
425 TDesC8& aMethod ) |
|
426 { |
|
427 iStartTime.HomeTime(); |
|
428 EUNIT_PRINT( aMethod ); |
|
429 } |
|
430 |
|
431 // ----------------------------------------------------------------------------- |
|
432 // Calculates SAPI method execution time |
|
433 // ----------------------------------------------------------------------------- |
|
434 // |
|
435 void MT_CHSPSTeststep::StopTiming() |
|
436 { |
|
437 TTime readyTime; |
|
438 readyTime.HomeTime(); |
|
439 TTimeIntervalMicroSeconds delay = readyTime.MicroSecondsFrom( iStartTime ); |
|
440 TTime transferTime( delay.Int64() ); |
|
441 TBuf<64> timeString; |
|
442 transferTime.FormatL( timeString,_L( "Execution time: %S%C microseconds" ) ); |
|
443 |
|
444 EUNIT_PRINT( timeString ); |
|
445 |
|
446 } |
|
447 |
|
448 // END OF FILE |