]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/lang/go/expressions/TestExpressions.py
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / lang / go / expressions / TestExpressions.py
1 """Test the go expression parser/interpreter."""
2
3 import os
4 import time
5 import unittest2
6 import lldb
7 from lldbsuite.test.decorators import *
8 from lldbsuite.test.lldbtest import *
9 from lldbsuite.test import lldbutil
10
11
12 class TestGoUserExpression(TestBase):
13
14     mydir = TestBase.compute_mydir(__file__)
15
16     @add_test_categories(['pyapi'])
17     @skipIfRemote  # Not remote test suit ready
18     @skipUnlessGoInstalled
19     def test_with_dsym_and_python_api(self):
20         """Test GoASTUserExpress."""
21         self.buildGo()
22         self.launchProcess()
23         self.go_expressions()
24
25     def setUp(self):
26         # Call super's setUp().
27         TestBase.setUp(self)
28         # Find the line numbers to break inside main().
29         self.main_source = "main.go"
30         self.break_line = line_number(
31             self.main_source, '// Set breakpoint here.')
32
33     def check_builtin(self, name, size=0, typeclass=lldb.eTypeClassBuiltin):
34         tl = self.target().FindTypes(name)
35         self.assertEqual(1, len(tl))
36         t = list(tl)[0]
37         self.assertEqual(name, t.name)
38         self.assertEqual(typeclass, t.type)
39         if size > 0:
40             self.assertEqual(size, t.size)
41
42     def launchProcess(self):
43         exe = os.path.join(os.getcwd(), "a.out")
44
45         target = self.dbg.CreateTarget(exe)
46         self.assertTrue(target, VALID_TARGET)
47
48         bpt = target.BreakpointCreateByLocation(
49             self.main_source, self.break_line)
50         self.assertTrue(bpt, VALID_BREAKPOINT)
51
52         # Now launch the process, and do not stop at entry point.
53         process = target.LaunchSimple(
54             None, None, self.get_process_working_directory())
55
56         self.assertTrue(process, PROCESS_IS_VALID)
57
58         # The stop reason of the thread should be breakpoint.
59         thread_list = lldbutil.get_threads_stopped_at_breakpoint(process, bpt)
60
61         # Make sure we stopped at the first breakpoint.
62         self.assertTrue(
63             len(thread_list) != 0,
64             "No thread stopped at our breakpoint.")
65         self.assertTrue(len(thread_list) == 1,
66                         "More than one thread stopped at our breakpoint.")
67
68         frame = thread_list[0].GetFrameAtIndex(0)
69         self.assertTrue(frame, "Got a valid frame 0 frame.")
70
71     def go_expressions(self):
72         frame = self.frame()
73         v = frame.EvaluateExpression("1")
74         self.assertEqual(1, v.GetValueAsSigned())
75         x = frame.EvaluateExpression("x")
76         self.assertEqual(22, x.GetValueAsSigned())
77
78         a = frame.EvaluateExpression("a")
79         self.assertEqual(3, a.GetNumChildren())
80         a0 = a.GetChildAtIndex(0)
81         self.assertEqual(8, a0.GetValueAsSigned())
82
83         # Array indexing
84         a0 = frame.EvaluateExpression("a[0]")
85         self.assertEqual(8, a0.GetValueAsSigned())
86
87         # Slice indexing
88         b1 = frame.EvaluateExpression("b[1]")
89         self.assertEqual(9, b1.GetValueAsSigned())
90
91         # Test global in this package
92         g = frame.EvaluateExpression("myGlobal")
93         self.assertEqual(17, g.GetValueAsSigned(), str(g))
94
95         # Global with package name
96         g = frame.EvaluateExpression("main.myGlobal")
97         self.assertEqual(17, g.GetValueAsSigned(), str(g))
98
99         # Global with quoted package name
100         g = frame.EvaluateExpression('"main".myGlobal')
101         self.assertEqual(17, g.GetValueAsSigned(), str(g))
102
103         # Casting with package local type
104         s = frame.EvaluateExpression("*(*myStruct)(i.data)")
105         sb = s.GetChildMemberWithName("a")
106         self.assertEqual(2, sb.GetValueAsSigned())
107
108         # casting with explicit package
109         s = frame.EvaluateExpression("*(*main.myStruct)(i.data)")
110         sb = s.GetChildMemberWithName("a")
111         self.assertEqual(2, sb.GetValueAsSigned())
112
113         # Casting quoted package
114         s = frame.EvaluateExpression('*(*"main".myStruct)(i.data)')
115         sb = s.GetChildMemberWithName("b")
116         self.assertEqual(-1, sb.GetValueAsSigned())
117
118 if __name__ == '__main__':
119     import atexit
120     lldb.SBDebugger.Initialize()
121     atexit.register(lambda: lldb.SBDebugger.Terminate())
122     unittest2.main()