1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/misc/t_tmout.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,143 @@
1.4 +// Copyright (c) 1996-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\misc\t_tmout.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include <e32test.h>
1.22 +#include "d_rndtim.h"
1.23 +
1.24 +RTest test(_L("T_TMOUT"));
1.25 +
1.26 +_LIT(KLitThread1Name,"IsrThread");
1.27 +const TInt KThread1Priority = 56;
1.28 +_LIT(KLitThread2Name,"WaitThread");
1.29 +const TInt KThread2Priority = 55;
1.30 +
1.31 +const TInt KTimeout = 5; // milliseconds
1.32 +
1.33 +volatile TUint32 RandomSignalInterval;
1.34 +volatile TUint32 RandomSignalCount;
1.35 +volatile TUint32 TotalCount;
1.36 +volatile TUint32 TimeoutCount;
1.37 +volatile TUint32 BadCount;
1.38 +volatile TUint32 Bad0Count;
1.39 +volatile TUint32 Bad1Count;
1.40 +volatile TUint32 Calibration;
1.41 +
1.42 +RThread IsrT;
1.43 +RThread WaitT;
1.44 +RSemaphore Sem;
1.45 +
1.46 +TInt IsrThread(TAny*)
1.47 + {
1.48 + RThread me;
1.49 + RRndTim rt;
1.50 + TInt r = rt.Open();
1.51 + if (r!=KErrNone)
1.52 + return r;
1.53 + r = rt.SetPriority(me, KThread1Priority);
1.54 + if (r!=KErrNone)
1.55 + return r;
1.56 + rt.StartTimer();
1.57 + Calibration = rt.Calibrate(1024);
1.58 + r = rt.SetPriority(WaitT, KThread2Priority);
1.59 + if (r!=KErrNone)
1.60 + return r;
1.61 + WaitT.Resume();
1.62 + RThread::Rendezvous(KErrNone);
1.63 + FOREVER
1.64 + {
1.65 + rt.Wait();
1.66 + if (RandomSignalCount && !--RandomSignalCount)
1.67 + {
1.68 + RandomSignalCount = RandomSignalInterval;
1.69 + Sem.Signal();
1.70 + }
1.71 + }
1.72 + }
1.73 +
1.74 +TInt WaitThread(TAny*)
1.75 + {
1.76 + TUint32 t1, t2;
1.77 + FOREVER
1.78 + {
1.79 + t1 = User::NTickCount();
1.80 + TInt r = Sem.Wait(KTimeout*1000);
1.81 + t2 = User::NTickCount();
1.82 + ++TotalCount;
1.83 + if (r == KErrTimedOut)
1.84 + {
1.85 + ++TimeoutCount;
1.86 + TInt d = (TInt)(t2-t1);
1.87 + if (d<KTimeout)
1.88 + ++BadCount;
1.89 + if (d==0)
1.90 + ++Bad0Count;
1.91 + if (d==1)
1.92 + ++Bad1Count;
1.93 + }
1.94 + }
1.95 + }
1.96 +
1.97 +GLDEF_C TInt E32Main()
1.98 + {
1.99 + test.Title();
1.100 +
1.101 + test.Start(_L("Load device driver"));
1.102 + TInt r = User::LoadLogicalDevice(_L("d_rndtim.ldd"));
1.103 + if (r == KErrNotFound)
1.104 + {
1.105 + test.Printf(_L("Test not supported on this platform\n"));
1.106 + test.End();
1.107 + return 0;
1.108 + }
1.109 +
1.110 + test.Next(_L("Create semaphore"));
1.111 + r = Sem.CreateLocal(0);
1.112 + test(r==KErrNone);
1.113 +
1.114 + test.Next(_L("Create ISR thread"));
1.115 + r=IsrT.Create(KLitThread1Name, &IsrThread, 0x1000, NULL, NULL);
1.116 + test(r==KErrNone);
1.117 +
1.118 + test.Next(_L("Create wait thread"));
1.119 + r=WaitT.Create(KLitThread2Name, &WaitThread, 0x1000, NULL, NULL);
1.120 + test(r==KErrNone);
1.121 +
1.122 + TRequestStatus s;
1.123 + IsrT.Rendezvous(s);
1.124 + test(s==KRequestPending);
1.125 +
1.126 + IsrT.Resume();
1.127 + User::WaitForRequest(s);
1.128 + test(s==KErrNone);
1.129 + test(IsrT.ExitType() == EExitPending);
1.130 + test(WaitT.ExitType() == EExitPending);
1.131 +
1.132 + test.Printf(_L("%d random timers in 1024ms"), Calibration);
1.133 + TUint32 interval = (KTimeout * Calibration + 512)/1024;
1.134 + test.Printf(_L("Interval %d"), interval);
1.135 + RandomSignalInterval = interval;
1.136 + RandomSignalCount = interval;
1.137 +
1.138 + FOREVER
1.139 + {
1.140 + test.Printf(_L("Total: %8d Timeout: %8d Bad: %4d Bad0: %4d Bad1: %4d\n"), TotalCount, TimeoutCount, BadCount, Bad0Count, Bad1Count);
1.141 + User::After(1000000);
1.142 + }
1.143 +
1.144 +
1.145 + return 0;
1.146 + }