datacommsserver/esockserver/test/TE_EsockTestSteps/src/Connections.TestSteps.cpp
changeset 65 41cc8e7ff496
parent 40 34fc115b8742
child 66 cbb19216b74d
equal deleted inserted replaced
40:34fc115b8742 65:41cc8e7ff496
   110         return EFalse;
   110         return EFalse;
   111         }
   111         }
   112 
   112 
   113     // Optional
   113     // Optional
   114     // Reads the protocol family to use
   114     // Reads the protocol family to use
   115     if (GetIntFromConfig(iSection, KTe_ConnectionType, iParams.iConnectionType) != 1)
   115     if (!GetIntFromConfig(iSection, KTe_ConnectionType, iParams.iConnectionType))
   116         {
   116         {
   117           iParams.iConnectionType = -1;
   117         iParams.iConnectionType = -1;
   118         }
   118         }
   119 
   119 
   120     // All ok if we got this far
   120     // All ok if we got this far
   121     return KErrNone;
   121     return KErrNone;
   122 	}
   122 	}
   153 		|| (iParams.iConnectionName.Length() == 0))
   153 		|| (iParams.iConnectionName.Length() == 0))
   154 		{
   154 		{
   155 		INFO_PRINTF1(_L("Couldn't find appropriate field in config file"));
   155 		INFO_PRINTF1(_L("Couldn't find appropriate field in config file"));
   156 		return KErrNotFound;
   156 		return KErrNotFound;
   157 		}
   157 		}
       
   158 	
       
   159     GetStringFromConfig(iSection, KTe_SocketServName, iParams.iSockServName);
       
   160     // Optional
       
   161     // Reads the protocol family to use
       
   162     if (!GetIntFromConfig(iSection, KTe_ConnectionType, iParams.iConnectionType))
       
   163         {
       
   164           iParams.iConnectionType = -1;
       
   165         }
   158 
   166 
   159 	TPtrC16 bearerSet;
   167 	TPtrC16 bearerSet;
   160 	TBool bearerPresent = ((GetStringFromConfig(iSection,KTe_BearerName,bearerSet)==1)
   168 	TBool bearerPresent = ((GetStringFromConfig(iSection,KTe_BearerName,bearerSet)==1)
   161 		&& (bearerSet.Length()>0));
   169 		&& (bearerSet.Length()>0));
   162 
   170 
   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 
  1317         }
  1471         }
  1318            
  1472            
  1319     return EPass;
  1473     return EPass;
  1320     }
  1474     }
  1321 
  1475 
       
  1476 // WaitStep
       
  1477 //-------------------------------
       
  1478 
       
  1479 CWaitStep::CWaitStep(CCEsockTestBase*& aEsockTest)
       
  1480 :   CTe_EsockStepBase(aEsockTest)
       
  1481     {
       
  1482     SetTestStepName(KWaitStep);
       
  1483     }
       
  1484 
       
  1485 TInt CWaitStep::ConfigureFromIni()
       
  1486     {
       
  1487     if(!GetIntFromConfig(iSection, KTimeoutInMilliSeconds, iTimeOutMs))
       
  1488         {
       
  1489         INFO_PRINTF1(_L("Couldn't find appropriate field in config file"));
       
  1490         return KErrNotFound;
       
  1491         }
       
  1492     
       
  1493     return KErrNone;
       
  1494     }
       
  1495 
       
  1496 TVerdict CWaitStep::doSingleTestStep()
       
  1497     {
       
  1498     User::After(iTimeOutMs *1000);
       
  1499     return EPass;
       
  1500     }
       
  1501 
       
  1502