loggingservices/eventlogger/test/src/t_logbench.cpp
changeset 0 08ec8eefde2f
child 11 667e88a979d7
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2002-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 #define __PROFILING__
       
    17 #include <s32file.h>
       
    18 #include "TEST.H"
       
    19 #include <logview.h>
       
    20 
       
    21 #undef test  //there is a "test" macro which hides "RTest test" declaration.
       
    22 
       
    23 RTest test(_L("Log Engine Benchmark Test Harness"));
       
    24 TLogConfig theConfig;
       
    25 
       
    26 
       
    27 _LIT(KTestString, "%dabcdefghijklmnopqrstuvwxyz");
       
    28 _LIT(KResultFile, "C:\\LOGENG_TEST.TXT");
       
    29 
       
    30 const TInt KLogSize = 50;
       
    31 const TInt KTestFactor = 2;  
       
    32 
       
    33 // Class used to record test details
       
    34 class TTestDetails
       
    35 	{
       
    36 public:
       
    37 	TInt iEventNum;
       
    38 	TInt iTimeToAdd;
       
    39 	//
       
    40 	TInt iViewSize;
       
    41 	TInt iTimeToNavigate;
       
    42 	//
       
    43 	TInt iDatabaseSize;
       
    44 	TInt iHeapSize;
       
    45 	};
       
    46 
       
    47 LOCAL_C TInt GetHeapSizeL()
       
    48 	{	
       
    49 	TInt heap = 0;
       
    50 	heap = User::Heap().Size();
       
    51 
       
    52 	return heap;
       
    53 	}
       
    54 
       
    55 LOCAL_C TInt GetServerHeapSizeL()
       
    56 	{
       
    57 	return 1024 * 1024;//By default - the process heap is 1M.
       
    58 	}
       
    59 
       
    60 LOCAL_C TInt DatabaseSizeL()
       
    61 	{
       
    62 		return TestUtils::DatabaseSizeL();
       
    63 	}
       
    64 
       
    65 /**
       
    66 @SYMTestCaseID          SYSLIB-LOGENG-CT-0988
       
    67 @SYMTestCaseDesc	    Sets the configuration setup for the tests
       
    68 @SYMTestPriority 	    High
       
    69 @SYMTestActions  	    Setup for the environment for the tests
       
    70 @SYMTestExpectedResults Test must not fail
       
    71 @SYMREQ                 REQ0000
       
    72 */
       
    73 LOCAL_C void TestSetupL(CLogClient& aClient)
       
    74 	{
       
    75 	test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0988 "));
       
    76 	CTestActive* active = new(ELeave)CTestActive;
       
    77 	CleanupStack::PushL(active);
       
    78 
       
    79 	// Get configuration
       
    80 	aClient.GetConfig(theConfig, active->iStatus);
       
    81 	active->StartL();
       
    82 	CActiveScheduler::Start();
       
    83 	TEST2(active->iStatus.Int(), KErrNone);
       
    84 
       
    85 	test.Printf(_L("  Log size: %d\n"), theConfig.iMaxLogSize);
       
    86 	test.Printf(_L("  Recent list size: %d\n"), theConfig.iMaxRecentLogSize);
       
    87 	test.Printf(_L("  Max Event Age: %d\n"), theConfig.iMaxEventAge);
       
    88 
       
    89 	TestUtils::DeleteDatabaseL();
       
    90 
       
    91 	// Get configuration
       
    92 	aClient.GetConfig(theConfig, active->iStatus);
       
    93 	active->StartL();
       
    94 	CActiveScheduler::Start();
       
    95 	TEST2(active->iStatus.Int(), KErrNone);
       
    96 
       
    97 	// Wait for user interation
       
    98 	//test.Printf(_L("  Quick tests performed if no key pressed in next 10 seconds\n"));
       
    99     //TKeyCode key;
       
   100 	//if (!TestUtils::WaitForKeyL(10000000, key))
       
   101 		{
       
   102 		theConfig.iMaxLogSize = KLogSize;
       
   103 
       
   104 		// Set configuration in database
       
   105 		aClient.ChangeConfig(theConfig, active->iStatus);
       
   106 		active->StartL();
       
   107 		CActiveScheduler::Start();
       
   108 		TEST2(active->iStatus.Int(), KErrNone);
       
   109 		}
       
   110 
       
   111 	CleanupStack::PopAndDestroy(); // active
       
   112 	}
       
   113 
       
   114 /**
       
   115 @SYMTestCaseID          SYSLIB-LOGENG-CT-0989
       
   116 @SYMTestCaseDesc	    Benchmark test
       
   117 						Tests for writing the log details to a file
       
   118 @SYMTestPriority 	    High
       
   119 @SYMTestActions  	    Add events to the log and write the configuration details to a file
       
   120 @SYMTestExpectedResults Test must not fail
       
   121 @SYMREQ                 REQ0000
       
   122 */
       
   123 LOCAL_C void BenchmarkTestL(CLogClient& aClient, RFile& aFile)
       
   124 	{
       
   125 	test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0989 "));
       
   126 	CTestActive* active = new(ELeave)CTestActive;
       
   127 	CleanupStack::PushL(active);
       
   128 
       
   129 	CLogViewEvent* view = CLogViewEvent::NewL(aClient);
       
   130 	CleanupStack::PushL(view);
       
   131 
       
   132 	CLogFilter* filter = CLogFilter::NewL();
       
   133 	CleanupStack::PushL(filter);
       
   134 
       
   135 	CLogEvent* event = CLogEvent::NewL();
       
   136 	CleanupStack::PushL(event);
       
   137 	event->SetEventType(KLogCallEventTypeUid);
       
   138 
       
   139 	aFile.Write(_L8("Adding Events\n"));
       
   140 
       
   141 	TBuf8<256> buf;
       
   142 	TInt count = 0;
       
   143 
       
   144 	TLogString string;
       
   145 	string.Format(KTestString, count);
       
   146 
       
   147 	while(count++ < theConfig.iMaxLogSize * KTestFactor)
       
   148 		{
       
   149 		event->SetRemoteParty(string);
       
   150 		event->SetSubject(string);
       
   151 		event->SetNumber(string);
       
   152 		event->SetStatus(string);
       
   153 
       
   154 		if (count % 10 == 0)
       
   155 			string.Format(KTestString, count);
       
   156 
       
   157 		TTime before;
       
   158 		before.UniversalTime();
       
   159 
       
   160 		// Add a new event
       
   161 		aClient.AddEvent(*event, active->iStatus);
       
   162 		active->StartL();
       
   163 		CActiveScheduler::Start();
       
   164 		TEST2(active->iStatus.Int(), KErrNone);
       
   165 
       
   166 		TTime after;
       
   167 		after.UniversalTime();
       
   168 		TTimeIntervalMicroSeconds interval = after.MicroSecondsFrom(before);
       
   169 
       
   170 		TInt dbSize = DatabaseSizeL();
       
   171 		TInt heapSize = GetHeapSizeL();
       
   172 		TInt serverHeapSize = GetServerHeapSizeL();
       
   173 
       
   174 		// Store details in file
       
   175 		test.Printf(_L("  Num: %d, Time: %d, Db Size: %d, Hs: %d, Server Hs: %d\n"), count, I64INT(interval.Int64()), dbSize, heapSize, serverHeapSize);
       
   176 		buf.Format(_L8("%d,%d,%d,%d,%d\n"), count, I64INT(interval.Int64()), dbSize, heapSize, serverHeapSize);
       
   177 		aFile.Write(buf);
       
   178 		}
       
   179 
       
   180 	aFile.Write(_L8("Navigating View\n"));
       
   181 	count = 1;
       
   182 
       
   183 	// Navigate the view
       
   184 	TEST(view->SetFilterL(*filter, active->iStatus));
       
   185 	active->StartL();
       
   186 	CActiveScheduler::Start();
       
   187 	TEST2(active->iStatus.Int(), KErrNone);
       
   188 
       
   189 	while(view->NextL(active->iStatus))
       
   190 		{
       
   191 		TTime before;
       
   192 		before.UniversalTime();
       
   193 
       
   194 		active->StartL();
       
   195 		CActiveScheduler::Start();
       
   196 		TEST2(active->iStatus.Int(), KErrNone);
       
   197 
       
   198 		TTime after;
       
   199 		after.UniversalTime();
       
   200 		TTimeIntervalMicroSeconds interval = after.MicroSecondsFrom(before);
       
   201 
       
   202 		TInt heapSize = GetHeapSizeL();
       
   203 		TInt serverHeapSize = GetServerHeapSizeL();
       
   204 
       
   205 		// Store details in file
       
   206 		test.Printf(_L("  Count: %d, Time: %d, Hs: %d, Server Hs: %d\n"), count, I64INT(interval.Int64()), heapSize, serverHeapSize);
       
   207 		buf.Format(_L8("%d,%d,%d,%d\n"), count++, I64INT(interval.Int64()), heapSize, serverHeapSize);
       
   208 		aFile.Write(buf);
       
   209 		}
       
   210 
       
   211 	CleanupStack::PopAndDestroy(4); // event, filter, view, active
       
   212 	}
       
   213 
       
   214 /**
       
   215 @SYMTestCaseID          SYSLIB-LOGENG-CT-0990
       
   216 @SYMTestCaseDesc	    Tests for CLogViewRecent::SetRecentListL(),CLogViewRecent::DuplicatesL() functions
       
   217 @SYMTestPriority 	    High
       
   218 @SYMTestActions  	    Set the recent log view list and refresh for the duplicates view.
       
   219                         Check for ErrNone flag
       
   220 @SYMTestExpectedResults Test must not fail
       
   221 @SYMREQ                 REQ0000
       
   222 */
       
   223 LOCAL_C void DoTestRecentViewsL(CLogClient& aClient, TLogRecentList aList, TInt aRecentCount, TInt aDuplicateCount)
       
   224 	{
       
   225 	test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0990 "));
       
   226 	CTestActive* active = new(ELeave)CTestActive();
       
   227 	CleanupStack::PushL(active);
       
   228 
       
   229 	CLogViewRecent* recent = CLogViewRecent::NewL(aClient);
       
   230 	CleanupStack::PushL(recent);
       
   231 
       
   232 	CLogViewDuplicate* duplicate = CLogViewDuplicate::NewL(aClient);
       
   233 	CleanupStack::PushL(duplicate);
       
   234 
       
   235 	TEST(recent->SetRecentListL(aList, active->iStatus) || aRecentCount == 0);
       
   236 	do
       
   237 		{
       
   238 		if (aRecentCount == 0)
       
   239 			break;
       
   240 
       
   241 		active->StartL();
       
   242 		CActiveScheduler::Start();
       
   243 		TEST2(active->iStatus.Int(), KErrNone);
       
   244 
       
   245 		TEST(recent->DuplicatesL(*duplicate, active->iStatus) || aDuplicateCount == 0);
       
   246 		do
       
   247 			{
       
   248 			if (aDuplicateCount == 0)
       
   249 				break;
       
   250 
       
   251 			active->StartL();
       
   252 			CActiveScheduler::Start();
       
   253 			TEST2(active->iStatus.Int(), KErrNone);
       
   254 			}
       
   255 		while(duplicate->NextL(active->iStatus));
       
   256 		TEST(duplicate->CountL() == aDuplicateCount);
       
   257 		}
       
   258 	while(recent->NextL(active->iStatus));
       
   259 	TEST(recent->CountL() == aRecentCount);
       
   260 
       
   261 	CleanupStack::PopAndDestroy(3); // active, recent, duplicate
       
   262 	}
       
   263 
       
   264 /**
       
   265 @SYMTestCaseID          SYSLIB-LOGENG-CT-0991
       
   266 @SYMTestCaseDesc	    Tests to clear the duplicates in a view
       
   267                         Tests CLogViewRecent::ClearDuplicatesL() function
       
   268 @SYMTestPriority 	    High
       
   269 @SYMTestActions  	    Set the recent log view list.Check for ErrNone flag.
       
   270                         Write the details to a file.
       
   271 @SYMTestExpectedResults Test must not fail
       
   272 @SYMREQ                 REQ0000
       
   273 */
       
   274 LOCAL_C void DoTestClearDuplicateL(CLogClient& aClient, TLogRecentList aList, RFile& aFile)
       
   275 	{
       
   276 	test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0991 "));
       
   277 	CTestActive* active = new(ELeave)CTestActive();
       
   278 	CleanupStack::PushL(active);
       
   279 
       
   280 	CLogViewRecent* recent = CLogViewRecent::NewL(aClient);
       
   281 	CleanupStack::PushL(recent);
       
   282 
       
   283 	TTime before;
       
   284 	before.UniversalTime();
       
   285 
       
   286 	recent->SetRecentListL(aList, active->iStatus);
       
   287 	active->StartL();
       
   288 	CActiveScheduler::Start();
       
   289 	TEST2(active->iStatus.Int(), KErrNone);
       
   290 	recent->ClearDuplicatesL();
       
   291 
       
   292 	TTime after;
       
   293 	after.UniversalTime();
       
   294 	TTimeIntervalMicroSeconds interval = after.MicroSecondsFrom(before);
       
   295 
       
   296 	TBuf8<256> buf;
       
   297 	test.Printf(_L("Clearing Duplicates for List %d, %d\n"), recent->RecentList(), I64INT(interval.Int64()));
       
   298 	buf.Format(_L8("Clearing Duplicates for List %d, %d\n"), recent->RecentList(), I64INT(interval.Int64()));
       
   299 	aFile.Write(buf);
       
   300 
       
   301 	CleanupStack::PopAndDestroy(2); // recent, active
       
   302 	}
       
   303 
       
   304 /**
       
   305 @SYMTestCaseID          SYSLIB-LOGENG-CT-0992
       
   306 @SYMTestCaseDesc	    Recent lists view test
       
   307 @SYMTestPriority 	    High
       
   308 @SYMTestActions  	    Add the events to the log and execute the test functions. 
       
   309 @SYMTestExpectedResults Test must not fail
       
   310 @SYMREQ                 REQ0000
       
   311 */
       
   312 LOCAL_C void TestRecentListsL(CLogClient& aClient, RFile& aFile)
       
   313 	{
       
   314 	test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0992 "));
       
   315 	aFile.Write(_L8("Recent Lists\n"));
       
   316 
       
   317 	CTestActive* active = new(ELeave)CTestActive();
       
   318 	CleanupStack::PushL(active);
       
   319 
       
   320 	TLogConfig config;
       
   321 	active->StartL();
       
   322 	aClient.GetConfig(config, active->iStatus);
       
   323 	CActiveScheduler::Start();
       
   324 	TEST2(active->iStatus.Int(), KErrNone);
       
   325 
       
   326 	CLogEvent* event = CLogEvent::NewL();
       
   327 	CleanupStack::PushL(event);
       
   328 	event->SetEventType(KLogCallEventTypeUid);
       
   329 
       
   330 	for(TInt duplicates = 0; duplicates < 10; duplicates++)
       
   331 		{
       
   332 		TTime before;
       
   333 		before.UniversalTime();
       
   334 
       
   335 		// Incoming
       
   336 		TLogString incoming;
       
   337 		aClient.GetString(incoming, R_LOG_DIR_IN);
       
   338 		event->SetDirection(incoming);
       
   339 
       
   340 		TInt count;
       
   341 		for(count = 0; count < config.iMaxRecentLogSize; count++)
       
   342 			{
       
   343 			TLogString number;
       
   344 			number.Num(count);
       
   345 			event->SetNumber(number);
       
   346 
       
   347 			active->StartL();
       
   348 			aClient.AddEvent(*event, active->iStatus);
       
   349 			CActiveScheduler::Start();
       
   350 			TEST2(active->iStatus.Int(), KErrNone);
       
   351 			}
       
   352 
       
   353 		// Outgoing
       
   354 		TLogString outgoing;
       
   355 		aClient.GetString(outgoing, R_LOG_DIR_OUT);
       
   356 		event->SetDirection(outgoing);
       
   357 
       
   358 		for(count = 0; count < config.iMaxRecentLogSize; count++)
       
   359 			{
       
   360 			TLogString number;
       
   361 			number.Num(count);
       
   362 			event->SetNumber(number);
       
   363 
       
   364 			active->StartL();
       
   365 			aClient.AddEvent(*event, active->iStatus);
       
   366 			CActiveScheduler::Start();
       
   367 			TEST2(active->iStatus.Int(), KErrNone);
       
   368 			}
       
   369 
       
   370 		// Missed
       
   371 		TLogString missed;
       
   372 		aClient.GetString(missed, R_LOG_DIR_MISSED);
       
   373 		event->SetDirection(missed);
       
   374 
       
   375 		for(count = 0; count < config.iMaxRecentLogSize; count++)
       
   376 			{
       
   377 			TLogString number;
       
   378 			number.Num(count);
       
   379 			event->SetNumber(number);
       
   380 
       
   381 			active->StartL();
       
   382 			aClient.AddEvent(*event, active->iStatus);
       
   383 			CActiveScheduler::Start();
       
   384 			TEST2(active->iStatus.Int(), KErrNone);
       
   385 			}
       
   386 
       
   387 		TTime afterAdd;
       
   388 		afterAdd.UniversalTime();
       
   389 
       
   390 		DoTestRecentViewsL(aClient, KLogRecentIncomingCalls, config.iMaxRecentLogSize, duplicates);
       
   391 		DoTestRecentViewsL(aClient, KLogRecentOutgoingCalls, config.iMaxRecentLogSize, duplicates);
       
   392 		DoTestRecentViewsL(aClient, KLogRecentMissedCalls, config.iMaxRecentLogSize, duplicates);
       
   393 
       
   394 		TTime afterNav;
       
   395 		afterNav.UniversalTime();
       
   396 
       
   397 		TTimeIntervalMicroSeconds interval1 = afterAdd.MicroSecondsFrom(before);
       
   398 		TTimeIntervalMicroSeconds interval2 = afterNav.MicroSecondsFrom(afterAdd);
       
   399 
       
   400 		// Store details in file
       
   401 		TBuf8<256> buf;
       
   402 		test.Printf(_L("  Count: %d, Add: %d, Nav: %d\n"), duplicates, I64INT(interval1.Int64()), I64INT(interval2.Int64()));
       
   403 		buf.Format(_L8("%d,%d,%d\n"), duplicates, I64INT(interval1.Int64()), I64INT(interval2.Int64()));
       
   404 		aFile.Write(buf);
       
   405 		}
       
   406 
       
   407 	DoTestClearDuplicateL(aClient, KLogRecentIncomingCalls, aFile);
       
   408 	DoTestClearDuplicateL(aClient, KLogRecentOutgoingCalls, aFile);
       
   409 	DoTestClearDuplicateL(aClient, KLogRecentMissedCalls, aFile);
       
   410 
       
   411 	CleanupStack::PopAndDestroy(2); // active, event
       
   412 	}
       
   413 
       
   414 
       
   415 void doTestsL()
       
   416 	{
       
   417 	TestUtils::Initialize(_L("T_LOGBENCH"));
       
   418 
       
   419 	CLogChangeNotifier* notifier = CLogChangeNotifier::NewL();
       
   420 	CleanupStack::PushL(notifier);
       
   421 
       
   422 	CLogClient* client = CLogClient::NewL(theFs);
       
   423 	CleanupStack::PushL(client);
       
   424 
       
   425 	CTestActive* active = new(ELeave)CTestActive();
       
   426 	CleanupStack::PushL(active);
       
   427 
       
   428 	TLogConfig config;
       
   429 	client->GetConfig(config, active->iStatus);
       
   430 	active->StartL();
       
   431 	CActiveScheduler::Start();
       
   432 	TEST2(active->iStatus.Int(), KErrNone);
       
   433 
       
   434 	test.Start(_L("Setup"));
       
   435 	TestSetupL(*client);
       
   436 	theLog.Write(_L8("Test 1 OK\n"));
       
   437 	
       
   438 	RFile results;
       
   439 	LEAVE_IF_ERROR(results.Replace(theFs, KResultFile, EFileWrite|EFileShareExclusive));
       
   440 
       
   441 	test.Next(_L("Benchmark tests"));
       
   442 	BenchmarkTestL(*client, results);
       
   443 	theLog.Write(_L8("Test 2 OK\n"));
       
   444 
       
   445 	TestUtils::DeleteDatabaseL();
       
   446 
       
   447 	test.Next(_L("Recent List tests"));
       
   448 	TestRecentListsL(*client, results);
       
   449 	theLog.Write(_L8("Test 3 OK\n"));
       
   450 
       
   451 	// Restore Config
       
   452 	client->ChangeConfig(config, active->iStatus);
       
   453 	active->StartL();
       
   454 	CActiveScheduler::Start();
       
   455 	TEST2(active->iStatus.Int(), KErrNone);
       
   456 
       
   457 	results.Close();
       
   458 	CleanupStack::PopAndDestroy(3); // active, notifier, client;
       
   459 	}
       
   460