0
|
1 |
// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// e32test\prime\t_timer.cpp
|
|
15 |
// Overview:
|
|
16 |
// Time and Timer tests.
|
|
17 |
// API Information:
|
|
18 |
// RTimer, TTime
|
|
19 |
// Details:
|
|
20 |
// - Test relative timers using the RTimer::After() method. Verify
|
|
21 |
// results are as expected.
|
|
22 |
// - Set the date and time using TTime::HomeTime() and verify results
|
|
23 |
// are as expected.
|
|
24 |
// - Test absolute timers using RTimer::At() method. Verify results
|
|
25 |
// are as expected.
|
|
26 |
// - Test the timer is ok if its thread terminates.
|
|
27 |
// - Test synchronising time via the RTimer::Lock() method. Verify
|
|
28 |
// results are as expected.
|
|
29 |
// - Test locked timers abort when the system time changes.
|
|
30 |
// - Test User::ResetInactivityTime() results are as expected.
|
|
31 |
// Platforms/Drives/Compatibility:
|
|
32 |
// All.
|
|
33 |
// Assumptions/Requirement/Pre-requisites:
|
|
34 |
// Failures and causes:
|
|
35 |
// Base Port information:
|
|
36 |
//
|
|
37 |
//
|
|
38 |
|
|
39 |
// the following was used to help debug emulator implemenation of user mode callbacks
|
|
40 |
//#define REQUEST_STATUS_POLL_SOAK_TEST
|
|
41 |
|
|
42 |
#define __E32TEST_EXTENSION__
|
|
43 |
|
|
44 |
#include <e32test.h>
|
|
45 |
#include <e32hal.h>
|
|
46 |
#include <e32panic.h>
|
|
47 |
#include <hal.h>
|
|
48 |
#include <e32power.h>
|
|
49 |
#include <e32math.h>
|
|
50 |
|
|
51 |
LOCAL_D RTest test(_L("T_TIMER"));
|
|
52 |
TInt MachineUid;
|
|
53 |
|
|
54 |
TInt AfterNegative(TAny*)
|
|
55 |
{
|
|
56 |
RTimer t;
|
|
57 |
TInt r=t.CreateLocal();
|
|
58 |
test(r==KErrNone);
|
|
59 |
TRequestStatus s;
|
|
60 |
t.After(s,-1);
|
|
61 |
return KErrNone;
|
|
62 |
}
|
|
63 |
|
|
64 |
TInt AfterTwice(TAny*)
|
|
65 |
{
|
|
66 |
RTimer t;
|
|
67 |
TInt r=t.CreateLocal();
|
|
68 |
test(r==KErrNone);
|
|
69 |
TRequestStatus s;
|
|
70 |
t.After(s,1000000);
|
|
71 |
test(s==KRequestPending);
|
|
72 |
t.After(s,1000000);
|
|
73 |
return KErrNone;
|
|
74 |
}
|
|
75 |
|
|
76 |
void PrintTime()
|
|
77 |
{
|
|
78 |
TTime now;
|
|
79 |
now.HomeTime();
|
|
80 |
TDateTime dt(now.DateTime());
|
|
81 |
test.Printf(_L("Time: %02d:%02d:%02d:%06d\n"),dt.Hour(),dt.Minute(),dt.Second(),dt.MicroSecond());
|
|
82 |
}
|
|
83 |
|
|
84 |
TBool RequestIsComplete(TRequestStatus& s)
|
|
85 |
{
|
|
86 |
return s != KRequestPending;
|
|
87 |
}
|
|
88 |
|
|
89 |
LOCAL_C void testRel()
|
|
90 |
//
|
|
91 |
// Test relative timers.
|
|
92 |
//
|
|
93 |
{
|
|
94 |
|
|
95 |
test.Start(_L("After 0"));
|
|
96 |
RTimer t;
|
|
97 |
TInt r=t.CreateLocal();
|
|
98 |
test(r==KErrNone);
|
|
99 |
TRequestStatus s;
|
|
100 |
t.After(s,0);
|
|
101 |
test(s==KRequestPending || s==KErrNone);
|
|
102 |
User::WaitForRequest(s);
|
|
103 |
test(s==KErrNone);
|
|
104 |
//
|
|
105 |
test.Next(_L("After 1 tenth"));
|
|
106 |
t.After(s,100000);
|
|
107 |
#ifdef __WINS__
|
|
108 |
// On WINS we can't guarantee thread scheduling so timer may already have
|
|
109 |
// completed before we get to test the status. Therefore, allow KErrNone.
|
|
110 |
test(s==KRequestPending || s==KErrNone);
|
|
111 |
if(s==KErrNone)
|
|
112 |
test.Printf(_L("NOTE: completed 'early'"));
|
|
113 |
#else
|
|
114 |
test(s==KRequestPending);
|
|
115 |
#endif
|
|
116 |
User::WaitForRequest(s);
|
|
117 |
test(s==KErrNone);
|
|
118 |
//
|
|
119 |
test.Next(_L("After -1 millionth"));
|
|
120 |
RThread thread;
|
|
121 |
r=thread.Create(_L("After -1"),AfterNegative,KDefaultStackSize,NULL,&thread);
|
|
122 |
test(r==KErrNone);
|
|
123 |
thread.Logon(s);
|
|
124 |
test(s==KRequestPending);
|
|
125 |
TBool justInTime=User::JustInTime();
|
|
126 |
User::SetJustInTime(EFalse);
|
|
127 |
thread.Resume();
|
|
128 |
User::WaitForRequest(s);
|
|
129 |
test(s==ERTimerAfterTimeNegative);
|
|
130 |
test(thread.ExitCategory()==_L("USER"));
|
|
131 |
test(thread.ExitReason()==ERTimerAfterTimeNegative);
|
|
132 |
test(thread.ExitType()==EExitPanic);
|
|
133 |
CLOSE_AND_WAIT(thread);
|
|
134 |
User::SetJustInTime(justInTime);
|
|
135 |
//
|
|
136 |
test.Next(_L("After 1 second"));
|
|
137 |
t.After(s,1000000);
|
|
138 |
test(s==KRequestPending);
|
|
139 |
User::WaitForRequest(s);
|
|
140 |
test(s==KErrNone);
|
|
141 |
//
|
|
142 |
test.Next(_L("After 1 second polling"));
|
|
143 |
t.After(s,1000000);
|
|
144 |
test(s==KRequestPending);
|
|
145 |
// Have to be careful the compiler doesn't optimise this away
|
|
146 |
while(!RequestIsComplete(s))
|
|
147 |
; // poll
|
|
148 |
test(s==KErrNone);
|
|
149 |
User::WaitForRequest(s);
|
|
150 |
//
|
|
151 |
test.Next(_L("Cancel"));
|
|
152 |
t.After(s,1000000);
|
|
153 |
test(s==KRequestPending);
|
|
154 |
t.Cancel();
|
|
155 |
User::WaitForRequest(s);
|
|
156 |
test(s==KErrCancel);
|
|
157 |
t.Close();
|
|
158 |
//
|
|
159 |
test.Next(_L("Request twice"));
|
|
160 |
r=thread.Create(_L("After twice"),AfterTwice,KDefaultStackSize,NULL,&thread);
|
|
161 |
test(r==KErrNone);
|
|
162 |
thread.Logon(s);
|
|
163 |
test(s==KRequestPending);
|
|
164 |
User::SetJustInTime(EFalse);
|
|
165 |
thread.Resume();
|
|
166 |
User::WaitForRequest(s);
|
|
167 |
test(s==ETimerAlreadyPending);
|
|
168 |
test(thread.ExitCategory()==_L("KERN-EXEC"));
|
|
169 |
test(thread.ExitReason()==ETimerAlreadyPending);
|
|
170 |
test(thread.ExitType()==EExitPanic);
|
|
171 |
CLOSE_AND_WAIT(thread);
|
|
172 |
User::SetJustInTime(justInTime);
|
|
173 |
//
|
|
174 |
test.End();
|
|
175 |
}
|
|
176 |
|
|
177 |
#ifdef REQUEST_STATUS_POLL_SOAK_TEST
|
|
178 |
|
|
179 |
static volatile TBool PollTestRunning;
|
|
180 |
|
|
181 |
LOCAL_C TInt PollThread(TAny* aArg)
|
|
182 |
{
|
|
183 |
const TInt KMaxTimers = 1000;
|
|
184 |
|
|
185 |
TInt threadIndex = (TInt)aArg;
|
|
186 |
TInt64 seed = 5511498647534504549 + RThread().Id();
|
|
187 |
RTimer timers[KMaxTimers];
|
|
188 |
TRequestStatus statuses[KMaxTimers];
|
|
189 |
|
|
190 |
TInt i;
|
|
191 |
for (i = 0 ; i < KMaxTimers ; ++i)
|
|
192 |
{
|
|
193 |
test_KErrNone(timers[i].CreateLocal());
|
|
194 |
statuses[i] = 1;
|
|
195 |
}
|
|
196 |
|
|
197 |
TInt totalComplete = 0;
|
|
198 |
TInt totalWaiting = 0;
|
|
199 |
|
|
200 |
while(PollTestRunning)
|
|
201 |
{
|
|
202 |
for (i = 0 ; i < KMaxTimers ; ++i)
|
|
203 |
{
|
|
204 |
switch(statuses[i].Int())
|
|
205 |
{
|
|
206 |
case KRequestPending:
|
|
207 |
// do nothing
|
|
208 |
++totalWaiting;
|
|
209 |
break;
|
|
210 |
|
|
211 |
case KErrNone:
|
|
212 |
User::WaitForRequest(statuses[i]);
|
|
213 |
++totalComplete;
|
|
214 |
// fall through
|
|
215 |
|
|
216 |
case 1:
|
|
217 |
{
|
|
218 |
TInt after = ((TUint)Math::Rand(seed) >> 28) + 1;
|
|
219 |
timers[i].HighRes(statuses[i], after);
|
|
220 |
}
|
|
221 |
break;
|
|
222 |
|
|
223 |
default:
|
|
224 |
return statuses[i].Int();
|
|
225 |
}
|
|
226 |
}
|
|
227 |
}
|
|
228 |
|
|
229 |
for (i = 0 ; i < KMaxTimers ; ++i)
|
|
230 |
{
|
|
231 |
User::WaitForRequest(statuses[i]);
|
|
232 |
if (statuses[i].Int() != KErrNone)
|
|
233 |
return statuses[i].Int();
|
|
234 |
timers[i].Close();
|
|
235 |
}
|
|
236 |
|
|
237 |
RDebug::Printf("%d: %d %d\n", threadIndex, totalComplete, totalWaiting);
|
|
238 |
return KErrNone;
|
|
239 |
}
|
|
240 |
|
|
241 |
LOCAL_C void testPoll()
|
|
242 |
{
|
|
243 |
const TInt KMaxThreads = 10;
|
|
244 |
const TInt KSecondsToTest = 60;
|
|
245 |
|
|
246 |
RThread threads[KMaxThreads];
|
|
247 |
TRequestStatus statuses[KMaxThreads];
|
|
248 |
|
|
249 |
test.Start(_L("Test polling"));
|
|
250 |
|
|
251 |
PollTestRunning = ETrue;
|
|
252 |
|
|
253 |
TInt i;
|
|
254 |
for (i = 0 ; i < KMaxThreads ; ++i)
|
|
255 |
{
|
|
256 |
test_KErrNone(threads[i].Create(KNullDesC, PollThread, 0x1000, NULL, (TAny*)i));
|
|
257 |
threads[i].Logon(statuses[i]);
|
|
258 |
threads[i].Resume();
|
|
259 |
}
|
|
260 |
|
|
261 |
User::After(KSecondsToTest * 1000 * 1000);
|
|
262 |
|
|
263 |
PollTestRunning = EFalse;
|
|
264 |
|
|
265 |
for (i = 0 ; i < KMaxThreads ; ++i)
|
|
266 |
{
|
|
267 |
User::WaitForRequest(statuses[i]);
|
|
268 |
test_KErrNone(statuses[i].Int());
|
|
269 |
test_Equal(EExitKill, threads[i].ExitType());
|
|
270 |
threads[i].Close();
|
|
271 |
}
|
|
272 |
|
|
273 |
test.End();
|
|
274 |
}
|
|
275 |
|
|
276 |
#endif
|
|
277 |
|
|
278 |
LOCAL_C void testHomeTime()
|
|
279 |
//
|
|
280 |
// Test HomeTime.
|
|
281 |
//
|
|
282 |
{
|
|
283 |
|
|
284 |
TTime t1, t2;
|
|
285 |
t1.HomeTime();
|
|
286 |
for (TInt x=0;x<100;x++)
|
|
287 |
{
|
|
288 |
do
|
|
289 |
{
|
|
290 |
t2.HomeTime();
|
|
291 |
}
|
|
292 |
while (t2==t1);
|
|
293 |
#if defined(_DEBUG)
|
|
294 |
TDateTime dt=t2.DateTime();
|
|
295 |
test.Printf(_L("%d:%d\r\n"),dt.Second(),dt.MicroSecond());
|
|
296 |
#endif
|
|
297 |
test(t2>t1);
|
|
298 |
t1=t2;
|
|
299 |
}
|
|
300 |
#if defined(_DEBUG)
|
|
301 |
test.Printf(_L("\r\n"));
|
|
302 |
#endif
|
|
303 |
}
|
|
304 |
|
|
305 |
TInt AtTwice(TAny*)
|
|
306 |
{
|
|
307 |
RTimer t;
|
|
308 |
TInt r=t.CreateLocal();
|
|
309 |
test(r==KErrNone);
|
|
310 |
TRequestStatus s;
|
|
311 |
TTime time;
|
|
312 |
time.UniversalTime();
|
|
313 |
t.AtUTC(s,time+TTimeIntervalSeconds(1));
|
|
314 |
test(s==KRequestPending);
|
|
315 |
t.AtUTC(s,time+TTimeIntervalSeconds(2));
|
|
316 |
return KErrNone;
|
|
317 |
}
|
|
318 |
|
|
319 |
TInt AtAfter(TAny*)
|
|
320 |
{
|
|
321 |
RTimer t;
|
|
322 |
TInt r=t.CreateLocal();
|
|
323 |
test(r==KErrNone);
|
|
324 |
TRequestStatus s;
|
|
325 |
TTime time;
|
|
326 |
time.UniversalTime();
|
|
327 |
t.AtUTC(s,time+TTimeIntervalSeconds(1));
|
|
328 |
test(s==KRequestPending);
|
|
329 |
t.After(s,1000000);
|
|
330 |
return KErrNone;
|
|
331 |
}
|
|
332 |
|
|
333 |
TInt AfterAt(TAny*)
|
|
334 |
{
|
|
335 |
RTimer t;
|
|
336 |
TInt r=t.CreateLocal();
|
|
337 |
test(r==KErrNone);
|
|
338 |
TRequestStatus s;
|
|
339 |
TTime time;
|
|
340 |
time.UniversalTime();
|
|
341 |
t.After(s,1000000);
|
|
342 |
test(s==KRequestPending);
|
|
343 |
t.AtUTC(s,time+TTimeIntervalSeconds(2));
|
|
344 |
return KErrNone;
|
|
345 |
}
|
|
346 |
|
|
347 |
LOCAL_C void testAbs()
|
|
348 |
//
|
|
349 |
// Test absolute timers.
|
|
350 |
//
|
|
351 |
{
|
|
352 |
|
|
353 |
test.Start(_L("Now -1"));
|
|
354 |
RTimer t;
|
|
355 |
TInt r=t.CreateLocal();
|
|
356 |
test(r==KErrNone);
|
|
357 |
TRequestStatus s;
|
|
358 |
TTime time;
|
|
359 |
time.UniversalTime();
|
|
360 |
t.AtUTC(s,time+TTimeIntervalSeconds(-2));
|
|
361 |
test(s==KErrUnderflow); // =KRequestPending
|
|
362 |
User::WaitForRequest(s);
|
|
363 |
test(s==KErrUnderflow);
|
|
364 |
//
|
|
365 |
TTime time2;
|
|
366 |
test.Next(_L("Synchronise to clock"));
|
|
367 |
time.UniversalTime();
|
|
368 |
TDateTime dateTime=time.DateTime();
|
|
369 |
dateTime.SetMicroSecond(0);
|
|
370 |
time=dateTime;
|
|
371 |
time+=TTimeIntervalSeconds(2);
|
|
372 |
t.AtUTC(s,time);
|
|
373 |
User::WaitForRequest(s);
|
|
374 |
|
|
375 |
test.Next(_L("Now +1"));
|
|
376 |
time += TTimeIntervalSeconds(1);
|
|
377 |
t.AtUTC(s,time);
|
|
378 |
test(s==KRequestPending);
|
|
379 |
User::WaitForRequest(s);
|
|
380 |
time2.UniversalTime();
|
|
381 |
test(s==KErrNone);
|
|
382 |
TTimeIntervalMicroSeconds delay=time2.MicroSecondsFrom(time);
|
|
383 |
// Test we are in the same second as the requested time...
|
|
384 |
test(delay>=TTimeIntervalMicroSeconds(0));
|
|
385 |
test(delay<TTimeIntervalMicroSeconds(1000000));
|
|
386 |
|
|
387 |
test.Next(_L("Now +3"));
|
|
388 |
time += TTimeIntervalSeconds(3);
|
|
389 |
t.AtUTC(s,time);
|
|
390 |
test(s==KRequestPending);
|
|
391 |
User::WaitForRequest(s);
|
|
392 |
time2.UniversalTime();
|
|
393 |
test(s==KErrNone);
|
|
394 |
delay=time2.MicroSecondsFrom(time);
|
|
395 |
// Test we are in the same second as the requested time...
|
|
396 |
test(delay>=TTimeIntervalMicroSeconds(0));
|
|
397 |
test(delay<TTimeIntervalMicroSeconds(1000000));
|
|
398 |
//
|
|
399 |
test.Next(_L("UTC vs local"));
|
|
400 |
TTimeIntervalSeconds savedOffset = User::UTCOffset();
|
|
401 |
User::SetUTCOffset(3600);
|
|
402 |
|
|
403 |
time.HomeTime();
|
|
404 |
time += TTimeIntervalSeconds(1);
|
|
405 |
t.At(s,time);
|
|
406 |
test(s==KRequestPending);
|
|
407 |
User::WaitForRequest(s);
|
|
408 |
time2.HomeTime();
|
|
409 |
test(s==KErrNone);
|
|
410 |
delay=time2.MicroSecondsFrom(time);
|
|
411 |
// Test we are in the same second as the requested time...
|
|
412 |
test(delay>=TTimeIntervalMicroSeconds(0));
|
|
413 |
test(delay<TTimeIntervalMicroSeconds(1000000));
|
|
414 |
|
|
415 |
time.UniversalTime();
|
|
416 |
time += TTimeIntervalSeconds(1);
|
|
417 |
t.AtUTC(s,time);
|
|
418 |
test(s==KRequestPending);
|
|
419 |
User::WaitForRequest(s);
|
|
420 |
time2.UniversalTime();
|
|
421 |
test(s==KErrNone);
|
|
422 |
delay=time2.MicroSecondsFrom(time);
|
|
423 |
// Test we are in the same second as the requested time...
|
|
424 |
test(delay>=TTimeIntervalMicroSeconds(0));
|
|
425 |
test(delay<TTimeIntervalMicroSeconds(1000000));
|
|
426 |
|
|
427 |
User::SetUTCOffset(savedOffset);
|
|
428 |
//
|
|
429 |
test.Next(_L("Cancel"));
|
|
430 |
time.UniversalTime();
|
|
431 |
t.AtUTC(s,time+TTimeIntervalSeconds(10));
|
|
432 |
test(s==KRequestPending);
|
|
433 |
t.Cancel();
|
|
434 |
User::WaitForRequest(s);
|
|
435 |
test(s==KErrCancel);
|
|
436 |
t.Close();
|
|
437 |
//
|
|
438 |
test.Next(_L("Request twice"));
|
|
439 |
RThread thread;
|
|
440 |
r=thread.Create(_L("At twice"),AtTwice,KDefaultStackSize,NULL,&thread);
|
|
441 |
test(r==KErrNone);
|
|
442 |
thread.Logon(s);
|
|
443 |
test(s==KRequestPending);
|
|
444 |
TBool justInTime=User::JustInTime();
|
|
445 |
User::SetJustInTime(EFalse);
|
|
446 |
thread.Resume();
|
|
447 |
User::WaitForRequest(s);
|
|
448 |
User::SetJustInTime(justInTime);
|
|
449 |
test(s==ETimerAlreadyPending);
|
|
450 |
test(thread.ExitCategory()==_L("KERN-EXEC"));
|
|
451 |
test(thread.ExitReason()==ETimerAlreadyPending);
|
|
452 |
test(thread.ExitType()==EExitPanic);
|
|
453 |
CLOSE_AND_WAIT(thread);
|
|
454 |
//
|
|
455 |
r=thread.Create(_L("At After"),AtAfter,KDefaultStackSize,NULL,&thread);
|
|
456 |
test(r==KErrNone);
|
|
457 |
thread.Logon(s);
|
|
458 |
test(s==KRequestPending);
|
|
459 |
User::SetJustInTime(EFalse);
|
|
460 |
thread.Resume();
|
|
461 |
User::WaitForRequest(s);
|
|
462 |
User::SetJustInTime(justInTime);
|
|
463 |
test(s==ETimerAlreadyPending);
|
|
464 |
test(thread.ExitCategory()==_L("KERN-EXEC"));
|
|
465 |
test(thread.ExitReason()==ETimerAlreadyPending);
|
|
466 |
test(thread.ExitType()==EExitPanic);
|
|
467 |
CLOSE_AND_WAIT(thread);
|
|
468 |
//
|
|
469 |
r=thread.Create(_L("After At"),AfterAt,KDefaultStackSize,NULL,&thread);
|
|
470 |
test(r==KErrNone);
|
|
471 |
thread.Logon(s);
|
|
472 |
test(s==KRequestPending);
|
|
473 |
User::SetJustInTime(EFalse);
|
|
474 |
thread.Resume();
|
|
475 |
User::WaitForRequest(s);
|
|
476 |
User::SetJustInTime(justInTime);
|
|
477 |
test(s==ETimerAlreadyPending);
|
|
478 |
test(thread.ExitCategory()==_L("KERN-EXEC"));
|
|
479 |
test(thread.ExitReason()==ETimerAlreadyPending);
|
|
480 |
test(thread.ExitType()==EExitPanic);
|
|
481 |
CLOSE_AND_WAIT(thread);
|
|
482 |
//
|
|
483 |
test.End();
|
|
484 |
}
|
|
485 |
|
|
486 |
TInt LockTwice(TAny*)
|
|
487 |
{
|
|
488 |
RTimer t;
|
|
489 |
test(t.CreateLocal()==KErrNone);
|
|
490 |
TRequestStatus stat;
|
|
491 |
t.Lock(stat, ETwelveOClock);
|
|
492 |
User::WaitForRequest(stat);
|
|
493 |
test(stat==KErrGeneral);
|
|
494 |
t.Lock(stat, ETwelveOClock);
|
|
495 |
t.Lock(stat, ETwelveOClock);
|
|
496 |
return KErrNone;
|
|
497 |
}
|
|
498 |
|
|
499 |
LOCAL_C void testLock()
|
|
500 |
//
|
|
501 |
// Test locked timers
|
|
502 |
//
|
|
503 |
{
|
|
504 |
|
|
505 |
test.Start(_L("Test synchronise to ETwelveOClock"));
|
|
506 |
RTimer t;
|
|
507 |
TTime time,time2;
|
|
508 |
test(t.CreateLocal()==KErrNone);
|
|
509 |
TRequestStatus stat;
|
|
510 |
t.Lock(stat, ETwelveOClock);
|
|
511 |
User::WaitForRequest(stat);
|
|
512 |
test(stat==KErrGeneral);
|
|
513 |
time.UniversalTime();
|
|
514 |
t.Lock(stat, ETwelveOClock);
|
|
515 |
User::WaitForRequest(stat);
|
|
516 |
test(stat==KErrNone);
|
|
517 |
time2.UniversalTime();
|
|
518 |
test(time<time2);
|
|
519 |
User::After(500000);
|
|
520 |
test.Next(_L("Test sync to EOneOClock for 4 seconds"));
|
|
521 |
t.Lock(stat, EOneOClock);
|
|
522 |
User::WaitForRequest(stat);
|
|
523 |
test(stat==KErrGeneral);
|
|
524 |
time.UniversalTime();
|
|
525 |
TInt i;
|
|
526 |
for (i=0; i<5; i++)
|
|
527 |
{
|
|
528 |
t.Lock(stat, EOneOClock);
|
|
529 |
User::WaitForRequest(stat);
|
|
530 |
test(stat==KErrNone);
|
|
531 |
test.Printf(_L("."));
|
|
532 |
}
|
|
533 |
time2.UniversalTime();
|
|
534 |
TTimeIntervalSeconds ti;
|
|
535 |
test(time2.SecondsFrom(time, ti)==KErrNone);
|
|
536 |
test(ti>=TTimeIntervalSeconds(4));
|
|
537 |
test.Printf(_L("\n"));
|
|
538 |
test.Next(_L("Test sync to every half second, from EFourOClock for 5 seconds"));
|
|
539 |
t.Lock(stat, ETwelveOClock);
|
|
540 |
User::WaitForRequest(stat);
|
|
541 |
for (i=0; i<5; i++)
|
|
542 |
{
|
|
543 |
t.Lock(stat, EFourOClock);
|
|
544 |
User::WaitForRequest(stat);
|
|
545 |
test(stat==KErrNone);
|
|
546 |
test.Printf(_L("."));
|
|
547 |
t.Lock(stat, ETenOClock);
|
|
548 |
User::WaitForRequest(stat);
|
|
549 |
test(stat==KErrNone);
|
|
550 |
test.Printf(_L(","));
|
|
551 |
}
|
|
552 |
test.Printf(_L("\n"));
|
|
553 |
test.Next(_L("Test KErrGeneral after delay"));
|
|
554 |
User::After(1000000);
|
|
555 |
t.Lock(stat,EThreeOClock);
|
|
556 |
User::WaitForRequest(stat);
|
|
557 |
test(stat==KErrGeneral);
|
|
558 |
test.Next(_L("Test cancel, and re-request immediately"));
|
|
559 |
User::After(1000000);
|
|
560 |
t.Lock(stat, ETwelveOClock);
|
|
561 |
User::WaitForRequest(stat);
|
|
562 |
test(stat==KErrGeneral);
|
|
563 |
t.Lock(stat, EElevenOClock);
|
|
564 |
t.Cancel();
|
|
565 |
User::WaitForRequest(stat);
|
|
566 |
test(stat==KErrCancel);
|
|
567 |
t.Lock(stat, EElevenOClock);
|
|
568 |
User::WaitForRequest(stat);
|
|
569 |
test(stat==KErrNone);
|
|
570 |
test.Next(_L("Test complete a request at 1, then cancel a request for 11, and re-request at 3 gives KErrGeneral"));
|
|
571 |
User::After(1000000);
|
|
572 |
t.Lock(stat, ETwelveOClock);
|
|
573 |
User::WaitForRequest(stat);
|
|
574 |
test(stat==KErrGeneral);
|
|
575 |
t.Lock(stat,EOneOClock);
|
|
576 |
User::WaitForRequest(stat);
|
|
577 |
test(stat==KErrNone);
|
|
578 |
t.Lock(stat,EElevenOClock);
|
|
579 |
User::After(400000); // ensure EThreeOClock is in the past
|
|
580 |
t.Cancel();
|
|
581 |
User::WaitForRequest(stat);
|
|
582 |
test(stat==KErrCancel);
|
|
583 |
t.Lock(stat,EThreeOClock);
|
|
584 |
User::WaitForRequest(stat);
|
|
585 |
// EThreeOClock should be more than one second away from the previous timer expiration
|
|
586 |
test(stat==KErrGeneral);
|
|
587 |
//
|
|
588 |
test.Next(_L("Lock twice"));
|
|
589 |
RThread thread;
|
|
590 |
TInt r=thread.Create(_L("Lock twice"),LockTwice,KDefaultStackSize,NULL,&thread);
|
|
591 |
test(r==KErrNone);
|
|
592 |
thread.Logon(stat);
|
|
593 |
test(stat==KRequestPending);
|
|
594 |
TBool justInTime=User::JustInTime();
|
|
595 |
User::SetJustInTime(EFalse);
|
|
596 |
thread.Resume();
|
|
597 |
User::WaitForRequest(stat);
|
|
598 |
User::SetJustInTime(justInTime);
|
|
599 |
test(stat==ETimerAlreadyPending);
|
|
600 |
test(thread.ExitCategory()==_L("KERN-EXEC"));
|
|
601 |
test(thread.ExitReason()==ETimerAlreadyPending);
|
|
602 |
test(thread.ExitType()==EExitPanic);
|
|
603 |
CLOSE_AND_WAIT(thread);
|
|
604 |
//
|
|
605 |
|
|
606 |
#if !(defined(__EPOC32__) && defined(__X86__))
|
|
607 |
TInt muid = 0;
|
|
608 |
HAL::Get(HAL::EMachineUid, muid);
|
|
609 |
if(muid!=HAL::EMachineUid_Lubbock && muid!=HAL::EMachineUid_NE1_TB)
|
|
610 |
{
|
|
611 |
test.Next(_L("Test sequential locks fail over on/off"));
|
|
612 |
RTimer tat;
|
|
613 |
TRequestStatus sat;
|
|
614 |
r=tat.CreateLocal();
|
|
615 |
TTime now;
|
|
616 |
now.UniversalTime();
|
|
617 |
tat.At(sat, now+TTimeIntervalSeconds(10)); // turn on in 10 seconds
|
|
618 |
t.Lock(stat, ETwelveOClock);
|
|
619 |
User::WaitForRequest(stat);
|
|
620 |
test(stat==KErrGeneral);
|
|
621 |
t.Lock(stat, EElevenOClock);
|
|
622 |
User::WaitForRequest(stat);
|
|
623 |
PrintTime();
|
|
624 |
// Go to standby
|
|
625 |
r = Power::EnableWakeupEvents(EPwStandby);
|
|
626 |
test (r == KErrNone);
|
|
627 |
r = Power::PowerDown();
|
|
628 |
test (r == KErrNone);
|
|
629 |
test(stat==KErrNone);
|
|
630 |
PrintTime();
|
|
631 |
t.Lock(stat, EElevenOClock);
|
|
632 |
User::WaitForRequest(stat);
|
|
633 |
test(stat==KErrGeneral);
|
|
634 |
tat.Close();
|
|
635 |
}
|
|
636 |
#endif
|
|
637 |
|
|
638 |
t.Close();
|
|
639 |
test.End();
|
|
640 |
}
|
|
641 |
|
|
642 |
|
|
643 |
void testChange()
|
|
644 |
//
|
|
645 |
// Bug HA-255
|
|
646 |
// Test locked timers abort when the system time changes
|
|
647 |
//
|
|
648 |
{
|
|
649 |
|
|
650 |
RTimer rr;
|
|
651 |
TRequestStatus stat;
|
|
652 |
rr.CreateLocal();
|
|
653 |
rr.Lock(stat, ETwelveOClock);
|
|
654 |
User::WaitForRequest(stat);
|
|
655 |
test(stat==KErrGeneral);
|
|
656 |
RTimer rrr;
|
|
657 |
rrr.CreateLocal();
|
|
658 |
rrr.After(stat, 1000000);
|
|
659 |
User::WaitForRequest(stat);
|
|
660 |
|
|
661 |
RTimer r;
|
|
662 |
TRequestStatus sstat;
|
|
663 |
TTime t;
|
|
664 |
r.CreateLocal();
|
|
665 |
r.Lock(stat,ETwelveOClock);
|
|
666 |
rr.Lock(sstat,EOneOClock);
|
|
667 |
User::WaitForRequest(stat);
|
|
668 |
test(stat==KErrGeneral);
|
|
669 |
User::WaitForRequest(sstat);
|
|
670 |
test(sstat==KErrGeneral);
|
|
671 |
r.Lock(stat,ETwelveOClock);
|
|
672 |
rr.Lock(sstat,EOneOClock);
|
|
673 |
User::WaitForRequest(stat);
|
|
674 |
test(stat==KErrNone);
|
|
675 |
User::WaitForRequest(sstat);
|
|
676 |
test(sstat==KErrNone);
|
|
677 |
t.UniversalTime();
|
|
678 |
r.Lock(stat,ETwelveOClock);
|
|
679 |
rr.Lock(sstat,EOneOClock);
|
|
680 |
TInt ret=User::SetUTCTime(t-TTimeIntervalSeconds(100));
|
|
681 |
test(ret==KErrNone);
|
|
682 |
t.UniversalTime();
|
|
683 |
ret=User::SetUTCTime(t+TTimeIntervalSeconds(100));
|
|
684 |
test(ret==KErrNone);
|
|
685 |
User::WaitForRequest(stat);
|
|
686 |
test(stat==KErrAbort);
|
|
687 |
User::WaitForRequest(sstat);
|
|
688 |
test(sstat==KErrAbort);
|
|
689 |
|
|
690 |
// Check that changing the *secure* time *doesn't* abort a locked timer
|
|
691 |
r.Lock(stat, ETwelveOClock);
|
|
692 |
User::WaitForRequest(stat); // stat will be KErrGeneral after abort above, but time will be TwelveOClock anyway
|
|
693 |
t.UniversalTimeSecure();
|
|
694 |
r.Lock(stat, EEightOClock);
|
|
695 |
ret = User::SetUTCTimeSecure(t+TTimeIntervalSeconds(100));
|
|
696 |
User::WaitForRequest(stat); // this timer should complete at EightOClock with status KErrNone, *not* KErrAbort
|
|
697 |
r.Lock(sstat, ETwelveOClock);
|
|
698 |
User::WaitForRequest(sstat); // this should complete one whole second after we read the secure time above
|
|
699 |
User::SetUTCTimeSecure(t+TTimeIntervalSeconds(1));
|
|
700 |
test(stat == KErrNone);
|
|
701 |
test(sstat == KErrNone);
|
|
702 |
if (ret != KErrNone)
|
|
703 |
RDebug::Printf("WARNING: Secure clock change test skipped because secure time could not be changed!");
|
|
704 |
|
|
705 |
r.Close();
|
|
706 |
rr.Close();
|
|
707 |
rrr.Close();
|
|
708 |
}
|
|
709 |
|
|
710 |
void testInactivity()
|
|
711 |
//
|
|
712 |
//
|
|
713 |
//
|
|
714 |
{
|
|
715 |
|
|
716 |
test.Start(_L("Test User::ResetInactivityTime()"));
|
|
717 |
RTimer t,t2;
|
|
718 |
TRequestStatus stat,stat2;
|
|
719 |
t.CreateLocal();
|
|
720 |
t2.CreateLocal();
|
|
721 |
User::ResetInactivityTime();
|
|
722 |
t.Inactivity(stat, 4);
|
|
723 |
t2.Inactivity(stat2, 2);
|
|
724 |
TTime now;
|
|
725 |
now.UniversalTime();
|
|
726 |
TInt r=User::SetUTCTime(now+TTimeIntervalDays(1));
|
|
727 |
test(r==KErrNone);
|
|
728 |
test(stat==KRequestPending);
|
|
729 |
test(stat2==KRequestPending);
|
|
730 |
r=User::SetUTCTime(now-TTimeIntervalDays(1));
|
|
731 |
test(r==KErrNone);
|
|
732 |
test(stat==KRequestPending);
|
|
733 |
test(stat2==KRequestPending);
|
|
734 |
r=User::SetUTCTime(now);
|
|
735 |
test(r==KErrNone);
|
|
736 |
test(stat==KRequestPending);
|
|
737 |
test(stat2==KRequestPending);
|
|
738 |
User::After(1000000);
|
|
739 |
User::ResetInactivityTime();
|
|
740 |
test(stat==KRequestPending);
|
|
741 |
test(stat2==KRequestPending);
|
|
742 |
User::After(3000000);
|
|
743 |
User::ResetInactivityTime();
|
|
744 |
test(stat==KRequestPending);
|
|
745 |
test(stat2!=KRequestPending);
|
|
746 |
User::After(2000000);
|
|
747 |
User::ResetInactivityTime();
|
|
748 |
test(stat==KRequestPending);
|
|
749 |
User::After(2000000);
|
|
750 |
User::ResetInactivityTime();
|
|
751 |
test(stat==KRequestPending);
|
|
752 |
User::After(5000000);
|
|
753 |
test(stat!=KRequestPending);
|
|
754 |
test.End();
|
|
755 |
}
|
|
756 |
|
|
757 |
GLDEF_C TInt E32Main()
|
|
758 |
//
|
|
759 |
// Test timers.
|
|
760 |
//
|
|
761 |
{
|
|
762 |
|
|
763 |
test.Title();
|
|
764 |
TInt r=HAL::Get(HAL::EMachineUid,MachineUid);
|
|
765 |
test(r==KErrNone);
|
|
766 |
test.Start(_L("Testing relative timers"));
|
|
767 |
testRel();
|
|
768 |
//
|
|
769 |
#ifdef REQUEST_STATUS_POLL_SOAK_TEST
|
|
770 |
test.Next(_L("Testing polling"));
|
|
771 |
testPoll();
|
|
772 |
#endif
|
|
773 |
//
|
|
774 |
test.Next(_L("Testing HomeTime()"));
|
|
775 |
testHomeTime();
|
|
776 |
//
|
|
777 |
test.Next(_L("Testing absolute timers"));
|
|
778 |
testAbs();
|
|
779 |
//
|
|
780 |
test.Next(_L("Testing locked timers"));
|
|
781 |
testLock();
|
|
782 |
//
|
|
783 |
test.Next(_L("Testing changing time"));
|
|
784 |
testChange();
|
|
785 |
//
|
|
786 |
test.Next(_L("Testing inactivity timers"));
|
|
787 |
testInactivity();
|
|
788 |
//
|
|
789 |
test.End();
|
|
790 |
return(KErrNone);
|
|
791 |
}
|
|
792 |
|