[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:
SND\EreTIk_cp 2012-03-07 19:13:26 +00:00 committed by Mikhail I. Izmestev
parent 234c60d1f2
commit 012b064e1d

View File

@ -6,6 +6,8 @@ import unittest
import target import target
import pykd import pykd
from sets import Set
class DiaTest( unittest.TestCase ): class DiaTest( unittest.TestCase ):
def testCtor(self): def testCtor(self):
@ -14,7 +16,6 @@ class DiaTest( unittest.TestCase ):
except RuntimeError: pass except RuntimeError: pass
def testFind(self): def testFind(self):
try:
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
self.assertNotEqual(0, len(gScope)) self.assertNotEqual(0, len(gScope))
symFunction = gScope.find("FuncWithName0") symFunction = gScope.find("FuncWithName0")
@ -23,43 +24,27 @@ class DiaTest( unittest.TestCase ):
"FuNc*Name?", "FuNc*Name?",
pykd.nsCaseInRegularExpression) pykd.nsCaseInRegularExpression)
self.assertTrue(len(symFunction) > 1) self.assertTrue(len(symFunction) > 1)
except pykd.DiaException as diaExcept:
print diaExcept
self.assertTrue(False)
def testSize(self): def testSize(self):
try:
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
self.assertEqual(1, gScope["g_ucharValue"].type().size()) self.assertEqual(1, gScope["g_ucharValue"].type().size())
self.assertEqual(2, gScope["g_ushortValue"].type().size()) self.assertEqual(2, gScope["g_ushortValue"].type().size())
self.assertEqual(4, gScope["g_ulongValue"].type().size()) self.assertEqual(4, gScope["g_ulongValue"].type().size())
self.assertEqual(8, gScope["g_ulonglongValue"].type().size()) self.assertEqual(8, gScope["g_ulonglongValue"].type().size())
except pykd.DiaException as diaExcept:
print diaExcept
self.assertTrue(False)
def testValue(self): def testValue(self):
try:
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
self.assertEqual(0x5555, gScope["g_constNumValue"].value()) self.assertEqual(0x5555, gScope["g_constNumValue"].value())
self.assertEqual(True, gScope["g_constBoolValue"].value()) self.assertEqual(True, gScope["g_constBoolValue"].value())
except pykd.DiaException as diaExcept:
print diaExcept
self.assertTrue(False)
def testName(self): def testName(self):
try:
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
self.assertEqual( "g_constNumValue", self.assertEqual( "g_constNumValue",
gScope["g_constNumValue"].name() ) gScope["g_constNumValue"].name() )
self.assertEqual( "FuncWithName0", self.assertEqual( "FuncWithName0",
gScope["FuncWithName0"].name() ) gScope["FuncWithName0"].name() )
except pykd.DiaException as diaExcept:
print diaExcept
self.assertTrue(False)
def testRva(self): def testRva(self):
try:
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
_rva = gScope["FuncWithName0"].rva() _rva = gScope["FuncWithName0"].rva()
self.assertNotEqual(0, _rva) self.assertNotEqual(0, _rva)
@ -68,34 +53,22 @@ class DiaTest( unittest.TestCase ):
_rva = gScope["g_string"].rva() _rva = gScope["g_string"].rva()
self.assertNotEqual(0, _rva) self.assertNotEqual(0, _rva)
self.assertTrue( _rva < modLen ) self.assertTrue( _rva < modLen )
except pykd.DiaException as diaExcept:
print diaExcept
self.assertTrue(False)
def testSymTag(self): def testSymTag(self):
try:
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
self.assertEqual( pykd.SymTagFunction, self.assertEqual( pykd.SymTagFunction,
gScope["FuncWithName0"].symTag() ) gScope["FuncWithName0"].symTag() )
self.assertEqual( pykd.SymTagData, self.assertEqual( pykd.SymTagData,
gScope["g_string"].symTag() ) gScope["g_string"].symTag() )
except pykd.DiaException as diaExcept:
print diaExcept
self.assertTrue(False)
def testLocType(self): def testLocType(self):
try:
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
self.assertEqual( pykd.LocIsConstant, self.assertEqual( pykd.LocIsConstant,
gScope["g_constNumValue"].locType() ) gScope["g_constNumValue"].locType() )
self.assertEqual( pykd.LocIsStatic, self.assertEqual( pykd.LocIsStatic,
gScope["FuncWithName1"].locType() ) gScope["FuncWithName1"].locType() )
except pykd.DiaException as diaExcept:
print diaExcept
self.assertTrue(False)
def testBasicType(self): def testBasicType(self):
try:
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
self.assertFalse(gScope["g_string"].type().isBasic()) self.assertFalse(gScope["g_string"].type().isBasic())
self.assertEqual( pykd.btBool, self.assertEqual( pykd.btBool,
@ -103,10 +76,6 @@ class DiaTest( unittest.TestCase ):
self.assertEqual( pykd.btULong, self.assertEqual( pykd.btULong,
gScope["g_ulongValue"].type().baseType() ) gScope["g_ulongValue"].type().baseType() )
except pykd.DiaException as diaExcept:
print diaExcept
self.assertTrue(False)
def testBasicName(self): def testBasicName(self):
self.assertEqual( "NoType", pykd.diaBasicType[ pykd.btNoType ] ) self.assertEqual( "NoType", pykd.diaBasicType[ pykd.btNoType ] )
self.assertEqual( "Void", pykd.diaBasicType[ pykd.btVoid ] ) self.assertEqual( "Void", pykd.diaBasicType[ pykd.btVoid ] )
@ -128,7 +97,6 @@ class DiaTest( unittest.TestCase ):
self.assertEqual( "Hresult", pykd.diaBasicType[ pykd.btHresult ] ) self.assertEqual( "Hresult", pykd.diaBasicType[ pykd.btHresult ] )
def testBits(self): def testBits(self):
try:
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
structWithBits = gScope["structWithBits"] structWithBits = gScope["structWithBits"]
bitField = structWithBits["m_bit0_4"] bitField = structWithBits["m_bit0_4"]
@ -143,33 +111,21 @@ class DiaTest( unittest.TestCase ):
self.assertEqual(pykd.LocIsBitField, bitField.locType()) self.assertEqual(pykd.LocIsBitField, bitField.locType())
self.assertEqual(6, bitField.bitPos()) self.assertEqual(6, bitField.bitPos())
self.assertEqual(2, bitField.size()) self.assertEqual(2, bitField.size())
except pykd.DiaException as diaExcept:
print diaExcept
self.assertTrue(False)
def testIndexId(self): def testIndexId(self):
try:
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
self.assertNotEqual( gScope["classChild"].indexId(), self.assertNotEqual( gScope["classChild"].indexId(),
gScope["classBase"].indexId() ) gScope["classBase"].indexId() )
self.assertNotEqual( gScope["FuncWithName0"].indexId(), self.assertNotEqual( gScope["FuncWithName0"].indexId(),
gScope["FuncWithName1"].indexId() ) gScope["FuncWithName1"].indexId() )
except pykd.DiaException as diaExcept:
print diaExcept
self.assertTrue(False)
def testUdtKind(self): def testUdtKind(self):
try:
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
self.assertEqual(pykd.UdtStruct, gScope["structTest"].udtKind()) self.assertEqual(pykd.UdtStruct, gScope["structTest"].udtKind())
self.assertEqual(pykd.UdtUnion, gScope["unionTest"].udtKind()) self.assertEqual(pykd.UdtUnion, gScope["unionTest"].udtKind())
self.assertEqual(pykd.UdtClass, gScope["classBase"].udtKind()) self.assertEqual(pykd.UdtClass, gScope["classBase"].udtKind())
except pykd.DiaException as diaExcept:
print diaExcept
self.assertTrue(False)
def testOffset(self): def testOffset(self):
try:
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
structTest = gScope["structTest"] structTest = gScope["structTest"]
self.assertEqual( 0, structTest["m_field0"].offset() ) self.assertEqual( 0, structTest["m_field0"].offset() )
@ -181,22 +137,14 @@ class DiaTest( unittest.TestCase ):
structTest["m_field3"].offset() ) structTest["m_field3"].offset() )
self.assertTrue( structTest["m_field3"].offset() < self.assertTrue( structTest["m_field3"].offset() <
structTest.size() ) structTest.size() )
except pykd.DiaException as diaExcept:
print diaExcept
self.assertTrue(False)
def testMachine(self): def testMachine(self):
try:
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
machine = gScope.machineType() machine = gScope.machineType()
self.assertTrue( (machine == pykd.IMAGE_FILE_MACHINE_I386) or self.assertTrue( (machine == pykd.IMAGE_FILE_MACHINE_I386) or
(machine == pykd.IMAGE_FILE_MACHINE_AMD64) ) (machine == pykd.IMAGE_FILE_MACHINE_AMD64) )
except pykd.DiaException as diaExcept:
print diaExcept
self.assertTrue(False)
def testFindByRva(self): def testFindByRva(self):
try:
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
func = gScope["FuncWithName0"] func = gScope["FuncWithName0"]
tplSymOffset = gScope.findByRva(func.rva(), pykd.SymTagFunction) tplSymOffset = gScope.findByRva(func.rva(), pykd.SymTagFunction)
@ -205,34 +153,27 @@ class DiaTest( unittest.TestCase ):
tplSymOffset = gScope.findByRva(func.rva()+2, pykd.SymTagFunction) tplSymOffset = gScope.findByRva(func.rva()+2, pykd.SymTagFunction)
self.assertEqual(tplSymOffset[0].indexId(), func.indexId()) self.assertEqual(tplSymOffset[0].indexId(), func.indexId())
self.assertEqual(tplSymOffset[1], 2) self.assertEqual(tplSymOffset[1], 2)
except pykd.DiaException as diaExcept:
print diaExcept
self.assertTrue(False)
def testSymbolById(self): def testSymbolById(self):
try:
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
func = gScope["FuncWithName0"] func = gScope["FuncWithName0"]
self.assertEqual( gScope.symbolById(func.indexId()).indexId(), self.assertEqual( gScope.symbolById(func.indexId()).indexId(),
func.indexId()) func.indexId())
except pykd.DiaException as diaExcept:
print diaExcept
self.assertTrue(False)
def testCount(self): def testCount(self):
try:
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
var = gScope["FuncWithName1"]["_unionTest"] var = gScope["FuncWithName1"]["_unionTest"]
self.assertEqual( 2, var.type().count() ) self.assertEqual( 2, var.type().count() )
except pykd.DiaException as diaExcept:
print diaExcept
self.assertTrue(False)
def testDataKind(self): def testDataKind(self):
try:
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
self.assertEqual( pykd.DataIsGlobal, gScope["g_structTest"].dataKind() ) self.assertEqual( pykd.DataIsGlobal, gScope["g_structTest"].dataKind() )
self.assertEqual( pykd.DataIsParam, gScope["EnumWindowsProc1"]["hWindow"].dataKind() ) self.assertEqual( pykd.DataIsParam, gScope["EnumWindowsProc1"]["hWindow"].dataKind() )
except pykd.DiaException as diaExcept:
print diaExcept def testSymbolHash(self):
self.assertTrue(False) """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 )