Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
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).
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
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.
38 #include "reventtracker.h"
40 RTest test(_L("T_EVENTTRACKER"));
42 _LIT(KTrackerServerName, "EventTrackerServer");
44 //////////////////////////////////////////////////////////////////////////////
46 /** Wrapper around LDD session with debug agent */
48 class CTracker : public CBase
52 void Start(TBool aUseHook);
55 REventTracker iEventTracker;
60 iEventTracker.Close();
63 void CTracker::Start(TBool aUseHook)
65 TInt r = User::LoadLogicalDevice(_L("D_EVENTTRACKER.LDD"));
66 test(r == KErrNone || r == KErrAlreadyExists);
68 test(iEventTracker.Open(aUseHook) == KErrNone);
69 test(iEventTracker.Start() == KErrNone);
74 TInt r=iEventTracker.Stop();
75 iEventTracker.Close();
79 //////////////////////////////////////////////////////////////////////////////
82 /** Server used to interact with the debug agent */
84 class CTrackerServer : public CServer2
87 static CTrackerServer* NewLC(TBool aUseHook);
90 CSession2* NewSessionL(const TVersion& aVersion,const RMessage2&) const;
97 /** Session used to stop event tracking */
99 class CTrackerSession : public CSession2
103 void ServiceL(const RMessage2& aMessage);
106 void CTrackerSession::ServiceL(const RMessage2& aMessage)
108 TInt r = ((CTrackerServer*)Server())->iTracker->Stop();
109 CActiveScheduler::Stop();
110 aMessage.Complete(r);
113 CTrackerServer* CTrackerServer::NewLC(TBool aUseHook)
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);
123 CTrackerServer::CTrackerServer()
124 : CServer2(EPriorityStandard)
128 CTrackerServer::~CTrackerServer()
133 CSession2* CTrackerServer::NewSessionL(const TVersion& /*aVersion*/,const RMessage2&) const
135 return new(ELeave) CTrackerSession;
138 //////////////////////////////////////////////////////////////////////////////
140 /** Handle to client/server session */
142 class RTracker : public RSessionBase
145 TInt Open() { return CreateSession(KTrackerServerName, TVersion(), 0); }
146 TInt Stop() { return SendReceive(0); }
149 //////////////////////////////////////////////////////////////////////////////
154 _LIT(KUseHook,"usehook");
156 User::CommandLine(c);
157 if (c.FindF(KStop) >= 0)
159 // Stop event tracking
161 test(t.Open() == KErrNone);
162 test(t.Stop() == KErrNone);
167 // Create server and start event tracking
168 test(User::RenameThread(KTrackerServerName) == KErrNone);
170 TBool useHook = EFalse;
171 if (c.FindF(KUseHook) >= 0)
176 CTrackerServer* server = CTrackerServer::NewLC(useHook);
178 CActiveScheduler::Start();
180 CleanupStack::PopAndDestroy(server);
191 CTrapCleanup* cleanup = CTrapCleanup::New();
192 test(cleanup != NULL);
193 CActiveScheduler* scheduler = new CActiveScheduler;
194 test(scheduler != NULL);
195 CActiveScheduler::Install(scheduler);
200 test.Printf(_L("Unexpected leave: %d\n"), r);