persistentstorage/centralrepository/test/t_cenrep_perf.cpp
changeset 55 44f437012c90
parent 0 08ec8eefde2f
equal deleted inserted replaced
51:7d4490026038 55:44f437012c90
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    16 #include <centralrepository.h>
    16 #include <centralrepository.h>
    17 #include <e32test.h>
    17 #include <e32test.h>
    18 #include <f32file.h>
    18 #include <f32file.h>
    19 #include <bautils.h>
    19 #include <bautils.h>
    20 #include <hal.h>
    20 #include <hal.h>
    21 
    21 #include "t_cenrep_helper.h"
    22 RTest 				TheTest(_L("t_cenrep_perf test"));
    22 
       
    23 RTest 				TheTest(_L("t_cenrep_perf.exe"));
       
    24 
       
    25 _LIT( KCentralRepositoryServerName, "Centralrepositorysrv");
       
    26 
    23 CRepository*		TheRepository = NULL;
    27 CRepository*		TheRepository = NULL;
    24 const TUid 			KTestCenRepUid = {0xCCCCCC03};
    28 const TUid 			KTestCenRepUid = {0xCCCCCC03};
    25 _LIT(KFileName, "c:\\private\\10202be9\\persists\\cccccc03.cre");
    29 
       
    30 #if defined(SYMBIAN_INCLUDE_APP_CENTRIC)
       
    31 const TUid          KPMATestCenRepUid = {0xF1000301};
       
    32 #endif
    26 
    33 
    27 ///////////////////////////////////////////////////////////////////////////////////////
    34 ///////////////////////////////////////////////////////////////////////////////////////
    28 
    35 
    29 // Shared test data 
    36 // Shared test data 
    30 
    37 
    61 // FindL range data
    68 // FindL range data
    62 const TUint32 KFindPartialKey = 0x08440000ul;
    69 const TUint32 KFindPartialKey = 0x08440000ul;
    63 const TUint32 KFindMask = 0x0FFF0000ul;
    70 const TUint32 KFindMask = 0x0FFF0000ul;
    64 const TInt KFindKeyCount = 15;
    71 const TInt KFindKeyCount = 15;
    65 
    72 
    66 
       
    67 ///////////////////////////////////////////////////////////////////////////////////////
    73 ///////////////////////////////////////////////////////////////////////////////////////
    68 
    74 void DestroyTestEnvL()
    69 TInt DeleteCreFile()
       
    70 	{
       
    71 	RFs fs;
       
    72 	fs.Connect();
       
    73 	TInt err = fs.Delete(KFileName);
       
    74 	fs.Close();
       
    75 
       
    76 	// it's fine if the file or path wasn't found as there's nothing to 
       
    77 	// delete so return KErrNone
       
    78 	return (err == KErrNotFound || err == KErrPathNotFound) ? KErrNone : err;
       
    79 	}
       
    80 
       
    81 ///////////////////////////////////////////////////////////////////////////////////////
       
    82 
       
    83 void DestroyTestEnv()
       
    84 	{
    75 	{
    85 	delete TheRepository;
    76 	delete TheRepository;
       
    77 	TheRepository = NULL;
    86 
    78 
    87 	// delete the CRE file to clear out any changes made during the test
    79 	// delete the CRE file to clear out any changes made during the test
    88 	DeleteCreFile(); 
    80 	CleanupCDriveL(); 
    89 	}
    81 	}
    90 
    82 
    91 ///////////////////////////////////////////////////////////////////////////////////////
    83 ///////////////////////////////////////////////////////////////////////////////////////
    92 
    84 
    93 //Test macros and functions
    85 //Test macros and functions
    94 void Check(TInt aValue, TInt aLine)
    86 void Check(TInt aValue, TInt aLine)
    95 	{
    87 	{
    96 	if(!aValue)
    88 	if(!aValue)
    97 		{
    89 		{
    98 		DestroyTestEnv();
    90 		TRAPD(err, DestroyTestEnvL());
       
    91         if (err != KErrNone)
       
    92             {
       
    93             RDebug::Print( _L( "*** DestroyTestEnvL also failed with error %d expecting KErrNone\r\n"), err );
       
    94             }
    99 		RDebug::Print(_L("*** Test failure. Boolean expression evaluates to false.\r\n"));
    95 		RDebug::Print(_L("*** Test failure. Boolean expression evaluates to false.\r\n"));
   100 		TheTest(EFalse, aLine);
    96 		TheTest(EFalse, aLine);
   101 		}
    97 		}
   102 	}
    98 	}
   103 void Check2(TInt aValue, TInt aExpected, TInt aLine)
    99 void Check2(TInt aValue, TInt aExpected, TInt aLine)
   104 	{
   100 	{
   105 	if(aValue != aExpected)
   101 	if(aValue != aExpected)
   106 		{
   102 		{
   107 		DestroyTestEnv();
   103 	    RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
   108 		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
   104 		TRAPD(err, DestroyTestEnvL());
       
   105         if (err != KErrNone)
       
   106             {
       
   107             RDebug::Print( _L( "*** DestroyTestEnvL also failed with error %d expecting KErrNone\r\n"), err );
       
   108             }
   109 		TheTest(EFalse, aLine);
   109 		TheTest(EFalse, aLine);
   110 		}
   110 		}
   111 	}
   111 	}
   112 #define TEST(arg) ::Check((arg), __LINE__)
   112 #define TEST(arg) ::Check((arg), __LINE__)
   113 #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__)
   113 #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__)
   114 
   114 
   115 ///////////////////////////////////////////////////////////////////////////////////////
   115 ///////////////////////////////////////////////////////////////////////////////////////
   116 
   116 
   117 // leaves if it can't successfully delete the cre file if it exists
   117 // leaves if it can't successfully delete the cre file if it exists
   118 void CreateTestEnvL()
   118 void CreateTestEnvL(const TUid& aRepUid)
   119 	{
   119 	{
   120 	// delete the CRE file to clear out any changes leftover from previous test runs
   120 	// delete the CRE file to clear out any changes leftover from previous test runs
   121 	User::LeaveIfError(DeleteCreFile());
   121 	CleanupCDriveL();
   122 	
   122 
   123 	TRAPD(err, TheRepository = CRepository::NewL(KTestCenRepUid));
   123 #if defined(SYMBIAN_INCLUDE_APP_CENTRIC)	
       
   124 	RFs fs;
       
   125     User::LeaveIfError(fs.Connect());
       
   126     CleanupClosePushL(fs);
       
   127 
       
   128     CFileMan* fm = CFileMan::NewL(fs);
       
   129     CleanupStack::PushL(fm);
       
   130     
       
   131     _LIT(KPMASourcePath, "z:\\private\\10202BE9\\f100031*.pma");
       
   132     _LIT(KPMATargetPath, "c:\\private\\10202BE9\\persists\\protected\\f100031*.cre");
       
   133     
       
   134     //Copying test PMA files to PMA drive to simulate there is 16 PMA keyspaces to see if performance degrades 
       
   135     CopyTestFilesL(*fm,KPMASourcePath, KPMATargetPath);
       
   136     CleanupStack::PopAndDestroy(2); //fs and fm
       
   137 #endif	
       
   138 
       
   139 	TRAPD(err, TheRepository = CRepository::NewL(aRepUid));
   124 	TEST2(err, KErrNone);
   140 	TEST2(err, KErrNone);
   125 	}
   141 	}
   126 
   142 
   127 
   143 
   128 //Prints aTicks parameter (converted to us)
   144 //Prints aTicks parameter (converted to us)
   440 	PrintStats(start, end);
   456 	PrintStats(start, end);
   441 	}
   457 	}
   442 
   458 
   443 
   459 
   444 /**
   460 /**
   445  * Common code for performing the Set() and Reset() tests for all datatypes
   461  * Common code for performing the Set() tests for all datatypes
   446  * 
   462  * 
   447  * @param aValType enum indicating which data type to test
   463  * @param aValType enum indicating which data type to test
   448  * 	(EIntVal, ERealVal, EBinaryVal or EStringVal -- any other value will fail with KErrArgument).
   464  * 	(EIntVal, ERealVal, EBinaryVal or EStringVal -- any other value will fail with KErrArgument).
   449  * @param aTestType enum defining whether Set() or Reset() should be timed
       
   450  */
   465  */
   451 void DoSetResetTest(TValType aValType, TTestType aTestType)
   466 void DoSetTest(TValType aValType)
   452 	{
   467 	{
   453 	TInt err(KErrNone);
   468 	TInt err(KErrNone);
   454 	TInt result(EFalse);
   469 	TInt result(EFalse);
   455 
   470 
   456 	// Check we get the old expected value
   471 	// Check we get the old expected value
   460 
   475 
   461 	TUint32 start(0);
   476 	TUint32 start(0);
   462 	TUint32 end(0);
   477 	TUint32 end(0);
   463 
   478 
   464 	// Set the new value
   479 	// Set the new value
   465 	start = aTestType == ESetTest ? User::FastCounter() : start;
   480 	start = User::FastCounter();
   466 	err = SetNewVal(aValType);
   481 	err = SetNewVal(aValType);
   467 	end = aTestType == ESetTest ? User::FastCounter() : end;
   482 	end = User::FastCounter();
   468 	TEST2(err, KErrNone);
   483 	TEST2(err, KErrNone);
   469 
   484 
   470 	// Test we get the new value to check it's worked
   485 	// Test we get the new value to check it's worked
   471 	err = GetNewVal(aValType, ESetTest, result);
   486 	err = GetNewVal(aValType, ESetTest, result);
   472 	TEST2(err, KErrNone);
   487 	TEST2(err, KErrNone);
   473 	TEST(result);
   488 	TEST(result);
   474 
   489 
   475 	// Restore the old value
       
   476 	start = aTestType == EResetTest ? User::FastCounter() : start;
       
   477 	err = ResetSetting(aValType);
       
   478 	end = aTestType == EResetTest ? User::FastCounter() : end;
       
   479 	TEST2(err, KErrNone);
       
   480 	
       
   481 	// Check reset's worked
       
   482 	err = GetOldVal(aValType, result);
       
   483 	TEST2(err, KErrNone);
       
   484 	TEST(result);
       
   485 	
   490 	
   486 	PrintStats(start, end);
   491 	PrintStats(start, end);
   487 	}
   492 	}
   488 
   493 
       
   494 /**
       
   495  * Common code for performing the Reset() tests
       
   496  * 
       
   497  * @param aValType enum indicating which data type to test
       
   498  * 	(EIntVal, ERealVal, EBinaryVal or EStringVal -- any other value will fail with KErrArgument).
       
   499  * @param aExpectedResult indicating the expected return value of Reset
       
   500  * 	(Any valid Symbian OS error codes) 
       
   501  */
       
   502 void DoResetTest(TValType aValType, TInt aExpectedResult)
       
   503     {
       
   504     TInt err(KErrNone);
       
   505     TInt result(EFalse);
       
   506     TUint32 start(0);
       
   507     TUint32 end(0);
       
   508 
       
   509     // Set the new value
       
   510     err = SetNewVal(aValType);
       
   511     TEST2(err, KErrNone);
       
   512 
       
   513     // Test we get the new value to check it's worked
       
   514     err = GetNewVal(aValType, ESetTest, result);
       
   515     TEST2(err, KErrNone);
       
   516     TEST(result);
       
   517 
       
   518     // Restore the old value
       
   519     start = User::FastCounter();
       
   520     err = ResetSetting(aValType);
       
   521     end = User::FastCounter();
       
   522     TEST2(err, aExpectedResult);
       
   523     
       
   524     // Check reset's worked
       
   525     if (aExpectedResult == KErrNone)
       
   526         {
       
   527         err = GetOldVal(aValType, result);
       
   528         TEST2(err, KErrNone);
       
   529         TEST(result);
       
   530         }
       
   531     // If aExpectedResult is not KErrNone, Reset should have failed
       
   532     //  The value should be still be the modified value (not reverted back to old value)
       
   533     else 
       
   534         {
       
   535         err = GetNewVal(aValType, ESetTest, result);
       
   536         TEST2(err, KErrNone);
       
   537         TEST(result);
       
   538         }
       
   539     
       
   540     PrintStats(start, end);
       
   541     }
   489 
   542 
   490 /**
   543 /**
   491  * Common code for performing all the Create() tests
   544  * Common code for performing all the Create() tests
   492  * 
   545  * 
   493  * @param aValType enum indicating which data type to test
   546  * @param aValType enum indicating which data type to test
   715 @SYMPREQ				PREQ2505
   768 @SYMPREQ				PREQ2505
   716 @SYMREQ					REQ13142
   769 @SYMREQ					REQ13142
   717 */
   770 */
   718 void SetIntTest()
   771 void SetIntTest()
   719 	{
   772 	{
   720 	DoSetResetTest(EIntVal, ESetTest);
   773 	DoSetTest(EIntVal);
   721 	}
   774 	}
   722 
   775 
   723 
   776 
   724 /**
   777 /**
   725 @SYMTestCaseID			PDS-CENTRALREPOSITORY-CT-4092
   778 @SYMTestCaseID			PDS-CENTRALREPOSITORY-CT-4092
   731 @SYMPREQ				PREQ2505
   784 @SYMPREQ				PREQ2505
   732 @SYMREQ					REQ13142
   785 @SYMREQ					REQ13142
   733 */
   786 */
   734 void SetRealTest()
   787 void SetRealTest()
   735 	{
   788 	{
   736 	DoSetResetTest(ERealVal, ESetTest);
   789 	DoSetTest(ERealVal);
   737 	}
   790 	}
   738 
   791 
   739 	
   792 	
   740 /**
   793 /**
   741 @SYMTestCaseID			PDS-CENTRALREPOSITORY-CT-4093
   794 @SYMTestCaseID			PDS-CENTRALREPOSITORY-CT-4093
   747 @SYMPREQ				PREQ2505
   800 @SYMPREQ				PREQ2505
   748 @SYMREQ					REQ13142
   801 @SYMREQ					REQ13142
   749 */
   802 */
   750 void SetBinaryTest()
   803 void SetBinaryTest()
   751 	{
   804 	{
   752 	DoSetResetTest(EBinaryVal, ESetTest);
   805 	DoSetTest(EBinaryVal);
   753 	}
   806 	}
   754 
   807 
   755 
   808 
   756 /**
   809 /**
   757 @SYMTestCaseID			PDS-CENTRALREPOSITORY-CT-4094
   810 @SYMTestCaseID			PDS-CENTRALREPOSITORY-CT-4094
   763 @SYMPREQ				PREQ2505
   816 @SYMPREQ				PREQ2505
   764 @SYMREQ					REQ13142
   817 @SYMREQ					REQ13142
   765 */
   818 */
   766 void SetStringTest()
   819 void SetStringTest()
   767 	{
   820 	{
   768 	DoSetResetTest(EStringVal, ESetTest);
   821 	DoSetTest(EStringVal);
   769 	}
   822 	}
   770 
   823 
   771 
   824 
   772 /**
   825 /**
   773 @SYMTestCaseID			PDS-CENTRALREPOSITORY-CT-4095
   826 @SYMTestCaseID			PDS-CENTRALREPOSITORY-CT-4095
  1158 @SYMPREQ				PREQ2505
  1211 @SYMPREQ				PREQ2505
  1159 @SYMREQ					REQ13142
  1212 @SYMREQ					REQ13142
  1160 */
  1213 */
  1161 void ResetTest()
  1214 void ResetTest()
  1162 	{
  1215 	{
  1163 	DoSetResetTest(EIntVal, EResetTest);
  1216 	DoResetTest(EIntVal, KErrNone);
  1164 	}
  1217 	}
  1165 
  1218 
  1166 
  1219 
  1167 /**
  1220 /**
  1168 @SYMTestCaseID			PDS-CENTRALREPOSITORY-CT-4112
  1221 @SYMTestCaseID			PDS-CENTRALREPOSITORY-CT-4112
  1193 	err = GetNewVal(EBinaryVal, ECreateTest, result);
  1246 	err = GetNewVal(EBinaryVal, ECreateTest, result);
  1194 	TEST2(err, KErrNotFound);
  1247 	TEST2(err, KErrNotFound);
  1195 	PrintStats(start, end);
  1248 	PrintStats(start, end);
  1196 	}
  1249 	}
  1197 
  1250 
       
  1251 
       
  1252 /**
       
  1253 @SYMTestCaseID          PDS-CENTRALREPOSITORY-CT-4129
       
  1254 @SYMTestCaseDesc        CRepository::Reset(TUint32 aKey) - performance test
       
  1255                         The test measures the time needed for resetting a single PMA integer setting.
       
  1256 @SYMTestPriority        High
       
  1257 @SYMTestActions         CRepository::Reset(TUint32 aKey)
       
  1258 @SYMTestExpectedResults Test must not fail
       
  1259 @SYMPREQ                PREQ2505
       
  1260 @SYMREQ                 REQ13142
       
  1261 */
       
  1262 void PMAResetTest()
       
  1263     {
       
  1264     DoResetTest(EIntVal, KErrNotSupported);
       
  1265     }
       
  1266 
       
  1267 
       
  1268 /**
       
  1269 @SYMTestCaseID          PDS-CENTRALREPOSITORY-CT-4130
       
  1270 @SYMTestCaseDesc        CRepository::Reset() - performance test
       
  1271                         The test measures the time needed for resetting the whole PMA keyspace.
       
  1272 @SYMTestPriority        High
       
  1273 @SYMTestActions         CRepository::Reset()
       
  1274 @SYMTestExpectedResults Test must not fail
       
  1275 @SYMPREQ                PREQ2505
       
  1276 @SYMREQ                 REQ13142
       
  1277 */
       
  1278 void PMAResetAllTest()
       
  1279     {
       
  1280     // Reset the whole keyspace
       
  1281     TInt start = User::FastCounter();
       
  1282     TInt err = TheRepository->Reset();
       
  1283     TInt end = User::FastCounter();
       
  1284     TEST2(err, KErrNotSupported);
       
  1285     PrintStats(start, end);
       
  1286     }
       
  1287 
  1198 ///////////////////////////////////////////////////////////////////////////////////////
  1288 ///////////////////////////////////////////////////////////////////////////////////////
  1199 
  1289 
  1200 // MAIN
  1290 // MAIN
  1201 
  1291 
  1202 void DoTestsL()
  1292 void DoTestsL()
  1203 	{
  1293 	{
  1204 	TheTest.Start(_L("@SYMTestCaseID:PDS-CENTRALREPOSITORY-UT-4047 Get Int test"));
  1294 	TheTest.Next(_L("@SYMTestCaseID:PDS-CENTRALREPOSITORY-UT-4047 Get Int test"));
  1205 	GetIntTest();
  1295 	GetIntTest();
  1206 
  1296 
  1207 	TheTest.Next(_L("@SYMTestCaseID:PDS-CENTRALREPOSITORY-CT-4087 Get Real test"));
  1297 	TheTest.Next(_L("@SYMTestCaseID:PDS-CENTRALREPOSITORY-CT-4087 Get Real test"));
  1208 	GetRealTest();
  1298 	GetRealTest();
  1209 
  1299 
  1279 	TheTest.Next(_L("@SYMTestCaseID:PDS-CENTRALREPOSITORY-CT-4109 Delete test"));
  1369 	TheTest.Next(_L("@SYMTestCaseID:PDS-CENTRALREPOSITORY-CT-4109 Delete test"));
  1280 	DeleteTest();
  1370 	DeleteTest();
  1281 
  1371 
  1282 	TheTest.Next(_L("@SYMTestCaseID:PDS-CENTRALREPOSITORY-CT-4110 Delete test"));
  1372 	TheTest.Next(_L("@SYMTestCaseID:PDS-CENTRALREPOSITORY-CT-4110 Delete test"));
  1283 	DeleteRangeTestL();
  1373 	DeleteRangeTestL();
  1284 
  1374 	
  1285 	TheTest.Next(_L("@SYMTestCaseID:PDS-CENTRALREPOSITORY-CT-4111 Reset Single test"));
  1375 	}
  1286 	ResetTest();
  1376 
  1287 
  1377 void DoResetTests()
  1288 	TheTest.Next(_L("@SYMTestCaseID:PDS-CENTRALREPOSITORY-CT-4112 Reset All test"));
  1378     {
  1289 	ResetAllTest();
  1379 
  1290 	}
  1380     TheTest.Next(_L("@SYMTestCaseID:PDS-CENTRALREPOSITORY-CT-4111 Reset Single test"));
       
  1381     ResetTest();
       
  1382 
       
  1383     TheTest.Next(_L("@SYMTestCaseID:PDS-CENTRALREPOSITORY-CT-4112 Reset All test"));
       
  1384     ResetAllTest();
       
  1385     }
       
  1386 
       
  1387 void DoPMAResetTests()
       
  1388     {
       
  1389 
       
  1390     TheTest.Next(_L("@SYMTestCaseID:PDS-CENTRALREPOSITORY-CT-4129 Reset Single test"));
       
  1391     PMAResetTest();
       
  1392 
       
  1393     TheTest.Next(_L("@SYMTestCaseID:PDS-CENTRALREPOSITORY-CT-4130 Reset All test"));
       
  1394     PMAResetAllTest();
       
  1395     }
       
  1396 
       
  1397 LOCAL_C void MainL()
       
  1398     {
       
  1399     //Non-PMA test
       
  1400 	CreateTestEnvL(KTestCenRepUid);
       
  1401 
       
  1402 	DoTestsL();
       
  1403 	DoResetTests();
       
  1404 	
       
  1405 #if defined(SYMBIAN_INCLUDE_APP_CENTRIC)
       
  1406     DestroyTestEnvL();
       
  1407 	CreateTestEnvL(KPMATestCenRepUid);
       
  1408     DoTestsL();
       
  1409     DoPMAResetTests();
       
  1410 #endif
       
  1411     DestroyTestEnvL();
       
  1412     }
  1291 
  1413 
  1292 
  1414 
  1293 TInt E32Main()
  1415 TInt E32Main()
  1294 	{
  1416 	{
  1295 	TheTest.Title();
  1417     TheTest.Title ();
  1296 	
  1418     TheTest.Start(_L("Centrep Performance Test"));
  1297 	CTrapCleanup* tc = CTrapCleanup::New();
  1419     
  1298 	TheTest(tc != NULL);
  1420     CTrapCleanup* cleanup = CTrapCleanup::New();
  1299 	
  1421     TheTest(cleanup != NULL);
  1300 	__UHEAP_MARK;
  1422     
  1301 	
  1423     __UHEAP_MARK;
  1302 	TRAPD(err, CreateTestEnvL());
  1424     
  1303 	TEST2(err, KErrNone);
  1425     KillProcess(KCentralRepositoryServerName);
  1304 
  1426     TRAPD(err, MainL());
  1305 	TRAP(err, DoTestsL());
  1427     KillProcess(KCentralRepositoryServerName);
  1306 	DestroyTestEnv();
  1428     TEST2(err, KErrNone);
  1307 	TEST2(err, KErrNone);
  1429     
  1308 	
  1430     
  1309 	__UHEAP_MARKEND;
  1431     __UHEAP_MARKEND;
  1310 	
  1432     
  1311 	TheTest.End();
  1433     TheTest.End ();
  1312 	TheTest.Close();
  1434     TheTest.Close ();
  1313 	
  1435     
  1314 	delete tc;
  1436     delete cleanup;
  1315 	
  1437         
  1316 	User::Heap().Check();
  1438     User::Heap().Check();
  1317 	return KErrNone;
  1439     return KErrNone;
  1318 	}
  1440 	}