[0.3.x] added : test onModuleLoad

git-svn-id: https://pykd.svn.codeplex.com/svn@89806 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2015-03-03 08:05:50 +00:00 committed by Mikhail I. Izmestev
parent 62c713b834
commit 2a6cadd3d2
2 changed files with 22 additions and 12 deletions

View File

@ -16,7 +16,7 @@ class ModuleLoadHandler(pykd.eventHandler):
self.wasLoad = 0 self.wasLoad = 0
self.wasUnload = False self.wasUnload = False
def onLoadModule(self, module): def onModuleLoad(self, module):
"""Load module handler""" """Load module handler"""
if ( fnmatch.fnmatch(module.name().lower(), self.moduleMask) ): if ( fnmatch.fnmatch(module.name().lower(), self.moduleMask) ):
@ -24,7 +24,7 @@ class ModuleLoadHandler(pykd.eventHandler):
return pykd.DEBUG_STATUS_NO_CHANGE return pykd.DEBUG_STATUS_NO_CHANGE
def onUnloadModule(self, modBase): def onModuleUnload(self, modBase):
"""Unload module handler""" """Unload module handler"""
if ( self.wasLoad and (self.wasLoad == modBase) ): if ( self.wasLoad and (self.wasLoad == modBase) ):
@ -37,15 +37,21 @@ class EhLoadTest(unittest.TestCase):
def testLoadUnload(self): def testLoadUnload(self):
"""Start new process and track loading and unloading modules""" """Start new process and track loading and unloading modules"""
pykd.startProcess(target.appPath + " -testLoadUnload") pykd.startProcess(target.appPath + " loadunloadmodule")
with testutils.ContextCallIt( pykd.killProcess ) as contextCallIt: with testutils.ContextCallIt( pykd.killProcess ) as contextCallIt:
modLoadHandler = ModuleLoadHandler( "*Iphlpapi*" )
with testutils.ContextCallIt( getattr(modLoadHandler, "reset") ) as resetEventHandler: pykd.go() # skip initail break
try:
while True: modLoadHandler = ModuleLoadHandler( "ws2_32*" )
pykd.go()
except pykd.WaitEventException: pykd.go()
pass
#with testutils.ContextCallIt( getattr(modLoadHandler, "reset") ) as resetEventHandler:
# try:
# while True:
# pykd.go()
# except pykd.WaitEventException:
# pass
self.assertTrue(modLoadHandler.wasLoad) self.assertTrue(modLoadHandler.wasLoad)
self.assertTrue(modLoadHandler.wasUnload) self.assertTrue(modLoadHandler.wasUnload)

View File

@ -9,6 +9,8 @@ import unittest
# Dynamically append current pykd.pyd path to PYTHONPATH # Dynamically append current pykd.pyd path to PYTHONPATH
sys.path.insert(0, os.path.dirname(sys.argv[1])) sys.path.insert(0, os.path.dirname(sys.argv[1]))
print os.path.abspath(os.curdir)
import pykd import pykd
import target import target
@ -25,6 +27,7 @@ import customtypestest
import mspdbtest import mspdbtest
import excepttest import excepttest
import targetprocess import targetprocess
import ehloadtest
pykd.initialize() pykd.initialize()
@ -61,6 +64,7 @@ def getTestSuite( singleName = "" ):
unittest.TestLoader().loadTestsFromTestCase( stacktest.StackTest ), unittest.TestLoader().loadTestsFromTestCase( stacktest.StackTest ),
unittest.TestLoader().loadTestsFromTestCase( mspdbtest.MsPdbTest ), unittest.TestLoader().loadTestsFromTestCase( mspdbtest.MsPdbTest ),
unittest.TestLoader().loadTestsFromTestCase( targetprocess.ProcessTest ), unittest.TestLoader().loadTestsFromTestCase( targetprocess.ProcessTest ),
unittest.TestLoader().loadTestsFromTestCase( ehloadtest.EhLoadTest ),
#unittest.TestLoader().loadTestsFromTestCase( excepttest.ExceptionTest ), #unittest.TestLoader().loadTestsFromTestCase( excepttest.ExceptionTest ),
] ) ] )
@ -74,12 +78,12 @@ def getTestSuite( singleName = "" ):
if __name__ == "__main__": if __name__ == "__main__":
print "\nTesting PyKd ver. " + pykd.__version__ print "\nTesting PyKd ver.", pykd.__version__, "File:", os.path.dirname(pykd.__file__)
target.appPath = sys.argv[1] target.appPath = sys.argv[1]
target.moduleName = os.path.splitext(os.path.basename(target.appPath))[0] target.moduleName = os.path.splitext(os.path.basename(target.appPath))[0]
unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run( getTestSuite() ) unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run( getTestSuite() )
# raw_input("Press <ENTER>...") #raw_input("Press <ENTER>...")