sl@0: // sl@0: // bootupperformance.cpp sl@0: sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // For testing Boot-up Performance Task Scheduler sl@0: // sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @internalComponent sl@0: @test sl@0: */ sl@0: // sl@0: #include sl@0: #include "e32debug.h" sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: _LIT(KTestName, "Boot-up Performance Task Scheduler"); sl@0: RTest TheTest(KTestName); sl@0: sl@0: //For time counter sl@0: TInt fastTimerFreq; sl@0: TReal ticksPerMicroSec; sl@0: TReal64 fsSessionMicroSecs; sl@0: TUint prevTime; sl@0: TUint timeDiff; sl@0: sl@0: //file server session sl@0: RFs TheFs; sl@0: sl@0: //Client side interface to the Task Scheduler sl@0: static RScheduler TheScheduler; sl@0: sl@0: //Backup file name of ask Scheduler sl@0: _LIT(KBackupFileName, "_:\\Private\\10005399\\SchedulesBackup.dat"); sl@0: _LIT(KBackupDir, "_:\\Private\\10005399\\"); sl@0: sl@0: static TBuf<64> backupFileName; sl@0: static TBuf<32> backupDir; sl@0: sl@0: /** sl@0: * This function will create a dummy new task sl@0: * It is used for test performance of Task Scheduler sl@0: */ sl@0: void CreateNewTask() sl@0: { sl@0: TScheduleEntryInfo aScheduleInfo; sl@0: aScheduleInfo.iIntervalType = EHourly; sl@0: aScheduleInfo.iInterval = 1; //every Hour sl@0: aScheduleInfo.iStartTime = TTime(TDateTime(2020,EJuly,3,13,36,0,0)); sl@0: aScheduleInfo.iValidityPeriod = KMaxTInt; sl@0: sl@0: TInt err; sl@0: err = TheScheduler.Connect(); sl@0: TheTest(err == KErrNone); sl@0: sl@0: TBuf<255>aFileName = _L("bootupperformance"); sl@0: sl@0: TName aName = _L("Performance Test"); sl@0: TTaskInfo aTaskInfo(0, aName, 1, -1); sl@0: err = TheScheduler.Register( aFileName, 1 ); sl@0: TheTest(err == KErrNone); sl@0: sl@0: //only one event to add sl@0: CArrayFixFlat* array = new (ELeave) CArrayFixFlat(1); sl@0: CleanupStack::PushL( array ); sl@0: array->AppendL( aScheduleInfo ); sl@0: sl@0: TSchedulerItemRef aItemRef; sl@0: TheScheduler.CreatePersistentSchedule( aItemRef, *array ); sl@0: sl@0: HBufC* aBuf = HBufC::NewLC(1); sl@0: TheScheduler.ScheduleTask( aTaskInfo, *aBuf, aItemRef, *array ); sl@0: sl@0: CleanupStack::PopAndDestroy( 2 ); sl@0: TheScheduler.Close(); sl@0: } sl@0: sl@0: /** sl@0: * This function Kill Task Scheduler if it is running sl@0: * It is used for test performance of Task Scheduler sl@0: */ sl@0: void KillTaskScheduler() sl@0: { sl@0: TFindProcess findProcess (_L("Schexe.*")); sl@0: TFullName result; sl@0: while(findProcess.Next(result) == KErrNone ) sl@0: { sl@0: TRequestStatus stat; sl@0: RProcess processHandle; sl@0: processHandle.Open (findProcess); sl@0: processHandle.Kill(0); sl@0: processHandle.Logon(stat); sl@0: User::WaitForRequest(stat); sl@0: processHandle.Close(); sl@0: User::After(1000000); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * This function will Start Task Scheduler directly calling Schexe.exe sl@0: * It is used for test performance of Task Scheduler sl@0: */ sl@0: void StartTaskScheduler() sl@0: { sl@0: TRequestStatus stat; sl@0: RProcess server; sl@0: _LIT(KScheduleServerExe, "Schexe"); sl@0: User::LeaveIfError(server.Create(KScheduleServerExe, _L("sysstartschexe"))); sl@0: server.Rendezvous(stat); sl@0: if (stat!=KRequestPending) sl@0: server.Kill(0); // abort startup sl@0: else sl@0: server.Resume(); // logon OK - start the server sl@0: User::WaitForRequest(stat); // wait for start or death sl@0: } sl@0: sl@0: //Tests sl@0: //=================================================================== sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SCHSVR-PT-1865 sl@0: @SYMTestCaseDesc Measure the overhead to Start Task Scheduler from client sl@0: @SYMTestPriority High sl@0: @SYMTestActions Start Task Scheduler by calling Connect & Close sl@0: @SYMTestExpectedResults Tests must not fail sl@0: @SYMDEF DEF074891: Task Scheduler: Persistent Schedules not ReScheduled on Device Bootup sl@0: */ sl@0: void PerformanceTestTS1() sl@0: { sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-PT-1865 Start Task Scheduler from client ")); sl@0: sl@0: //Kill the Task Scheduler if running sl@0: KillTaskScheduler(); sl@0: sl@0: //Test Case 1 sl@0: //Delete SchedulesBackup.dat file sl@0: BaflUtils::DeleteFile(TheFs, backupFileName); sl@0: TheFs.RmDir(backupDir); sl@0: sl@0: //Performance Test to start Task Scheduler first run sl@0: prevTime = User::FastCounter(); sl@0: sl@0: TheScheduler.Connect(); sl@0: TheScheduler.Close(); sl@0: sl@0: timeDiff = User::FastCounter() - prevTime; sl@0: fsSessionMicroSecs = timeDiff / (ticksPerMicroSec); sl@0: TheTest.Printf(_L("\nTime to start Task Scheduler from client first run (no file)= %10.2lf microseconds\n"), fsSessionMicroSecs); sl@0: sl@0: //Test Case 2 sl@0: //Performance Test to start Task Scheduler second run sl@0: sl@0: prevTime = User::FastCounter(); sl@0: sl@0: TheScheduler.Connect(); sl@0: TheScheduler.Close(); sl@0: sl@0: timeDiff = User::FastCounter() - prevTime; sl@0: fsSessionMicroSecs = timeDiff / (ticksPerMicroSec); sl@0: TheTest.Printf(_L("\nTime to start Task Scheduler from client second run (with file) = %10.2lf microseconds\n"), fsSessionMicroSecs); sl@0: sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SCHSVR-PT-1866 sl@0: @SYMTestCaseDesc Measure the overhead to Start Task Scheduler directly sl@0: @SYMTestPriority High sl@0: @SYMTestActions Start Task Scheduler exe directly and measure the performance sl@0: @SYMTestExpectedResults Tests must not fail sl@0: @SYMDEF DEF074891: Task Scheduler: Persistent Schedules not ReScheduled on Device Bootup sl@0: */ sl@0: void PerformanceTestTS2() sl@0: { sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-PT-1866 Start Task Scheduler exe directly ")); sl@0: sl@0: //Test Case 1 sl@0: KillTaskScheduler(); sl@0: sl@0: //Delete SchedulesBackup.dat file sl@0: BaflUtils::DeleteFile(TheFs, backupFileName); sl@0: TheFs.RmDir(backupDir); sl@0: sl@0: //Performance Test to start Task Scheduler first run sl@0: prevTime = User::FastCounter(); sl@0: sl@0: StartTaskScheduler(); sl@0: sl@0: timeDiff = User::FastCounter() - prevTime; sl@0: fsSessionMicroSecs = timeDiff / (ticksPerMicroSec); sl@0: TheTest.Printf(_L("\nTime to start Task Schedular directly first run (no file) = %10.2lf microseconds\n"), fsSessionMicroSecs); sl@0: sl@0: //Test Case 2 sl@0: //Performance Test to start Task Scheduler first run sl@0: prevTime = User::FastCounter(); sl@0: sl@0: StartTaskScheduler(); sl@0: sl@0: timeDiff = User::FastCounter() - prevTime; sl@0: fsSessionMicroSecs = timeDiff / (ticksPerMicroSec); sl@0: TheTest.Printf(_L("\nTime to start Task Schedular directly second run (with file) = %10.2lf microseconds\n"), fsSessionMicroSecs); sl@0: sl@0: //Test Case 3 sl@0: CreateNewTask(); sl@0: sl@0: KillTaskScheduler(); sl@0: //Performance Test to start Task Scheduler first run sl@0: prevTime = User::FastCounter(); sl@0: sl@0: StartTaskScheduler(); sl@0: sl@0: timeDiff = User::FastCounter() - prevTime; sl@0: fsSessionMicroSecs = timeDiff / (ticksPerMicroSec); sl@0: TheTest.Printf(_L("\nTime to Start Task Schedular with Schedule = %10.2lf microseconds\n"), fsSessionMicroSecs); sl@0: sl@0: } sl@0: sl@0: /** sl@0: Runs all the tests. sl@0: */ sl@0: void RunTestsL() sl@0: { sl@0: PerformanceTestTS1(); sl@0: PerformanceTestTS2(); sl@0: } sl@0: sl@0: GLDEF_C TInt E32Main() // main function called by E32 sl@0: { sl@0: sl@0: CTrapCleanup* tc = CTrapCleanup::New(); sl@0: __UHEAP_MARK; sl@0: sl@0: backupFileName.Copy(KBackupFileName); sl@0: backupFileName[0] = RFs::GetSystemDriveChar(); sl@0: sl@0: backupDir.Copy(KBackupDir); sl@0: backupDir[0] = RFs::GetSystemDriveChar(); sl@0: sl@0: TheTest.Start(_L("=== Start Task Scheduler tests \n")); sl@0: TheTest.Title(); sl@0: HAL::Get(HALData::EFastCounterFrequency, fastTimerFreq); sl@0: ticksPerMicroSec = 1.0E-6 * fastTimerFreq; sl@0: sl@0: User::LeaveIfError(TheFs.Connect()); sl@0: sl@0: TRAPD(err,RunTestsL()); sl@0: TheTest(err == KErrNone); sl@0: sl@0: //Clean up Backup File sl@0: BaflUtils::DeleteFile(TheFs, backupFileName); sl@0: TheFs.RmDir(backupDir); sl@0: TheFs.Close(); sl@0: TheTest.End(); sl@0: TheTest.Close(); sl@0: sl@0: __UHEAP_MARKEND; sl@0: delete tc; sl@0: return 0; // and return sl@0: }