sl@0
|
1 |
// Copyright (c) 2003-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\debug\t_eventtracker.cpp
|
sl@0
|
15 |
// User-side harness for a LDD-based debug agent which keeps
|
sl@0
|
16 |
// track of various events (e.g. thread creation) and tests
|
sl@0
|
17 |
// them for consistency (e.g. a thread deletion event should be
|
sl@0
|
18 |
// preceded with a thread creation one).
|
sl@0
|
19 |
// USAGE:
|
sl@0
|
20 |
// 1. start t_eventtracker usehook
|
sl@0
|
21 |
// to hook event tracker to the stop-mode debugger breakpoint, or
|
sl@0
|
22 |
// start t_eventtracker
|
sl@0
|
23 |
// to add it to the kernel event handler queue
|
sl@0
|
24 |
// 2. << do something e.g. run some tests >>
|
sl@0
|
25 |
// 3. t_eventtracker stop
|
sl@0
|
26 |
// KNOWN ISSUES:
|
sl@0
|
27 |
// * The debug agent allocates memory on the kernel heap.
|
sl@0
|
28 |
// Consequently, it will perturbate any test using
|
sl@0
|
29 |
// __KHEAP_FAILNEXT() (e.g. t_kheap).
|
sl@0
|
30 |
// * There is a window of opportunity when tracking is started
|
sl@0
|
31 |
// or stopped during which some events may be lost, leading
|
sl@0
|
32 |
// to incorrect results. Therefore t_eventtracker should
|
sl@0
|
33 |
// be called only when the system is idle.
|
sl@0
|
34 |
//
|
sl@0
|
35 |
//
|
sl@0
|
36 |
|
sl@0
|
37 |
#include <e32test.h>
|
sl@0
|
38 |
#include "reventtracker.h"
|
sl@0
|
39 |
|
sl@0
|
40 |
RTest test(_L("T_EVENTTRACKER"));
|
sl@0
|
41 |
|
sl@0
|
42 |
_LIT(KTrackerServerName, "EventTrackerServer");
|
sl@0
|
43 |
|
sl@0
|
44 |
//////////////////////////////////////////////////////////////////////////////
|
sl@0
|
45 |
|
sl@0
|
46 |
/** Wrapper around LDD session with debug agent */
|
sl@0
|
47 |
|
sl@0
|
48 |
class CTracker : public CBase
|
sl@0
|
49 |
{
|
sl@0
|
50 |
public:
|
sl@0
|
51 |
~CTracker();
|
sl@0
|
52 |
void Start(TBool aUseHook);
|
sl@0
|
53 |
TInt Stop();
|
sl@0
|
54 |
private:
|
sl@0
|
55 |
REventTracker iEventTracker;
|
sl@0
|
56 |
};
|
sl@0
|
57 |
|
sl@0
|
58 |
CTracker::~CTracker()
|
sl@0
|
59 |
{
|
sl@0
|
60 |
iEventTracker.Close();
|
sl@0
|
61 |
}
|
sl@0
|
62 |
|
sl@0
|
63 |
void CTracker::Start(TBool aUseHook)
|
sl@0
|
64 |
{
|
sl@0
|
65 |
TInt r = User::LoadLogicalDevice(_L("D_EVENTTRACKER.LDD"));
|
sl@0
|
66 |
test(r == KErrNone || r == KErrAlreadyExists);
|
sl@0
|
67 |
|
sl@0
|
68 |
test(iEventTracker.Open(aUseHook) == KErrNone);
|
sl@0
|
69 |
test(iEventTracker.Start() == KErrNone);
|
sl@0
|
70 |
}
|
sl@0
|
71 |
|
sl@0
|
72 |
TInt CTracker::Stop()
|
sl@0
|
73 |
{
|
sl@0
|
74 |
TInt r=iEventTracker.Stop();
|
sl@0
|
75 |
iEventTracker.Close();
|
sl@0
|
76 |
return r;
|
sl@0
|
77 |
}
|
sl@0
|
78 |
|
sl@0
|
79 |
//////////////////////////////////////////////////////////////////////////////
|
sl@0
|
80 |
|
sl@0
|
81 |
|
sl@0
|
82 |
/** Server used to interact with the debug agent */
|
sl@0
|
83 |
|
sl@0
|
84 |
class CTrackerServer : public CServer2
|
sl@0
|
85 |
{
|
sl@0
|
86 |
public:
|
sl@0
|
87 |
static CTrackerServer* NewLC(TBool aUseHook);
|
sl@0
|
88 |
~CTrackerServer();
|
sl@0
|
89 |
// from CServer2
|
sl@0
|
90 |
CSession2* NewSessionL(const TVersion& aVersion,const RMessage2&) const;
|
sl@0
|
91 |
private:
|
sl@0
|
92 |
CTrackerServer();
|
sl@0
|
93 |
public:
|
sl@0
|
94 |
CTracker* iTracker;
|
sl@0
|
95 |
};
|
sl@0
|
96 |
|
sl@0
|
97 |
/** Session used to stop event tracking */
|
sl@0
|
98 |
|
sl@0
|
99 |
class CTrackerSession : public CSession2
|
sl@0
|
100 |
{
|
sl@0
|
101 |
private:
|
sl@0
|
102 |
// from CSession2
|
sl@0
|
103 |
void ServiceL(const RMessage2& aMessage);
|
sl@0
|
104 |
};
|
sl@0
|
105 |
|
sl@0
|
106 |
void CTrackerSession::ServiceL(const RMessage2& aMessage)
|
sl@0
|
107 |
{
|
sl@0
|
108 |
TInt r = ((CTrackerServer*)Server())->iTracker->Stop();
|
sl@0
|
109 |
CActiveScheduler::Stop();
|
sl@0
|
110 |
aMessage.Complete(r);
|
sl@0
|
111 |
}
|
sl@0
|
112 |
|
sl@0
|
113 |
CTrackerServer* CTrackerServer::NewLC(TBool aUseHook)
|
sl@0
|
114 |
{
|
sl@0
|
115 |
CTrackerServer* server = new(ELeave) CTrackerServer;
|
sl@0
|
116 |
CleanupStack::PushL(server);
|
sl@0
|
117 |
server->iTracker = new(ELeave) CTracker;
|
sl@0
|
118 |
server->StartL(KTrackerServerName);
|
sl@0
|
119 |
server->iTracker->Start(aUseHook);
|
sl@0
|
120 |
return server;
|
sl@0
|
121 |
}
|
sl@0
|
122 |
|
sl@0
|
123 |
CTrackerServer::CTrackerServer()
|
sl@0
|
124 |
: CServer2(EPriorityStandard)
|
sl@0
|
125 |
{
|
sl@0
|
126 |
}
|
sl@0
|
127 |
|
sl@0
|
128 |
CTrackerServer::~CTrackerServer()
|
sl@0
|
129 |
{
|
sl@0
|
130 |
delete iTracker;
|
sl@0
|
131 |
}
|
sl@0
|
132 |
|
sl@0
|
133 |
CSession2* CTrackerServer::NewSessionL(const TVersion& /*aVersion*/,const RMessage2&) const
|
sl@0
|
134 |
{
|
sl@0
|
135 |
return new(ELeave) CTrackerSession;
|
sl@0
|
136 |
}
|
sl@0
|
137 |
|
sl@0
|
138 |
//////////////////////////////////////////////////////////////////////////////
|
sl@0
|
139 |
|
sl@0
|
140 |
/** Handle to client/server session */
|
sl@0
|
141 |
|
sl@0
|
142 |
class RTracker : public RSessionBase
|
sl@0
|
143 |
{
|
sl@0
|
144 |
public:
|
sl@0
|
145 |
TInt Open() { return CreateSession(KTrackerServerName, TVersion(), 0); }
|
sl@0
|
146 |
TInt Stop() { return SendReceive(0); }
|
sl@0
|
147 |
};
|
sl@0
|
148 |
|
sl@0
|
149 |
//////////////////////////////////////////////////////////////////////////////
|
sl@0
|
150 |
|
sl@0
|
151 |
void MainL()
|
sl@0
|
152 |
{
|
sl@0
|
153 |
_LIT(KStop,"stop");
|
sl@0
|
154 |
_LIT(KUseHook,"usehook");
|
sl@0
|
155 |
TBuf<64> c;
|
sl@0
|
156 |
User::CommandLine(c);
|
sl@0
|
157 |
if (c.FindF(KStop) >= 0)
|
sl@0
|
158 |
{
|
sl@0
|
159 |
// Stop event tracking
|
sl@0
|
160 |
RTracker t;
|
sl@0
|
161 |
test(t.Open() == KErrNone);
|
sl@0
|
162 |
test(t.Stop() == KErrNone);
|
sl@0
|
163 |
t.Close();
|
sl@0
|
164 |
}
|
sl@0
|
165 |
else
|
sl@0
|
166 |
{
|
sl@0
|
167 |
// Create server and start event tracking
|
sl@0
|
168 |
test(User::RenameThread(KTrackerServerName) == KErrNone);
|
sl@0
|
169 |
|
sl@0
|
170 |
TBool useHook = EFalse;
|
sl@0
|
171 |
if (c.FindF(KUseHook) >= 0)
|
sl@0
|
172 |
{
|
sl@0
|
173 |
useHook = ETrue;
|
sl@0
|
174 |
}
|
sl@0
|
175 |
|
sl@0
|
176 |
CTrackerServer* server = CTrackerServer::NewLC(useHook);
|
sl@0
|
177 |
|
sl@0
|
178 |
CActiveScheduler::Start();
|
sl@0
|
179 |
|
sl@0
|
180 |
CleanupStack::PopAndDestroy(server);
|
sl@0
|
181 |
}
|
sl@0
|
182 |
}
|
sl@0
|
183 |
|
sl@0
|
184 |
|
sl@0
|
185 |
TInt E32Main()
|
sl@0
|
186 |
{
|
sl@0
|
187 |
test.Title();
|
sl@0
|
188 |
|
sl@0
|
189 |
__UHEAP_MARK;
|
sl@0
|
190 |
|
sl@0
|
191 |
CTrapCleanup* cleanup = CTrapCleanup::New();
|
sl@0
|
192 |
test(cleanup != NULL);
|
sl@0
|
193 |
CActiveScheduler* scheduler = new CActiveScheduler;
|
sl@0
|
194 |
test(scheduler != NULL);
|
sl@0
|
195 |
CActiveScheduler::Install(scheduler);
|
sl@0
|
196 |
|
sl@0
|
197 |
TRAPD(r, MainL());
|
sl@0
|
198 |
if (r != KErrNone)
|
sl@0
|
199 |
{
|
sl@0
|
200 |
test.Printf(_L("Unexpected leave: %d\n"), r);
|
sl@0
|
201 |
test(EFalse);
|
sl@0
|
202 |
}
|
sl@0
|
203 |
|
sl@0
|
204 |
delete scheduler;
|
sl@0
|
205 |
delete cleanup;
|
sl@0
|
206 |
|
sl@0
|
207 |
__UHEAP_MARKEND;
|
sl@0
|
208 |
|
sl@0
|
209 |
return 0;
|
sl@0
|
210 |
}
|