1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
#ifndef _CLIENT_H_
#define _CLIENT_H_
#include <QList>
#include <QObject>
#include <policy/resource-set.h>
#include <sys/time.h>
#define RES_AUDIO_PLAYBACK (1<<0)
#define RES_VIDEO_PLAYBACK (1<<1)
#define RES_AUDIO_RECORDING (1<<2)
#define RES_VIDEO_RECORDING (1<<3)
#define RES_VIBRA (1<<4)
#define RES_LEDS (1<<5)
#define RES_BACKLIGHT (1<<6)
#define RES_SYSTEM_BUTTON (1<<7)
#define RES_LOCK_BUTTON (1<<8)
#define RES_SCALE_BUTTON (1<<9)
#define RES_SNAP_BUTTON (1<<10)
#define RES_LENS_COVER (1<<11)
class TimeStat
{
public:
double totalTime;
double caseTime;
double totalMax;
double totalMin;
int caseCount;
TimeStat()
{
running = false;
totalTime = 0;
caseTime = 0;
caseCount = 0;
totalMax = 0;
totalMin = 9999999999.;
};
inline void markStart()
{
if( running )
return;
running = true;
gettimeofday(&start, NULL);
}
inline void markEnd(bool failed)
{
if( !running )
return;
gettimeofday(&end, NULL);
running = false;
timevalSub(&end, &start, &end);
caseTime = end.tv_sec * 1000.0 + end.tv_usec / 1000.0;
if( !failed )
{
totalMax = (totalMax < caseTime) ? caseTime : totalMax;
totalMin = (totalMin > caseTime) ? caseTime : totalMin;
totalTime += caseTime;
data.push_back(caseTime);
caseCount++;
}
}
void exportData(const char* name)
{
FILE* f = fopen(name, "wt");
fprintf(f, "Cnt;%d\n", caseCount);
fprintf(f, "Tot;%.4f\n", totalTime);
fprintf(f, "Max;%.4f\n", totalMax);
fprintf(f, "Min;%.4f\n", totalMin);
fprintf(f, "Avg;%.4f\n", totalTime / (double)caseCount);
int pos = 0;
DataList::iterator it;
for( it = data.begin(); it != data.end(); ++it )
{
fprintf(f, "%d;%.4f\n", ++pos, *it);
}
fclose(f);
}
private:
typedef QList<double> DataList;
DataList data;
bool running;
struct timeval start;
struct timeval end;
void timevalSub(struct timeval *a, struct timeval *b, struct timeval *diff)
{
diff->tv_sec = a->tv_sec - b->tv_sec;
if( a->tv_usec < b->tv_usec )
{
diff->tv_sec--;
diff->tv_usec = 1000000 - b->tv_usec + a->tv_usec;
}
else
diff->tv_usec = a->tv_usec - b->tv_usec;
}
};
class Client : public QObject
{
Q_OBJECT
public:
static uint32_t parseResourceList(QString resourceListStr);
public:
Client(int testCnt, QString appClass, uint32_t all, uint32_t optional);
~Client();
bool initialize();
bool cleanup();
int getFailed() { return failed; }
double getAcquireAverage() { return timeStatAcq.totalTime / (double)timeStatAcq.caseCount; }
double getReleaseAverage() { return timeStatRel.totalTime / (double)timeStatRel.caseCount; }
private slots:
void resourceAcquiredHandler(const QList<ResourcePolicy::ResourceType>& grantedResList);
void resourceDeniedHandler();
void resourceLostHandler();
void resourceReleasedHandler();
protected:
void timerEvent(QTimerEvent *e);
private:
enum TestState
{
TestFinished = 0,
TestStart,
TestAcquire,
TestRelease,
TestWaiting
};
QString reportAcquire;
QString reportRelease;
TestState testState;
int testCounter;
int mainTimerID;
QString applicationClass;
TimeStat timeStatAcq;
TimeStat timeStatRel;
TimeStat timeStatTotal;
bool firstTime;
uint32_t allResources;
uint32_t optionalResources;
int failed;
int totalTestCount;
ResourcePolicy::ResourceSet* resourceSet;
ResourcePolicy::Resource* allocateResource(ResourcePolicy::ResourceType resource, bool optional);
ResourcePolicy::ResourceType getResourceType(uint32_t resource);
void createSet(uint32_t list, uint32_t optional);
};
#endif
|