]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/lang/c/blocks/TestBlocks.py
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / lang / c / blocks / TestBlocks.py
1 """Test that lldb can invoke blocks and access variables inside them"""
2
3 from __future__ import print_function
4
5
6 import unittest2
7 import os
8 import time
9 import lldb
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test.decorators import *
12 import lldbsuite.test.lldbutil as lldbutil
13
14
15 class BlocksTestCase(TestBase):
16
17     mydir = TestBase.compute_mydir(__file__)
18     lines = []
19
20     def setUp(self):
21         # Call super's setUp().
22         TestBase.setUp(self)
23         # Find the line numbers to break at.
24         self.lines.append(line_number('main.c', '// Set breakpoint 0 here.'))
25         self.lines.append(line_number('main.c', '// Set breakpoint 1 here.'))
26
27     def launch_common(self):
28         self.build()
29         exe = os.path.join(os.getcwd(), "a.out")
30         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
31
32         self.is_started = False
33
34         # Break inside the foo function which takes a bar_ptr argument.
35         for line in self.lines:
36             lldbutil.run_break_set_by_file_and_line(
37                 self, "main.c", line, num_expected_locations=1, loc_exact=True)
38
39         self.wait_for_breakpoint()
40
41     @skipUnlessDarwin
42     def test_expr(self):
43         self.launch_common()
44
45         self.expect("expression a + b", VARIABLES_DISPLAYED_CORRECTLY,
46                     substrs=["= 7"])
47
48         self.expect("expression c", VARIABLES_DISPLAYED_CORRECTLY,
49                     substrs=["= 1"])
50
51         self.wait_for_breakpoint()
52
53         # This should display correctly.
54         self.expect("expression (int)neg (-12)", VARIABLES_DISPLAYED_CORRECTLY,
55                     substrs=["= 12"])
56
57     @skipUnlessDarwin
58     def test_define(self):
59         self.launch_common()
60
61         self.runCmd(
62             "expression int (^$add)(int, int) = ^int(int a, int b) { return a + b; };")
63         self.expect(
64             "expression $add(2,3)",
65             VARIABLES_DISPLAYED_CORRECTLY,
66             substrs=[" = 5"])
67
68         self.runCmd("expression int $a = 3")
69         self.expect(
70             "expression int (^$addA)(int) = ^int(int b) { return $a + b; };",
71             "Proper error is reported on capture",
72             error=True)
73
74     def wait_for_breakpoint(self):
75         if not self.is_started:
76             self.is_started = True
77             self.runCmd("process launch", RUN_SUCCEEDED)
78         else:
79             self.runCmd("process continue", RUN_SUCCEEDED)
80
81         # The stop reason of the thread should be breakpoint.
82         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
83                     substrs=['stopped',
84                              'stop reason = breakpoint'])