|
1 // |
|
2 // bootupperformance.cpp |
|
3 |
|
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". |
|
10 // |
|
11 // Initial Contributors: |
|
12 // Nokia Corporation - initial contribution. |
|
13 // |
|
14 // Contributors: |
|
15 // |
|
16 // Description: |
|
17 // For testing Boot-up Performance Task Scheduler |
|
18 // |
|
19 // |
|
20 |
|
21 /** |
|
22 @file |
|
23 @internalComponent |
|
24 @test |
|
25 */ |
|
26 // |
|
27 #include <e32base.h> |
|
28 #include "e32debug.h" |
|
29 #include <hal.h> |
|
30 #include <csch_cli.h> |
|
31 #include <bautils.h> |
|
32 #include <f32file.h> |
|
33 #include <e32test.h> |
|
34 |
|
35 _LIT(KTestName, "Boot-up Performance Task Scheduler"); |
|
36 RTest TheTest(KTestName); |
|
37 |
|
38 //For time counter |
|
39 TInt fastTimerFreq; |
|
40 TReal ticksPerMicroSec; |
|
41 TReal64 fsSessionMicroSecs; |
|
42 TUint prevTime; |
|
43 TUint timeDiff; |
|
44 |
|
45 //file server session |
|
46 RFs TheFs; |
|
47 |
|
48 //Client side interface to the Task Scheduler |
|
49 static RScheduler TheScheduler; |
|
50 |
|
51 //Backup file name of ask Scheduler |
|
52 _LIT(KBackupFileName, "_:\\Private\\10005399\\SchedulesBackup.dat"); |
|
53 _LIT(KBackupDir, "_:\\Private\\10005399\\"); |
|
54 |
|
55 static TBuf<64> backupFileName; |
|
56 static TBuf<32> backupDir; |
|
57 |
|
58 /** |
|
59 * This function will create a dummy new task |
|
60 * It is used for test performance of Task Scheduler |
|
61 */ |
|
62 void CreateNewTask() |
|
63 { |
|
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; |
|
69 |
|
70 TInt err; |
|
71 err = TheScheduler.Connect(); |
|
72 TheTest(err == KErrNone); |
|
73 |
|
74 TBuf<255>aFileName = _L("bootupperformance"); |
|
75 |
|
76 TName aName = _L("Performance Test"); |
|
77 TTaskInfo aTaskInfo(0, aName, 1, -1); |
|
78 err = TheScheduler.Register( aFileName, 1 ); |
|
79 TheTest(err == KErrNone); |
|
80 |
|
81 //only one event to add |
|
82 CArrayFixFlat<TScheduleEntryInfo>* array = new (ELeave) CArrayFixFlat<TScheduleEntryInfo>(1); |
|
83 CleanupStack::PushL( array ); |
|
84 array->AppendL( aScheduleInfo ); |
|
85 |
|
86 TSchedulerItemRef aItemRef; |
|
87 TheScheduler.CreatePersistentSchedule( aItemRef, *array ); |
|
88 |
|
89 HBufC* aBuf = HBufC::NewLC(1); |
|
90 TheScheduler.ScheduleTask( aTaskInfo, *aBuf, aItemRef, *array ); |
|
91 |
|
92 CleanupStack::PopAndDestroy( 2 ); |
|
93 TheScheduler.Close(); |
|
94 } |
|
95 |
|
96 /** |
|
97 * This function Kill Task Scheduler if it is running |
|
98 * It is used for test performance of Task Scheduler |
|
99 */ |
|
100 void KillTaskScheduler() |
|
101 { |
|
102 TFindProcess findProcess (_L("Schexe.*")); |
|
103 TFullName result; |
|
104 while(findProcess.Next(result) == KErrNone ) |
|
105 { |
|
106 TRequestStatus stat; |
|
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); |
|
114 } |
|
115 } |
|
116 |
|
117 /** |
|
118 * This function will Start Task Scheduler directly calling Schexe.exe |
|
119 * It is used for test performance of Task Scheduler |
|
120 */ |
|
121 void StartTaskScheduler() |
|
122 { |
|
123 TRequestStatus stat; |
|
124 RProcess server; |
|
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 |
|
130 else |
|
131 server.Resume(); // logon OK - start the server |
|
132 User::WaitForRequest(stat); // wait for start or death |
|
133 } |
|
134 |
|
135 //Tests |
|
136 //=================================================================== |
|
137 |
|
138 /** |
|
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 |
|
145 */ |
|
146 void PerformanceTestTS1() |
|
147 { |
|
148 |
|
149 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-PT-1865 Start Task Scheduler from client ")); |
|
150 |
|
151 //Kill the Task Scheduler if running |
|
152 KillTaskScheduler(); |
|
153 |
|
154 //Test Case 1 |
|
155 //Delete SchedulesBackup.dat file |
|
156 BaflUtils::DeleteFile(TheFs, backupFileName); |
|
157 TheFs.RmDir(backupDir); |
|
158 |
|
159 //Performance Test to start Task Scheduler first run |
|
160 prevTime = User::FastCounter(); |
|
161 |
|
162 TheScheduler.Connect(); |
|
163 TheScheduler.Close(); |
|
164 |
|
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); |
|
168 |
|
169 //Test Case 2 |
|
170 //Performance Test to start Task Scheduler second run |
|
171 |
|
172 prevTime = User::FastCounter(); |
|
173 |
|
174 TheScheduler.Connect(); |
|
175 TheScheduler.Close(); |
|
176 |
|
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); |
|
180 |
|
181 } |
|
182 |
|
183 /** |
|
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 |
|
190 */ |
|
191 void PerformanceTestTS2() |
|
192 { |
|
193 |
|
194 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-PT-1866 Start Task Scheduler exe directly ")); |
|
195 |
|
196 //Test Case 1 |
|
197 KillTaskScheduler(); |
|
198 |
|
199 //Delete SchedulesBackup.dat file |
|
200 BaflUtils::DeleteFile(TheFs, backupFileName); |
|
201 TheFs.RmDir(backupDir); |
|
202 |
|
203 //Performance Test to start Task Scheduler first run |
|
204 prevTime = User::FastCounter(); |
|
205 |
|
206 StartTaskScheduler(); |
|
207 |
|
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); |
|
211 |
|
212 //Test Case 2 |
|
213 //Performance Test to start Task Scheduler first run |
|
214 prevTime = User::FastCounter(); |
|
215 |
|
216 StartTaskScheduler(); |
|
217 |
|
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); |
|
221 |
|
222 //Test Case 3 |
|
223 CreateNewTask(); |
|
224 |
|
225 KillTaskScheduler(); |
|
226 //Performance Test to start Task Scheduler first run |
|
227 prevTime = User::FastCounter(); |
|
228 |
|
229 StartTaskScheduler(); |
|
230 |
|
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); |
|
234 |
|
235 } |
|
236 |
|
237 /** |
|
238 Runs all the tests. |
|
239 */ |
|
240 void RunTestsL() |
|
241 { |
|
242 PerformanceTestTS1(); |
|
243 PerformanceTestTS2(); |
|
244 } |
|
245 |
|
246 GLDEF_C TInt E32Main() // main function called by E32 |
|
247 { |
|
248 |
|
249 CTrapCleanup* tc = CTrapCleanup::New(); |
|
250 __UHEAP_MARK; |
|
251 |
|
252 backupFileName.Copy(KBackupFileName); |
|
253 backupFileName[0] = RFs::GetSystemDriveChar(); |
|
254 |
|
255 backupDir.Copy(KBackupDir); |
|
256 backupDir[0] = RFs::GetSystemDriveChar(); |
|
257 |
|
258 TheTest.Start(_L("=== Start Task Scheduler tests \n")); |
|
259 TheTest.Title(); |
|
260 HAL::Get(HALData::EFastCounterFrequency, fastTimerFreq); |
|
261 ticksPerMicroSec = 1.0E-6 * fastTimerFreq; |
|
262 |
|
263 User::LeaveIfError(TheFs.Connect()); |
|
264 |
|
265 TRAPD(err,RunTestsL()); |
|
266 TheTest(err == KErrNone); |
|
267 |
|
268 //Clean up Backup File |
|
269 BaflUtils::DeleteFile(TheFs, backupFileName); |
|
270 TheFs.RmDir(backupDir); |
|
271 TheFs.Close(); |
|
272 TheTest.End(); |
|
273 TheTest.Close(); |
|
274 |
|
275 __UHEAP_MARKEND; |
|
276 delete tc; |
|
277 return 0; // and return |
|
278 } |