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 TUint us; |
231 TInt64 us; |
232 |
232 |
233 // Test time is initially zero |
233 // Test cpu time is initially zero |
234 FailIfError(thread.GetCpuTime(time)); |
234 FailIfError(thread.GetCpuTime(time)); |
235 test(time == 0); |
235 test(time == 0); |
236 |
236 |
237 // Test not increased while waiting on semaphore |
237 // Test cpu time is not increased while thread is waiting on semaphore |
238 thread.Resume(); |
238 thread.Resume(); |
239 User::After(KShortWait); |
239 User::After(KShortWait); |
240 FailIfError(thread.GetCpuTime(time)); |
240 FailIfError(thread.GetCpuTime(time2)); |
241 us = I64LOW(time.Int64()); |
241 us = time2.Int64(); |
242 test.Printf(_L("Time %dus\n"), us); |
242 test.Printf(_L("Time %dus\n"), us); |
243 test(time < KTolerance); // wait happens in less than 0.5ms |
243 test(us < KTolerance); // wait should happen in less than 1ms |
244 |
244 |
245 // Test increases when thread allowed to run |
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 |
246 (threadParam.iSem).Signal(); |
257 (threadParam.iSem).Signal(); |
247 User::After(KShortWait); |
258 User::After(KShortWait); |
248 FailIfError(thread.GetCpuTime(time)); |
259 FailIfError(thread.GetCpuTime(time)); |
249 us = I64LOW(time.Int64()); |
260 us = time.Int64() - time2.Int64(); |
250 test.Printf(_L("Time %dus\n"), us); |
261 test.Printf(_L("Time %dus\n"), us); |
251 test(time > (KShortWait - KTolerance)); |
262 test(100*us >= 98*KShortWait); // left limit |
|
263 test(us - KShortWait <= user_after_tolerance); // right limit |
|
264 |
|
265 FailIfError(thread.GetCpuTime(time)); |
252 User::After(KLongWait); |
266 User::After(KLongWait); |
253 FailIfError(thread.GetCpuTime(time2)); |
267 FailIfError(thread.GetCpuTime(time2)); |
254 us = I64LOW(time2.Int64()); |
268 us = time2.Int64() - time.Int64(); |
255 test.Printf(_L("Time %dus\n"), us); |
269 test.Printf(_L("Time %dus\n"), us); |
256 test(time2.Int64() - time.Int64() > (KLongWait - KTolerance)); |
270 test(100*us >= 98*KLongWait); // left limit |
|
271 test(us - KLongWait <= user_after_tolerance); // right limit |
257 |
272 |
258 // Test not increased while suspended |
273 // Test not increased while suspended |
259 thread.Suspend(); |
274 thread.Suspend(); |
260 FailIfError(thread.GetCpuTime(time)); |
275 FailIfError(thread.GetCpuTime(time)); |
261 User::After(KShortWait); |
276 User::After(KShortWait); |
262 FailIfError(thread.GetCpuTime(time2)); |
277 FailIfError(thread.GetCpuTime(time2)); |
263 test(time == time2); |
278 test(time == time2); |
264 thread.Resume(); |
279 thread.Resume(); |
265 |
280 |
266 // Test not increased while dead |
281 // Test not increased while dead |
267 thread.Kill(KErrNone); |
282 thread.Kill(KErrNone); |
268 User::WaitForRequest(s); // wait on undertaker since that completes in supervisor thread |
283 User::WaitForRequest(s); // wait on undertaker since that completes in supervisor thread |
269 FailIfError(thread.GetCpuTime(time)); |
284 FailIfError(thread.GetCpuTime(time)); |
270 User::After(KShortWait); |
285 User::After(KShortWait); |