author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 21 Jun 2010 17:12:14 +0300 | |
branch | RCL_3 |
changeset 198 | 2bb754abd467 |
parent 87 | 2f92ad2dc5db |
permissions | -rw-r--r-- |
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: |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
36 |
// |
0 | 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 |
||
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
89 |
|
0 | 90 |
LOCAL_C void testRel() |
91 |
// |
|
92 |
// Test relative timers. |
|
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); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
104 |
|
0 | 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); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
118 |
|
0 | 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); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
135 |
|
0 | 136 |
test.Next(_L("After 1 second")); |
137 |
t.After(s,1000000); |
|
138 |
test(s==KRequestPending); |
|
139 |
User::WaitForRequest(s); |
|
140 |
test(s==KErrNone); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
141 |
|
0 | 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); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
150 |
|
0 | 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(); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
158 |
|
0 | 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); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
173 |
|
0 | 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; |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
199 |
|
0 | 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; |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
210 |
|
0 | 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 |
} |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
228 |
|
0 | 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]; |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
248 |
|
0 | 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); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
262 |
|
0 | 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 |
} |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
272 |
|
0 | 273 |
test.End(); |
274 |
} |
|
275 |
||
276 |
#endif |
|
277 |
||
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
278 |
|
0 | 279 |
LOCAL_C void testHomeTime() |
280 |
// |
|
281 |
// Test HomeTime. |
|
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); |
|
198
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
87
diff
changeset
|
293 |
|
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
87
diff
changeset
|
294 |
if (t2 <= t1 && t1.MicroSecondsFrom(t2) > TTimeIntervalMicroSeconds(1000)) // HomeTime() only operates at ms precision |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
87
diff
changeset
|
295 |
{ |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
87
diff
changeset
|
296 |
test.Printf(_L("Time comparison failed\r\n")); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
87
diff
changeset
|
297 |
test.Printf(_L("Before: 0x%lx\r\n"), t1.Int64()); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
87
diff
changeset
|
298 |
test.Printf(_L("After: 0x%lx\r\n"), t2.Int64()); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
87
diff
changeset
|
299 |
test(t2>t1); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
87
diff
changeset
|
300 |
} |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
87
diff
changeset
|
301 |
|
0 | 302 |
t1=t2; |
303 |
} |
|
304 |
} |
|
305 |
||
306 |
TInt AtTwice(TAny*) |
|
307 |
{ |
|
308 |
RTimer t; |
|
309 |
TInt r=t.CreateLocal(); |
|
310 |
test(r==KErrNone); |
|
311 |
TRequestStatus s; |
|
312 |
TTime time; |
|
313 |
time.UniversalTime(); |
|
314 |
t.AtUTC(s,time+TTimeIntervalSeconds(1)); |
|
315 |
test(s==KRequestPending); |
|
316 |
t.AtUTC(s,time+TTimeIntervalSeconds(2)); |
|
317 |
return KErrNone; |
|
318 |
} |
|
319 |
||
320 |
TInt AtAfter(TAny*) |
|
321 |
{ |
|
322 |
RTimer t; |
|
323 |
TInt r=t.CreateLocal(); |
|
324 |
test(r==KErrNone); |
|
325 |
TRequestStatus s; |
|
326 |
TTime time; |
|
327 |
time.UniversalTime(); |
|
328 |
t.AtUTC(s,time+TTimeIntervalSeconds(1)); |
|
329 |
test(s==KRequestPending); |
|
330 |
t.After(s,1000000); |
|
331 |
return KErrNone; |
|
332 |
} |
|
333 |
||
334 |
TInt AfterAt(TAny*) |
|
335 |
{ |
|
336 |
RTimer t; |
|
337 |
TInt r=t.CreateLocal(); |
|
338 |
test(r==KErrNone); |
|
339 |
TRequestStatus s; |
|
340 |
TTime time; |
|
341 |
time.UniversalTime(); |
|
342 |
t.After(s,1000000); |
|
343 |
test(s==KRequestPending); |
|
344 |
t.AtUTC(s,time+TTimeIntervalSeconds(2)); |
|
345 |
return KErrNone; |
|
346 |
} |
|
347 |
||
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
348 |
|
0 | 349 |
LOCAL_C void testAbs() |
350 |
// |
|
351 |
// Test absolute timers. |
|
352 |
// |
|
353 |
{ |
|
354 |
test.Start(_L("Now -1")); |
|
355 |
RTimer t; |
|
356 |
TInt r=t.CreateLocal(); |
|
357 |
test(r==KErrNone); |
|
358 |
TRequestStatus s; |
|
359 |
TTime time; |
|
360 |
time.UniversalTime(); |
|
361 |
t.AtUTC(s,time+TTimeIntervalSeconds(-2)); |
|
362 |
test(s==KErrUnderflow); // =KRequestPending |
|
363 |
User::WaitForRequest(s); |
|
364 |
test(s==KErrUnderflow); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
365 |
|
0 | 366 |
TTime time2; |
367 |
test.Next(_L("Synchronise to clock")); |
|
368 |
time.UniversalTime(); |
|
369 |
TDateTime dateTime=time.DateTime(); |
|
370 |
dateTime.SetMicroSecond(0); |
|
371 |
time=dateTime; |
|
372 |
time+=TTimeIntervalSeconds(2); |
|
373 |
t.AtUTC(s,time); |
|
374 |
User::WaitForRequest(s); |
|
375 |
||
376 |
test.Next(_L("Now +1")); |
|
377 |
time += TTimeIntervalSeconds(1); |
|
378 |
t.AtUTC(s,time); |
|
379 |
test(s==KRequestPending); |
|
380 |
User::WaitForRequest(s); |
|
381 |
time2.UniversalTime(); |
|
382 |
test(s==KErrNone); |
|
383 |
TTimeIntervalMicroSeconds delay=time2.MicroSecondsFrom(time); |
|
384 |
// Test we are in the same second as the requested time... |
|
385 |
test(delay>=TTimeIntervalMicroSeconds(0)); |
|
386 |
test(delay<TTimeIntervalMicroSeconds(1000000)); |
|
387 |
||
388 |
test.Next(_L("Now +3")); |
|
389 |
time += TTimeIntervalSeconds(3); |
|
390 |
t.AtUTC(s,time); |
|
391 |
test(s==KRequestPending); |
|
392 |
User::WaitForRequest(s); |
|
393 |
time2.UniversalTime(); |
|
394 |
test(s==KErrNone); |
|
395 |
delay=time2.MicroSecondsFrom(time); |
|
396 |
// Test we are in the same second as the requested time... |
|
397 |
test(delay>=TTimeIntervalMicroSeconds(0)); |
|
398 |
test(delay<TTimeIntervalMicroSeconds(1000000)); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
399 |
|
0 | 400 |
test.Next(_L("UTC vs local")); |
401 |
TTimeIntervalSeconds savedOffset = User::UTCOffset(); |
|
402 |
User::SetUTCOffset(3600); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
403 |
|
0 | 404 |
time.HomeTime(); |
405 |
time += TTimeIntervalSeconds(1); |
|
406 |
t.At(s,time); |
|
407 |
test(s==KRequestPending); |
|
408 |
User::WaitForRequest(s); |
|
409 |
time2.HomeTime(); |
|
410 |
test(s==KErrNone); |
|
411 |
delay=time2.MicroSecondsFrom(time); |
|
412 |
// Test we are in the same second as the requested time... |
|
413 |
test(delay>=TTimeIntervalMicroSeconds(0)); |
|
414 |
test(delay<TTimeIntervalMicroSeconds(1000000)); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
415 |
|
0 | 416 |
time.UniversalTime(); |
417 |
time += TTimeIntervalSeconds(1); |
|
418 |
t.AtUTC(s,time); |
|
419 |
test(s==KRequestPending); |
|
420 |
User::WaitForRequest(s); |
|
421 |
time2.UniversalTime(); |
|
422 |
test(s==KErrNone); |
|
423 |
delay=time2.MicroSecondsFrom(time); |
|
424 |
// Test we are in the same second as the requested time... |
|
425 |
test(delay>=TTimeIntervalMicroSeconds(0)); |
|
426 |
test(delay<TTimeIntervalMicroSeconds(1000000)); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
427 |
|
0 | 428 |
User::SetUTCOffset(savedOffset); |
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
429 |
|
0 | 430 |
test.Next(_L("Cancel")); |
431 |
time.UniversalTime(); |
|
432 |
t.AtUTC(s,time+TTimeIntervalSeconds(10)); |
|
433 |
test(s==KRequestPending); |
|
434 |
t.Cancel(); |
|
435 |
User::WaitForRequest(s); |
|
436 |
test(s==KErrCancel); |
|
437 |
t.Close(); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
438 |
|
0 | 439 |
test.Next(_L("Request twice")); |
440 |
RThread thread; |
|
441 |
r=thread.Create(_L("At twice"),AtTwice,KDefaultStackSize,NULL,&thread); |
|
442 |
test(r==KErrNone); |
|
443 |
thread.Logon(s); |
|
444 |
test(s==KRequestPending); |
|
445 |
TBool justInTime=User::JustInTime(); |
|
446 |
User::SetJustInTime(EFalse); |
|
447 |
thread.Resume(); |
|
448 |
User::WaitForRequest(s); |
|
449 |
User::SetJustInTime(justInTime); |
|
450 |
test(s==ETimerAlreadyPending); |
|
451 |
test(thread.ExitCategory()==_L("KERN-EXEC")); |
|
452 |
test(thread.ExitReason()==ETimerAlreadyPending); |
|
453 |
test(thread.ExitType()==EExitPanic); |
|
454 |
CLOSE_AND_WAIT(thread); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
455 |
|
0 | 456 |
r=thread.Create(_L("At After"),AtAfter,KDefaultStackSize,NULL,&thread); |
457 |
test(r==KErrNone); |
|
458 |
thread.Logon(s); |
|
459 |
test(s==KRequestPending); |
|
460 |
User::SetJustInTime(EFalse); |
|
461 |
thread.Resume(); |
|
462 |
User::WaitForRequest(s); |
|
463 |
User::SetJustInTime(justInTime); |
|
464 |
test(s==ETimerAlreadyPending); |
|
465 |
test(thread.ExitCategory()==_L("KERN-EXEC")); |
|
466 |
test(thread.ExitReason()==ETimerAlreadyPending); |
|
467 |
test(thread.ExitType()==EExitPanic); |
|
468 |
CLOSE_AND_WAIT(thread); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
469 |
|
0 | 470 |
r=thread.Create(_L("After At"),AfterAt,KDefaultStackSize,NULL,&thread); |
471 |
test(r==KErrNone); |
|
472 |
thread.Logon(s); |
|
473 |
test(s==KRequestPending); |
|
474 |
User::SetJustInTime(EFalse); |
|
475 |
thread.Resume(); |
|
476 |
User::WaitForRequest(s); |
|
477 |
User::SetJustInTime(justInTime); |
|
478 |
test(s==ETimerAlreadyPending); |
|
479 |
test(thread.ExitCategory()==_L("KERN-EXEC")); |
|
480 |
test(thread.ExitReason()==ETimerAlreadyPending); |
|
481 |
test(thread.ExitType()==EExitPanic); |
|
482 |
CLOSE_AND_WAIT(thread); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
483 |
|
0 | 484 |
test.End(); |
485 |
} |
|
486 |
||
487 |
TInt LockTwice(TAny*) |
|
488 |
{ |
|
489 |
RTimer t; |
|
490 |
test(t.CreateLocal()==KErrNone); |
|
491 |
TRequestStatus stat; |
|
492 |
t.Lock(stat, ETwelveOClock); |
|
493 |
User::WaitForRequest(stat); |
|
494 |
test(stat==KErrGeneral); |
|
495 |
t.Lock(stat, ETwelveOClock); |
|
496 |
t.Lock(stat, ETwelveOClock); |
|
497 |
return KErrNone; |
|
498 |
} |
|
499 |
||
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
500 |
|
0 | 501 |
LOCAL_C void testLock() |
502 |
// |
|
503 |
// Test locked timers |
|
504 |
// |
|
505 |
{ |
|
506 |
test.Start(_L("Test synchronise to ETwelveOClock")); |
|
507 |
RTimer t; |
|
508 |
TTime time,time2; |
|
509 |
test(t.CreateLocal()==KErrNone); |
|
510 |
TRequestStatus stat; |
|
511 |
t.Lock(stat, ETwelveOClock); |
|
512 |
User::WaitForRequest(stat); |
|
513 |
test(stat==KErrGeneral); |
|
514 |
time.UniversalTime(); |
|
515 |
t.Lock(stat, ETwelveOClock); |
|
516 |
User::WaitForRequest(stat); |
|
517 |
test(stat==KErrNone); |
|
518 |
time2.UniversalTime(); |
|
519 |
test(time<time2); |
|
520 |
User::After(500000); |
|
521 |
test.Next(_L("Test sync to EOneOClock for 4 seconds")); |
|
522 |
t.Lock(stat, EOneOClock); |
|
523 |
User::WaitForRequest(stat); |
|
524 |
test(stat==KErrGeneral); |
|
525 |
time.UniversalTime(); |
|
526 |
TInt i; |
|
527 |
for (i=0; i<5; i++) |
|
528 |
{ |
|
529 |
t.Lock(stat, EOneOClock); |
|
530 |
User::WaitForRequest(stat); |
|
531 |
test(stat==KErrNone); |
|
532 |
test.Printf(_L(".")); |
|
533 |
} |
|
534 |
time2.UniversalTime(); |
|
535 |
TTimeIntervalSeconds ti; |
|
536 |
test(time2.SecondsFrom(time, ti)==KErrNone); |
|
537 |
test(ti>=TTimeIntervalSeconds(4)); |
|
538 |
test.Printf(_L("\n")); |
|
539 |
test.Next(_L("Test sync to every half second, from EFourOClock for 5 seconds")); |
|
540 |
t.Lock(stat, ETwelveOClock); |
|
541 |
User::WaitForRequest(stat); |
|
542 |
for (i=0; i<5; i++) |
|
543 |
{ |
|
544 |
t.Lock(stat, EFourOClock); |
|
545 |
User::WaitForRequest(stat); |
|
546 |
test(stat==KErrNone); |
|
547 |
test.Printf(_L(".")); |
|
548 |
t.Lock(stat, ETenOClock); |
|
549 |
User::WaitForRequest(stat); |
|
550 |
test(stat==KErrNone); |
|
551 |
test.Printf(_L(",")); |
|
552 |
} |
|
553 |
test.Printf(_L("\n")); |
|
554 |
test.Next(_L("Test KErrGeneral after delay")); |
|
555 |
User::After(1000000); |
|
556 |
t.Lock(stat,EThreeOClock); |
|
557 |
User::WaitForRequest(stat); |
|
558 |
test(stat==KErrGeneral); |
|
559 |
test.Next(_L("Test cancel, and re-request immediately")); |
|
560 |
User::After(1000000); |
|
561 |
t.Lock(stat, ETwelveOClock); |
|
562 |
User::WaitForRequest(stat); |
|
563 |
test(stat==KErrGeneral); |
|
564 |
t.Lock(stat, EElevenOClock); |
|
565 |
t.Cancel(); |
|
566 |
User::WaitForRequest(stat); |
|
567 |
test(stat==KErrCancel); |
|
568 |
t.Lock(stat, EElevenOClock); |
|
569 |
User::WaitForRequest(stat); |
|
570 |
test(stat==KErrNone); |
|
571 |
test.Next(_L("Test complete a request at 1, then cancel a request for 11, and re-request at 3 gives KErrGeneral")); |
|
572 |
User::After(1000000); |
|
573 |
t.Lock(stat, ETwelveOClock); |
|
574 |
User::WaitForRequest(stat); |
|
575 |
test(stat==KErrGeneral); |
|
576 |
t.Lock(stat,EOneOClock); |
|
577 |
User::WaitForRequest(stat); |
|
578 |
test(stat==KErrNone); |
|
579 |
t.Lock(stat,EElevenOClock); |
|
580 |
User::After(400000); // ensure EThreeOClock is in the past |
|
581 |
t.Cancel(); |
|
582 |
User::WaitForRequest(stat); |
|
583 |
test(stat==KErrCancel); |
|
584 |
t.Lock(stat,EThreeOClock); |
|
585 |
User::WaitForRequest(stat); |
|
586 |
// EThreeOClock should be more than one second away from the previous timer expiration |
|
587 |
test(stat==KErrGeneral); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
588 |
|
0 | 589 |
test.Next(_L("Lock twice")); |
590 |
RThread thread; |
|
591 |
TInt r=thread.Create(_L("Lock twice"),LockTwice,KDefaultStackSize,NULL,&thread); |
|
592 |
test(r==KErrNone); |
|
593 |
thread.Logon(stat); |
|
594 |
test(stat==KRequestPending); |
|
595 |
TBool justInTime=User::JustInTime(); |
|
596 |
User::SetJustInTime(EFalse); |
|
597 |
thread.Resume(); |
|
598 |
User::WaitForRequest(stat); |
|
599 |
User::SetJustInTime(justInTime); |
|
600 |
test(stat==ETimerAlreadyPending); |
|
601 |
test(thread.ExitCategory()==_L("KERN-EXEC")); |
|
602 |
test(thread.ExitReason()==ETimerAlreadyPending); |
|
603 |
test(thread.ExitType()==EExitPanic); |
|
604 |
CLOSE_AND_WAIT(thread); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
605 |
|
0 | 606 |
#if !(defined(__EPOC32__) && defined(__X86__)) |
607 |
TInt muid = 0; |
|
608 |
HAL::Get(HAL::EMachineUid, muid); |
|
87
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
609 |
if(muid==HAL::EMachineUid_OmapH2 || muid==HAL::EMachineUid_OmapH4 || muid==HAL::EMachineUid_OmapH6) |
0 | 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(); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
617 |
tat.AtUTC(sat, now+TTimeIntervalSeconds(10)); // turn on in 10 seconds |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
618 |
test(sat==KRequestPending); |
0 | 619 |
t.Lock(stat, ETwelveOClock); |
620 |
User::WaitForRequest(stat); |
|
621 |
test(stat==KErrGeneral); |
|
622 |
t.Lock(stat, EElevenOClock); |
|
623 |
User::WaitForRequest(stat); |
|
624 |
PrintTime(); |
|
625 |
// Go to standby |
|
626 |
r = Power::EnableWakeupEvents(EPwStandby); |
|
627 |
test (r == KErrNone); |
|
628 |
r = Power::PowerDown(); |
|
629 |
test (r == KErrNone); |
|
630 |
test(stat==KErrNone); |
|
631 |
PrintTime(); |
|
632 |
t.Lock(stat, EElevenOClock); |
|
633 |
User::WaitForRequest(stat); |
|
634 |
test(stat==KErrGeneral); |
|
635 |
tat.Close(); |
|
636 |
} |
|
637 |
#endif |
|
638 |
||
639 |
t.Close(); |
|
640 |
test.End(); |
|
641 |
} |
|
642 |
||
643 |
||
644 |
void testChange() |
|
645 |
// |
|
646 |
// Bug HA-255 |
|
647 |
// Test locked timers abort when the system time changes |
|
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); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
660 |
|
0 | 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 |
test.Start(_L("Test User::ResetInactivityTime()")); |
|
713 |
RTimer t,t2; |
|
714 |
TRequestStatus stat,stat2; |
|
715 |
t.CreateLocal(); |
|
716 |
t2.CreateLocal(); |
|
717 |
User::ResetInactivityTime(); |
|
718 |
t.Inactivity(stat, 4); |
|
719 |
t2.Inactivity(stat2, 2); |
|
720 |
TTime now; |
|
721 |
now.UniversalTime(); |
|
722 |
TInt r=User::SetUTCTime(now+TTimeIntervalDays(1)); |
|
723 |
test(r==KErrNone); |
|
724 |
test(stat==KRequestPending); |
|
725 |
test(stat2==KRequestPending); |
|
726 |
r=User::SetUTCTime(now-TTimeIntervalDays(1)); |
|
727 |
test(r==KErrNone); |
|
728 |
test(stat==KRequestPending); |
|
729 |
test(stat2==KRequestPending); |
|
730 |
r=User::SetUTCTime(now); |
|
731 |
test(r==KErrNone); |
|
732 |
test(stat==KRequestPending); |
|
733 |
test(stat2==KRequestPending); |
|
734 |
User::After(1000000); |
|
735 |
User::ResetInactivityTime(); |
|
736 |
test(stat==KRequestPending); |
|
737 |
test(stat2==KRequestPending); |
|
738 |
User::After(3000000); |
|
739 |
User::ResetInactivityTime(); |
|
740 |
test(stat==KRequestPending); |
|
741 |
test(stat2!=KRequestPending); |
|
742 |
User::After(2000000); |
|
743 |
User::ResetInactivityTime(); |
|
744 |
test(stat==KRequestPending); |
|
745 |
User::After(2000000); |
|
746 |
User::ResetInactivityTime(); |
|
747 |
test(stat==KRequestPending); |
|
748 |
User::After(5000000); |
|
749 |
test(stat!=KRequestPending); |
|
750 |
test.End(); |
|
751 |
} |
|
752 |
||
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
753 |
|
0 | 754 |
GLDEF_C TInt E32Main() |
755 |
// |
|
756 |
// Test timers. |
|
757 |
// |
|
758 |
{ |
|
759 |
test.Title(); |
|
760 |
TInt r=HAL::Get(HAL::EMachineUid,MachineUid); |
|
761 |
test(r==KErrNone); |
|
762 |
test.Start(_L("Testing relative timers")); |
|
763 |
testRel(); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
764 |
|
0 | 765 |
#ifdef REQUEST_STATUS_POLL_SOAK_TEST |
766 |
test.Next(_L("Testing polling")); |
|
767 |
testPoll(); |
|
768 |
#endif |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
769 |
|
0 | 770 |
test.Next(_L("Testing HomeTime()")); |
771 |
testHomeTime(); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
772 |
|
0 | 773 |
test.Next(_L("Testing absolute timers")); |
774 |
testAbs(); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
775 |
|
0 | 776 |
test.Next(_L("Testing locked timers")); |
777 |
testLock(); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
778 |
|
0 | 779 |
test.Next(_L("Testing changing time")); |
780 |
testChange(); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
781 |
|
0 | 782 |
test.Next(_L("Testing inactivity timers")); |
783 |
testInactivity(); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
784 |
|
0 | 785 |
test.End(); |
786 |
return(KErrNone); |
|
787 |
} |
|
788 |