sl@0
|
1 |
// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// e32test\misc\t_tmout.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <e32test.h>
|
sl@0
|
19 |
#include "d_rndtim.h"
|
sl@0
|
20 |
|
sl@0
|
21 |
RTest test(_L("T_TMOUT"));
|
sl@0
|
22 |
|
sl@0
|
23 |
_LIT(KLitThread1Name,"IsrThread");
|
sl@0
|
24 |
const TInt KThread1Priority = 56;
|
sl@0
|
25 |
_LIT(KLitThread2Name,"WaitThread");
|
sl@0
|
26 |
const TInt KThread2Priority = 55;
|
sl@0
|
27 |
|
sl@0
|
28 |
const TInt KTimeout = 5; // milliseconds
|
sl@0
|
29 |
|
sl@0
|
30 |
volatile TUint32 RandomSignalInterval;
|
sl@0
|
31 |
volatile TUint32 RandomSignalCount;
|
sl@0
|
32 |
volatile TUint32 TotalCount;
|
sl@0
|
33 |
volatile TUint32 TimeoutCount;
|
sl@0
|
34 |
volatile TUint32 BadCount;
|
sl@0
|
35 |
volatile TUint32 Bad0Count;
|
sl@0
|
36 |
volatile TUint32 Bad1Count;
|
sl@0
|
37 |
volatile TUint32 Calibration;
|
sl@0
|
38 |
|
sl@0
|
39 |
RThread IsrT;
|
sl@0
|
40 |
RThread WaitT;
|
sl@0
|
41 |
RSemaphore Sem;
|
sl@0
|
42 |
|
sl@0
|
43 |
TInt IsrThread(TAny*)
|
sl@0
|
44 |
{
|
sl@0
|
45 |
RThread me;
|
sl@0
|
46 |
RRndTim rt;
|
sl@0
|
47 |
TInt r = rt.Open();
|
sl@0
|
48 |
if (r!=KErrNone)
|
sl@0
|
49 |
return r;
|
sl@0
|
50 |
r = rt.SetPriority(me, KThread1Priority);
|
sl@0
|
51 |
if (r!=KErrNone)
|
sl@0
|
52 |
return r;
|
sl@0
|
53 |
rt.StartTimer();
|
sl@0
|
54 |
Calibration = rt.Calibrate(1024);
|
sl@0
|
55 |
r = rt.SetPriority(WaitT, KThread2Priority);
|
sl@0
|
56 |
if (r!=KErrNone)
|
sl@0
|
57 |
return r;
|
sl@0
|
58 |
WaitT.Resume();
|
sl@0
|
59 |
RThread::Rendezvous(KErrNone);
|
sl@0
|
60 |
FOREVER
|
sl@0
|
61 |
{
|
sl@0
|
62 |
rt.Wait();
|
sl@0
|
63 |
if (RandomSignalCount && !--RandomSignalCount)
|
sl@0
|
64 |
{
|
sl@0
|
65 |
RandomSignalCount = RandomSignalInterval;
|
sl@0
|
66 |
Sem.Signal();
|
sl@0
|
67 |
}
|
sl@0
|
68 |
}
|
sl@0
|
69 |
}
|
sl@0
|
70 |
|
sl@0
|
71 |
TInt WaitThread(TAny*)
|
sl@0
|
72 |
{
|
sl@0
|
73 |
TUint32 t1, t2;
|
sl@0
|
74 |
FOREVER
|
sl@0
|
75 |
{
|
sl@0
|
76 |
t1 = User::NTickCount();
|
sl@0
|
77 |
TInt r = Sem.Wait(KTimeout*1000);
|
sl@0
|
78 |
t2 = User::NTickCount();
|
sl@0
|
79 |
++TotalCount;
|
sl@0
|
80 |
if (r == KErrTimedOut)
|
sl@0
|
81 |
{
|
sl@0
|
82 |
++TimeoutCount;
|
sl@0
|
83 |
TInt d = (TInt)(t2-t1);
|
sl@0
|
84 |
if (d<KTimeout)
|
sl@0
|
85 |
++BadCount;
|
sl@0
|
86 |
if (d==0)
|
sl@0
|
87 |
++Bad0Count;
|
sl@0
|
88 |
if (d==1)
|
sl@0
|
89 |
++Bad1Count;
|
sl@0
|
90 |
}
|
sl@0
|
91 |
}
|
sl@0
|
92 |
}
|
sl@0
|
93 |
|
sl@0
|
94 |
GLDEF_C TInt E32Main()
|
sl@0
|
95 |
{
|
sl@0
|
96 |
test.Title();
|
sl@0
|
97 |
|
sl@0
|
98 |
test.Start(_L("Load device driver"));
|
sl@0
|
99 |
TInt r = User::LoadLogicalDevice(_L("d_rndtim.ldd"));
|
sl@0
|
100 |
if (r == KErrNotFound)
|
sl@0
|
101 |
{
|
sl@0
|
102 |
test.Printf(_L("Test not supported on this platform\n"));
|
sl@0
|
103 |
test.End();
|
sl@0
|
104 |
return 0;
|
sl@0
|
105 |
}
|
sl@0
|
106 |
|
sl@0
|
107 |
test.Next(_L("Create semaphore"));
|
sl@0
|
108 |
r = Sem.CreateLocal(0);
|
sl@0
|
109 |
test(r==KErrNone);
|
sl@0
|
110 |
|
sl@0
|
111 |
test.Next(_L("Create ISR thread"));
|
sl@0
|
112 |
r=IsrT.Create(KLitThread1Name, &IsrThread, 0x1000, NULL, NULL);
|
sl@0
|
113 |
test(r==KErrNone);
|
sl@0
|
114 |
|
sl@0
|
115 |
test.Next(_L("Create wait thread"));
|
sl@0
|
116 |
r=WaitT.Create(KLitThread2Name, &WaitThread, 0x1000, NULL, NULL);
|
sl@0
|
117 |
test(r==KErrNone);
|
sl@0
|
118 |
|
sl@0
|
119 |
TRequestStatus s;
|
sl@0
|
120 |
IsrT.Rendezvous(s);
|
sl@0
|
121 |
test(s==KRequestPending);
|
sl@0
|
122 |
|
sl@0
|
123 |
IsrT.Resume();
|
sl@0
|
124 |
User::WaitForRequest(s);
|
sl@0
|
125 |
test(s==KErrNone);
|
sl@0
|
126 |
test(IsrT.ExitType() == EExitPending);
|
sl@0
|
127 |
test(WaitT.ExitType() == EExitPending);
|
sl@0
|
128 |
|
sl@0
|
129 |
test.Printf(_L("%d random timers in 1024ms"), Calibration);
|
sl@0
|
130 |
TUint32 interval = (KTimeout * Calibration + 512)/1024;
|
sl@0
|
131 |
test.Printf(_L("Interval %d"), interval);
|
sl@0
|
132 |
RandomSignalInterval = interval;
|
sl@0
|
133 |
RandomSignalCount = interval;
|
sl@0
|
134 |
|
sl@0
|
135 |
FOREVER
|
sl@0
|
136 |
{
|
sl@0
|
137 |
test.Printf(_L("Total: %8d Timeout: %8d Bad: %4d Bad0: %4d Bad1: %4d\n"), TotalCount, TimeoutCount, BadCount, Bad0Count, Bad1Count);
|
sl@0
|
138 |
User::After(1000000);
|
sl@0
|
139 |
}
|
sl@0
|
140 |
|
sl@0
|
141 |
|
sl@0
|
142 |
return 0;
|
sl@0
|
143 |
}
|