[0.1.x] +reset for EventHandler

git-svn-id: https://pykd.svn.codeplex.com/svn@78241 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\EreTIk_cp 2012-07-22 15:23:18 +00:00 committed by Mikhail I. Izmestev
parent 2750f694a8
commit 487b4a8f6d
10 changed files with 66 additions and 43 deletions

View File

@ -429,7 +429,7 @@ void DebugClient::terminateProcess()
hres = m_client->TerminateCurrentProcess();
if ( FAILED( hres ) )
throw DbgException( "IDebugClient::TerminateCurrentProcess failed" );
throw DbgException( "IDebugClient::TerminateCurrentProcess", hres );
}
void terminateProcess()

View File

@ -50,7 +50,6 @@ EventHandler::EventHandler( DebugClientPtr &client )
EventHandler::~EventHandler()
{
m_handlerClient->SetEventCallbacks( NULL );
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -17,13 +17,16 @@ namespace pykd {
class EventHandler : public DebugBaseEventCallbacks
{
public:
EventHandler();
EventHandler( DebugClientPtr &client );
virtual ~EventHandler();
void reset() {
m_handlerClient.Release();
}
protected:
STDMETHOD_(ULONG, AddRef)() { return 1; }
@ -67,7 +70,6 @@ protected:
protected:
virtual ULONG onBreakpoint(ULONG Id) = 0;
virtual ULONG onException(const python::dict &/*exceptData*/) = 0;
@ -81,7 +83,6 @@ protected:
virtual ULONG onChangeDebugeeState() = 0;
protected:
CComPtr<IDebugClient> m_handlerClient;
DebugClientPtr m_parentClient;

View File

@ -1,14 +1,10 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Version="9,00"
Name="pykd"
ProjectGUID="{FE961905-666F-4908-A212-961465F46F13}"
RootNamespace="pykd"
SccProjectName="$/pykd/branch/0.1.x/pykd"
SccAuxPath="https://tfs.codeplex.com/tfs/TFS08"
SccLocalPath="."
SccProvider="{4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}"
Keyword="Win32Proj"
TargetFrameworkVersion="0"
>

View File

@ -652,7 +652,8 @@ BOOST_PYTHON_MODULE( pykd )
python::class_<EventHandlerWrap, boost::noncopyable>(
"eventHandler", "Base class for overriding and handling debug notifications" )
.def( python::init<>() )
.def( python::init<DebugClientPtr&>() )
.def( "reset", &pykd::EventHandler::reset,
"Reset event handler" )
.def( "onBreakpoint", &pykd::EventHandlerWrap::onBreakpoint,
"Triggered breakpoint event. Parameter is int: ID of breakpoint\n"
"For ignore event method must return DEBUG_STATUS_NO_CHANGE value" )

View File

@ -112,7 +112,7 @@ class BaseTest( unittest.TestCase ):
def testNewAddededApi( self ):
""" Branch test: new API 0.1.x what must be available """
self.assertTrue( hasattr(pykd, 'createDbgClient') )
# self.assertTrue( hasattr(pykd, 'createDbgClient') )
self.assertTrue( hasattr(pykd, 'detachProcess') )
self.assertTrue( hasattr(pykd, 'diaLoadPdb') )
self.assertTrue( hasattr(pykd, 'getDebuggeeType' ) )
@ -131,7 +131,7 @@ class BaseTest( unittest.TestCase ):
self.assertTrue( hasattr(pykd, 'DiaException') )
self.assertTrue( hasattr(pykd, 'DiaScope') )
self.assertTrue( hasattr(pykd, 'DiaSymbol') )
self.assertTrue( hasattr(pykd, 'dbgClient') )
# self.assertTrue( hasattr(pykd, 'dbgClient') )
self.assertTrue( hasattr(pykd, 'din') )
self.assertTrue( hasattr(pykd, 'dout') )
self.assertTrue( hasattr(pykd, 'eventHandler' ) )

View File

@ -4,11 +4,12 @@ import unittest
import target
import pykd
import fnmatch
import testutils
class ModuleLoadHandler(pykd.eventHandler):
"""Track load/unload module implementation"""
def __init__(self, client, moduleMask):
pykd.eventHandler.__init__(self, client)
def __init__(self, moduleMask):
pykd.eventHandler.__init__(self)
self.moduleMask = moduleMask.lower()
@ -36,13 +37,13 @@ class EhLoadTest(unittest.TestCase):
def testLoadUnload(self):
"""Start new process and track loading and unloading modules"""
testClient = pykd.createDbgClient()
testClient.startProcess( target.appPath + " -testLoadUnload" )
modLoadHandler = ModuleLoadHandler( testClient, "*Iphlpapi*" )
pykd.startProcess(target.appPath + " -testLoadUnload")
with testutils.ContextCallIt( pykd.killProcess ) as contextCallIt:
modLoadHandler = ModuleLoadHandler( "*Iphlpapi*" )
with testutils.ContextCallIt( getattr(modLoadHandler, "reset") ) as resetEventHandler:
try:
while True:
testClient.go()
pykd.go()
except pykd.WaitEventException:
pass

View File

@ -43,14 +43,19 @@ def getTestSuite( singleName = "" ):
unittest.TestLoader().loadTestsFromTestCase( intbase.IntBaseTest ),
unittest.TestLoader().loadTestsFromTestCase( synsymtest.SynSymTest ),
unittest.TestLoader().loadTestsFromTestCase( thrdctxtest.ThreadContextTest ),
unittest.TestLoader().loadTestsFromTestCase( ehloadtest.EhLoadTest ),
unittest.TestLoader().loadTestsFromTestCase( localstest.LocalVarsTest ),
unittest.TestLoader().loadTestsFromTestCase( ehexcepttest.EhExceptionBreakpointTest ),
unittest.TestLoader().loadTestsFromTestCase( regtest.CpuRegTest ),
] )
else:
return unittest.TestSuite( unittest.TestLoader().loadTestsFromName( singleName ) )
def getNewProcessTestSuite():
return unittest.TestSuite(
[
unittest.TestLoader().loadTestsFromTestCase( ehloadtest.EhLoadTest ),
# unittest.TestLoader().loadTestsFromTestCase( localstest.LocalVarsTest ),
# unittest.TestLoader().loadTestsFromTestCase( ehexcepttest.EhExceptionBreakpointTest ),
] )
if __name__ == "__main__":
@ -70,12 +75,16 @@ if __name__ == "__main__":
print ""
suite = getTestSuite()
#suite = getTestSuite( "diatest.DiaTest.testFind" )
#suite = getTestSuite( "typedvar.TypedVarTest.testTypeVarArg" )
#suite = getTestSuite( "typeinfo.TypeInfoTest.testCreateByName" )
#suite = getTestSuite( "typedvar.TypedVarTest.testBitField" )
oneProcessTests = getTestSuite()
#oneProcessTests = getTestSuite( "diatest.DiaTest.testFind" )
#oneProcessTests = getTestSuite( "typedvar.TypedVarTest.testTypeVarArg" )
#oneProcessTests = getTestSuite( "typeinfo.TypeInfoTest.testCreateByName" )
#oneProcessTests = getTestSuite( "typedvar.TypedVarTest.testBitField" )
unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run( suite )
unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run( oneProcessTests )
pykd.killProcess()
unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run( getNewProcessTestSuite() )
raw_input("\npress return\n")

16
test/scripts/testutils.py Normal file
View File

@ -0,0 +1,16 @@
"""PyKd test heplers/wrappers"""
import pykd
class ContextCallIt:
"""Context manager/with statement"""
def __init__(self, callIt):
self.callIt = callIt
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, exc_tb):
try: self.callIt()
except: pass

View File

@ -1,14 +1,10 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Version="9,00"
Name="targetapp"
ProjectGUID="{C6254E16-AB8E-41EE-887D-31458E93FC68}"
RootNamespace="targetapp"
SccProjectName="$/pykd/branch/0.1.x/test/targetapp"
SccAuxPath="https://tfs.codeplex.com/tfs/TFS08"
SccLocalPath="."
SccProvider="{4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}"
Keyword="Win32Proj"
TargetFrameworkVersion="131072"
>
@ -460,6 +456,10 @@
RelativePath="..\scripts\target.py"
>
</File>
<File
RelativePath="..\scripts\testutils.py"
>
</File>
<File
RelativePath="..\scripts\thrdctxtest.py"
>