mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-20 03:23:23 +08:00
[0.1.x] +test of DIA symbols set
git-svn-id: https://pykd.svn.codeplex.com/svn@74771 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
234c60d1f2
commit
012b064e1d
@ -6,6 +6,8 @@ import unittest
|
||||
import target
|
||||
import pykd
|
||||
|
||||
from sets import Set
|
||||
|
||||
class DiaTest( unittest.TestCase ):
|
||||
|
||||
def testCtor(self):
|
||||
@ -14,7 +16,6 @@ class DiaTest( unittest.TestCase ):
|
||||
except RuntimeError: pass
|
||||
|
||||
def testFind(self):
|
||||
try:
|
||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||
self.assertNotEqual(0, len(gScope))
|
||||
symFunction = gScope.find("FuncWithName0")
|
||||
@ -23,43 +24,27 @@ class DiaTest( unittest.TestCase ):
|
||||
"FuNc*Name?",
|
||||
pykd.nsCaseInRegularExpression)
|
||||
self.assertTrue(len(symFunction) > 1)
|
||||
except pykd.DiaException as diaExcept:
|
||||
print diaExcept
|
||||
self.assertTrue(False)
|
||||
|
||||
def testSize(self):
|
||||
try:
|
||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||
self.assertEqual(1, gScope["g_ucharValue"].type().size())
|
||||
self.assertEqual(2, gScope["g_ushortValue"].type().size())
|
||||
self.assertEqual(4, gScope["g_ulongValue"].type().size())
|
||||
self.assertEqual(8, gScope["g_ulonglongValue"].type().size())
|
||||
except pykd.DiaException as diaExcept:
|
||||
print diaExcept
|
||||
self.assertTrue(False)
|
||||
|
||||
def testValue(self):
|
||||
try:
|
||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||
self.assertEqual(0x5555, gScope["g_constNumValue"].value())
|
||||
self.assertEqual(True, gScope["g_constBoolValue"].value())
|
||||
except pykd.DiaException as diaExcept:
|
||||
print diaExcept
|
||||
self.assertTrue(False)
|
||||
|
||||
def testName(self):
|
||||
try:
|
||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||
self.assertEqual( "g_constNumValue",
|
||||
gScope["g_constNumValue"].name() )
|
||||
self.assertEqual( "FuncWithName0",
|
||||
gScope["FuncWithName0"].name() )
|
||||
except pykd.DiaException as diaExcept:
|
||||
print diaExcept
|
||||
self.assertTrue(False)
|
||||
|
||||
def testRva(self):
|
||||
try:
|
||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||
_rva = gScope["FuncWithName0"].rva()
|
||||
self.assertNotEqual(0, _rva)
|
||||
@ -68,34 +53,22 @@ class DiaTest( unittest.TestCase ):
|
||||
_rva = gScope["g_string"].rva()
|
||||
self.assertNotEqual(0, _rva)
|
||||
self.assertTrue( _rva < modLen )
|
||||
except pykd.DiaException as diaExcept:
|
||||
print diaExcept
|
||||
self.assertTrue(False)
|
||||
|
||||
def testSymTag(self):
|
||||
try:
|
||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||
self.assertEqual( pykd.SymTagFunction,
|
||||
gScope["FuncWithName0"].symTag() )
|
||||
self.assertEqual( pykd.SymTagData,
|
||||
gScope["g_string"].symTag() )
|
||||
except pykd.DiaException as diaExcept:
|
||||
print diaExcept
|
||||
self.assertTrue(False)
|
||||
|
||||
def testLocType(self):
|
||||
try:
|
||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||
self.assertEqual( pykd.LocIsConstant,
|
||||
gScope["g_constNumValue"].locType() )
|
||||
self.assertEqual( pykd.LocIsStatic,
|
||||
gScope["FuncWithName1"].locType() )
|
||||
except pykd.DiaException as diaExcept:
|
||||
print diaExcept
|
||||
self.assertTrue(False)
|
||||
|
||||
def testBasicType(self):
|
||||
try:
|
||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||
self.assertFalse(gScope["g_string"].type().isBasic())
|
||||
self.assertEqual( pykd.btBool,
|
||||
@ -103,10 +76,6 @@ class DiaTest( unittest.TestCase ):
|
||||
self.assertEqual( pykd.btULong,
|
||||
gScope["g_ulongValue"].type().baseType() )
|
||||
|
||||
except pykd.DiaException as diaExcept:
|
||||
print diaExcept
|
||||
self.assertTrue(False)
|
||||
|
||||
def testBasicName(self):
|
||||
self.assertEqual( "NoType", pykd.diaBasicType[ pykd.btNoType ] )
|
||||
self.assertEqual( "Void", pykd.diaBasicType[ pykd.btVoid ] )
|
||||
@ -128,7 +97,6 @@ class DiaTest( unittest.TestCase ):
|
||||
self.assertEqual( "Hresult", pykd.diaBasicType[ pykd.btHresult ] )
|
||||
|
||||
def testBits(self):
|
||||
try:
|
||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||
structWithBits = gScope["structWithBits"]
|
||||
bitField = structWithBits["m_bit0_4"]
|
||||
@ -143,33 +111,21 @@ class DiaTest( unittest.TestCase ):
|
||||
self.assertEqual(pykd.LocIsBitField, bitField.locType())
|
||||
self.assertEqual(6, bitField.bitPos())
|
||||
self.assertEqual(2, bitField.size())
|
||||
except pykd.DiaException as diaExcept:
|
||||
print diaExcept
|
||||
self.assertTrue(False)
|
||||
|
||||
def testIndexId(self):
|
||||
try:
|
||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||
self.assertNotEqual( gScope["classChild"].indexId(),
|
||||
gScope["classBase"].indexId() )
|
||||
self.assertNotEqual( gScope["FuncWithName0"].indexId(),
|
||||
gScope["FuncWithName1"].indexId() )
|
||||
except pykd.DiaException as diaExcept:
|
||||
print diaExcept
|
||||
self.assertTrue(False)
|
||||
|
||||
def testUdtKind(self):
|
||||
try:
|
||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||
self.assertEqual(pykd.UdtStruct, gScope["structTest"].udtKind())
|
||||
self.assertEqual(pykd.UdtUnion, gScope["unionTest"].udtKind())
|
||||
self.assertEqual(pykd.UdtClass, gScope["classBase"].udtKind())
|
||||
except pykd.DiaException as diaExcept:
|
||||
print diaExcept
|
||||
self.assertTrue(False)
|
||||
|
||||
def testOffset(self):
|
||||
try:
|
||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||
structTest = gScope["structTest"]
|
||||
self.assertEqual( 0, structTest["m_field0"].offset() )
|
||||
@ -181,22 +137,14 @@ class DiaTest( unittest.TestCase ):
|
||||
structTest["m_field3"].offset() )
|
||||
self.assertTrue( structTest["m_field3"].offset() <
|
||||
structTest.size() )
|
||||
except pykd.DiaException as diaExcept:
|
||||
print diaExcept
|
||||
self.assertTrue(False)
|
||||
|
||||
def testMachine(self):
|
||||
try:
|
||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||
machine = gScope.machineType()
|
||||
self.assertTrue( (machine == pykd.IMAGE_FILE_MACHINE_I386) or
|
||||
(machine == pykd.IMAGE_FILE_MACHINE_AMD64) )
|
||||
except pykd.DiaException as diaExcept:
|
||||
print diaExcept
|
||||
self.assertTrue(False)
|
||||
|
||||
def testFindByRva(self):
|
||||
try:
|
||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||
func = gScope["FuncWithName0"]
|
||||
tplSymOffset = gScope.findByRva(func.rva(), pykd.SymTagFunction)
|
||||
@ -205,34 +153,27 @@ class DiaTest( unittest.TestCase ):
|
||||
tplSymOffset = gScope.findByRva(func.rva()+2, pykd.SymTagFunction)
|
||||
self.assertEqual(tplSymOffset[0].indexId(), func.indexId())
|
||||
self.assertEqual(tplSymOffset[1], 2)
|
||||
except pykd.DiaException as diaExcept:
|
||||
print diaExcept
|
||||
self.assertTrue(False)
|
||||
|
||||
def testSymbolById(self):
|
||||
try:
|
||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||
func = gScope["FuncWithName0"]
|
||||
self.assertEqual( gScope.symbolById(func.indexId()).indexId(),
|
||||
func.indexId())
|
||||
except pykd.DiaException as diaExcept:
|
||||
print diaExcept
|
||||
self.assertTrue(False)
|
||||
|
||||
def testCount(self):
|
||||
try:
|
||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||
var = gScope["FuncWithName1"]["_unionTest"]
|
||||
self.assertEqual( 2, var.type().count() )
|
||||
except pykd.DiaException as diaExcept:
|
||||
print diaExcept
|
||||
self.assertTrue(False)
|
||||
|
||||
def testDataKind(self):
|
||||
try:
|
||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||
self.assertEqual( pykd.DataIsGlobal, gScope["g_structTest"].dataKind() )
|
||||
self.assertEqual( pykd.DataIsParam, gScope["EnumWindowsProc1"]["hWindow"].dataKind() )
|
||||
except pykd.DiaException as diaExcept:
|
||||
print diaExcept
|
||||
self.assertTrue(False)
|
||||
|
||||
def testSymbolHash(self):
|
||||
"""Test set of DIA symbols"""
|
||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||
symSet = set([ gScope["g_structTest"], gScope["EnumWindowsProc1"], gScope["g_structTest"] ])
|
||||
self.assertEqual( 2, len(symSet) )
|
||||
self.assertTrue( gScope["g_structTest"] in symSet )
|
||||
self.assertFalse( gScope["EnumWindowsProc2"] in symSet )
|
||||
|
Loading…
Reference in New Issue
Block a user