247 SetTestStepError((ret == iExpectedError) ? KErrNone : ret); |
255 SetTestStepError((ret == iExpectedError) ? KErrNone : ret); |
248 } |
256 } |
249 |
257 |
250 return TestStepResult(); |
258 return TestStepResult(); |
251 } |
259 } |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 // CStartStopCrazyLoopRConnectionStep |
|
270 //----------------- |
|
271 |
|
272 CStartStopCrazyLoopRConnectionStep::CStartStopCrazyLoopRConnectionStep(CCEsockTestBase*& aEsockTest) |
|
273 : CStartRConnectionStep(aEsockTest) |
|
274 { |
|
275 SetTestStepName(KStartStopCrazyLoopRConnectionStep); |
|
276 } |
|
277 |
|
278 TInt CStartStopCrazyLoopRConnectionStep::CalibrateStart() |
|
279 { |
|
280 TTime timeBegin; |
|
281 TTime timeEnd; |
|
282 |
|
283 TRequestStatus* pConnectionStartStatus = iEsockTest->iRequestStatuses.Find(iParams.iConnectionName); |
|
284 if (pConnectionStartStatus == NULL) |
|
285 { |
|
286 return KErrCorrupt; |
|
287 } |
|
288 |
|
289 timeBegin.HomeTime(); |
|
290 TInt error = iEsockTest->StartConnection(iParams); |
|
291 if (error != KErrNone) |
|
292 { |
|
293 return error; |
|
294 } |
|
295 User::WaitForRequest(*pConnectionStartStatus); |
|
296 if (pConnectionStartStatus->Int() != KErrNone) |
|
297 { |
|
298 return pConnectionStartStatus->Int(); |
|
299 } |
|
300 timeEnd.HomeTime(); |
|
301 iEsockTest->StopConnection(iParams); |
|
302 return timeEnd.MicroSecondsFrom(timeBegin).Int64(); |
|
303 } |
|
304 |
|
305 |
|
306 TVerdict CStartStopCrazyLoopRConnectionStep::doSingleTestStep() |
|
307 { |
|
308 // Default to failing |
|
309 SetTestStepResult(EFail); |
|
310 iParams.iAsynch = ETrue; //force async. |
|
311 RTimer timer; |
|
312 TInt error = timer.CreateLocal(); |
|
313 if (error!=KErrNone) |
|
314 { |
|
315 INFO_PRINTF2(_L("Creating RTimer object failed with %d"), error); |
|
316 return TestStepResult(); |
|
317 } |
|
318 |
|
319 TRequestStatus timerRequestStatus; |
|
320 TRequestStatus* pConnectionStartStatus = new TRequestStatus; |
|
321 if (pConnectionStartStatus == NULL) |
|
322 { |
|
323 INFO_PRINTF1(_L("Heap allocation for TRequestStatus failed")); |
|
324 timer.Close(); |
|
325 return TestStepResult(); |
|
326 } |
|
327 error = iEsockTest->iRequestStatuses.Add(pConnectionStartStatus, iParams.iConnectionName); |
|
328 if (error!=KErrNone) |
|
329 { |
|
330 INFO_PRINTF2(_L("Failed "), error); |
|
331 timer.Close(); |
|
332 delete pConnectionStartStatus; |
|
333 return TestStepResult(); |
|
334 } |
|
335 TRequestStatus& connectionStartStatus = *pConnectionStartStatus; |
|
336 |
|
337 const TInt KLoops = 10; |
|
338 INFO_PRINTF1(_L("Calibrating timer by running full start")); |
|
339 //Well, we're running the full start twice as the first run is likely to take more than the representative time. |
|
340 TInt timerIncrement = Min<TInt>(CalibrateStart(), CalibrateStart()); |
|
341 if (timerIncrement < 0) |
|
342 { |
|
343 INFO_PRINTF2(_L("Full start failed, unable to calibrate, test failed with %d"), timerIncrement); |
|
344 return TestStepResult(); |
|
345 } |
|
346 INFO_PRINTF3(_L("Start took %dus, will divide by %d and use as the increment"), timerIncrement, KLoops); |
|
347 |
|
348 |
|
349 TInt timerVal = 1; |
|
350 timerIncrement /= KLoops; |
|
351 |
|
352 INFO_PRINTF1(_L("Beginning crazy start/stop loop")); |
|
353 |
|
354 for (TInt i = 1; i < KLoops+1; i++) |
|
355 { |
|
356 INFO_PRINTF2(_L("[Loop %d], Starting a new loop=============================="), i); |
|
357 INFO_PRINTF2(_L("[Loop %d], Closing connection"), i); |
|
358 iEsockTest->CloseConnection(iParams.iConnectionName); |
|
359 INFO_PRINTF2(_L("[Loop %d], Re-openning connection"), i); |
|
360 if (iEsockTest->OpenConnection(iParams) != KErrNone) |
|
361 { |
|
362 INFO_PRINTF1(_L("Can't reopen connection, most likely you didn't supply the session name")); |
|
363 timer.Close(); |
|
364 return TestStepResult(); |
|
365 } |
|
366 INFO_PRINTF2(_L("[Loop %d], Starting connection (asynch)"), i); |
|
367 error = iEsockTest->StartConnection(iParams); |
|
368 if (error != KErrNone) |
|
369 { |
|
370 INFO_PRINTF1(_L("Starting connection failed, aborting")); |
|
371 timer.Close(); |
|
372 return TestStepResult(); |
|
373 } |
|
374 INFO_PRINTF3(_L("[Loop %d], Setting timer to %dus .zzz...."), i, timerVal); |
|
375 timer.After(timerRequestStatus,timerVal); |
|
376 User::WaitForRequest(timerRequestStatus,connectionStartStatus); |
|
377 if (timerRequestStatus.Int() == KRequestPending) |
|
378 { |
|
379 INFO_PRINTF2(_L("Connection Start completed with %d"), connectionStartStatus.Int()); |
|
380 INFO_PRINTF1(_L("Irrespective of the start result the test has failed, because it hadn't execute enough iterations")); |
|
381 //If you get this a lot this means there;s a flaw in the logic of this test and for some reason the execution of |
|
382 //RConnection::Start speeds up with time. You may want to re-calibrate then and rerun the loop again with finer |
|
383 //interval. |
|
384 timer.Cancel(); |
|
385 User::WaitForRequest(timerRequestStatus); |
|
386 timer.Close(); |
|
387 return TestStepResult(); |
|
388 } |
|
389 |
|
390 timerVal += timerIncrement; |
|
391 INFO_PRINTF2(_L("[Loop %d], ....zzz. Stopping connection"), i); |
|
392 iEsockTest->StopConnection(iParams); |
|
393 User::WaitForRequest(connectionStartStatus); |
|
394 INFO_PRINTF2(_L("[Loop %d], Connection stopped"), i); |
|
395 } |
|
396 timer.Close(); |
|
397 SetTestStepResult(EPass); |
|
398 return TestStepResult(); |
|
399 } |
|
400 |
|
401 |
|
402 |
|
403 |
|
404 |
|
405 |
252 |
406 |
253 |
407 |
254 // Stop Connection |
408 // Stop Connection |
255 //---------------- |
409 //---------------- |
256 |
410 |