os/ossrv/genericservices/taskscheduler/Test/bootupperformance/bootupperformance.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200 (2014-06-10)
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
//
sl@0
     2
// bootupperformance.cpp
sl@0
     3
sl@0
     4
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     5
// All rights reserved.
sl@0
     6
// This component and the accompanying materials are made available
sl@0
     7
// under the terms of "Eclipse Public License v1.0"
sl@0
     8
// which accompanies this distribution, and is available
sl@0
     9
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
    10
//
sl@0
    11
// Initial Contributors:
sl@0
    12
// Nokia Corporation - initial contribution.
sl@0
    13
//
sl@0
    14
// Contributors:
sl@0
    15
//
sl@0
    16
// Description:
sl@0
    17
// For testing Boot-up Performance Task Scheduler
sl@0
    18
// 
sl@0
    19
//
sl@0
    20
sl@0
    21
/**
sl@0
    22
 @file
sl@0
    23
 @internalComponent
sl@0
    24
 @test
sl@0
    25
*/
sl@0
    26
//
sl@0
    27
#include <e32base.h>
sl@0
    28
#include "e32debug.h"
sl@0
    29
#include <hal.h>
sl@0
    30
#include <csch_cli.h>
sl@0
    31
#include <bautils.h>
sl@0
    32
#include <f32file.h>
sl@0
    33
#include <e32test.h>
sl@0
    34
sl@0
    35
_LIT(KTestName,	"Boot-up Performance Task Scheduler");
sl@0
    36
RTest	TheTest(KTestName);
sl@0
    37
sl@0
    38
//For time counter
sl@0
    39
TInt fastTimerFreq;
sl@0
    40
TReal ticksPerMicroSec; 
sl@0
    41
TReal64 fsSessionMicroSecs;
sl@0
    42
TUint prevTime;
sl@0
    43
TUint timeDiff;
sl@0
    44
sl@0
    45
//file server session
sl@0
    46
RFs TheFs;
sl@0
    47
sl@0
    48
//Client side interface to the Task Scheduler
sl@0
    49
static RScheduler	TheScheduler;
sl@0
    50
sl@0
    51
//Backup file name of ask Scheduler
sl@0
    52
_LIT(KBackupFileName, "_:\\Private\\10005399\\SchedulesBackup.dat");
sl@0
    53
_LIT(KBackupDir, "_:\\Private\\10005399\\");
sl@0
    54
sl@0
    55
static TBuf<64> backupFileName;
sl@0
    56
static TBuf<32> backupDir;
sl@0
    57
sl@0
    58
/**
sl@0
    59
 * This function will create a dummy new task
sl@0
    60
 * It is used for test performance of Task Scheduler
sl@0
    61
 */ 
sl@0
    62
void CreateNewTask()
sl@0
    63
{
sl@0
    64
	TScheduleEntryInfo aScheduleInfo;
sl@0
    65
	aScheduleInfo.iIntervalType = EHourly;
sl@0
    66
	aScheduleInfo.iInterval = 1;			//every Hour
sl@0
    67
	aScheduleInfo.iStartTime = TTime(TDateTime(2020,EJuly,3,13,36,0,0));
sl@0
    68
	aScheduleInfo.iValidityPeriod = KMaxTInt;
sl@0
    69
sl@0
    70
	TInt err;
sl@0
    71
	err = TheScheduler.Connect();
sl@0
    72
	TheTest(err == KErrNone);
sl@0
    73
	
sl@0
    74
	TBuf<255>aFileName = _L("bootupperformance");
sl@0
    75
sl@0
    76
	TName  aName = _L("Performance Test");
sl@0
    77
	TTaskInfo aTaskInfo(0, aName, 1, -1);
sl@0
    78
	err = TheScheduler.Register( aFileName, 1 );
sl@0
    79
	TheTest(err == KErrNone);
sl@0
    80
	
sl@0
    81
	//only one event to add
sl@0
    82
	CArrayFixFlat<TScheduleEntryInfo>* array = new (ELeave) CArrayFixFlat<TScheduleEntryInfo>(1);
sl@0
    83
	CleanupStack::PushL( array );
sl@0
    84
	array->AppendL( aScheduleInfo );
sl@0
    85
sl@0
    86
	TSchedulerItemRef aItemRef;
sl@0
    87
	TheScheduler.CreatePersistentSchedule( aItemRef, *array );
sl@0
    88
sl@0
    89
	HBufC* aBuf = HBufC::NewLC(1);      
sl@0
    90
	TheScheduler.ScheduleTask( aTaskInfo, *aBuf, aItemRef, *array );
sl@0
    91
	
sl@0
    92
	CleanupStack::PopAndDestroy( 2 );
sl@0
    93
	TheScheduler.Close();
sl@0
    94
}
sl@0
    95
sl@0
    96
/**
sl@0
    97
 * This function Kill Task Scheduler if it is running
sl@0
    98
 * It is used for test performance of Task Scheduler
sl@0
    99
 */ 
sl@0
   100
void KillTaskScheduler()
sl@0
   101
	{
sl@0
   102
	TFindProcess findProcess (_L("Schexe.*"));
sl@0
   103
	TFullName result;
sl@0
   104
	while(findProcess.Next(result) == KErrNone )
sl@0
   105
		{
sl@0
   106
		TRequestStatus stat;
sl@0
   107
		RProcess processHandle;
sl@0
   108
		processHandle.Open (findProcess);
sl@0
   109
		processHandle.Kill(0);
sl@0
   110
		processHandle.Logon(stat);
sl@0
   111
		User::WaitForRequest(stat);
sl@0
   112
		processHandle.Close();
sl@0
   113
		User::After(1000000);
sl@0
   114
		}
sl@0
   115
	}
sl@0
   116
sl@0
   117
/**
sl@0
   118
 * This function will Start Task Scheduler directly calling Schexe.exe
sl@0
   119
 * It is used for test performance of Task Scheduler
sl@0
   120
 */ 	
sl@0
   121
void StartTaskScheduler()
sl@0
   122
	{
sl@0
   123
	TRequestStatus stat;
sl@0
   124
	RProcess server;
sl@0
   125
	_LIT(KScheduleServerExe, "Schexe");
sl@0
   126
	User::LeaveIfError(server.Create(KScheduleServerExe, _L("sysstartschexe")));
sl@0
   127
	server.Rendezvous(stat);
sl@0
   128
	if (stat!=KRequestPending)
sl@0
   129
		server.Kill(0);		// abort startup
sl@0
   130
	else
sl@0
   131
		server.Resume();	// logon OK - start the server
sl@0
   132
	User::WaitForRequest(stat);		// wait for start or death
sl@0
   133
	}
sl@0
   134
sl@0
   135
//Tests
sl@0
   136
//===================================================================
sl@0
   137
sl@0
   138
/**
sl@0
   139
@SYMTestCaseID          SYSLIB-SCHSVR-PT-1865
sl@0
   140
@SYMTestCaseDesc        Measure the overhead to Start Task Scheduler from client
sl@0
   141
@SYMTestPriority        High
sl@0
   142
@SYMTestActions         Start Task Scheduler by calling Connect & Close
sl@0
   143
@SYMTestExpectedResults Tests must not fail
sl@0
   144
@SYMDEF                 DEF074891: Task Scheduler: Persistent Schedules not ReScheduled on Device Bootup
sl@0
   145
*/
sl@0
   146
void PerformanceTestTS1()
sl@0
   147
	{
sl@0
   148
	
sl@0
   149
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-PT-1865 Start Task Scheduler from client "));	
sl@0
   150
	
sl@0
   151
	//Kill the Task Scheduler if running 
sl@0
   152
	KillTaskScheduler();
sl@0
   153
sl@0
   154
//Test Case 1
sl@0
   155
	//Delete SchedulesBackup.dat file
sl@0
   156
	BaflUtils::DeleteFile(TheFs, backupFileName);
sl@0
   157
	TheFs.RmDir(backupDir);
sl@0
   158
sl@0
   159
	//Performance Test to start Task Scheduler first run
sl@0
   160
	prevTime = User::FastCounter();
sl@0
   161
sl@0
   162
	TheScheduler.Connect();
sl@0
   163
	TheScheduler.Close();
sl@0
   164
	
sl@0
   165
	timeDiff = User::FastCounter() - prevTime;
sl@0
   166
	fsSessionMicroSecs = timeDiff / (ticksPerMicroSec);
sl@0
   167
	TheTest.Printf(_L("\nTime to start Task Scheduler from client first run (no file)= %10.2lf microseconds\n"), fsSessionMicroSecs);
sl@0
   168
sl@0
   169
//Test Case 2
sl@0
   170
	//Performance Test to start Task Scheduler second run
sl@0
   171
sl@0
   172
	prevTime = User::FastCounter();
sl@0
   173
sl@0
   174
	TheScheduler.Connect();
sl@0
   175
	TheScheduler.Close();
sl@0
   176
	
sl@0
   177
	timeDiff = User::FastCounter() - prevTime;
sl@0
   178
	fsSessionMicroSecs = timeDiff / (ticksPerMicroSec);
sl@0
   179
	TheTest.Printf(_L("\nTime to start Task Scheduler from client second run (with file) = %10.2lf microseconds\n"), fsSessionMicroSecs);
sl@0
   180
	
sl@0
   181
	}
sl@0
   182
	
sl@0
   183
/**
sl@0
   184
@SYMTestCaseID          SYSLIB-SCHSVR-PT-1866
sl@0
   185
@SYMTestCaseDesc        Measure the overhead to Start Task Scheduler directly
sl@0
   186
@SYMTestPriority        High
sl@0
   187
@SYMTestActions         Start Task Scheduler exe directly and measure the performance
sl@0
   188
@SYMTestExpectedResults Tests must not fail
sl@0
   189
@SYMDEF                 DEF074891: Task Scheduler: Persistent Schedules not ReScheduled on Device Bootup
sl@0
   190
*/
sl@0
   191
void PerformanceTestTS2()
sl@0
   192
	{
sl@0
   193
	
sl@0
   194
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-PT-1866 Start Task Scheduler exe directly "));	
sl@0
   195
	
sl@0
   196
//Test Case 1	
sl@0
   197
	KillTaskScheduler();
sl@0
   198
	
sl@0
   199
	//Delete SchedulesBackup.dat file
sl@0
   200
	BaflUtils::DeleteFile(TheFs, backupFileName);
sl@0
   201
	TheFs.RmDir(backupDir);
sl@0
   202
	
sl@0
   203
	//Performance Test to start Task Scheduler first run
sl@0
   204
	prevTime = User::FastCounter();
sl@0
   205
sl@0
   206
	StartTaskScheduler();
sl@0
   207
	
sl@0
   208
	timeDiff = User::FastCounter() - prevTime;
sl@0
   209
	fsSessionMicroSecs = timeDiff / (ticksPerMicroSec);
sl@0
   210
	TheTest.Printf(_L("\nTime to start Task Schedular directly first run (no file) = %10.2lf microseconds\n"), fsSessionMicroSecs);
sl@0
   211
sl@0
   212
//Test Case 2
sl@0
   213
	//Performance Test to start Task Scheduler first run
sl@0
   214
	prevTime = User::FastCounter();
sl@0
   215
sl@0
   216
	StartTaskScheduler();
sl@0
   217
	
sl@0
   218
	timeDiff = User::FastCounter() - prevTime;
sl@0
   219
	fsSessionMicroSecs = timeDiff / (ticksPerMicroSec);
sl@0
   220
	TheTest.Printf(_L("\nTime to start Task Schedular directly second run (with file) = %10.2lf microseconds\n"), fsSessionMicroSecs);
sl@0
   221
	
sl@0
   222
//Test Case 3
sl@0
   223
	CreateNewTask();
sl@0
   224
	
sl@0
   225
	KillTaskScheduler();
sl@0
   226
	//Performance Test to start Task Scheduler first run
sl@0
   227
	prevTime = User::FastCounter();
sl@0
   228
sl@0
   229
	StartTaskScheduler();
sl@0
   230
	
sl@0
   231
	timeDiff = User::FastCounter() - prevTime;
sl@0
   232
	fsSessionMicroSecs = timeDiff / (ticksPerMicroSec);
sl@0
   233
	TheTest.Printf(_L("\nTime to Start Task Schedular with Schedule = %10.2lf microseconds\n"), fsSessionMicroSecs);
sl@0
   234
sl@0
   235
	}
sl@0
   236
sl@0
   237
/**
sl@0
   238
Runs all the tests.
sl@0
   239
*/
sl@0
   240
void RunTestsL()
sl@0
   241
	{
sl@0
   242
	PerformanceTestTS1();
sl@0
   243
	PerformanceTestTS2();
sl@0
   244
	}
sl@0
   245
sl@0
   246
GLDEF_C TInt E32Main() // main function called by E32
sl@0
   247
    {
sl@0
   248
    
sl@0
   249
  	CTrapCleanup* tc = CTrapCleanup::New();
sl@0
   250
  	__UHEAP_MARK;
sl@0
   251
sl@0
   252
	backupFileName.Copy(KBackupFileName);
sl@0
   253
	backupFileName[0] = RFs::GetSystemDriveChar();
sl@0
   254
	
sl@0
   255
	backupDir.Copy(KBackupDir);
sl@0
   256
	backupDir[0] = RFs::GetSystemDriveChar();
sl@0
   257
  	
sl@0
   258
  	TheTest.Start(_L("=== Start Task Scheduler tests \n"));
sl@0
   259
	TheTest.Title();
sl@0
   260
	HAL::Get(HALData::EFastCounterFrequency, fastTimerFreq);
sl@0
   261
	ticksPerMicroSec = 1.0E-6 * fastTimerFreq;
sl@0
   262
	
sl@0
   263
	User::LeaveIfError(TheFs.Connect());
sl@0
   264
sl@0
   265
	TRAPD(err,RunTestsL());
sl@0
   266
	TheTest(err == KErrNone);
sl@0
   267
	
sl@0
   268
	//Clean up 	Backup File
sl@0
   269
	BaflUtils::DeleteFile(TheFs, backupFileName);
sl@0
   270
	TheFs.RmDir(backupDir);
sl@0
   271
	TheFs.Close();
sl@0
   272
	TheTest.End();
sl@0
   273
	TheTest.Close();
sl@0
   274
	
sl@0
   275
	__UHEAP_MARKEND;
sl@0
   276
	delete tc;
sl@0
   277
	return 0; // and return
sl@0
   278
    }