pykd

Форк
0
/
stacktest.py 
138 строк · 5.0 Кб
1
import unittest
2
import os
3
import sys
4

5
import pykd
6
import target
7

8
class StackTest(unittest.TestCase):
9
    
10
    def setUp(self):
11
        self.processId = pykd.startProcess( target.appPath + " stacktest" )
12
        pykd.go() # skip initial breakpoint
13

14
    def tearDown(self):
15
        pykd.killProcess( self.processId )
16

17
    def testGetStack(self):
18

19
        expectedStack = [
20
                  'targetapp!stackTestClass::stackMethod',
21
                  'targetapp!stackTestRun2',
22
                  'targetapp!stackTestRun1',
23
                  'targetapp!stackTestRun']
24

25
        realStack = []
26
        for frame in pykd.getStack():
27
            moduleName, symbolName, disp = pykd.findSymbolAndDisp( frame.ip )
28
            realStack.append( "%s!%s" % ( moduleName, symbolName ) )
29

30
        self.assertEqual( expectedStack, realStack[0:4])
31

32
    def testGetParams(self):
33

34
        frame0 = pykd.getFrame()
35
        self.assertEqual( ["this", "a", "b"], [ name for name, param in frame0.getParams() ] )
36

37
        frame1 = pykd.getStack()[1]
38
        self.assertEqual( ["a", "b", "c"], [ name for name, param in frame1.getParams() ] )
39
        self.assertEqual( 10, frame1.getParam("a") )
40
        self.assertEqual( 10, frame1.params["a"] )
41

42
        frame2 = pykd.getStack()[2]
43
        self.assertEqual( 10, frame2.params["a"] )
44
        self.assertEqual( 10, frame2.getParam("a") )
45

46
    def testGetLocals(self):
47
        expectedLocals = ["localDouble", "localFloat", "localChars"]
48
        frame2 = pykd.getStack()[2]
49
        self.assertEqual( expectedLocals, [name for name, param in frame2.getLocals() ] )
50
        self.assertEqual( 0.0, frame2.locals["localDouble"] )
51

52
    def testGetParamsNoSymbol(self):
53
        topFrame = pykd.getStack()[-1]
54
        self.assertEqual(0, len(topFrame.getParams()))
55

56
    def testGetLocalsNoSymbol(self):
57
        topFrame = pykd.getStack()[-1]
58
        self.assertEqual(0, len(topFrame.getLocals()))
59

60

61
class InlineStackTest(unittest.TestCase):
62

63
    def setUp(self):
64
        dumpDir = os.path.join( os.path.dirname(sys.argv[0]), r"..\..\kdlibcpp\kdlib\tests\dumps\targetapp_stacktest_x64_release")
65
        dump_file = os.path.join( dumpDir, "targetapp_stacktest_x64_release.cab" )
66
        self.symbolPath = pykd.getSymbolPath()
67
        symbolPath = self.symbolPath + ";" + dumpDir
68
        pykd.setSymbolPath(symbolPath)
69
        self.dump_id = pykd.loadDump( dump_file )
70

71
    def tearDown(self):
72
        pykd.closeDump( self.dump_id )
73
        pykd.setSymbolPath(self.symbolPath)
74

75
    def testGetStack(self):
76

77
        expectedStack = [
78
                  'targetapp!stackTestClass::stackMethod',
79
                  'targetapp!stackTestRun2',
80
                  'targetapp!stackTestRun1',
81
                  'targetapp!stackTestRun']
82

83
        realStack = []
84
        for frame in pykd.getStack(inlineFrames = True):
85
            moduleName, symbolName, disp = frame.findSymbol()
86
            realStack.append( "%s!%s" % ( moduleName, symbolName ) )
87

88
        self.assertEqual( expectedStack, realStack[0:4])
89

90
    def testFrameIsInline(self):
91
        self.assertEqual([True, True, False, True], 
92
                         [fr.isInline() for fr in pykd.getStack(inlineFrames = True)][:4]
93
                         )
94

95
    def testGetSourceLine(self):
96

97
        expectedStack = ['targetapp.cpp+129', 'targetapp.cpp+144', 'targetapp.cpp+172', 'targetapp.cpp+185']
98

99
        realStack = []
100
        for frame in pykd.getStack(inlineFrames = True)[:4]:
101
            fileName, lineNo = frame.getSourceLine()
102
            realStack.append("%s+%s" % ( os.path.basename(fileName), lineNo ) )
103
 
104
        self.assertEqual( expectedStack, realStack)
105

106
class DiaRegToRegRelativeI386Test(unittest.TestCase):
107
    def setUp(self):
108
        dumpDir = os.path.join( os.path.dirname(sys.argv[0]), r"..\..\kdlibcpp\kdlib\tests\dumps\targetapp_test_cv_allreg_i386")
109
        dump_file = os.path.join( dumpDir, "targetapp_test_cv_allreg_i386.cab" )
110
        self.symbolPath = pykd.getSymbolPath()
111
        symbolPath = self.symbolPath + ";" + dumpDir
112
        pykd.setSymbolPath(symbolPath)
113
        self.dump_id = pykd.loadDump( dump_file )
114

115
    def tearDown(self):
116
        pykd.closeDump( self.dump_id )
117
        pykd.setSymbolPath(self.symbolPath)
118

119
    def testParams(self):
120
        params = pykd.getFrame().getParams()
121
        self.assertNotEqual(0, len(params))
122

123
class DiaRegToRegRelativeAmd64Test(unittest.TestCase):
124
    def setUp(self):
125
        dumpDir = os.path.join( os.path.dirname(sys.argv[0]), r"..\..\kdlibcpp\kdlib\tests\dumps\targetapp_test_cv_allreg_amd64")
126
        dump_file = os.path.join( dumpDir, "targetapp_test_cv_allreg_amd64.cab" )
127
        self.symbolPath = pykd.getSymbolPath()
128
        symbolPath = self.symbolPath + ";" + dumpDir
129
        pykd.setSymbolPath(symbolPath)
130
        self.dump_id = pykd.loadDump( dump_file )
131

132
    def tearDown(self):
133
        pykd.closeDump( self.dump_id )
134
        pykd.setSymbolPath(self.symbolPath)
135

136
    def testLocals(self):
137
        locals = pykd.getFrame().getLocals()
138
        self.assertNotEqual(0, len(locals))
139

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.