persistentstorage/centralrepository/test/testexecute/performance/src/TE_DefectTestStep.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 "TE_DefectTestStep.h"
       
    17 #include "TE_PerfTestUtilities.h"
       
    18 #include <centralrepository.h>
       
    19 #include "t_cenrep_helper.h"
       
    20 #include "srvdefs.h"
       
    21 #include "srvreqs.h"
       
    22 #include <bautils.h>
       
    23 #include "cachemgr.h"
       
    24 
       
    25 #ifdef __CENTREP_SERVER_CACHETEST__
       
    26 
       
    27 const TUid KUidLargeRepository          = { 0xCCCCCC01 };
       
    28 const TUid KUidRep1						= { 0x00000100 };
       
    29 const TUid KUidLargeCreRepository       = { 0xCCCCCC02 };
       
    30 
       
    31 const TUint32 KNewInt = 1000;
       
    32 const TInt KIntValue = 1234;
       
    33 
       
    34 const TInt KNumOfAttempts = 10;
       
    35 
       
    36 _LIT(KZRep1File, 				"z:\\private\\10202BE9\\00000100.txt");
       
    37 _LIT(KCRep1TxtFile,				"c:\\private\\10202BE9\\persists\\00000100.txt");
       
    38 _LIT(KCRep1CreFile,				"c:\\private\\10202BE9\\persists\\00000100.cre");
       
    39 #endif
       
    40 
       
    41 CPerfTestDefectStep057491::CPerfTestDefectStep057491()
       
    42 	{
       
    43 	SetTestStepName(KPerfTestDefectStepDEF057491);
       
    44 	}
       
    45 	
       
    46 TVerdict CPerfTestDefectStep057491::doTestStepL()
       
    47 	{
       
    48 #ifndef __CENTREP_SERVER_CACHETEST__
       
    49 	return EPass;
       
    50 #else	
       
    51 	SetTestStepResult(EFail);
       
    52 	
       
    53 	CRepository* rep;
       
    54 	TInt64 totalRomMs=0;
       
    55 	TInt64 totalCreMs=0;
       
    56 	TInt64 totalRepWriteMs=0;
       
    57 	
       
    58    	TUint32 startFastCounter;	
       
    59    	TUint64 fastCounterromOpenMicroseconds;
       
    60    	TUint64 fastCounterrepWriteMicroseconds;
       
    61    	TUint64 fastCountercreOpenMicroseconds;
       
    62 	
       
    63 	// Flush and disable cache for this test
       
    64 	TInt r;
       
    65 	r = SetGetParameters(TIpcArgs(EDisableCache));
       
    66 	TEST(r==KErrNone);
       
    67 
       
    68 	// Time opening and writing repository
       
    69 	for(TInt i=0; i<KNumOfAttempts;i++)
       
    70 		{
       
    71 		// Get start time for ROM file
       
    72 	    startFastCounter = User::FastCounter();
       
    73 		User::LeaveIfNull(rep = CRepository::NewLC(KUidLargeRepository));
       
    74 		
       
    75 		// Get finish time for ROM file
       
    76 		fastCounterromOpenMicroseconds = FastCountToMicrosecondsInInt(User::FastCounter() - startFastCounter);
       
    77 		totalRomMs+=fastCounterromOpenMicroseconds;
       
    78 		Logger().WriteFormat(_L("Time to open large repos from ROM      file = %lu microseconds\n"), fastCounterromOpenMicroseconds);
       
    79 		
       
    80 	    startFastCounter = User::FastCounter();
       
    81 		TInt r = rep->Create(KNewInt, KIntValue);
       
    82 		fastCounterrepWriteMicroseconds = FastCountToMicrosecondsInInt(User::FastCounter() - startFastCounter);
       
    83 		totalRepWriteMs+=fastCounterrepWriteMicroseconds;
       
    84 		Logger().WriteFormat(_L("Time to write large repos              file = %lu microseconds\n"), fastCounterrepWriteMicroseconds);
       
    85 
       
    86 		TEST(r==KErrNone);
       
    87 		
       
    88 		// Close repository
       
    89 		CleanupStack::PopAndDestroy(rep);
       
    90 		
       
    91 		// Get start time and ticks for .cre file
       
    92 	    startFastCounter = User::FastCounter();
       
    93 		
       
    94 		// Open repository 
       
    95 		User::LeaveIfNull(rep = CRepository::NewLC(KUidLargeRepository));
       
    96 		
       
    97 		// Get finish time and ticks for .cre file
       
    98 		fastCountercreOpenMicroseconds  = FastCountToMicrosecondsInInt(User::FastCounter() - startFastCounter);
       
    99 		totalCreMs+=fastCountercreOpenMicroseconds;
       
   100 		Logger().WriteFormat(_L("Time to open large repos from persists file = %lu microseconds\n"), fastCountercreOpenMicroseconds);
       
   101 
       
   102 #if !defined(__WINS__) && !defined(__WINSCW__)
       
   103 		TEST(fastCounterromOpenMicroseconds>fastCountercreOpenMicroseconds);
       
   104 #endif		
       
   105 		const TUint32 	KIntKey1 		= 8847616;
       
   106 		const TInt 		KIntKey1Value 	= 1;
       
   107 		const TUint32 	KIntKey2 		= 139068928;
       
   108 		const TInt 		KIntKey2Value 	= 30;
       
   109 		const TUint32 	KIntKey3 		= 2373975808UL;
       
   110 		const TInt 		KIntKey3Value 	= -1920991488;
       
   111 		
       
   112 		// Test 3 random int key values from repository
       
   113 		TInt keyValue;
       
   114 		r=rep->Get(KIntKey1, keyValue);
       
   115 		TEST(r == KErrNone);
       
   116 		TEST(keyValue == KIntKey1Value);
       
   117 
       
   118 		r=rep->Get(KIntKey2, keyValue);
       
   119 		TEST(r == KErrNone);
       
   120 		TEST(keyValue == KIntKey2Value);
       
   121 		
       
   122 		r=rep->Get(KIntKey3, keyValue);
       
   123 		TEST(r == KErrNone);
       
   124 		TEST(keyValue == KIntKey3Value);
       
   125 		
       
   126 		// Close repository
       
   127 		CleanupStack::PopAndDestroy(rep);
       
   128 
       
   129 		CleanupFileFromCDriveL(KUidLargeRepository);
       
   130 		}
       
   131 	
       
   132 	Logger().WriteFormat(_L("Average time to open large repos from ROM      file = %lu ms\n"), totalRomMs/KNumOfAttempts);
       
   133 	Logger().WriteFormat(_L("Average time to open large repos from persists file = %lu ms\n"), totalCreMs/KNumOfAttempts);		
       
   134 	Logger().WriteFormat(_L("Average time to write large repos to  persists file = %lu ms\n"), totalRepWriteMs/KNumOfAttempts);		
       
   135 
       
   136 	RFs fs;			
       
   137 	User::LeaveIfError(fs.Connect());
       
   138 	CleanupClosePushL(fs);
       
   139 	CFileMan* fm = CFileMan::NewL(fs);
       
   140 	CleanupStack::PushL(fm);
       
   141 	// Copy a repository txt file to the C:
       
   142 	User::LeaveIfError(fm->Copy(KZRep1File, KCPersistsDir));
       
   143 	// Reset read-only bit
       
   144 	User::LeaveIfError(fm->Attribs(KCRep1TxtFile,0,KEntryAttReadOnly,TTime(0)));
       
   145 	// Check it exists
       
   146 	TEST( BaflUtils::FileExists (fs, KCRep1TxtFile));	
       
   147 	
       
   148 	// Open repository
       
   149 	User::LeaveIfNull(rep = CRepository::NewLC(KUidRep1));
       
   150 	
       
   151 	// Create a setting
       
   152 	r = rep->Create(KNewInt, KIntValue);
       
   153 	TEST(r == KErrNone);
       
   154 	
       
   155 	// Check persists file exists
       
   156 	TEST(BaflUtils::FileExists (fs, KCRep1CreFile));	
       
   157 
       
   158 	// Check that .txt file is gone	
       
   159 	TEST(BaflUtils::FileExists (fs, KCRep1TxtFile) == EFalse);	
       
   160 
       
   161 	// Close the repository
       
   162 	CleanupStack::PopAndDestroy(rep);
       
   163 	
       
   164 	CleanupStack::PopAndDestroy(2);		// fm, fs
       
   165 
       
   166 	CleanupFileFromCDriveL(KUidRep1);
       
   167 
       
   168 	// Enable cache
       
   169 	r = SetGetParameters(TIpcArgs(EEnableCache, KDefaultEvictionTimeout, KDefaultCacheSize));
       
   170 	TEST(r==KErrNone);
       
   171 
       
   172 	SetTestStepResult(EPass);
       
   173 	
       
   174 	return TestStepResult();
       
   175 #endif
       
   176 	}
       
   177 
       
   178 CPerfTestDefectStep059633::CPerfTestDefectStep059633()
       
   179 	{
       
   180 	SetTestStepName(KPerfTestDefectStepDEF059633);
       
   181 	}
       
   182 
       
   183 TVerdict CPerfTestDefectStep059633::doTestStepL()
       
   184 	{
       
   185 #ifndef __CENTREP_SERVER_CACHETEST__
       
   186 	return EPass;
       
   187 #else	
       
   188 	SetTestStepResult(EFail);
       
   189 
       
   190 	// Flush and disable cache for this test
       
   191 	TInt r;
       
   192 	r = SetGetParameters(TIpcArgs(EDisableCache));
       
   193 	TEST(r==KErrNone);
       
   194 
       
   195 	CleanupFileFromCDriveL(KUidLargeRepository);
       
   196 	CleanupFileFromCDriveL(KUidLargeCreRepository);
       
   197 
       
   198    	CRepository* rep; 
       
   199    	
       
   200    	TUint32 startFastCounter;
       
   201    	TUint64 fastCountertimeToOpenLargeIniRep;
       
   202    	TUint64 fastCountertimeToOpenLargeCreRep;
       
   203    	TUint64 fastCountertimeToOpenXLargeInis;
       
   204    	TUint64 fastCountertimeToOpenXLargeCres;
       
   205     
       
   206     //=========================================================================================
       
   207    	//Single .ini - opening
       
   208     startFastCounter = User::FastCounter();
       
   209 	User::LeaveIfNull(rep = CRepository::NewLC(KUidLargeRepository));
       
   210 	fastCountertimeToOpenLargeIniRep = FastCountToMicrosecondsInInt(User::FastCounter() - startFastCounter);
       
   211 	Logger().WriteFormat(_L("Time to open text based rep from ROM = %lu microseconds\n\n"), fastCountertimeToOpenLargeIniRep);
       
   212 	CleanupStack::PopAndDestroy(rep);
       
   213 	
       
   214     //=========================================================================================
       
   215 	//KNumOfAttempts .ini
       
   216 	
       
   217 	startFastCounter = User::FastCounter();	
       
   218 	for (TInt i=0; i<KNumOfAttempts; i++)
       
   219 	    {
       
   220 	    User::LeaveIfNull(rep = CRepository::NewLC(KUidLargeRepository));
       
   221 	    CleanupStack::PopAndDestroy(rep);
       
   222 	    }
       
   223 	fastCountertimeToOpenXLargeInis = FastCountToMicrosecondsInInt(User::FastCounter() - startFastCounter);
       
   224 
       
   225 	//=========================================================================================
       
   226 	//single .cre
       
   227 	startFastCounter = User::FastCounter();	
       
   228 	User::LeaveIfNull(rep = CRepository::NewLC(KUidLargeCreRepository));
       
   229 	fastCountertimeToOpenLargeCreRep = FastCountToMicrosecondsInInt(User::FastCounter() - startFastCounter);
       
   230 	Logger().WriteFormat(_L("Time to open binary rep from ROM = %lu microseconds\n\n"), fastCountertimeToOpenLargeCreRep);
       
   231 	CleanupStack::PopAndDestroy(rep);
       
   232 	
       
   233 	//=========================================================================================
       
   234 	//KNumOfAttempts .cre
       
   235 	startFastCounter = User::FastCounter();	
       
   236 	for (TInt j=0; j<KNumOfAttempts; j++)
       
   237 	    {	    
       
   238   	    User::LeaveIfNull(rep = CRepository::NewLC(KUidLargeCreRepository));
       
   239   	    CleanupStack::PopAndDestroy(rep);
       
   240 	    }
       
   241 	fastCountertimeToOpenXLargeCres = FastCountToMicrosecondsInInt(User::FastCounter() - startFastCounter);
       
   242 
       
   243     //=========================================================================================	    
       
   244 	//average 
       
   245 	TInt64 averageFastCounterTimeToOpenIni = fastCountertimeToOpenXLargeInis / KNumOfAttempts;
       
   246 	Logger().WriteFormat(_L("Average time to open text based rep from ROM = %lu  microseconds\n\n"), averageFastCounterTimeToOpenIni);
       
   247 	
       
   248 	TInt64 averageFastCounterTimeToOpenCre = fastCountertimeToOpenXLargeCres / KNumOfAttempts;
       
   249 	Logger().WriteFormat(_L("Average time to open binary rep from ROM = %lu  microseconds\n\n"), averageFastCounterTimeToOpenCre);
       
   250   	
       
   251   	//=========================================================================================
       
   252     //prove that opening .ini is slower than opening .cre files 
       
   253     // (even though the difference is now much less after the performance 
       
   254     // improvements of PREQ 1192, the test is now much more precise by using fastcounter)
       
   255 #if !defined(__WINS__) && !defined(__WINSCW__)
       
   256     TEST(fastCountertimeToOpenLargeIniRep > fastCountertimeToOpenLargeCreRep);
       
   257     TEST(fastCountertimeToOpenXLargeInis > fastCountertimeToOpenXLargeCres);
       
   258     TEST(averageFastCounterTimeToOpenIni > averageFastCounterTimeToOpenCre);
       
   259 #endif		
       
   260 
       
   261     //==========================================================================================
       
   262     //benchmarks - open
       
   263 	#if !defined(__WINS__) && !defined(__WINSCW__)
       
   264 	    #ifdef _DEBUG
       
   265       	  	const TInt64 KOpenCreTime  = 150000; //armv5 debug
       
   266 	    #else
       
   267       	   const TInt64 KOpenCreTime  = 75000;  //armv5 urel
       
   268       	#endif
       
   269 	
       
   270 	TEST(averageFastCounterTimeToOpenCre < KOpenCreTime);      	
       
   271 	
       
   272     #endif//!defined(__WINS__) && !defined(__WINSCW__)
       
   273 
       
   274     //========================================================================
       
   275 
       
   276 	CleanupFileFromCDriveL(KUidLargeRepository);
       
   277 	CleanupFileFromCDriveL(KUidLargeCreRepository);
       
   278 
       
   279 	// Enable cache
       
   280 	r = SetGetParameters(TIpcArgs(EEnableCache, KDefaultEvictionTimeout, KDefaultCacheSize));
       
   281 	TEST(r==KErrNone);
       
   282 
       
   283 	SetTestStepResult(EPass);
       
   284 	
       
   285 	return TestStepResult();
       
   286 #endif
       
   287 	}