1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/debug/t_eventtracker.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,210 @@
1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32test\debug\t_eventtracker.cpp
1.18 +// User-side harness for a LDD-based debug agent which keeps
1.19 +// track of various events (e.g. thread creation) and tests
1.20 +// them for consistency (e.g. a thread deletion event should be
1.21 +// preceded with a thread creation one).
1.22 +// USAGE:
1.23 +// 1. start t_eventtracker usehook
1.24 +// to hook event tracker to the stop-mode debugger breakpoint, or
1.25 +// start t_eventtracker
1.26 +// to add it to the kernel event handler queue
1.27 +// 2. << do something e.g. run some tests >>
1.28 +// 3. t_eventtracker stop
1.29 +// KNOWN ISSUES:
1.30 +// * The debug agent allocates memory on the kernel heap.
1.31 +// Consequently, it will perturbate any test using
1.32 +// __KHEAP_FAILNEXT() (e.g. t_kheap).
1.33 +// * There is a window of opportunity when tracking is started
1.34 +// or stopped during which some events may be lost, leading
1.35 +// to incorrect results. Therefore t_eventtracker should
1.36 +// be called only when the system is idle.
1.37 +//
1.38 +//
1.39 +
1.40 +#include <e32test.h>
1.41 +#include "reventtracker.h"
1.42 +
1.43 +RTest test(_L("T_EVENTTRACKER"));
1.44 +
1.45 +_LIT(KTrackerServerName, "EventTrackerServer");
1.46 +
1.47 +//////////////////////////////////////////////////////////////////////////////
1.48 +
1.49 +/** Wrapper around LDD session with debug agent */
1.50 +
1.51 +class CTracker : public CBase
1.52 + {
1.53 +public:
1.54 + ~CTracker();
1.55 + void Start(TBool aUseHook);
1.56 + TInt Stop();
1.57 +private:
1.58 + REventTracker iEventTracker;
1.59 + };
1.60 +
1.61 +CTracker::~CTracker()
1.62 + {
1.63 + iEventTracker.Close();
1.64 + }
1.65 +
1.66 +void CTracker::Start(TBool aUseHook)
1.67 + {
1.68 + TInt r = User::LoadLogicalDevice(_L("D_EVENTTRACKER.LDD"));
1.69 + test(r == KErrNone || r == KErrAlreadyExists);
1.70 +
1.71 + test(iEventTracker.Open(aUseHook) == KErrNone);
1.72 + test(iEventTracker.Start() == KErrNone);
1.73 + }
1.74 +
1.75 +TInt CTracker::Stop()
1.76 + {
1.77 + TInt r=iEventTracker.Stop();
1.78 + iEventTracker.Close();
1.79 + return r;
1.80 + }
1.81 +
1.82 +//////////////////////////////////////////////////////////////////////////////
1.83 +
1.84 +
1.85 +/** Server used to interact with the debug agent */
1.86 +
1.87 +class CTrackerServer : public CServer2
1.88 + {
1.89 +public:
1.90 + static CTrackerServer* NewLC(TBool aUseHook);
1.91 + ~CTrackerServer();
1.92 + // from CServer2
1.93 + CSession2* NewSessionL(const TVersion& aVersion,const RMessage2&) const;
1.94 +private:
1.95 + CTrackerServer();
1.96 +public:
1.97 + CTracker* iTracker;
1.98 + };
1.99 +
1.100 +/** Session used to stop event tracking */
1.101 +
1.102 +class CTrackerSession : public CSession2
1.103 + {
1.104 +private:
1.105 + // from CSession2
1.106 + void ServiceL(const RMessage2& aMessage);
1.107 + };
1.108 +
1.109 +void CTrackerSession::ServiceL(const RMessage2& aMessage)
1.110 + {
1.111 + TInt r = ((CTrackerServer*)Server())->iTracker->Stop();
1.112 + CActiveScheduler::Stop();
1.113 + aMessage.Complete(r);
1.114 + }
1.115 +
1.116 +CTrackerServer* CTrackerServer::NewLC(TBool aUseHook)
1.117 + {
1.118 + CTrackerServer* server = new(ELeave) CTrackerServer;
1.119 + CleanupStack::PushL(server);
1.120 + server->iTracker = new(ELeave) CTracker;
1.121 + server->StartL(KTrackerServerName);
1.122 + server->iTracker->Start(aUseHook);
1.123 + return server;
1.124 + }
1.125 +
1.126 +CTrackerServer::CTrackerServer()
1.127 + : CServer2(EPriorityStandard)
1.128 + {
1.129 + }
1.130 +
1.131 +CTrackerServer::~CTrackerServer()
1.132 + {
1.133 + delete iTracker;
1.134 + }
1.135 +
1.136 +CSession2* CTrackerServer::NewSessionL(const TVersion& /*aVersion*/,const RMessage2&) const
1.137 + {
1.138 + return new(ELeave) CTrackerSession;
1.139 + }
1.140 +
1.141 +//////////////////////////////////////////////////////////////////////////////
1.142 +
1.143 +/** Handle to client/server session */
1.144 +
1.145 +class RTracker : public RSessionBase
1.146 + {
1.147 +public:
1.148 + TInt Open() { return CreateSession(KTrackerServerName, TVersion(), 0); }
1.149 + TInt Stop() { return SendReceive(0); }
1.150 + };
1.151 +
1.152 +//////////////////////////////////////////////////////////////////////////////
1.153 +
1.154 +void MainL()
1.155 + {
1.156 + _LIT(KStop,"stop");
1.157 + _LIT(KUseHook,"usehook");
1.158 + TBuf<64> c;
1.159 + User::CommandLine(c);
1.160 + if (c.FindF(KStop) >= 0)
1.161 + {
1.162 + // Stop event tracking
1.163 + RTracker t;
1.164 + test(t.Open() == KErrNone);
1.165 + test(t.Stop() == KErrNone);
1.166 + t.Close();
1.167 + }
1.168 + else
1.169 + {
1.170 + // Create server and start event tracking
1.171 + test(User::RenameThread(KTrackerServerName) == KErrNone);
1.172 +
1.173 + TBool useHook = EFalse;
1.174 + if (c.FindF(KUseHook) >= 0)
1.175 + {
1.176 + useHook = ETrue;
1.177 + }
1.178 +
1.179 + CTrackerServer* server = CTrackerServer::NewLC(useHook);
1.180 +
1.181 + CActiveScheduler::Start();
1.182 +
1.183 + CleanupStack::PopAndDestroy(server);
1.184 + }
1.185 + }
1.186 +
1.187 +
1.188 +TInt E32Main()
1.189 + {
1.190 + test.Title();
1.191 +
1.192 + __UHEAP_MARK;
1.193 +
1.194 + CTrapCleanup* cleanup = CTrapCleanup::New();
1.195 + test(cleanup != NULL);
1.196 + CActiveScheduler* scheduler = new CActiveScheduler;
1.197 + test(scheduler != NULL);
1.198 + CActiveScheduler::Install(scheduler);
1.199 +
1.200 + TRAPD(r, MainL());
1.201 + if (r != KErrNone)
1.202 + {
1.203 + test.Printf(_L("Unexpected leave: %d\n"), r);
1.204 + test(EFalse);
1.205 + }
1.206 +
1.207 + delete scheduler;
1.208 + delete cleanup;
1.209 +
1.210 + __UHEAP_MARKEND;
1.211 +
1.212 + return 0;
1.213 + }