datacommsserver/esockserver/test/TE_EsockTestSteps/src/Connections.TestSteps.cpp
branchRCL_3
changeset 25 9d7ce34704c8
parent 23 cbb19216b74d
child 26 b564fb5fd78b
equal deleted inserted replaced
24:00c6709d25aa 25:9d7ce34704c8
   284     if (pConnectionStartStatus == NULL)
   284     if (pConnectionStartStatus == NULL)
   285         {
   285         {
   286         return KErrCorrupt;
   286         return KErrCorrupt;
   287         }
   287         }
   288     
   288     
   289     if (iEsockTest->OpenConnection(iParams) != KErrNone)
       
   290         {
       
   291         INFO_PRINTF1(_L("Can't reopen connection, most likely you didn't supply the session name"));
       
   292         return KErrCorrupt;
       
   293         }
       
   294     
       
   295     timeBegin.HomeTime();
   289     timeBegin.HomeTime();
   296     TInt error = iEsockTest->StartConnection(iParams);
   290     TInt error = iEsockTest->StartConnection(iParams);
   297     if (error != KErrNone)
   291     if (error != KErrNone)
   298         {
   292         {
   299         return error;
   293         return error;
   303         {
   297         {
   304         return pConnectionStartStatus->Int();
   298         return pConnectionStartStatus->Int();
   305         }    
   299         }    
   306     timeEnd.HomeTime();
   300     timeEnd.HomeTime();
   307     iEsockTest->StopConnection(iParams);
   301     iEsockTest->StopConnection(iParams);
   308     iEsockTest->CloseConnection(iParams.iConnectionName);
       
   309     
       
   310     return timeEnd.MicroSecondsFrom(timeBegin).Int64();
   302     return timeEnd.MicroSecondsFrom(timeBegin).Int64();
   311     }
   303     }
   312 
   304 
   313 CStartStopCrazyLoopRConnectionStep::~CStartStopCrazyLoopRConnectionStep()
       
   314     {
       
   315     iTimer.Close();
       
   316     }
       
   317 
   305 
   318 TVerdict CStartStopCrazyLoopRConnectionStep::doSingleTestStep()
   306 TVerdict CStartStopCrazyLoopRConnectionStep::doSingleTestStep()
   319     {
   307     {
   320     // Default to failing
   308     // Default to failing
   321     SetTestStepResult(EFail);
   309     SetTestStepResult(EFail);
   322     iParams.iAsynch = ETrue; //force async.
   310     iParams.iAsynch = ETrue; //force async.
   323     TInt error = iTimer.CreateLocal();
   311     RTimer timer;
       
   312     TInt error = timer.CreateLocal();
   324     if (error!=KErrNone)
   313     if (error!=KErrNone)
   325         {
   314         {
   326         INFO_PRINTF2(_L("Creating RTimer object failed with %d"), error);
   315         INFO_PRINTF2(_L("Creating RTimer object failed with %d"), error);
   327         return TestStepResult();
   316         return TestStepResult();
   328         }
   317         }
   329     
   318     
   330     ipConnectionStartStatus = new TRequestStatus;
   319     TRequestStatus timerRequestStatus;
   331     if (ipConnectionStartStatus == NULL)
   320     TRequestStatus* pConnectionStartStatus = new TRequestStatus; 
       
   321     if (pConnectionStartStatus == NULL)
   332         {
   322         {
   333         INFO_PRINTF1(_L("Heap allocation for TRequestStatus failed"));
   323         INFO_PRINTF1(_L("Heap allocation for TRequestStatus failed"));
       
   324         timer.Close();
   334         return TestStepResult();
   325         return TestStepResult();
   335         }
   326         }
   336     error = iEsockTest->iRequestStatuses.Add(ipConnectionStartStatus, iParams.iConnectionName); //And will be owned here
   327     error = iEsockTest->iRequestStatuses.Add(pConnectionStartStatus, iParams.iConnectionName);
   337     if (error!=KErrNone)
   328     if (error!=KErrNone)
   338         {
   329         {
   339         INFO_PRINTF2(_L("Failed "), error);
   330         INFO_PRINTF2(_L("Failed "), error);
       
   331         timer.Close();
       
   332         delete pConnectionStartStatus;
   340         return TestStepResult();
   333         return TestStepResult();
   341         }
   334         }
       
   335     TRequestStatus& connectionStartStatus = *pConnectionStartStatus;
   342     
   336     
       
   337     const TInt KLoops = 10;
   343     INFO_PRINTF1(_L("Calibrating timer by running full start"));
   338     INFO_PRINTF1(_L("Calibrating timer by running full start"));
   344     //Well, we're running the full start twice as the first run is likely to take more than the representative time.
   339     //Well, we're running the full start twice as the first run is likely to take more than the representative time.
   345     TInt timerIncrement = Min<TInt>(CalibrateStart(), CalibrateStart());
   340     TInt timerIncrement = Min<TInt>(CalibrateStart(), CalibrateStart());
   346     if (timerIncrement < 0)
   341     if (timerIncrement < 0)
   347         {
   342         {
   348         INFO_PRINTF2(_L("Full start failed, unable to calibrate, test failed with %d"), timerIncrement);
   343         INFO_PRINTF2(_L("Full start failed, unable to calibrate, test failed with %d"), timerIncrement);
   349         return TestStepResult();
   344         return TestStepResult();
   350         }
   345         }
   351     INFO_PRINTF3(_L("Start took %dus, will divide by %d and use as the increment"), timerIncrement, EPlannedLoops);
   346     INFO_PRINTF3(_L("Start took %dus, will divide by %d and use as the increment"), timerIncrement, KLoops);
   352     
   347     
   353     timerIncrement /= EPlannedLoops;
       
   354 
       
   355     
   348     
   356     /*=======================================================
       
   357      * The loop
       
   358      */
       
   359     TInt timerVal = 1;
   349     TInt timerVal = 1;
   360     TInt i = 0;
   350     timerIncrement /= KLoops;
   361     INFO_PRINTF1(_L("Beginning crazy loop"));
   351     
   362     while (ETrue)
   352     INFO_PRINTF1(_L("Beginning crazy start/stop loop"));
   363         {
   353 
   364         if (++i > (2 * EPlannedLoops))
   354     for (TInt i = 1; i < KLoops+1; i++)
   365             {
   355         {
   366             INFO_PRINTF1(_L("The test has been executing far too many iterations than can be reasonably expected, aborting.."));
       
   367             return TestStepResult();
       
   368             }
       
   369         INFO_PRINTF2(_L("[Loop %d], Starting a new loop=============================="), i);
   356         INFO_PRINTF2(_L("[Loop %d], Starting a new loop=============================="), i);
   370         INFO_PRINTF2(_L("***********Re-openning connection"), 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);        
   371         if (iEsockTest->OpenConnection(iParams) != KErrNone)
   360         if (iEsockTest->OpenConnection(iParams) != KErrNone)
   372             {
   361             {
   373             INFO_PRINTF1(_L("Can't reopen connection, most likely you didn't supply the session name"));
   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();
   374             return TestStepResult();
   387             return TestStepResult();
   375             }
   388             }
   376         
   389         
   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             }
       
   392         timerVal += timerIncrement;
   390         timerVal += timerIncrement;
   393         
   391         INFO_PRINTF2(_L("[Loop %d], ....zzz. Stopping connection"), i);
   394         INFO_PRINTF2(_L("***********Closing connection"), i);
   392         iEsockTest->StopConnection(iParams);
   395         iEsockTest->CloseConnection(iParams.iConnectionName);
   393         User::WaitForRequest(connectionStartStatus);
   396         }
   394         INFO_PRINTF2(_L("[Loop %d], Connection stopped"), i);
   397 
   395         }
       
   396     timer.Close();
   398     SetTestStepResult(EPass);
   397     SetTestStepResult(EPass);
   399     return TestStepResult();
   398     return TestStepResult();
   400     }
   399     }
   401 
   400 
   402 TInt CStartStopCrazyLoopRConnectionStep::doLoopStep(TInt aTimerVal)
   401 
   403     {
   402 
   404     TRequestStatus timerRequestStatus;
   403 
   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     }
       
   464 
   404 
   465 
   405 
   466 
   406 
   467 
   407 
   468 // Stop Connection
   408 // Stop Connection