os/ossrv/genericservices/taskscheduler/Test/bootupperformance/bootupperformance.cpp
First public contribution.
2 // bootupperformance.cpp
4 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
5 // All rights reserved.
6 // This component and the accompanying materials are made available
7 // under the terms of "Eclipse Public License v1.0"
8 // which accompanies this distribution, and is available
9 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
11 // Initial Contributors:
12 // Nokia Corporation - initial contribution.
17 // For testing Boot-up Performance Task Scheduler
35 _LIT(KTestName, "Boot-up Performance Task Scheduler");
36 RTest TheTest(KTestName);
40 TReal ticksPerMicroSec;
41 TReal64 fsSessionMicroSecs;
48 //Client side interface to the Task Scheduler
49 static RScheduler TheScheduler;
51 //Backup file name of ask Scheduler
52 _LIT(KBackupFileName, "_:\\Private\\10005399\\SchedulesBackup.dat");
53 _LIT(KBackupDir, "_:\\Private\\10005399\\");
55 static TBuf<64> backupFileName;
56 static TBuf<32> backupDir;
59 * This function will create a dummy new task
60 * It is used for test performance of Task Scheduler
64 TScheduleEntryInfo aScheduleInfo;
65 aScheduleInfo.iIntervalType = EHourly;
66 aScheduleInfo.iInterval = 1; //every Hour
67 aScheduleInfo.iStartTime = TTime(TDateTime(2020,EJuly,3,13,36,0,0));
68 aScheduleInfo.iValidityPeriod = KMaxTInt;
71 err = TheScheduler.Connect();
72 TheTest(err == KErrNone);
74 TBuf<255>aFileName = _L("bootupperformance");
76 TName aName = _L("Performance Test");
77 TTaskInfo aTaskInfo(0, aName, 1, -1);
78 err = TheScheduler.Register( aFileName, 1 );
79 TheTest(err == KErrNone);
81 //only one event to add
82 CArrayFixFlat<TScheduleEntryInfo>* array = new (ELeave) CArrayFixFlat<TScheduleEntryInfo>(1);
83 CleanupStack::PushL( array );
84 array->AppendL( aScheduleInfo );
86 TSchedulerItemRef aItemRef;
87 TheScheduler.CreatePersistentSchedule( aItemRef, *array );
89 HBufC* aBuf = HBufC::NewLC(1);
90 TheScheduler.ScheduleTask( aTaskInfo, *aBuf, aItemRef, *array );
92 CleanupStack::PopAndDestroy( 2 );
97 * This function Kill Task Scheduler if it is running
98 * It is used for test performance of Task Scheduler
100 void KillTaskScheduler()
102 TFindProcess findProcess (_L("Schexe.*"));
104 while(findProcess.Next(result) == KErrNone )
107 RProcess processHandle;
108 processHandle.Open (findProcess);
109 processHandle.Kill(0);
110 processHandle.Logon(stat);
111 User::WaitForRequest(stat);
112 processHandle.Close();
113 User::After(1000000);
118 * This function will Start Task Scheduler directly calling Schexe.exe
119 * It is used for test performance of Task Scheduler
121 void StartTaskScheduler()
125 _LIT(KScheduleServerExe, "Schexe");
126 User::LeaveIfError(server.Create(KScheduleServerExe, _L("sysstartschexe")));
127 server.Rendezvous(stat);
128 if (stat!=KRequestPending)
129 server.Kill(0); // abort startup
131 server.Resume(); // logon OK - start the server
132 User::WaitForRequest(stat); // wait for start or death
136 //===================================================================
139 @SYMTestCaseID SYSLIB-SCHSVR-PT-1865
140 @SYMTestCaseDesc Measure the overhead to Start Task Scheduler from client
141 @SYMTestPriority High
142 @SYMTestActions Start Task Scheduler by calling Connect & Close
143 @SYMTestExpectedResults Tests must not fail
144 @SYMDEF DEF074891: Task Scheduler: Persistent Schedules not ReScheduled on Device Bootup
146 void PerformanceTestTS1()
149 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-PT-1865 Start Task Scheduler from client "));
151 //Kill the Task Scheduler if running
155 //Delete SchedulesBackup.dat file
156 BaflUtils::DeleteFile(TheFs, backupFileName);
157 TheFs.RmDir(backupDir);
159 //Performance Test to start Task Scheduler first run
160 prevTime = User::FastCounter();
162 TheScheduler.Connect();
163 TheScheduler.Close();
165 timeDiff = User::FastCounter() - prevTime;
166 fsSessionMicroSecs = timeDiff / (ticksPerMicroSec);
167 TheTest.Printf(_L("\nTime to start Task Scheduler from client first run (no file)= %10.2lf microseconds\n"), fsSessionMicroSecs);
170 //Performance Test to start Task Scheduler second run
172 prevTime = User::FastCounter();
174 TheScheduler.Connect();
175 TheScheduler.Close();
177 timeDiff = User::FastCounter() - prevTime;
178 fsSessionMicroSecs = timeDiff / (ticksPerMicroSec);
179 TheTest.Printf(_L("\nTime to start Task Scheduler from client second run (with file) = %10.2lf microseconds\n"), fsSessionMicroSecs);
184 @SYMTestCaseID SYSLIB-SCHSVR-PT-1866
185 @SYMTestCaseDesc Measure the overhead to Start Task Scheduler directly
186 @SYMTestPriority High
187 @SYMTestActions Start Task Scheduler exe directly and measure the performance
188 @SYMTestExpectedResults Tests must not fail
189 @SYMDEF DEF074891: Task Scheduler: Persistent Schedules not ReScheduled on Device Bootup
191 void PerformanceTestTS2()
194 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-PT-1866 Start Task Scheduler exe directly "));
199 //Delete SchedulesBackup.dat file
200 BaflUtils::DeleteFile(TheFs, backupFileName);
201 TheFs.RmDir(backupDir);
203 //Performance Test to start Task Scheduler first run
204 prevTime = User::FastCounter();
206 StartTaskScheduler();
208 timeDiff = User::FastCounter() - prevTime;
209 fsSessionMicroSecs = timeDiff / (ticksPerMicroSec);
210 TheTest.Printf(_L("\nTime to start Task Schedular directly first run (no file) = %10.2lf microseconds\n"), fsSessionMicroSecs);
213 //Performance Test to start Task Scheduler first run
214 prevTime = User::FastCounter();
216 StartTaskScheduler();
218 timeDiff = User::FastCounter() - prevTime;
219 fsSessionMicroSecs = timeDiff / (ticksPerMicroSec);
220 TheTest.Printf(_L("\nTime to start Task Schedular directly second run (with file) = %10.2lf microseconds\n"), fsSessionMicroSecs);
226 //Performance Test to start Task Scheduler first run
227 prevTime = User::FastCounter();
229 StartTaskScheduler();
231 timeDiff = User::FastCounter() - prevTime;
232 fsSessionMicroSecs = timeDiff / (ticksPerMicroSec);
233 TheTest.Printf(_L("\nTime to Start Task Schedular with Schedule = %10.2lf microseconds\n"), fsSessionMicroSecs);
242 PerformanceTestTS1();
243 PerformanceTestTS2();
246 GLDEF_C TInt E32Main() // main function called by E32
249 CTrapCleanup* tc = CTrapCleanup::New();
252 backupFileName.Copy(KBackupFileName);
253 backupFileName[0] = RFs::GetSystemDriveChar();
255 backupDir.Copy(KBackupDir);
256 backupDir[0] = RFs::GetSystemDriveChar();
258 TheTest.Start(_L("=== Start Task Scheduler tests \n"));
260 HAL::Get(HALData::EFastCounterFrequency, fastTimerFreq);
261 ticksPerMicroSec = 1.0E-6 * fastTimerFreq;
263 User::LeaveIfError(TheFs.Connect());
265 TRAPD(err,RunTestsL());
266 TheTest(err == KErrNone);
268 //Clean up Backup File
269 BaflUtils::DeleteFile(TheFs, backupFileName);
270 TheFs.RmDir(backupDir);
277 return 0; // and return