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