sl@0
|
1 |
// Copyright (c) 2005-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 |
// Overview:
|
sl@0
|
15 |
// The test measures the duration of the user-side timer services.
|
sl@0
|
16 |
// API Information:
|
sl@0
|
17 |
// User::After(...)
|
sl@0
|
18 |
// User::At(...)
|
sl@0
|
19 |
// User::AfterHighRes(...)
|
sl@0
|
20 |
// Details:
|
sl@0
|
21 |
// - Calls time services a number of times with the same input arguments.
|
sl@0
|
22 |
// - Records and prints the minimum and maximum duration of each test case.
|
sl@0
|
23 |
// - Tests the duration of User::After and User::AfterHighRes on target.
|
sl@0
|
24 |
// Platforms/Drives/Compatibility:
|
sl@0
|
25 |
// Emulator and Hardware (Automatic).
|
sl@0
|
26 |
// Assumptions/Requirement/Pre-requisites:
|
sl@0
|
27 |
// Failures and causes:
|
sl@0
|
28 |
// The test can fail only on target.
|
sl@0
|
29 |
// - The duration of Timer::After(aTime) is not within the limits (from <aTime> to <aTime + 1000000/64+2*NanoKarnelTickPeriod>)
|
sl@0
|
30 |
// - The duration of Timer::AfterHighRes(aTime) is not within the limits (from <aTime> to <aTime+2*NanoKarnelTickPeriod>)
|
sl@0
|
31 |
// Base Port information:
|
sl@0
|
32 |
//
|
sl@0
|
33 |
//
|
sl@0
|
34 |
|
sl@0
|
35 |
#include <e32std.h>
|
sl@0
|
36 |
#include <e32std_private.h>
|
sl@0
|
37 |
#include <e32test.h>
|
sl@0
|
38 |
#include <e32math.h>
|
sl@0
|
39 |
#include <e32svr.h>
|
sl@0
|
40 |
#include <hal.h>
|
sl@0
|
41 |
|
sl@0
|
42 |
LOCAL_D RTest test(_L("T_TIMERDURATION"));
|
sl@0
|
43 |
|
sl@0
|
44 |
// Max number of different time values measured
|
sl@0
|
45 |
const TInt KMaxTimeValues = 12;
|
sl@0
|
46 |
|
sl@0
|
47 |
// number of times measurement taken to average
|
sl@0
|
48 |
const TInt KMaxTimeMeasurements = 20;
|
sl@0
|
49 |
TInt MaxTimeMeasurements;
|
sl@0
|
50 |
TInt TimeRawMS[KMaxTimeMeasurements];//Holds the ROW time in Kernel ticks
|
sl@0
|
51 |
|
sl@0
|
52 |
TInt* TimeValue;
|
sl@0
|
53 |
TInt TimeMin[KMaxTimeValues];
|
sl@0
|
54 |
TInt TimeMax[KMaxTimeValues];
|
sl@0
|
55 |
|
sl@0
|
56 |
void calcStats(TInt i)
|
sl@0
|
57 |
{
|
sl@0
|
58 |
TimeMin[i]=TimeRawMS[0];
|
sl@0
|
59 |
TimeMax[i]=TimeRawMS[0];
|
sl@0
|
60 |
for (TInt j=1; j<MaxTimeMeasurements; ++j)
|
sl@0
|
61 |
{
|
sl@0
|
62 |
if (TimeMin[i]>TimeRawMS[j]) TimeMin[i]=TimeRawMS[j];
|
sl@0
|
63 |
if (TimeMax[i]<TimeRawMS[j]) TimeMax[i]=TimeRawMS[j];
|
sl@0
|
64 |
}
|
sl@0
|
65 |
}
|
sl@0
|
66 |
|
sl@0
|
67 |
void printStats()
|
sl@0
|
68 |
{
|
sl@0
|
69 |
test.Printf(_L("Value\tMin\tMax"));
|
sl@0
|
70 |
for (TInt i=0;i<KMaxTimeValues;++i)
|
sl@0
|
71 |
{
|
sl@0
|
72 |
if (TimeValue[i]<0) break;
|
sl@0
|
73 |
test.Printf(_L("%d\t%d\t%d"),TimeValue[i],TimeMin[i],TimeMax[i]);
|
sl@0
|
74 |
}
|
sl@0
|
75 |
}
|
sl@0
|
76 |
|
sl@0
|
77 |
#define __BEFORE_WAIT__ \
|
sl@0
|
78 |
test.Printf(_L("Measuring value(%d measurements at each value):"), MaxTimeMeasurements);\
|
sl@0
|
79 |
for (i=0;i<KMaxTimeValues;++i)\
|
sl@0
|
80 |
{\
|
sl@0
|
81 |
if (TimeValue[i]<0) break;\
|
sl@0
|
82 |
test.Printf(_L("%d microseconds ..."),TimeValue[i]);\
|
sl@0
|
83 |
value = TimeValue[i];\
|
sl@0
|
84 |
for (j=0; j<MaxTimeMeasurements; ++j)\
|
sl@0
|
85 |
{\
|
sl@0
|
86 |
User::AfterHighRes((Math::Random()&0xf)*1000);\
|
sl@0
|
87 |
|
sl@0
|
88 |
#define __MEASURE1__ tick1 = User::NTickCount();
|
sl@0
|
89 |
|
sl@0
|
90 |
#define __MEASURE2__ tick2 = User::NTickCount();
|
sl@0
|
91 |
|
sl@0
|
92 |
#define __AFTER_WAIT__ \
|
sl@0
|
93 |
TimeRawMS[j]=(tick2-tick1)*tickPeriod;\
|
sl@0
|
94 |
}\
|
sl@0
|
95 |
calcStats(i);\
|
sl@0
|
96 |
}\
|
sl@0
|
97 |
printStats();\
|
sl@0
|
98 |
|
sl@0
|
99 |
GLDEF_C TInt E32Main()
|
sl@0
|
100 |
{
|
sl@0
|
101 |
TInt i,j;
|
sl@0
|
102 |
test.Title();
|
sl@0
|
103 |
test.Start(_L("Timer resolution test"));
|
sl@0
|
104 |
test.SetLogged(ETrue);
|
sl@0
|
105 |
RThread This;
|
sl@0
|
106 |
This.SetPriority(EPriorityRealTime);
|
sl@0
|
107 |
TUint tick1,tick2;
|
sl@0
|
108 |
TInt value, tickPeriod;
|
sl@0
|
109 |
HAL::Get(HAL::ENanoTickPeriod, tickPeriod);
|
sl@0
|
110 |
test.Printf(_L("tickPeriod=%d"),tickPeriod);
|
sl@0
|
111 |
///////////////////////////////////////////
|
sl@0
|
112 |
test.Next(_L("Calibrate"));
|
sl@0
|
113 |
MaxTimeMeasurements = KMaxTimeMeasurements;
|
sl@0
|
114 |
TInt TimeValues1[KMaxTimeValues]={0,-1};
|
sl@0
|
115 |
TimeValue = &TimeValues1[0];
|
sl@0
|
116 |
__BEFORE_WAIT__
|
sl@0
|
117 |
__MEASURE1__
|
sl@0
|
118 |
__MEASURE2__
|
sl@0
|
119 |
__AFTER_WAIT__
|
sl@0
|
120 |
///////////////////////////////////////////
|
sl@0
|
121 |
test.Next(_L("User::After"));
|
sl@0
|
122 |
TInt TimeValues2[KMaxTimeValues]={10000, 40000,80000,160000,320000,-1};
|
sl@0
|
123 |
TimeValue = &TimeValues2[0];
|
sl@0
|
124 |
__BEFORE_WAIT__
|
sl@0
|
125 |
__MEASURE1__
|
sl@0
|
126 |
User::After(value);
|
sl@0
|
127 |
__MEASURE2__
|
sl@0
|
128 |
__AFTER_WAIT__
|
sl@0
|
129 |
#if defined(__EPOC32__)
|
sl@0
|
130 |
//Check that User::After calls completed within boundaries
|
sl@0
|
131 |
TInt k;
|
sl@0
|
132 |
for (k = 0; k<KMaxTimeValues; k++)
|
sl@0
|
133 |
{
|
sl@0
|
134 |
if (TimeValue[k] == -1) break;
|
sl@0
|
135 |
test(TimeValue[k] <= TimeMin[k]);
|
sl@0
|
136 |
TInt aTimerResolution = 1000000/64;
|
sl@0
|
137 |
test((TimeValue[k] + aTimerResolution +2*tickPeriod) >= TimeMax[k]);
|
sl@0
|
138 |
}
|
sl@0
|
139 |
#endif
|
sl@0
|
140 |
///////////////////////////////////////////
|
sl@0
|
141 |
test.Next(_L("User::At"));
|
sl@0
|
142 |
MaxTimeMeasurements = KMaxTimeMeasurements/2;
|
sl@0
|
143 |
TInt TimeValues3[KMaxTimeValues]={950000,1000000,-1};
|
sl@0
|
144 |
TimeValue = &TimeValues3[0];
|
sl@0
|
145 |
TTime time;
|
sl@0
|
146 |
time.Set(_L("20050101:000001.000000"));
|
sl@0
|
147 |
User::SetHomeTime(time);
|
sl@0
|
148 |
__BEFORE_WAIT__
|
sl@0
|
149 |
time.HomeTime();
|
sl@0
|
150 |
time += (TTimeIntervalMicroSeconds32)value;
|
sl@0
|
151 |
__MEASURE1__
|
sl@0
|
152 |
User::At(time);
|
sl@0
|
153 |
__MEASURE2__
|
sl@0
|
154 |
__AFTER_WAIT__
|
sl@0
|
155 |
///////////////////////////////////////////
|
sl@0
|
156 |
test.Next(_L("User::AfterHighRes"));
|
sl@0
|
157 |
MaxTimeMeasurements = KMaxTimeMeasurements;
|
sl@0
|
158 |
TInt TimeValues4[KMaxTimeValues]={1000,2000,4000,8000,16000,32000,64000,128000,-1};
|
sl@0
|
159 |
TimeValue = &TimeValues4[0];
|
sl@0
|
160 |
__BEFORE_WAIT__
|
sl@0
|
161 |
__MEASURE1__
|
sl@0
|
162 |
User::AfterHighRes(value);
|
sl@0
|
163 |
__MEASURE2__
|
sl@0
|
164 |
__AFTER_WAIT__
|
sl@0
|
165 |
#if defined(__EPOC32__)
|
sl@0
|
166 |
//Check that User::AfterHighRes calls completed within boundaries
|
sl@0
|
167 |
for (k = 0; k<KMaxTimeValues; k++)
|
sl@0
|
168 |
{
|
sl@0
|
169 |
if (TimeValue[k] == -1) break;
|
sl@0
|
170 |
test(TimeValue[k] <= TimeMin[k]);
|
sl@0
|
171 |
test((TimeValue[k] + 2*tickPeriod) >= TimeMax[k]);
|
sl@0
|
172 |
}
|
sl@0
|
173 |
#endif
|
sl@0
|
174 |
///////////////////////////////////////////
|
sl@0
|
175 |
test.End();
|
sl@0
|
176 |
return(KErrNone);
|
sl@0
|
177 |
}
|