persistentstorage/centralrepository/test/testexecute/performance/src/TE_MemTestStep.cpp
branchRCL_3
changeset 24 cc28652e0254
parent 0 08ec8eefde2f
equal deleted inserted replaced
23:26645d81f48d 24:cc28652e0254
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <centralrepository.h>
       
    17 #include "t_cenrep_helper.h"
       
    18 #include "srvPerf.h"
       
    19 #include "srvreqs.h"
       
    20 #include "TE_MemTestStep.h"
       
    21 
       
    22 #ifdef __CENTREP_SERVER_MEMTEST__
       
    23 // Method used for TIdentityRelation for TMemTestResult arrays
       
    24 TBool MatchMemTestResult(const TMemTestResult& aKey, const TMemTestResult& aIndexItem)
       
    25 	{
       
    26 	return aIndexItem.iLocation   == aKey.iLocation   && 
       
    27 		   aIndexItem.iIdentifier == aKey.iIdentifier && 
       
    28 		   aIndexItem.iIsComplete == aKey.iIsComplete;
       
    29 	}
       
    30 
       
    31 void CMemTestStep::ProcessMemTestResults(TAny* aRawData, TInt32 aRawCount, RArray<TMemTestResult>& aMemTestResults)
       
    32 	{
       
    33 	ASSERT(aRawCount);
       
    34 	ASSERT(aRawCount>=3);
       
    35 	
       
    36 	for(TInt i=0; i+2<aRawCount;)
       
    37 		{
       
    38 		TInt32 value1 = static_cast<TInt32*>(aRawData)[i++];
       
    39 		TInt32 value2 = static_cast<TInt32*>(aRawData)[i++];
       
    40 		TInt32 value3 = static_cast<TInt32*>(aRawData)[i++];
       
    41 		
       
    42 		if(value1 == KMagicMemTestOutOfBounds && value2 == KMagicMemTestOutOfBounds && value2 == KMagicMemTestOutOfBounds)
       
    43 			{
       
    44 			WARN_PRINTF1(_L("Memory test was not able to store all the requested values. Only the stored values will be reported."));
       
    45 			}
       
    46 		else
       
    47 			{
       
    48 			TMemTestResult result(value1, value2, EFalse);
       
    49 			//look for not completed memTestResult that match the criteria
       
    50 			TIdentityRelation<TMemTestResult> identity(MatchMemTestResult);
       
    51 			
       
    52 			TInt idx = aMemTestResults.Find(result, identity);
       
    53 			if(idx == KErrNotFound)
       
    54 				{
       
    55 				result.iInitHeapSize = value3;
       
    56 				aMemTestResults.Append(result);
       
    57 				}
       
    58 			else
       
    59 				{
       
    60 				TMemTestResult& foundResult = aMemTestResults[idx];
       
    61 				foundResult.iFinalHeapSize = value3;
       
    62 				foundResult.iIsComplete = ETrue;
       
    63 				}
       
    64 			}
       
    65 		}
       
    66 	}
       
    67 #endif //__CENTREP_SERVER_MEMTEST__
       
    68 
       
    69 CMemTestStep::CMemTestStep()
       
    70 	{
       
    71 	SetTestStepName(KMemTestName);
       
    72 	}
       
    73 	
       
    74 // doTestStepL
       
    75 // This test fetches the memory data collected by
       
    76 // CentRep server, processes it and reports the result.
       
    77 TVerdict CMemTestStep::doTestStepL()
       
    78 	{
       
    79 #ifdef __CENTREP_SERVER_MEMTEST__
       
    80 	SetTestStepResult(EFail);
       
    81 	// Pause a few seconds to ensure startup sequence is finished.
       
    82 #ifdef __WINS__
       
    83  	const TTimeIntervalMicroSeconds32 interval = 12000000;
       
    84 #else
       
    85  	const TTimeIntervalMicroSeconds32 interval = 4000000;
       
    86 #endif
       
    87  	User::After(interval);
       
    88 
       
    89 	TAny* buf = User::AllocL((KMemBufMaxEntry) * sizeof(TInt32));
       
    90 	CleanupStack::PushL(buf);
       
    91 	TPtr8 pBuf(static_cast<TUint8*>(buf), (KMemBufMaxEntry) * sizeof(TInt32));
       
    92 	TInt numEntries;
       
    93 	TPckg<TInt> pNumEntries(numEntries);
       
    94 	TInt error = SetGetParameters(TIpcArgs(EGetMemResults, &pNumEntries, &pBuf));
       
    95 
       
    96 	if(error == KErrNone && numEntries > 0)
       
    97 		{
       
    98 		RArray<TMemTestResult> memTestResults;
       
    99 		
       
   100 		ProcessMemTestResults(buf, numEntries, memTestResults);
       
   101 		
       
   102 		TInt count = memTestResults.Count();
       
   103 		for(TInt i=0; i<count; i++)
       
   104 			{
       
   105 			TMemTestResult& result = memTestResults[i];
       
   106 			if(result.iIsComplete)
       
   107 				{
       
   108 				if(result.iLocation == EMemLcnRepositoryOpen)
       
   109 					{
       
   110 					Logger().WriteFormat(_L("Memory usage for repository [%08X]: %d"), 
       
   111 										 result.iIdentifier, 
       
   112 										 result.iFinalHeapSize - result.iInitHeapSize);
       
   113 					}
       
   114 				else if(result.iLocation == EMemLcnOnDemand)
       
   115 					{
       
   116 					Logger().WriteFormat(_L("Heap memory usage of Centrep server at step %d: %d"), 
       
   117 										 result.iIdentifier, 					
       
   118 										 result.iFinalHeapSize);
       
   119 					static TInt prevResult;
       
   120 					switch (result.iIdentifier)
       
   121 						{
       
   122 						case 1: TESTL(result.iFinalHeapSize > prevResult); break;
       
   123 						case 3: TESTL(result.iFinalHeapSize < prevResult); break;
       
   124 						case 4: TESTL(result.iFinalHeapSize > prevResult); break;						
       
   125 						}
       
   126 					prevResult = result.iFinalHeapSize;
       
   127 					}
       
   128 				else
       
   129 					{
       
   130 					Logger().WriteFormat(_L("Memory usage at location[%d] for identifier[%d]: %d"),
       
   131 										 result.iLocation, 
       
   132 										 result.iIdentifier, 
       
   133 										 result.iFinalHeapSize - result.iInitHeapSize);
       
   134 					}
       
   135 				}
       
   136 			else
       
   137 				{
       
   138 				Logger().WriteFormat(_L("Incomplete memory reading at location[%d] for identifier[%d]"),
       
   139 									 result.iLocation, 
       
   140 									 result.iIdentifier);
       
   141 				}
       
   142 			}
       
   143 		}
       
   144 	
       
   145     CleanupStack::PopAndDestroy();
       
   146 
       
   147 	if(error == KErrNone)
       
   148 		{
       
   149 		SetTestStepResult(EPass);
       
   150 		}
       
   151 #else
       
   152 	WARN_PRINTF1(_L("Memory test macro __CENTREP_SERVER_MEMTEST__ is not defined. Test was not run."));
       
   153 #endif //__CENTREP_SERVER_MEMTEST__
       
   154 
       
   155 	return TestStepResult();
       
   156 	}
       
   157