smsprotocols/smsstack/smsprot/Test/TE_Smsprt/TE_DoESockMemoryLeakTest.cpp
changeset 20 244d7c5f118e
parent 19 1f776524b15c
child 23 6b1d113cdff3
equal deleted inserted replaced
19:1f776524b15c 20:244d7c5f118e
     1 
       
     2 // Copyright (c) 2007-2009 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:
       
    15 //
       
    16 
       
    17 #include <cfshared.h>
       
    18 #include <c32root.h>
       
    19 
       
    20 #include "Te_SmsTestSteps.h"
       
    21 
       
    22 /**
       
    23 	Test for any leaks in ESOCK
       
    24 	The socket server must be closed down before this step is run, or no clients must be connected to esock
       
    25 	when running this test step.
       
    26 */
       
    27 TVerdict CESockMemoryLeakTest::doTestStepL()
       
    28 	{
       
    29 	//
       
    30 	// Find the current number of leaked cells in ESock...
       
    31 	//
       
    32 	TInt  ret, startLeakCounter;
       
    33 	
       
    34 	ret = RProperty::Get(KUidCommsProcess, KUidCommsModuleLeakCounter, startLeakCounter);
       
    35 	if (ret == KErrNotFound)
       
    36 		{
       
    37 		// No variable to monitor, ESock is probably not in debug mode.
       
    38 		INFO_PRINTF1(_L("<font size=2 color=00FFCC><B>ESock is probably not in debug mode.</B></font>"));		
       
    39 		return EPass;
       
    40 		}
       
    41 	else
       
    42 		{
       
    43 		TESTL(ret == KErrNone);
       
    44 		}
       
    45 
       
    46 	//
       
    47 	// Connect to Rootserver...
       
    48 	//
       
    49 	RRootServ  rootserver;
       
    50 
       
    51 	User::LeaveIfError(rootserver.Connect());
       
    52 	CleanupClosePushL(rootserver);
       
    53 
       
    54 	//
       
    55 	// Shutdown all the ESock CPMs gracefully...
       
    56 	//
       
    57 	TRSIter  iter;
       
    58 	TCFModuleName  modName;
       
    59 	TRSModuleInfo  modInfo;
       
    60 	TRequestStatus  statusArray[16];
       
    61 	TInt  statusCount = 0;
       
    62 
       
    63 	while (rootserver.EnumerateModules(iter, modName) == KErrNone)
       
    64 		{
       
    65 		if (rootserver.GetModuleInfo(modName, modInfo) == KErrNone  &&
       
    66 		    modInfo.iParams.iDll.MatchF(_L("*ESOCKSVR.DLL")) >= 0)
       
    67 			{
       
    68 			rootserver.UnloadCpm(statusArray[statusCount++], modInfo.iParams.iName,
       
    69 			                     EGraceful);
       
    70 			}
       
    71 		}
       
    72 
       
    73 	while (statusCount > 0)
       
    74 		{
       
    75 		statusCount--;
       
    76 		User::WaitForRequest(statusArray[statusCount]);
       
    77 		TEST(statusArray[statusCount] == KErrNone);
       
    78 		}
       
    79 
       
    80 	//
       
    81 	// Close Rootserver session...
       
    82 	//
       
    83 	CleanupStack::PopAndDestroy(1, &rootserver);
       
    84 	
       
    85 	//
       
    86 	// Get the latest number of leaked cells in ESock...
       
    87 	//
       
    88 	TInt  finalLeakCounter;
       
    89 
       
    90 	ret = RProperty::Get(KUidCommsProcess, KUidCommsModuleLeakCounter, finalLeakCounter);
       
    91 	TESTL(ret == KErrNone);
       
    92 
       
    93 	if (finalLeakCounter > startLeakCounter)
       
    94 		{
       
    95 		INFO_PRINTF1(_L("<font size=2 color=FF0000><B>A memory leak has been detected inside ESock - Check SMS Stack!</B></font>"));
       
    96 		TEST(finalLeakCounter == startLeakCounter);
       
    97 		}
       
    98 
       
    99 	//
       
   100 	// Restart C32...
       
   101 	//
       
   102 	_LIT(KDummyCMI, "");
       
   103 	WarmBootC32(KDummyCMI);
       
   104 	
       
   105 	return TestStepResult();
       
   106 	} // CSmsPrtTestStep::DoESockMemoryLeakTestL