226 FailIfError(u.Create()); |
226 FailIfError(u.Create()); |
227 FailIfError(u.Logon(s,h)); |
227 FailIfError(u.Logon(s,h)); |
228 test(s==KRequestPending); |
228 test(s==KRequestPending); |
229 |
229 |
230 TTimeIntervalMicroSeconds time, time2; |
230 TTimeIntervalMicroSeconds time, time2; |
231 TInt64 us; |
231 |
232 |
232 // Test time is initially zero |
233 // Test cpu time is initially zero |
|
234 FailIfError(thread.GetCpuTime(time)); |
233 FailIfError(thread.GetCpuTime(time)); |
235 test(time == 0); |
234 test(time == 0); |
236 |
235 |
237 // Test cpu time is not increased while thread is waiting on semaphore |
236 // Test not increased while waiting on semaphore |
238 thread.Resume(); |
237 thread.Resume(); |
239 User::After(KShortWait); |
238 User::After(KShortWait); |
240 FailIfError(thread.GetCpuTime(time2)); |
239 FailIfError(thread.GetCpuTime(time)); |
241 us = time2.Int64(); |
240 test(time < KTolerance); // wait happens in less than 0.5ms |
242 test.Printf(_L("Time %dus\n"), us); |
241 |
243 test(us < KTolerance); // wait should happen in less than 1ms |
242 // Test increases when thread allowed to run |
244 |
|
245 // Test cpu time increases when thread allowed to run |
|
246 // We want to allow 2% tolerance for the thread's CPU time, as there could be |
|
247 // something else running on the system during that time which would result lower CPU time than the |
|
248 // actual KShortPeriod or KLongPeriod wait time. |
|
249 // Also User::After(t) might return within the range of <t, t + 1000000/64 + 2*NanoKarnelTickPeriod>. |
|
250 // Given all that - we expect that the the cpu time should be within the range of: |
|
251 // <t - 0.02*t, t + 15625 + 2*NanoKernelTickPeriod> |
|
252 // or <0.98*t, t + 15625 + 2*NanoKernelTickPeriod> |
|
253 TInt user_after_tolerance = 0; |
|
254 HAL::Get(HAL::ENanoTickPeriod, user_after_tolerance); |
|
255 user_after_tolerance += user_after_tolerance + 15625; |
|
256 |
|
257 (threadParam.iSem).Signal(); |
243 (threadParam.iSem).Signal(); |
258 User::After(KShortWait); |
244 User::After(KShortWait); |
259 FailIfError(thread.GetCpuTime(time)); |
245 FailIfError(thread.GetCpuTime(time)); |
260 us = time.Int64() - time2.Int64(); |
246 test(time > (KShortWait - KTolerance)); |
261 test.Printf(_L("Time %dus\n"), us); |
|
262 test(100*us >= 98*KShortWait); // left limit |
|
263 test(us - KShortWait <= user_after_tolerance); // right limit |
|
264 |
|
265 FailIfError(thread.GetCpuTime(time)); |
|
266 User::After(KLongWait); |
|
267 FailIfError(thread.GetCpuTime(time2)); |
|
268 us = time2.Int64() - time.Int64(); |
|
269 test.Printf(_L("Time %dus\n"), us); |
|
270 test(100*us >= 98*KLongWait); // left limit |
|
271 test(us - KLongWait <= user_after_tolerance); // right limit |
|
272 |
247 |
273 // Test not increased while suspended |
248 // Test not increased while suspended |
274 thread.Suspend(); |
249 thread.Suspend(); |
275 FailIfError(thread.GetCpuTime(time)); |
250 FailIfError(thread.GetCpuTime(time)); |
276 User::After(KShortWait); |
251 User::After(KShortWait); |
277 FailIfError(thread.GetCpuTime(time2)); |
252 FailIfError(thread.GetCpuTime(time2)); |
278 test(time == time2); |
253 test(time == time2); |
279 thread.Resume(); |
254 thread.Resume(); |
280 |
255 |
281 // Test not increased while dead |
256 // Test not increased while dead |
282 thread.Kill(KErrNone); |
257 thread.Kill(KErrNone); |
283 User::WaitForRequest(s); // wait on undertaker since that completes in supervisor thread |
258 User::WaitForRequest(s); // wait on undertaker since that completes in supervisor thread |
284 FailIfError(thread.GetCpuTime(time)); |
259 FailIfError(thread.GetCpuTime(time)); |
285 User::After(KShortWait); |
260 User::After(KShortWait); |