297 { |
303 { |
298 return pConnectionStartStatus->Int(); |
304 return pConnectionStartStatus->Int(); |
299 } |
305 } |
300 timeEnd.HomeTime(); |
306 timeEnd.HomeTime(); |
301 iEsockTest->StopConnection(iParams); |
307 iEsockTest->StopConnection(iParams); |
|
308 iEsockTest->CloseConnection(iParams.iConnectionName); |
|
309 |
302 return timeEnd.MicroSecondsFrom(timeBegin).Int64(); |
310 return timeEnd.MicroSecondsFrom(timeBegin).Int64(); |
303 } |
311 } |
304 |
312 |
|
313 CStartStopCrazyLoopRConnectionStep::~CStartStopCrazyLoopRConnectionStep() |
|
314 { |
|
315 iTimer.Close(); |
|
316 } |
305 |
317 |
306 TVerdict CStartStopCrazyLoopRConnectionStep::doSingleTestStep() |
318 TVerdict CStartStopCrazyLoopRConnectionStep::doSingleTestStep() |
307 { |
319 { |
308 // Default to failing |
320 // Default to failing |
309 SetTestStepResult(EFail); |
321 SetTestStepResult(EFail); |
310 iParams.iAsynch = ETrue; //force async. |
322 iParams.iAsynch = ETrue; //force async. |
311 RTimer timer; |
323 TInt error = iTimer.CreateLocal(); |
312 TInt error = timer.CreateLocal(); |
|
313 if (error!=KErrNone) |
324 if (error!=KErrNone) |
314 { |
325 { |
315 INFO_PRINTF2(_L("Creating RTimer object failed with %d"), error); |
326 INFO_PRINTF2(_L("Creating RTimer object failed with %d"), error); |
316 return TestStepResult(); |
327 return TestStepResult(); |
317 } |
328 } |
318 |
329 |
319 TRequestStatus timerRequestStatus; |
330 ipConnectionStartStatus = new TRequestStatus; |
320 TRequestStatus* pConnectionStartStatus = new TRequestStatus; |
331 if (ipConnectionStartStatus == NULL) |
321 if (pConnectionStartStatus == NULL) |
|
322 { |
332 { |
323 INFO_PRINTF1(_L("Heap allocation for TRequestStatus failed")); |
333 INFO_PRINTF1(_L("Heap allocation for TRequestStatus failed")); |
324 timer.Close(); |
|
325 return TestStepResult(); |
334 return TestStepResult(); |
326 } |
335 } |
327 error = iEsockTest->iRequestStatuses.Add(pConnectionStartStatus, iParams.iConnectionName); |
336 error = iEsockTest->iRequestStatuses.Add(ipConnectionStartStatus, iParams.iConnectionName); //And will be owned here |
328 if (error!=KErrNone) |
337 if (error!=KErrNone) |
329 { |
338 { |
330 INFO_PRINTF2(_L("Failed "), error); |
339 INFO_PRINTF2(_L("Failed "), error); |
331 timer.Close(); |
|
332 delete pConnectionStartStatus; |
|
333 return TestStepResult(); |
340 return TestStepResult(); |
334 } |
341 } |
335 TRequestStatus& connectionStartStatus = *pConnectionStartStatus; |
|
336 |
342 |
337 const TInt KLoops = 10; |
|
338 INFO_PRINTF1(_L("Calibrating timer by running full start")); |
343 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. |
344 //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()); |
345 TInt timerIncrement = Min<TInt>(CalibrateStart(), CalibrateStart()); |
341 if (timerIncrement < 0) |
346 if (timerIncrement < 0) |
342 { |
347 { |
343 INFO_PRINTF2(_L("Full start failed, unable to calibrate, test failed with %d"), timerIncrement); |
348 INFO_PRINTF2(_L("Full start failed, unable to calibrate, test failed with %d"), timerIncrement); |
344 return TestStepResult(); |
349 return TestStepResult(); |
345 } |
350 } |
346 INFO_PRINTF3(_L("Start took %dus, will divide by %d and use as the increment"), timerIncrement, KLoops); |
351 INFO_PRINTF3(_L("Start took %dus, will divide by %d and use as the increment"), timerIncrement, EPlannedLoops); |
347 |
352 |
|
353 timerIncrement /= EPlannedLoops; |
|
354 |
348 |
355 |
|
356 /*======================================================= |
|
357 * The loop |
|
358 */ |
349 TInt timerVal = 1; |
359 TInt timerVal = 1; |
350 timerIncrement /= KLoops; |
360 TInt i = 0; |
351 |
361 INFO_PRINTF1(_L("Beginning crazy loop")); |
352 INFO_PRINTF1(_L("Beginning crazy start/stop loop")); |
362 while (ETrue) |
353 |
363 { |
354 for (TInt i = 1; i < KLoops+1; i++) |
364 if (++i > (2 * EPlannedLoops)) |
355 { |
365 { |
|
366 INFO_PRINTF1(_L("The test has been executing far too many iterations than can be reasonably expected, aborting..")); |
|
367 return TestStepResult(); |
|
368 } |
356 INFO_PRINTF2(_L("[Loop %d], Starting a new loop=============================="), i); |
369 INFO_PRINTF2(_L("[Loop %d], Starting a new loop=============================="), i); |
357 INFO_PRINTF2(_L("[Loop %d], Closing connection"), i); |
370 INFO_PRINTF2(_L("***********Re-openning connection"), i); |
358 iEsockTest->CloseConnection(iParams.iConnectionName); |
|
359 INFO_PRINTF2(_L("[Loop %d], Re-openning connection"), i); |
|
360 if (iEsockTest->OpenConnection(iParams) != KErrNone) |
371 if (iEsockTest->OpenConnection(iParams) != KErrNone) |
361 { |
372 { |
362 INFO_PRINTF1(_L("Can't reopen connection, most likely you didn't supply the session name")); |
373 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(); |
374 return TestStepResult(); |
388 } |
375 } |
389 |
376 |
|
377 error = doLoopStep(timerVal); |
|
378 if ( error == KErrUnderflow ) |
|
379 { |
|
380 if ( i < EMandatoryLoops ) |
|
381 { |
|
382 INFO_PRINTF1(_L("The test didn't execute enough iterations and hence hasn't tested what needed to be tested")); |
|
383 return TestStepResult(); |
|
384 } |
|
385 break; //The only EPass exit condition |
|
386 } |
|
387 else if ( error != KErrNone ) |
|
388 { |
|
389 INFO_PRINTF2(_L("Loop test has failed with %d"), error); |
|
390 return TestStepResult(); |
|
391 } |
390 timerVal += timerIncrement; |
392 timerVal += timerIncrement; |
391 INFO_PRINTF2(_L("[Loop %d], ....zzz. Stopping connection"), i); |
393 |
392 iEsockTest->StopConnection(iParams); |
394 INFO_PRINTF2(_L("***********Closing connection"), i); |
393 User::WaitForRequest(connectionStartStatus); |
395 iEsockTest->CloseConnection(iParams.iConnectionName); |
394 INFO_PRINTF2(_L("[Loop %d], Connection stopped"), i); |
396 } |
395 } |
397 |
396 timer.Close(); |
|
397 SetTestStepResult(EPass); |
398 SetTestStepResult(EPass); |
398 return TestStepResult(); |
399 return TestStepResult(); |
399 } |
400 } |
400 |
401 |
401 |
402 TInt CStartStopCrazyLoopRConnectionStep::doLoopStep(TInt aTimerVal) |
402 |
403 { |
403 |
404 TRequestStatus timerRequestStatus; |
|
405 |
|
406 INFO_PRINTF1(_L("***********Starting connection (asynch)")); |
|
407 TInt error = iEsockTest->StartConnection(iParams); |
|
408 if (error != KErrNone) |
|
409 { |
|
410 INFO_PRINTF1(_L("Starting connection failed, aborting")); |
|
411 return error; |
|
412 } |
|
413 INFO_PRINTF2(_L("***********Setting timer to %dus .zzz...."), aTimerVal); |
|
414 iTimer.After(timerRequestStatus,aTimerVal); |
|
415 User::WaitForRequest(timerRequestStatus, *ipConnectionStartStatus); |
|
416 if (timerRequestStatus.Int() == KRequestPending) |
|
417 { |
|
418 INFO_PRINTF2(_L("Connection Start completed with %d and before the timer"), ipConnectionStartStatus->Int()); |
|
419 iTimer.Cancel(); |
|
420 User::WaitForRequest(timerRequestStatus); |
|
421 return ipConnectionStartStatus->Int() == KErrNone ? KErrUnderflow : ipConnectionStartStatus->Int(); //Whether this is fatal for the test or not, will be determined by the caller; |
|
422 } |
|
423 |
|
424 INFO_PRINTF1(_L("*********** ....zzz. Stopping connection")); |
|
425 iEsockTest->StopConnection(iParams); |
|
426 User::WaitForRequest(*ipConnectionStartStatus); |
|
427 INFO_PRINTF1(_L("***********Connection stopped")); |
|
428 return KErrNone; |
|
429 } |
|
430 |
|
431 |
|
432 // CStartCloseCrazyLoopRConnectionStep |
|
433 //----------------- |
|
434 |
|
435 CStartCloseCrazyLoopRConnectionStep::CStartCloseCrazyLoopRConnectionStep(CCEsockTestBase*& aEsockTest) |
|
436 : CStartStopCrazyLoopRConnectionStep(aEsockTest) |
|
437 { |
|
438 SetTestStepName(KStartCloseCrazyLoopRConnectionStep); |
|
439 } |
|
440 |
|
441 TInt CStartCloseCrazyLoopRConnectionStep::doLoopStep(TInt aTimerVal) |
|
442 { |
|
443 TRequestStatus timerRequestStatus; |
|
444 |
|
445 INFO_PRINTF1(_L("***********Starting connection (asynch)")); |
|
446 TInt error = iEsockTest->StartConnection(iParams); |
|
447 if (error != KErrNone) |
|
448 { |
|
449 INFO_PRINTF1(_L("Starting connection failed, aborting")); |
|
450 return error; |
|
451 } |
|
452 INFO_PRINTF2(_L("***********Setting timer to %dus .zzz...."), aTimerVal); |
|
453 iTimer.After(timerRequestStatus,aTimerVal); |
|
454 User::WaitForRequest(timerRequestStatus, *ipConnectionStartStatus); |
|
455 if (timerRequestStatus.Int() == KRequestPending) |
|
456 { |
|
457 INFO_PRINTF2(_L("Connection Start completed with %d and before the timer"), ipConnectionStartStatus->Int()); |
|
458 iTimer.Cancel(); |
|
459 User::WaitForRequest(timerRequestStatus); |
|
460 return ipConnectionStartStatus->Int() == KErrNone ? KErrUnderflow : ipConnectionStartStatus->Int(); //Whether this is fatal for the test or not, will be determined by the caller; |
|
461 } |
|
462 return KErrNone; |
|
463 } |
404 |
464 |
405 |
465 |
406 |
466 |
407 |
467 |
408 // Stop Connection |
468 // Stop Connection |