1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/prime/t_timer.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,787 @@
1.4 +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32test\prime\t_timer.cpp
1.18 +// Overview:
1.19 +// Time and Timer tests.
1.20 +// API Information:
1.21 +// RTimer, TTime
1.22 +// Details:
1.23 +// - Test relative timers using the RTimer::After() method. Verify
1.24 +// results are as expected.
1.25 +// - Set the date and time using TTime::HomeTime() and verify results
1.26 +// are as expected.
1.27 +// - Test absolute timers using RTimer::At() method. Verify results
1.28 +// are as expected.
1.29 +// - Test the timer is ok if its thread terminates.
1.30 +// - Test synchronising time via the RTimer::Lock() method. Verify
1.31 +// results are as expected.
1.32 +// - Test locked timers abort when the system time changes.
1.33 +// - Test User::ResetInactivityTime() results are as expected.
1.34 +// Platforms/Drives/Compatibility:
1.35 +// All.
1.36 +// Assumptions/Requirement/Pre-requisites:
1.37 +// Failures and causes:
1.38 +// Base Port information:
1.39 +//
1.40 +//
1.41 +
1.42 +// the following was used to help debug emulator implemenation of user mode callbacks
1.43 +//#define REQUEST_STATUS_POLL_SOAK_TEST
1.44 +
1.45 +#define __E32TEST_EXTENSION__
1.46 +
1.47 +#include <e32test.h>
1.48 +#include <e32hal.h>
1.49 +#include <e32panic.h>
1.50 +#include <hal.h>
1.51 +#include <e32power.h>
1.52 +#include <e32math.h>
1.53 +
1.54 +LOCAL_D RTest test(_L("T_TIMER"));
1.55 +TInt MachineUid;
1.56 +
1.57 +TInt AfterNegative(TAny*)
1.58 + {
1.59 + RTimer t;
1.60 + TInt r=t.CreateLocal();
1.61 + test(r==KErrNone);
1.62 + TRequestStatus s;
1.63 + t.After(s,-1);
1.64 + return KErrNone;
1.65 + }
1.66 +
1.67 +TInt AfterTwice(TAny*)
1.68 + {
1.69 + RTimer t;
1.70 + TInt r=t.CreateLocal();
1.71 + test(r==KErrNone);
1.72 + TRequestStatus s;
1.73 + t.After(s,1000000);
1.74 + test(s==KRequestPending);
1.75 + t.After(s,1000000);
1.76 + return KErrNone;
1.77 + }
1.78 +
1.79 +void PrintTime()
1.80 + {
1.81 + TTime now;
1.82 + now.HomeTime();
1.83 + TDateTime dt(now.DateTime());
1.84 + test.Printf(_L("Time: %02d:%02d:%02d:%06d\n"),dt.Hour(),dt.Minute(),dt.Second(),dt.MicroSecond());
1.85 + }
1.86 +
1.87 +TBool RequestIsComplete(TRequestStatus& s)
1.88 + {
1.89 + return s != KRequestPending;
1.90 + }
1.91 +
1.92 +
1.93 +LOCAL_C void testRel()
1.94 +//
1.95 +// Test relative timers.
1.96 +//
1.97 + {
1.98 + test.Start(_L("After 0"));
1.99 + RTimer t;
1.100 + TInt r=t.CreateLocal();
1.101 + test(r==KErrNone);
1.102 + TRequestStatus s;
1.103 + t.After(s,0);
1.104 + test(s==KRequestPending || s==KErrNone);
1.105 + User::WaitForRequest(s);
1.106 + test(s==KErrNone);
1.107 +
1.108 + test.Next(_L("After 1 tenth"));
1.109 + t.After(s,100000);
1.110 +#ifdef __WINS__
1.111 + // On WINS we can't guarantee thread scheduling so timer may already have
1.112 + // completed before we get to test the status. Therefore, allow KErrNone.
1.113 + test(s==KRequestPending || s==KErrNone);
1.114 + if(s==KErrNone)
1.115 + test.Printf(_L("NOTE: completed 'early'"));
1.116 +#else
1.117 + test(s==KRequestPending);
1.118 +#endif
1.119 + User::WaitForRequest(s);
1.120 + test(s==KErrNone);
1.121 +
1.122 + test.Next(_L("After -1 millionth"));
1.123 + RThread thread;
1.124 + r=thread.Create(_L("After -1"),AfterNegative,KDefaultStackSize,NULL,&thread);
1.125 + test(r==KErrNone);
1.126 + thread.Logon(s);
1.127 + test(s==KRequestPending);
1.128 + TBool justInTime=User::JustInTime();
1.129 + User::SetJustInTime(EFalse);
1.130 + thread.Resume();
1.131 + User::WaitForRequest(s);
1.132 + test(s==ERTimerAfterTimeNegative);
1.133 + test(thread.ExitCategory()==_L("USER"));
1.134 + test(thread.ExitReason()==ERTimerAfterTimeNegative);
1.135 + test(thread.ExitType()==EExitPanic);
1.136 + CLOSE_AND_WAIT(thread);
1.137 + User::SetJustInTime(justInTime);
1.138 +
1.139 + test.Next(_L("After 1 second"));
1.140 + t.After(s,1000000);
1.141 + test(s==KRequestPending);
1.142 + User::WaitForRequest(s);
1.143 + test(s==KErrNone);
1.144 +
1.145 + test.Next(_L("After 1 second polling"));
1.146 + t.After(s,1000000);
1.147 + test(s==KRequestPending);
1.148 + // Have to be careful the compiler doesn't optimise this away
1.149 + while(!RequestIsComplete(s))
1.150 + ; // poll
1.151 + test(s==KErrNone);
1.152 + User::WaitForRequest(s);
1.153 +
1.154 + test.Next(_L("Cancel"));
1.155 + t.After(s,1000000);
1.156 + test(s==KRequestPending);
1.157 + t.Cancel();
1.158 + User::WaitForRequest(s);
1.159 + test(s==KErrCancel);
1.160 + t.Close();
1.161 +
1.162 + test.Next(_L("Request twice"));
1.163 + r=thread.Create(_L("After twice"),AfterTwice,KDefaultStackSize,NULL,&thread);
1.164 + test(r==KErrNone);
1.165 + thread.Logon(s);
1.166 + test(s==KRequestPending);
1.167 + User::SetJustInTime(EFalse);
1.168 + thread.Resume();
1.169 + User::WaitForRequest(s);
1.170 + test(s==ETimerAlreadyPending);
1.171 + test(thread.ExitCategory()==_L("KERN-EXEC"));
1.172 + test(thread.ExitReason()==ETimerAlreadyPending);
1.173 + test(thread.ExitType()==EExitPanic);
1.174 + CLOSE_AND_WAIT(thread);
1.175 + User::SetJustInTime(justInTime);
1.176 +
1.177 + test.End();
1.178 + }
1.179 +
1.180 +#ifdef REQUEST_STATUS_POLL_SOAK_TEST
1.181 +
1.182 +static volatile TBool PollTestRunning;
1.183 +
1.184 +LOCAL_C TInt PollThread(TAny* aArg)
1.185 + {
1.186 + const TInt KMaxTimers = 1000;
1.187 +
1.188 + TInt threadIndex = (TInt)aArg;
1.189 + TInt64 seed = 5511498647534504549 + RThread().Id();
1.190 + RTimer timers[KMaxTimers];
1.191 + TRequestStatus statuses[KMaxTimers];
1.192 +
1.193 + TInt i;
1.194 + for (i = 0 ; i < KMaxTimers ; ++i)
1.195 + {
1.196 + test_KErrNone(timers[i].CreateLocal());
1.197 + statuses[i] = 1;
1.198 + }
1.199 +
1.200 + TInt totalComplete = 0;
1.201 + TInt totalWaiting = 0;
1.202 +
1.203 + while(PollTestRunning)
1.204 + {
1.205 + for (i = 0 ; i < KMaxTimers ; ++i)
1.206 + {
1.207 + switch(statuses[i].Int())
1.208 + {
1.209 + case KRequestPending:
1.210 + // do nothing
1.211 + ++totalWaiting;
1.212 + break;
1.213 +
1.214 + case KErrNone:
1.215 + User::WaitForRequest(statuses[i]);
1.216 + ++totalComplete;
1.217 + // fall through
1.218 +
1.219 + case 1:
1.220 + {
1.221 + TInt after = ((TUint)Math::Rand(seed) >> 28) + 1;
1.222 + timers[i].HighRes(statuses[i], after);
1.223 + }
1.224 + break;
1.225 +
1.226 + default:
1.227 + return statuses[i].Int();
1.228 + }
1.229 + }
1.230 + }
1.231 +
1.232 + for (i = 0 ; i < KMaxTimers ; ++i)
1.233 + {
1.234 + User::WaitForRequest(statuses[i]);
1.235 + if (statuses[i].Int() != KErrNone)
1.236 + return statuses[i].Int();
1.237 + timers[i].Close();
1.238 + }
1.239 +
1.240 + RDebug::Printf("%d: %d %d\n", threadIndex, totalComplete, totalWaiting);
1.241 + return KErrNone;
1.242 + }
1.243 +
1.244 +LOCAL_C void testPoll()
1.245 + {
1.246 + const TInt KMaxThreads = 10;
1.247 + const TInt KSecondsToTest = 60;
1.248 +
1.249 + RThread threads[KMaxThreads];
1.250 + TRequestStatus statuses[KMaxThreads];
1.251 +
1.252 + test.Start(_L("Test polling"));
1.253 +
1.254 + PollTestRunning = ETrue;
1.255 +
1.256 + TInt i;
1.257 + for (i = 0 ; i < KMaxThreads ; ++i)
1.258 + {
1.259 + test_KErrNone(threads[i].Create(KNullDesC, PollThread, 0x1000, NULL, (TAny*)i));
1.260 + threads[i].Logon(statuses[i]);
1.261 + threads[i].Resume();
1.262 + }
1.263 +
1.264 + User::After(KSecondsToTest * 1000 * 1000);
1.265 +
1.266 + PollTestRunning = EFalse;
1.267 +
1.268 + for (i = 0 ; i < KMaxThreads ; ++i)
1.269 + {
1.270 + User::WaitForRequest(statuses[i]);
1.271 + test_KErrNone(statuses[i].Int());
1.272 + test_Equal(EExitKill, threads[i].ExitType());
1.273 + threads[i].Close();
1.274 + }
1.275 +
1.276 + test.End();
1.277 + }
1.278 +
1.279 +#endif
1.280 +
1.281 +
1.282 +LOCAL_C void testHomeTime()
1.283 +//
1.284 +// Test HomeTime.
1.285 +//
1.286 + {
1.287 + TTime t1, t2;
1.288 + t1.HomeTime();
1.289 + for (TInt x=0;x<100;x++)
1.290 + {
1.291 + do
1.292 + {
1.293 + t2.HomeTime();
1.294 + }
1.295 + while (t2==t1);
1.296 +#if defined(_DEBUG)
1.297 + TDateTime dt=t2.DateTime();
1.298 + test.Printf(_L("%d:%d\r\n"),dt.Second(),dt.MicroSecond());
1.299 +#endif
1.300 + test(t2>t1);
1.301 + t1=t2;
1.302 + }
1.303 +#if defined(_DEBUG)
1.304 + test.Printf(_L("\r\n"));
1.305 +#endif
1.306 + }
1.307 +
1.308 +TInt AtTwice(TAny*)
1.309 + {
1.310 + RTimer t;
1.311 + TInt r=t.CreateLocal();
1.312 + test(r==KErrNone);
1.313 + TRequestStatus s;
1.314 + TTime time;
1.315 + time.UniversalTime();
1.316 + t.AtUTC(s,time+TTimeIntervalSeconds(1));
1.317 + test(s==KRequestPending);
1.318 + t.AtUTC(s,time+TTimeIntervalSeconds(2));
1.319 + return KErrNone;
1.320 + }
1.321 +
1.322 +TInt AtAfter(TAny*)
1.323 + {
1.324 + RTimer t;
1.325 + TInt r=t.CreateLocal();
1.326 + test(r==KErrNone);
1.327 + TRequestStatus s;
1.328 + TTime time;
1.329 + time.UniversalTime();
1.330 + t.AtUTC(s,time+TTimeIntervalSeconds(1));
1.331 + test(s==KRequestPending);
1.332 + t.After(s,1000000);
1.333 + return KErrNone;
1.334 + }
1.335 +
1.336 +TInt AfterAt(TAny*)
1.337 + {
1.338 + RTimer t;
1.339 + TInt r=t.CreateLocal();
1.340 + test(r==KErrNone);
1.341 + TRequestStatus s;
1.342 + TTime time;
1.343 + time.UniversalTime();
1.344 + t.After(s,1000000);
1.345 + test(s==KRequestPending);
1.346 + t.AtUTC(s,time+TTimeIntervalSeconds(2));
1.347 + return KErrNone;
1.348 + }
1.349 +
1.350 +
1.351 +LOCAL_C void testAbs()
1.352 +//
1.353 +// Test absolute timers.
1.354 +//
1.355 + {
1.356 + test.Start(_L("Now -1"));
1.357 + RTimer t;
1.358 + TInt r=t.CreateLocal();
1.359 + test(r==KErrNone);
1.360 + TRequestStatus s;
1.361 + TTime time;
1.362 + time.UniversalTime();
1.363 + t.AtUTC(s,time+TTimeIntervalSeconds(-2));
1.364 + test(s==KErrUnderflow); // =KRequestPending
1.365 + User::WaitForRequest(s);
1.366 + test(s==KErrUnderflow);
1.367 +
1.368 + TTime time2;
1.369 + test.Next(_L("Synchronise to clock"));
1.370 + time.UniversalTime();
1.371 + TDateTime dateTime=time.DateTime();
1.372 + dateTime.SetMicroSecond(0);
1.373 + time=dateTime;
1.374 + time+=TTimeIntervalSeconds(2);
1.375 + t.AtUTC(s,time);
1.376 + User::WaitForRequest(s);
1.377 +
1.378 + test.Next(_L("Now +1"));
1.379 + time += TTimeIntervalSeconds(1);
1.380 + t.AtUTC(s,time);
1.381 + test(s==KRequestPending);
1.382 + User::WaitForRequest(s);
1.383 + time2.UniversalTime();
1.384 + test(s==KErrNone);
1.385 + TTimeIntervalMicroSeconds delay=time2.MicroSecondsFrom(time);
1.386 + // Test we are in the same second as the requested time...
1.387 + test(delay>=TTimeIntervalMicroSeconds(0));
1.388 + test(delay<TTimeIntervalMicroSeconds(1000000));
1.389 +
1.390 + test.Next(_L("Now +3"));
1.391 + time += TTimeIntervalSeconds(3);
1.392 + t.AtUTC(s,time);
1.393 + test(s==KRequestPending);
1.394 + User::WaitForRequest(s);
1.395 + time2.UniversalTime();
1.396 + test(s==KErrNone);
1.397 + delay=time2.MicroSecondsFrom(time);
1.398 + // Test we are in the same second as the requested time...
1.399 + test(delay>=TTimeIntervalMicroSeconds(0));
1.400 + test(delay<TTimeIntervalMicroSeconds(1000000));
1.401 +
1.402 + test.Next(_L("UTC vs local"));
1.403 + TTimeIntervalSeconds savedOffset = User::UTCOffset();
1.404 + User::SetUTCOffset(3600);
1.405 +
1.406 + time.HomeTime();
1.407 + time += TTimeIntervalSeconds(1);
1.408 + t.At(s,time);
1.409 + test(s==KRequestPending);
1.410 + User::WaitForRequest(s);
1.411 + time2.HomeTime();
1.412 + test(s==KErrNone);
1.413 + delay=time2.MicroSecondsFrom(time);
1.414 + // Test we are in the same second as the requested time...
1.415 + test(delay>=TTimeIntervalMicroSeconds(0));
1.416 + test(delay<TTimeIntervalMicroSeconds(1000000));
1.417 +
1.418 + time.UniversalTime();
1.419 + time += TTimeIntervalSeconds(1);
1.420 + t.AtUTC(s,time);
1.421 + test(s==KRequestPending);
1.422 + User::WaitForRequest(s);
1.423 + time2.UniversalTime();
1.424 + test(s==KErrNone);
1.425 + delay=time2.MicroSecondsFrom(time);
1.426 + // Test we are in the same second as the requested time...
1.427 + test(delay>=TTimeIntervalMicroSeconds(0));
1.428 + test(delay<TTimeIntervalMicroSeconds(1000000));
1.429 +
1.430 + User::SetUTCOffset(savedOffset);
1.431 +
1.432 + test.Next(_L("Cancel"));
1.433 + time.UniversalTime();
1.434 + t.AtUTC(s,time+TTimeIntervalSeconds(10));
1.435 + test(s==KRequestPending);
1.436 + t.Cancel();
1.437 + User::WaitForRequest(s);
1.438 + test(s==KErrCancel);
1.439 + t.Close();
1.440 +
1.441 + test.Next(_L("Request twice"));
1.442 + RThread thread;
1.443 + r=thread.Create(_L("At twice"),AtTwice,KDefaultStackSize,NULL,&thread);
1.444 + test(r==KErrNone);
1.445 + thread.Logon(s);
1.446 + test(s==KRequestPending);
1.447 + TBool justInTime=User::JustInTime();
1.448 + User::SetJustInTime(EFalse);
1.449 + thread.Resume();
1.450 + User::WaitForRequest(s);
1.451 + User::SetJustInTime(justInTime);
1.452 + test(s==ETimerAlreadyPending);
1.453 + test(thread.ExitCategory()==_L("KERN-EXEC"));
1.454 + test(thread.ExitReason()==ETimerAlreadyPending);
1.455 + test(thread.ExitType()==EExitPanic);
1.456 + CLOSE_AND_WAIT(thread);
1.457 +
1.458 + r=thread.Create(_L("At After"),AtAfter,KDefaultStackSize,NULL,&thread);
1.459 + test(r==KErrNone);
1.460 + thread.Logon(s);
1.461 + test(s==KRequestPending);
1.462 + User::SetJustInTime(EFalse);
1.463 + thread.Resume();
1.464 + User::WaitForRequest(s);
1.465 + User::SetJustInTime(justInTime);
1.466 + test(s==ETimerAlreadyPending);
1.467 + test(thread.ExitCategory()==_L("KERN-EXEC"));
1.468 + test(thread.ExitReason()==ETimerAlreadyPending);
1.469 + test(thread.ExitType()==EExitPanic);
1.470 + CLOSE_AND_WAIT(thread);
1.471 +
1.472 + r=thread.Create(_L("After At"),AfterAt,KDefaultStackSize,NULL,&thread);
1.473 + test(r==KErrNone);
1.474 + thread.Logon(s);
1.475 + test(s==KRequestPending);
1.476 + User::SetJustInTime(EFalse);
1.477 + thread.Resume();
1.478 + User::WaitForRequest(s);
1.479 + User::SetJustInTime(justInTime);
1.480 + test(s==ETimerAlreadyPending);
1.481 + test(thread.ExitCategory()==_L("KERN-EXEC"));
1.482 + test(thread.ExitReason()==ETimerAlreadyPending);
1.483 + test(thread.ExitType()==EExitPanic);
1.484 + CLOSE_AND_WAIT(thread);
1.485 +
1.486 + test.End();
1.487 + }
1.488 +
1.489 +TInt LockTwice(TAny*)
1.490 + {
1.491 + RTimer t;
1.492 + test(t.CreateLocal()==KErrNone);
1.493 + TRequestStatus stat;
1.494 + t.Lock(stat, ETwelveOClock);
1.495 + User::WaitForRequest(stat);
1.496 + test(stat==KErrGeneral);
1.497 + t.Lock(stat, ETwelveOClock);
1.498 + t.Lock(stat, ETwelveOClock);
1.499 + return KErrNone;
1.500 + }
1.501 +
1.502 +
1.503 +LOCAL_C void testLock()
1.504 +//
1.505 +// Test locked timers
1.506 +//
1.507 + {
1.508 + test.Start(_L("Test synchronise to ETwelveOClock"));
1.509 + RTimer t;
1.510 + TTime time,time2;
1.511 + test(t.CreateLocal()==KErrNone);
1.512 + TRequestStatus stat;
1.513 + t.Lock(stat, ETwelveOClock);
1.514 + User::WaitForRequest(stat);
1.515 + test(stat==KErrGeneral);
1.516 + time.UniversalTime();
1.517 + t.Lock(stat, ETwelveOClock);
1.518 + User::WaitForRequest(stat);
1.519 + test(stat==KErrNone);
1.520 + time2.UniversalTime();
1.521 + test(time<time2);
1.522 + User::After(500000);
1.523 + test.Next(_L("Test sync to EOneOClock for 4 seconds"));
1.524 + t.Lock(stat, EOneOClock);
1.525 + User::WaitForRequest(stat);
1.526 + test(stat==KErrGeneral);
1.527 + time.UniversalTime();
1.528 + TInt i;
1.529 + for (i=0; i<5; i++)
1.530 + {
1.531 + t.Lock(stat, EOneOClock);
1.532 + User::WaitForRequest(stat);
1.533 + test(stat==KErrNone);
1.534 + test.Printf(_L("."));
1.535 + }
1.536 + time2.UniversalTime();
1.537 + TTimeIntervalSeconds ti;
1.538 + test(time2.SecondsFrom(time, ti)==KErrNone);
1.539 + test(ti>=TTimeIntervalSeconds(4));
1.540 + test.Printf(_L("\n"));
1.541 + test.Next(_L("Test sync to every half second, from EFourOClock for 5 seconds"));
1.542 + t.Lock(stat, ETwelveOClock);
1.543 + User::WaitForRequest(stat);
1.544 + for (i=0; i<5; i++)
1.545 + {
1.546 + t.Lock(stat, EFourOClock);
1.547 + User::WaitForRequest(stat);
1.548 + test(stat==KErrNone);
1.549 + test.Printf(_L("."));
1.550 + t.Lock(stat, ETenOClock);
1.551 + User::WaitForRequest(stat);
1.552 + test(stat==KErrNone);
1.553 + test.Printf(_L(","));
1.554 + }
1.555 + test.Printf(_L("\n"));
1.556 + test.Next(_L("Test KErrGeneral after delay"));
1.557 + User::After(1000000);
1.558 + t.Lock(stat,EThreeOClock);
1.559 + User::WaitForRequest(stat);
1.560 + test(stat==KErrGeneral);
1.561 + test.Next(_L("Test cancel, and re-request immediately"));
1.562 + User::After(1000000);
1.563 + t.Lock(stat, ETwelveOClock);
1.564 + User::WaitForRequest(stat);
1.565 + test(stat==KErrGeneral);
1.566 + t.Lock(stat, EElevenOClock);
1.567 + t.Cancel();
1.568 + User::WaitForRequest(stat);
1.569 + test(stat==KErrCancel);
1.570 + t.Lock(stat, EElevenOClock);
1.571 + User::WaitForRequest(stat);
1.572 + test(stat==KErrNone);
1.573 + test.Next(_L("Test complete a request at 1, then cancel a request for 11, and re-request at 3 gives KErrGeneral"));
1.574 + User::After(1000000);
1.575 + t.Lock(stat, ETwelveOClock);
1.576 + User::WaitForRequest(stat);
1.577 + test(stat==KErrGeneral);
1.578 + t.Lock(stat,EOneOClock);
1.579 + User::WaitForRequest(stat);
1.580 + test(stat==KErrNone);
1.581 + t.Lock(stat,EElevenOClock);
1.582 + User::After(400000); // ensure EThreeOClock is in the past
1.583 + t.Cancel();
1.584 + User::WaitForRequest(stat);
1.585 + test(stat==KErrCancel);
1.586 + t.Lock(stat,EThreeOClock);
1.587 + User::WaitForRequest(stat);
1.588 + // EThreeOClock should be more than one second away from the previous timer expiration
1.589 + test(stat==KErrGeneral);
1.590 +
1.591 + test.Next(_L("Lock twice"));
1.592 + RThread thread;
1.593 + TInt r=thread.Create(_L("Lock twice"),LockTwice,KDefaultStackSize,NULL,&thread);
1.594 + test(r==KErrNone);
1.595 + thread.Logon(stat);
1.596 + test(stat==KRequestPending);
1.597 + TBool justInTime=User::JustInTime();
1.598 + User::SetJustInTime(EFalse);
1.599 + thread.Resume();
1.600 + User::WaitForRequest(stat);
1.601 + User::SetJustInTime(justInTime);
1.602 + test(stat==ETimerAlreadyPending);
1.603 + test(thread.ExitCategory()==_L("KERN-EXEC"));
1.604 + test(thread.ExitReason()==ETimerAlreadyPending);
1.605 + test(thread.ExitType()==EExitPanic);
1.606 + CLOSE_AND_WAIT(thread);
1.607 +
1.608 +#if !(defined(__EPOC32__) && defined(__X86__))
1.609 + TInt muid = 0;
1.610 + HAL::Get(HAL::EMachineUid, muid);
1.611 + if(muid!=HAL::EMachineUid_Lubbock && muid!=HAL::EMachineUid_NE1_TB && muid!=HAL::EMachineUid_STE8500)
1.612 + {
1.613 + test.Next(_L("Test sequential locks fail over on/off"));
1.614 + RTimer tat;
1.615 + TRequestStatus sat;
1.616 + r=tat.CreateLocal();
1.617 + TTime now;
1.618 + now.UniversalTime();
1.619 + tat.AtUTC(sat, now+TTimeIntervalSeconds(10)); // turn on in 10 seconds
1.620 + test(sat==KRequestPending);
1.621 + t.Lock(stat, ETwelveOClock);
1.622 + User::WaitForRequest(stat);
1.623 + test(stat==KErrGeneral);
1.624 + t.Lock(stat, EElevenOClock);
1.625 + User::WaitForRequest(stat);
1.626 + PrintTime();
1.627 + // Go to standby
1.628 + r = Power::EnableWakeupEvents(EPwStandby);
1.629 + test (r == KErrNone);
1.630 + r = Power::PowerDown();
1.631 + test (r == KErrNone);
1.632 + test(stat==KErrNone);
1.633 + PrintTime();
1.634 + t.Lock(stat, EElevenOClock);
1.635 + User::WaitForRequest(stat);
1.636 + test(stat==KErrGeneral);
1.637 + tat.Close();
1.638 + }
1.639 +#endif
1.640 +
1.641 + t.Close();
1.642 + test.End();
1.643 + }
1.644 +
1.645 +
1.646 +void testChange()
1.647 +//
1.648 +// Bug HA-255
1.649 +// Test locked timers abort when the system time changes
1.650 +//
1.651 + {
1.652 + RTimer rr;
1.653 + TRequestStatus stat;
1.654 + rr.CreateLocal();
1.655 + rr.Lock(stat, ETwelveOClock);
1.656 + User::WaitForRequest(stat);
1.657 + test(stat==KErrGeneral);
1.658 + RTimer rrr;
1.659 + rrr.CreateLocal();
1.660 + rrr.After(stat, 1000000);
1.661 + User::WaitForRequest(stat);
1.662 +
1.663 + RTimer r;
1.664 + TRequestStatus sstat;
1.665 + TTime t;
1.666 + r.CreateLocal();
1.667 + r.Lock(stat,ETwelveOClock);
1.668 + rr.Lock(sstat,EOneOClock);
1.669 + User::WaitForRequest(stat);
1.670 + test(stat==KErrGeneral);
1.671 + User::WaitForRequest(sstat);
1.672 + test(sstat==KErrGeneral);
1.673 + r.Lock(stat,ETwelveOClock);
1.674 + rr.Lock(sstat,EOneOClock);
1.675 + User::WaitForRequest(stat);
1.676 + test(stat==KErrNone);
1.677 + User::WaitForRequest(sstat);
1.678 + test(sstat==KErrNone);
1.679 + t.UniversalTime();
1.680 + r.Lock(stat,ETwelveOClock);
1.681 + rr.Lock(sstat,EOneOClock);
1.682 + TInt ret=User::SetUTCTime(t-TTimeIntervalSeconds(100));
1.683 + test(ret==KErrNone);
1.684 + t.UniversalTime();
1.685 + ret=User::SetUTCTime(t+TTimeIntervalSeconds(100));
1.686 + test(ret==KErrNone);
1.687 + User::WaitForRequest(stat);
1.688 + test(stat==KErrAbort);
1.689 + User::WaitForRequest(sstat);
1.690 + test(sstat==KErrAbort);
1.691 +
1.692 + // Check that changing the *secure* time *doesn't* abort a locked timer
1.693 + r.Lock(stat, ETwelveOClock);
1.694 + User::WaitForRequest(stat); // stat will be KErrGeneral after abort above, but time will be TwelveOClock anyway
1.695 + t.UniversalTimeSecure();
1.696 + r.Lock(stat, EEightOClock);
1.697 + ret = User::SetUTCTimeSecure(t+TTimeIntervalSeconds(100));
1.698 + User::WaitForRequest(stat); // this timer should complete at EightOClock with status KErrNone, *not* KErrAbort
1.699 + r.Lock(sstat, ETwelveOClock);
1.700 + User::WaitForRequest(sstat); // this should complete one whole second after we read the secure time above
1.701 + User::SetUTCTimeSecure(t+TTimeIntervalSeconds(1));
1.702 + test(stat == KErrNone);
1.703 + test(sstat == KErrNone);
1.704 + if (ret != KErrNone)
1.705 + RDebug::Printf("WARNING: Secure clock change test skipped because secure time could not be changed!");
1.706 +
1.707 + r.Close();
1.708 + rr.Close();
1.709 + rrr.Close();
1.710 + }
1.711 +
1.712 +void testInactivity()
1.713 + {
1.714 + test.Start(_L("Test User::ResetInactivityTime()"));
1.715 + RTimer t,t2;
1.716 + TRequestStatus stat,stat2;
1.717 + t.CreateLocal();
1.718 + t2.CreateLocal();
1.719 + User::ResetInactivityTime();
1.720 + t.Inactivity(stat, 4);
1.721 + t2.Inactivity(stat2, 2);
1.722 + TTime now;
1.723 + now.UniversalTime();
1.724 + TInt r=User::SetUTCTime(now+TTimeIntervalDays(1));
1.725 + test(r==KErrNone);
1.726 + test(stat==KRequestPending);
1.727 + test(stat2==KRequestPending);
1.728 + r=User::SetUTCTime(now-TTimeIntervalDays(1));
1.729 + test(r==KErrNone);
1.730 + test(stat==KRequestPending);
1.731 + test(stat2==KRequestPending);
1.732 + r=User::SetUTCTime(now);
1.733 + test(r==KErrNone);
1.734 + test(stat==KRequestPending);
1.735 + test(stat2==KRequestPending);
1.736 + User::After(1000000);
1.737 + User::ResetInactivityTime();
1.738 + test(stat==KRequestPending);
1.739 + test(stat2==KRequestPending);
1.740 + User::After(3000000);
1.741 + User::ResetInactivityTime();
1.742 + test(stat==KRequestPending);
1.743 + test(stat2!=KRequestPending);
1.744 + User::After(2000000);
1.745 + User::ResetInactivityTime();
1.746 + test(stat==KRequestPending);
1.747 + User::After(2000000);
1.748 + User::ResetInactivityTime();
1.749 + test(stat==KRequestPending);
1.750 + User::After(5000000);
1.751 + test(stat!=KRequestPending);
1.752 + test.End();
1.753 + }
1.754 +
1.755 +
1.756 +GLDEF_C TInt E32Main()
1.757 +//
1.758 +// Test timers.
1.759 +//
1.760 + {
1.761 + test.Title();
1.762 + TInt r=HAL::Get(HAL::EMachineUid,MachineUid);
1.763 + test(r==KErrNone);
1.764 + test.Start(_L("Testing relative timers"));
1.765 + testRel();
1.766 +
1.767 +#ifdef REQUEST_STATUS_POLL_SOAK_TEST
1.768 + test.Next(_L("Testing polling"));
1.769 + testPoll();
1.770 +#endif
1.771 +
1.772 + test.Next(_L("Testing HomeTime()"));
1.773 + testHomeTime();
1.774 +
1.775 + test.Next(_L("Testing absolute timers"));
1.776 + testAbs();
1.777 +
1.778 + test.Next(_L("Testing locked timers"));
1.779 + testLock();
1.780 +
1.781 + test.Next(_L("Testing changing time"));
1.782 + testChange();
1.783 +
1.784 + test.Next(_L("Testing inactivity timers"));
1.785 + testInactivity();
1.786 +
1.787 + test.End();
1.788 + return(KErrNone);
1.789 + }
1.790 +