persistentstorage/centralrepository/test/testexecute/performance/src/TE_PerfTestClientOpenStep.cpp
branchRCL_3
changeset 24 cc28652e0254
parent 0 08ec8eefde2f
equal deleted inserted replaced
23:26645d81f48d 24:cc28652e0254
       
     1 // Copyright (c) 2006-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 "TE_PerfTestClientOpenStep.h"
       
    17 #include "TE_PerfTestUtilities.h"
       
    18 #include "t_cenrep_helper.h"
       
    19 #include "srvreqs.h"
       
    20 #include "srvdefs.h"
       
    21 #include <centralrepository.h>
       
    22 #include "cachemgr.h"
       
    23 
       
    24 #ifdef __CENTREP_SERVER_CACHETEST__
       
    25 
       
    26 const TInt KMaxRepositories = 5;
       
    27 const TInt KIterationCount = 100;
       
    28 const TUid KUidClientOpenTestRepositoryIds[KMaxRepositories] = { 0x00000106,
       
    29                                                                  0x00000107,
       
    30                                                                  0x00000108,
       
    31                                                                  0x00000109,
       
    32                                                                  0x0000010A };
       
    33 #endif //__CENTREP_SERVER_CACHETEST__
       
    34 
       
    35 CPerfTestClientOpenStep::CPerfTestClientOpenStep()
       
    36 	{
       
    37 	SetTestStepName(KPerfTestClientOpenName);
       
    38 	}
       
    39 	
       
    40 // doTestStepL
       
    41 // This test fetches the memory data collected by
       
    42 // CentRep server, processes it and reports the result.
       
    43 TVerdict CPerfTestClientOpenStep::doTestStepL()
       
    44 	{
       
    45 	SetTestStepResult(EFail);
       
    46 
       
    47 #ifndef __CENTREP_SERVER_CACHETEST__
       
    48 	WARN_PRINTF1(_L("Test macro __CENTREP_SERVER_CACHETEST__ is not defined. Unable to disable cache. Test was not run."));
       
    49 #else
       
    50 	CRepository* repositories[KMaxRepositories];
       
    51 	TReal openResults[KMaxRepositories];
       
    52 	TReal closeResults[KMaxRepositories];
       
    53 	TInt res = KErrNone;
       
    54 	
       
    55 	//enable cache back.
       
    56 	res = SetGetParameters(TIpcArgs(EDisableCache, KDefaultEvictionTimeout, KDefaultCacheSize));
       
    57 	TESTL(res == KErrNone);
       
    58 	
       
    59 	for(TInt i=0; i<KMaxRepositories; i++)
       
    60 		{
       
    61 		openResults[i] = 0;
       
    62 		closeResults[i] = 0;
       
    63 		}
       
    64 	
       
    65 	for(TInt k=0; k<KIterationCount; k++)
       
    66 		{
       
    67 		//all of these operations are repeated for 100 times. Otherwise the measurement value
       
    68 		//is too small to have an accurate value
       
    69 		for(TInt i=0; i<KMaxRepositories; i++)
       
    70 			{
       
    71 			TUint32 startTick = 0;
       
    72 			TUint32 endTick = 0;
       
    73 			
       
    74 			//open repositories and measure how long it takes to open them.
       
    75 			for(TInt j=0; j<=i; j++)
       
    76 				{
       
    77 				startTick = User::FastCounter();
       
    78 				TRAP(res, repositories[j] = CRepository::NewL(KUidClientOpenTestRepositoryIds[j]));
       
    79 				endTick = User::FastCounter();
       
    80 				openResults[i] += endTick - startTick;
       
    81 				
       
    82 				TESTL(res == KErrNone);
       
    83 				TESTL(repositories[j] != NULL);
       
    84 				CleanupStack::PushL(repositories[j]);
       
    85 				}
       
    86 
       
    87 			//close repositories in the reverse order, make sure cleanup stack is happy.
       
    88 			for(TInt j=i; j>=0; j--)
       
    89 				{
       
    90 				startTick = User::FastCounter();
       
    91 				CleanupStack::PopAndDestroy(repositories[j]);
       
    92 				endTick = User::FastCounter();
       
    93 				closeResults[i] += endTick - startTick;
       
    94 
       
    95 				repositories[j] = NULL;
       
    96 				}
       
    97 			}
       
    98 		}
       
    99 		
       
   100 	for(TInt i=0; i<KMaxRepositories; i++)
       
   101 		{
       
   102 		INFO_PRINTF4(_L("Total time spent to open %d times %d repositories is %f[ns]"), KIterationCount, i+1, FastCountToMicrosecondsInReal(openResults[i]));
       
   103 		INFO_PRINTF4(_L("Total time spent to close %d times %d repositories is %f[ns]"), KIterationCount, i+1, FastCountToMicrosecondsInReal(closeResults[i]));
       
   104 		}
       
   105 
       
   106 	//enable cache back.
       
   107 	res = SetGetParameters(TIpcArgs(EEnableCache, KDefaultEvictionTimeout, KDefaultCacheSize));
       
   108 	TESTL(res == KErrNone);
       
   109 	
       
   110 #endif	
       
   111 	SetTestStepResult(EPass);
       
   112 
       
   113 	return TestStepResult();
       
   114 	}
       
   115